Commit e56d640a authored by Alexandre Delanoë's avatar Alexandre Delanoë

[CHARTS.Histo] implemented + column date fixed in docTable.

parent 443aba7a
...@@ -19,6 +19,7 @@ import Data.Map (Map) ...@@ -19,6 +19,7 @@ import Data.Map (Map)
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Data.Int (fromString)
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Effect (Effect) import Effect (Effect)
...@@ -81,7 +82,7 @@ newtype DocumentsView ...@@ -81,7 +82,7 @@ newtype DocumentsView
= DocumentsView = DocumentsView
{ _id :: Int { _id :: Int
, url :: String , url :: String
, date :: String , date :: Int
, title :: String , title :: String
, source :: String , source :: String
, fav :: Boolean , fav :: Boolean
...@@ -98,7 +99,6 @@ instance showDocumentsView :: Show DocumentsView where ...@@ -98,7 +99,6 @@ instance showDocumentsView :: Show DocumentsView where
newtype Response = Response newtype Response = Response
{ cid :: Int { cid :: Int
, created :: String
, hyperdata :: Hyperdata , hyperdata :: Hyperdata
, favorite :: Boolean , favorite :: Boolean
, ngramCount :: Int , ngramCount :: Int
...@@ -108,6 +108,7 @@ newtype Response = Response ...@@ -108,6 +108,7 @@ newtype Response = Response
newtype Hyperdata = Hyperdata newtype Hyperdata = Hyperdata
{ title :: String { title :: String
, source :: String , source :: String
, pub_year :: Int
} }
--instance decodeHyperdata :: DecodeJson Hyperdata where --instance decodeHyperdata :: DecodeJson Hyperdata where
...@@ -130,20 +131,19 @@ newtype Hyperdata = Hyperdata ...@@ -130,20 +131,19 @@ newtype Hyperdata = Hyperdata
instance decodeHyperdata :: DecodeJson Hyperdata where instance decodeHyperdata :: DecodeJson Hyperdata where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
title <- obj .| "title" title <- obj .? "title"
source <- obj .| "source" source <- obj .? "source"
pure $ Hyperdata { title,source } pub_year <- obj .? "publication_year"
pure $ Hyperdata { title,source, pub_year}
instance decodeResponse :: DecodeJson Response where instance decodeResponse :: DecodeJson Response where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
cid <- obj .? "id" cid <- obj .? "id"
created <- pure "2019"
--created <- obj .? "date"
favorite <- obj .? "favorite" favorite <- obj .? "favorite"
ngramCount <- obj .? "id" ngramCount <- obj .? "id"
hyperdata <- obj .? "hyperdata" hyperdata <- obj .? "hyperdata"
pure $ Response { cid, created, favorite, ngramCount, hyperdata } pure $ Response { cid, favorite, ngramCount, hyperdata }
...@@ -168,7 +168,6 @@ layoutDocview = simpleSpec performAction render ...@@ -168,7 +168,6 @@ layoutDocview = simpleSpec performAction render
void $ lift $ if fav void $ lift $ if fav
then putFavorites nodeId (FavoriteQuery {favorites: [nid]}) then putFavorites nodeId (FavoriteQuery {favorites: [nid]})
else deleteFavorites nodeId (FavoriteQuery {favorites: [nid]}) else deleteFavorites nodeId (FavoriteQuery {favorites: [nid]})
--TODO add array of delete rows here
performAction (ToggleDocumentToDelete nid) _ _ = performAction (ToggleDocumentToDelete nid) _ _ =
modifyState_ \state -> state {documentIdsToDelete = toggleSet nid state.documentIdsToDelete} modifyState_ \state -> state {documentIdsToDelete = toggleSet nid state.documentIdsToDelete}
performAction Trash {nodeId} {documentIdsToDelete} = do performAction Trash {nodeId} {documentIdsToDelete} = do
...@@ -232,7 +231,7 @@ loadPage {nodeId, tabType, params: {limit, offset, orderBy}} = do ...@@ -232,7 +231,7 @@ loadPage {nodeId, tabType, params: {limit, offset, orderBy}} = do
res2corpus (Response r) = res2corpus (Response r) =
DocumentsView { _id : r.cid DocumentsView { _id : r.cid
, url : "" , url : ""
, date : r.created , date : (\(Hyperdata hr) -> hr.pub_year) r.hyperdata
, title : (\(Hyperdata hr) -> hr.title) r.hyperdata , title : (\(Hyperdata hr) -> hr.title) r.hyperdata
, source : (\(Hyperdata hr) -> hr.source) r.hyperdata , source : (\(Hyperdata hr) -> hr.source) r.hyperdata
, fav : r.favorite , fav : r.favorite
...@@ -299,9 +298,9 @@ renderPage loaderDispatch { totalRecords, dispatch ...@@ -299,9 +298,9 @@ renderPage loaderDispatch { totalRecords, dispatch
] ]
-- TODO show date: Year-Month-Day only -- TODO show date: Year-Month-Day only
, if (toDelete $ DocumentsView r) then , if (toDelete $ DocumentsView r) then
div [ style {textDecoration : "line-through"}][text r.date] div [ style {textDecoration : "line-through"}][text (show r.date)]
else else
div [ ][text r.date] div [ ][text (show r.date)]
, if (toDelete $ DocumentsView r) then , if (toDelete $ DocumentsView r) then
a [ href (toUrl Front Url_Document (Just r._id)) a [ href (toUrl Front Url_Document (Just r._id))
, style {textDecoration : "line-through"} , style {textDecoration : "line-through"}
...@@ -329,11 +328,11 @@ pageLoader props = React.createElement pageLoaderClass props [] ...@@ -329,11 +328,11 @@ pageLoader props = React.createElement pageLoaderClass props []
--------------------------------------------------------- ---------------------------------------------------------
sampleData' :: DocumentsView sampleData' :: DocumentsView
sampleData' = DocumentsView {_id : 1, url : "", date : "date3", title : "title", source : "source", fav : false, ngramCount : 1, delete : false} sampleData' = DocumentsView {_id : 1, url : "", date : 2010, title : "title", source : "source", fav : false, ngramCount : 1, delete : false}
sampleData :: Array DocumentsView sampleData :: Array DocumentsView
--sampleData = replicate 10 sampleData' --sampleData = replicate 10 sampleData'
sampleData = map (\(Tuple t s) -> DocumentsView {_id : 1, url : "", date : "2017", title: t, source: s, fav : false, ngramCount : 10, delete : false}) sampleDocuments sampleData = map (\(Tuple t s) -> DocumentsView {_id : 1, url : "", date : 2017, title: t, source: s, fav : false, ngramCount : 10, delete : false}) sampleDocuments
sampleDocuments :: Array (Tuple String String) sampleDocuments :: Array (Tuple String String)
sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"] sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"]
......
...@@ -169,6 +169,13 @@ pathUrl c (CorpusMetrics {tabType, listId, limit}) i = ...@@ -169,6 +169,13 @@ pathUrl c (CorpusMetrics {tabType, listId, limit}) i =
<> "?list=" <> show listId <> "?list=" <> show listId
<> "&ngramsType=" <> showTabType' tabType <> "&ngramsType=" <> showTabType' tabType
<> maybe "" (\x -> "&limit=" <> show x) limit <> maybe "" (\x -> "&limit=" <> show x) limit
-- TODO fix this url path
pathUrl c (Chart {chartType}) i =
pathUrl c (NodeAPI Corpus) i <> "/chart"
-- <> "?list=1" -- <> show listId
-- <> "&ngramsType=Sources" -- <> showTabType' tabType
-- <> maybe "" (\x -> "&limit=" <> show x) limit
------------------------------------------------------------ ------------------------------------------------------------
...@@ -250,6 +257,12 @@ data Path ...@@ -250,6 +257,12 @@ data Path
, listId :: ListId , listId :: ListId
, limit :: Maybe Limit , limit :: Maybe Limit
} }
| Chart { chartType :: ChartType
-- , listId :: ListId
-- , limit :: Maybe Limit
}
data ChartType = Histo | Scatter
data End = Back | Front data End = Back | Front
type Id = Int type Id = Int
......
module Gargantext.Pages.Corpus.Chart.Histo where
import Data.Array (foldl)
import Data.Tuple (Tuple(..))
import Data.Map as Map
import Data.Int (toNumber)
import Data.Map (Map)
import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Data.Maybe (Maybe(..), maybe)
import Effect.Aff (Aff)
import Gargantext.Config -- (End(..), Path(..), TabType, toUrl)
import Gargantext.Config.REST (get)
import React (ReactClass, ReactElement, createElement)
import Thermite (Spec, Render, defaultPerformAction, simpleSpec, createClass)
import Gargantext.Prelude
import Gargantext.Types (TermList(..))
import Gargantext.Components.Loader as Loader
import Gargantext.Components.Charts.Options.ECharts
import Gargantext.Components.Charts.Options.Type
import Gargantext.Components.Charts.Options.Series
import Gargantext.Components.Charts.Options.Color
import Gargantext.Components.Charts.Options.Font
import Gargantext.Components.Charts.Options.Data
import Gargantext.Pages.Corpus.Dashboard (distriBySchool)
type Path =
{ corpusId :: Int
}
newtype ChartMetrics = ChartMetrics
{ "data" :: HistoMetrics
}
instance decodeChartMetrics :: DecodeJson ChartMetrics where
decodeJson json = do
obj <- decodeJson json
d <- obj .? "data"
pure $ ChartMetrics { "data": d }
newtype HistoMetrics = HistoMetrics
{ dates :: Array String
, count :: Array Number
}
instance decodeHistoMetrics :: DecodeJson HistoMetrics where
decodeJson json = do
obj <- decodeJson json
d <- obj .? "dates"
c <- obj .? "count"
pure $ HistoMetrics { dates : d , count: c}
type Loaded = HistoMetrics
loadedMetricsSpec :: Spec {} (Loader.InnerProps Path Loaded ()) Void
loadedMetricsSpec = simpleSpec defaultPerformAction render
where
render :: Render {} (Loader.InnerProps Path Loaded ()) Void
-- render dispatch {loaded} {} _ = [chart distriBySchool]
render dispatch {loaded:histoMetrics} {} _ = [chart (chartOptions histoMetrics)]
chartOptions :: HistoMetrics -> Options
chartOptions (HistoMetrics { dates: dates', count: count'}) = Options
{ mainTitle : "Histogram"
, subTitle : "Distribution of publications over time"
, xAxis : xAxis' dates'
, yAxis : yAxis' { position: "left", show: true }
, series : [seriesBarD1 {name: "Number of publication / year"} $ map (\n -> dataSerie {name: "", value: n }) count']
, addZoom : true
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
}
metricsLoader :: Loader.Props' Path HistoMetrics -> ReactElement
metricsLoader props = createElement metricsLoaderClass props []
where
metricsLoaderClass :: ReactClass (Loader.Props Path HistoMetrics)
metricsLoaderClass = Loader.createLoaderClass "MetricsLoader" getMetrics
getMetrics :: Path -> Aff HistoMetrics
getMetrics {corpusId} = do
ChartMetrics ms <- get $ toUrl Back (Chart {chartType: Histo}) $ Just corpusId
pure ms."data"
histoSpec :: Spec {} Path Void
histoSpec = simpleSpec defaultPerformAction render
where
render :: Render {} Path Void
render dispatch path {} _ =
[ metricsLoader
{ path
, component: createClass "LoadedMetrics" loadedMetricsSpec (const {})
} ]
...@@ -12,6 +12,7 @@ import Gargantext.Config (TabType(..), TabSubType(..)) ...@@ -12,6 +12,7 @@ import Gargantext.Config (TabType(..), TabSubType(..))
import Gargantext.Config (CTabNgramType(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl) import Gargantext.Config (CTabNgramType(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Pages.Corpus.Tabs.Types (Props) import Gargantext.Pages.Corpus.Tabs.Types (Props)
import Gargantext.Pages.Corpus.Chart.Histo (histoSpec)
import Gargantext.Pages.Corpus.Chart.Metrics (metricsSpec) import Gargantext.Pages.Corpus.Chart.Metrics (metricsSpec)
import Gargantext.Pages.Corpus.Chart.Pie (pieSpec) import Gargantext.Pages.Corpus.Chart.Pie (pieSpec)
import Gargantext.Pages.Corpus.Chart.Tree (treeSpec) import Gargantext.Pages.Corpus.Chart.Tree (treeSpec)
...@@ -56,16 +57,20 @@ statefulTabs = ...@@ -56,16 +57,20 @@ statefulTabs =
] ]
where where
-- TODO totalRecords -- TODO totalRecords
chart = ECharts.chart globalPublis
docs = cmapProps (\{path: nodeId} -> docs = noState ( cmapProps (\{path: corpusId} -> {corpusId : corpusId}) histoSpec
{nodeId, chart , tabType: TabCorpus TabDocs, totalRecords: 4736}) $ <>
noState DT.docViewSpec (cmapProps (\{path: nodeId} -> { nodeId : nodeId
, chart : div [][] -- ECharts.chart globalPublis
trash = cmapProps (\{path: nodeId} -> , tabType: TabCorpus TabDocs
{nodeId, chart: div [][], tabType: TabCorpus TabTrash, totalRecords: 4736}) $ , totalRecords: 4736}) $ noState DT.docViewSpec
noState DT.docViewSpec )
)
trash = cmapProps (\{path: nodeId} -> { nodeId
, chart: div [][]
, tabType: TabCorpus TabTrash
, totalRecords: 4736}) $ noState DT.docViewSpec
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment