Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit fa3bc49

Browse files
justinwoocryogenian
authored andcommitted
add a heatmap calendar DSL (#39)
add a heatmap calendar DSL
1 parent 5d4aec0 commit fa3bc49

File tree

5 files changed

+165
-1
lines changed

5 files changed

+165
-1
lines changed

example/src/HeatmapCalendar.purs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
module HeatmapCalendar where
2+
3+
import Prelude
4+
5+
import Control.Monad.Eff (Eff)
6+
import Control.Monad.Eff.Exception (EXCEPTION)
7+
8+
import Data.Array as A
9+
import Data.Date as D
10+
import Data.Enum (toEnum)
11+
import Data.Foldable (traverse_)
12+
import Data.Maybe (Maybe(..), fromJust)
13+
14+
import Debug.Trace as DT
15+
16+
import DOM (DOM)
17+
import DOM.Node.Types (ElementId(..))
18+
19+
import ECharts.Chart as EC
20+
import ECharts.Types as ET
21+
import ECharts.Types.Phantom as ETP
22+
import ECharts.Commands as E
23+
import ECharts.Monad (DSL)
24+
25+
import Partial.Unsafe (unsafePartial)
26+
import Utils as U
27+
28+
arrValues Array (Array String)
29+
arrValues =
30+
[ [ "2017-01-01", "203" ], [ "2017-01-02", "980" ], [ "2017-01-03", "14" ]
31+
, [ "2017-01-04", "284" ], [ "2017-01-05", "584" ], [ "2017-01-06", "723" ]
32+
, [ "2017-01-07", "209" ], [ "2017-01-08", "219" ], [ "2017-01-09", "916" ]
33+
, [ "2017-01-10", "747" ], [ "2017-01-11", "702" ], [ "2017-01-12", "749" ]
34+
, [ "2017-01-13", "815" ], [ "2017-01-14", "777" ], [ "2017-01-15", "831" ]
35+
, [ "2017-01-16", "109" ], [ "2017-01-17", "385" ], [ "2017-01-18", "428" ]
36+
, [ "2017-01-19", "499" ], [ "2017-01-20", "58" ], [ "2017-01-21", "818" ]
37+
, [ "2017-01-22", "455" ], [ "2017-01-23", "40" ], [ "2017-01-24", "612" ]
38+
, [ "2017-01-25", "219" ], [ "2017-01-26", "854" ], [ "2017-01-27", "398" ]
39+
, [ "2017-01-28", "193" ], [ "2017-01-29", "31" ], [ "2017-01-30", "575" ]
40+
, [ "2017-01-31", "541" ], [ "2017-02-01", "548" ], [ "2017-02-02", "915" ]
41+
, [ "2017-02-03", "606" ], [ "2017-02-04", "380" ], [ "2017-02-05", "853" ]
42+
, [ "2017-02-06", "530" ], [ "2017-02-07", "295" ], [ "2017-02-08", "424" ]
43+
, [ "2017-02-09", "593" ], [ "2017-02-10", "352" ], [ "2017-02-11", "939" ]
44+
, [ "2017-02-12", "244" ], [ "2017-02-13", "726" ], [ "2017-02-14", "624" ]
45+
, [ "2017-02-15", "38" ], [ "2017-02-16", "87" ], [ "2017-02-17", "905" ]
46+
, [ "2017-02-18", "925" ], [ "2017-02-19", "477" ], [ "2017-02-20", "514" ]
47+
, [ "2017-02-21", "762" ], [ "2017-02-22", "365" ], [ "2017-02-23", "425" ]
48+
, [ "2017-02-24", "528" ], [ "2017-02-25", "859" ], [ "2017-02-26", "802" ]
49+
, [ "2017-02-27", "992" ], [ "2017-02-28", "342" ] ]
50+
51+
values i. Array (DSL (value ETP.I|i))
52+
values = A.catMaybes $ arrValues <#> case _ of
53+
[x, y] → pure $ E.buildValues do
54+
E.addStringValue x
55+
E.addStringValue y
56+
_ → Nothing
57+
58+
options DSL ETP.OptionI
59+
options = do
60+
E.tooltip do
61+
E.positionTop
62+
E.visualMap $ E.continuous do
63+
E.min 0.0
64+
E.max 1000.0
65+
E.calculable true
66+
E.orient ET.Horizontal
67+
E.leftCenter
68+
E.bottom $ ET.Percent 15.0
69+
E.calendar do
70+
E.calendarSpec do
71+
E.buildRange do
72+
E.addDateValue $ D.canonicalDate year D.January day
73+
E.addDateValue $ D.canonicalDate year D.January day'
74+
E.buildCellSize do
75+
E.autoValue
76+
E.addValue 12.0
77+
E.calendarSpec do
78+
E.buildRange do
79+
E.addStringValue "2017-02"
80+
E.buildCellSize do
81+
E.autoValue
82+
E.addValue 12.0
83+
E.top (ET.Pixel 300)
84+
E.series do
85+
E.heatMap do
86+
E.calendarCoordinateSystem
87+
E.calendarIndex 0
88+
E.buildItems
89+
$ traverse_ E.addItem values
90+
E.heatMap do
91+
E.calendarCoordinateSystem
92+
E.calendarIndex 1
93+
E.buildItems
94+
$ traverse_ E.addItem values
95+
where
96+
year = unsafePartial $ fromJust <<< toEnum $ 2017
97+
day = unsafePartial $ fromJust <<< toEnum $ 1
98+
day' = unsafePartial $ fromJust <<< toEnum $ 31
99+
100+
101+
chart e. Eff (dom DOM, echarts ET.ECHARTS, exception EXCEPTION|e) Unit
102+
chart = do
103+
mbEl ← U.getElementById $ ElementId "heatmap-calendar"
104+
case mbEl of
105+
NothingDT.traceAnyA "There is no element with 'heatmap-calendar' id"
106+
Just el → do
107+
ch ← EC.init el
108+
EC.setOption options ch

example/src/Main.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Radar as Radar
2121
import Graph as Graph
2222
import K as K
2323
import Heatmap as Heatmap
24+
import HeatmapCalendar as HeatmapCalendar
2425

2526
import Utils as U
2627

@@ -36,3 +37,4 @@ main = U.onLoad do
3637
Graph.chart
3738
K.chart
3839
Heatmap.chart
40+
HeatmapCalendar.chart

public/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@
4343
</div>
4444
<div id="heatmap" class="example">
4545
</div>
46+
<div id="heatmap-calendar" class="example">
47+
</div>
4648
</body>
4749
</html>

src/ECharts/Commands.purs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import Prelude
55
import Color as C
66

77
import Data.Array as Arr
8+
import Data.Date (Date, year, month, day)
9+
import Data.Enum (fromEnum)
810
import Data.Foldable as F
911
import Data.Foreign (toForeign)
1012

@@ -113,6 +115,9 @@ addItem = set "" <<< buildObj
113115
buildItems i. DSL TP.ItemsI DSL (items I|i)
114116
buildItems is = set "data" $ buildArr is
115117

118+
calendarIndex i. Int DSL (calendarIndex I|i)
119+
calendarIndex i = set "calendarIndex" $ toForeign i
120+
116121
visibleContent i. Boolean DSL (showContent I|i)
117122
visibleContent a = set "showContent" $ toForeign a
118123

@@ -170,6 +175,9 @@ candlestick = set "candlestick" <<< buildObj
170175
heatMap i. DSL TP.HeatMapI DSL (heatMap I|i)
171176
heatMap = set "heatmap" <<< buildObj
172177

178+
calendarSpec i. DSL TP.CalendarSpecI DSL (calendarSpec I|i)
179+
calendarSpec = set "calendar" <<< buildObj
180+
173181
map_ i. DSL TP.MapI DSL (map I|i)
174182
map_ = set "map" <<< buildObj
175183

@@ -260,6 +268,9 @@ addValue = set "" <<< toForeign
260268
addStringValue i. String DSL (addValue I|i)
261269
addStringValue = set "" <<< toForeign
262270

271+
autoValue i. DSL (addValue I|i)
272+
autoValue = set "" $ toForeign "auto"
273+
263274
buildNames i. DSL TP.NamesI DSL (name I|i)
264275
buildNames = set "name" <<< buildArr
265276

@@ -476,6 +487,9 @@ inverse a = set "inverse" $ toForeign a
476487
visualMap i. DSL TP.VisualMapI DSL (visualMap I|i)
477488
visualMap a = set "visualMap" $ buildSeries a
478489

490+
calendar i. DSL TP.CalendarI DSL (calendar I|i)
491+
calendar a = set "calendar" $ buildSeries a
492+
479493
continuous i. DSL TP.ContinuousVisualMapI DSL (continuousVisualMap I|i)
480494
continuous a = set "continuous" $ buildObj a
481495

@@ -587,6 +601,9 @@ readOnly = set "readOnly" <<< toForeign
587601
positionInside i. DSL (position I|i)
588602
positionInside = set "position" $ toForeign "inside"
589603

604+
positionTop i. DSL (position I|i)
605+
positionTop = set "position" $ toForeign "top"
606+
590607
labelLine i. DSL TP.LabelLineI DSL (labelLine I|i)
591608
labelLine = set "labelLine" <<< buildObj
592609

@@ -991,6 +1008,9 @@ cartesianCoordinateSystem = set "coordinateSystem" $ toForeign "cartesian2d"
9911008
geoCoordinateSystem i. DSL (coordinateSystem I|i)
9921009
geoCoordinateSystem = set "coordinateSystem" $ toForeign "geo"
9931010

1011+
calendarCoordinateSystem i. DSL (coordinateSystem I|i)
1012+
calendarCoordinateSystem = set "coordinateSystem" $ toForeign "calendar"
1013+
9941014
dim i. Int DSL (dim I|i)
9951015
dim = set "dim" <<< toForeign
9961016

@@ -999,3 +1019,22 @@ nameLocationStart = set "nameLocation" $ toForeign "start"
9991019

10001020
nameLocationEnd i. DSL (nameLocation I|i)
10011021
nameLocationEnd = set "nameLocation" $ toForeign "end"
1022+
1023+
buildCellSize i. DSL TP.ValuesI DSL (cellSize I|i)
1024+
buildCellSize = set "cellSize" <<< buildArr
1025+
1026+
buildRange i. DSL TP.ValuesI DSL (range I|i)
1027+
buildRange = set "range" <<< buildArr
1028+
1029+
addDateValue i. Date DSL (addValue I|i)
1030+
addDateValue dt =
1031+
set "" <<< toForeign
1032+
$ year' dt
1033+
<> "-"
1034+
<> month' dt
1035+
<> "-"
1036+
<> day' dt
1037+
where
1038+
year' = show <<< fromEnum <<< year
1039+
month' = show <<< fromEnum <<< month
1040+
day' = show <<< fromEnum <<< day

src/ECharts/Types/Phantom.purs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ type TooltipI =
130130
, showDelay I
131131
, hideDelay I
132132
, enterable I
133-
, tooltipPosition I
133+
, position I
134134
, transitionDuration I
135135
, formatter I
136136
, animation I
@@ -182,6 +182,7 @@ type OptionI =
182182
, brush I
183183
, toolbox I
184184
, visualMap I
185+
, calendar :: I
185186
, radar I
186187
, polar I
187188
, radiusAxis I
@@ -347,6 +348,17 @@ type VisualMapI =
347348
( continuousVisualMap I
348349
, piecewiseVisualMap I)
349350

351+
type CalendarI =
352+
( calendarSpec :: I )
353+
354+
type CalendarSpecI =
355+
PositionMixin
356+
(ZMixin
357+
(SizeMixin
358+
( range :: I
359+
, cellSize :: I
360+
, orient :: I )))
361+
350362
type ContinuousVisualMapI =
351363
PositionMixin
352364
(ZMixin
@@ -823,6 +835,7 @@ type HeatMapI =
823835
( name I
824836
, xAxisIndex I
825837
, yAxisIndex I
838+
, calendarIndex :: I
826839
, geoIndex I
827840
, blurSize I
828841
, minOpacity I

0 commit comments

Comments
 (0)