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

Commit f3d1a6d

Browse files
committed
events, showTitle, markPoint|Line|Area
1 parent ad9e6ec commit f3d1a6d

File tree

11 files changed

+149
-12
lines changed

11 files changed

+149
-12
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"purescript-foreign": "^4.0.0",
2929
"purescript-dom": "^4.0.0",
3030
"purescript-transformers": "^3.0.0",
31-
"purescript-colors": "^3.0.0"
31+
"purescript-colors": "^3.0.0",
32+
"purescript-variant": "^3.2.1"
3233
},
3334
"devDependencies": {
3435
"purescript-debug": "^3.0.0",

example/src/Bar.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import ECharts.Types as ET
2222
import ECharts.Monad (DSL)
2323
import ECharts.Types.Phantom as ETP
2424
import ECharts.Commands as E
25+
import ECharts.Event as EE
2526

2627
import Utils as U
2728

@@ -151,3 +152,4 @@ chart = do
151152
ch ← EC.init el
152153
inp ← genInp
153154
EC.setOption (options inp) ch
155+
EE.listenAll ch DT.traceAnyA

example/src/Main.purs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ import HeatmapCalendar as HeatmapCalendar
2525

2626
import Utils as U
2727

28-
main e. Eff (now NOW, dom DOM, echarts ET.ECHARTS, exception EXCEPTION, random RANDOM|e) Unit
28+
main
29+
e
30+
. Eff ( now NOW
31+
, dom DOM
32+
, echarts ET.ECHARTS
33+
, exception EXCEPTION
34+
, random RANDOM
35+
| e )
36+
Unit
2937
main = U.onLoad do
3038
Line.chart
3139
Scatter.chart

example/src/Pie.purs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@ import Prelude
44

55
import Control.Monad.Eff (Eff)
66
import Control.Monad.Eff.Exception (EXCEPTION)
7-
87
import Data.Maybe (Maybe(..))
9-
108
import Debug.Trace as DT
11-
129
import DOM (DOM)
1310
import DOM.Node.Types (ElementId(..))
14-
1511
import ECharts.Chart as EC
12+
import ECharts.Event as EE
1613
import ECharts.Types as ET
1714
import ECharts.Types.Phantom as ETP
1815
import ECharts.Commands as E
1916
import ECharts.Monad (DSL)
20-
2117
import Utils as U
2218

2319
options DSL ETP.OptionI
@@ -86,3 +82,4 @@ chart = do
8682
Just el → do
8783
ch ← EC.init el
8884
EC.setOption options ch
85+
EE.listenAll ch DT.traceAnyA

example/src/Scatter.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ options sinData cosData = do
8181

8282
E.series do
8383
E.scatter do
84+
E.markPoint do
85+
E.label $ E.normal $ E.shown
86+
E.buildItems $ E.addItem do
87+
E.buildCoord do
88+
E.coordXValue "6.0"
89+
E.coordY "1.3"
90+
E.symbolSize 30
91+
E.symbol ET.Rect
92+
8493
E.name "sin"
8594
E.large true
8695
E.symbolSize 3

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
},
88
"scripts": {
99
"build": "pulp browserify --include example/src --to public/build.js",
10-
"serve": "node script/serve.js"
10+
"serve": "node script/serve.js",
11+
"ide": "purs ide server"
1112
},
1213
"dependencies": {
13-
"pulp": "^11.0.0",
14-
"purescript": "^0.11.4",
15-
"purescript-psa": "^0.5.0"
14+
"pulp": "^11.0.2",
15+
"purescript": "^0.11.6",
16+
"purescript-psa": "^0.5.1"
1617
}
1718
}

src/ECharts/Commands.purs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ shown = visible true
7070
hidden i. DSL (show I|i)
7171
hidden = visible false
7272

73+
showTitle i. Boolean DSL (showTitle I|i)
74+
showTitle a = set "showTitle" $ toForeign a
75+
7376
textStyle i. DSL TP.TextStyleI DSL (textStyle I|i)
7477
textStyle a = set "textStyle" $ buildObj a
7578

@@ -373,6 +376,9 @@ label = set "label" <<< buildObj
373376
normalLabel i. DSL TP.LabelInnerI DSL (normal R TP.LabelInnerI|i)
374377
normalLabel = normal
375378

379+
precision i. Number DSL (precision I|i)
380+
precision = set "precision" <<< toForeign
381+
376382
emphasisLabel i. DSL TP.LabelInnerI DSL (emphasis R TP.LabelInnerI|i)
377383
emphasisLabel = emphasis
378384

@@ -898,6 +904,15 @@ markType = set "type" <<< toForeign
898904
margin i. Int DSL (margin I|i)
899905
margin = set "margin" <<< toForeign
900906

907+
markLine i. DSL TP.MarkLineI DSL (markLine I|i)
908+
markLine = set "markLine" <<< buildObj
909+
910+
markPoint i. DSL TP.MarkPointI DSL (markPoint I|i)
911+
markPoint = set "markPoint" <<< buildObj
912+
913+
markArea i. DSL TP.MarkAreaI DSL (markArea I|i)
914+
markArea = set "markArea" <<< buildObj
915+
901916
repulsion i. Number DSL (repulsion I|i)
902917
repulsion = set "repulsion" <<< toForeign
903918

@@ -934,6 +949,14 @@ colorSource = set "color" $ toForeign "source"
934949
colorTarget i. DSL (color I|i)
935950
colorTarget = set "target" $ toForeign "target"
936951

952+
buildCoord i. DSL TP.PointI DSL (coord I|i)
953+
buildCoord dsl =
954+
let
955+
xx = get "x" dsl
956+
yy = get "y" dsl
957+
in
958+
set "coord" $ toForeign $ Arr.catMaybes [ xx, yy ]
959+
937960
buildCenter i. DSL TP.PointI DSL (center I|i)
938961
buildCenter dsl =
939962
let
@@ -974,6 +997,15 @@ setZ ∷ ∀ i. DSL TP.DimensionI → DSL (z ∷ I|i)
974997
setZ dsl =
975998
F.traverse_ (set "z") $ lastWithKeys ["pixels", "percents"] dsl
976999

1000+
coordXIx i. Int DSL (x I|i)
1001+
coordXIx = set "x" <<< toForeign
1002+
1003+
coordXValue i. String DSL (x I|i)
1004+
coordXValue = set "x" <<< toForeign
1005+
1006+
coordY i. String DSL (y I|i)
1007+
coordY = set "y" <<< toForeign
1008+
9771009
pixels i. Int DSL (pixels I|i)
9781010
pixels = set "pixels" <<< toForeign
9791011

@@ -1037,4 +1069,4 @@ addDateValue dt =
10371069
where
10381070
year' = show <<< fromEnum <<< year
10391071
month' = show <<< fromEnum <<< month
1040-
day' = show <<< fromEnum <<< day
1072+
day' = show <<< fromEnum <<< day

src/ECharts/Event.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.on_ = function(chart) {
2+
return function(eName) {
3+
return function(callback) {
4+
return function() {
5+
return chart.on(eName, function(e) {
6+
callback(e)();
7+
});
8+
};
9+
};
10+
};
11+
};

src/ECharts/Event.purs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module ECharts.Event where
2+
3+
import Prelude
4+
5+
import Control.Monad.Eff (Eff)
6+
import Control.Monad.Except (runExcept)
7+
import Data.Foldable (for_)
8+
import Data.Foreign (Foreign, readString)
9+
import Data.Foreign.Index (readProp)
10+
import Data.List as L
11+
import Data.Tuple (Tuple(..))
12+
import Data.Variant.Internal (RLProxy(..), variantTags, class VariantTags)
13+
import ECharts.Types (EChartsEvent, EChartsEventR, Chart, ECHARTS)
14+
import Type.Row (class RowToList)
15+
import Unsafe.Coerce (unsafeCoerce)
16+
17+
foreign import on_
18+
e
19+
. Chart
20+
String
21+
( Foreign Eff (echarts ECHARTS|e) Unit )
22+
Eff (echarts ECHARTS|e) Unit
23+
24+
25+
listenAll
26+
e
27+
. Chart
28+
( EChartsEvent Eff (echarts ECHARTS|e) Unit )
29+
Eff (echarts ECHARTS|e) Unit
30+
listenAll chart cb =
31+
for_ eventNames \en → on_ chart en \frn →
32+
for_ (runExcept $ readProp "type" frn >>= readString) \tp →
33+
when (tp == en) $ cb $ toEChartsEvent $ Tuple tp frn
34+
where
35+
eventNames rl. RowToList EChartsEventR rl VariantTags rl L.List String
36+
eventNames = variantTags (RLProxy RLProxy rl)
37+
38+
toEChartsEvent ω. Tuple String ω EChartsEvent
39+
toEChartsEvent = unsafeCoerce

src/ECharts/Types.purs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module ECharts.Types where
22

33
import Prelude
4+
45
import Control.Monad.Eff (kind Effect)
56
import Data.Foreign (Foreign, toForeign)
7+
import Data.Variant as V
68

79
foreign import data ChartType
810

@@ -176,3 +178,37 @@ newtype Coord = Coord Foreign
176178

177179
coord Number Number Coord
178180
coord x y = Coord $ toForeign [ x, y ]
181+
182+
type EChartsEventR =
183+
( click Foreign
184+
, dblclick Foreign
185+
, mousedown Foreign
186+
, mousemove Foreign
187+
, mouseup Foreign
188+
, mouseover Foreign
189+
, mouseout Foreign
190+
, legendselectchanged Foreign
191+
, legendselected Foreign
192+
, legendunselected Foreign
193+
, datazoom Foreign
194+
, datarangeselected Foreign
195+
, timelinechanged Foreign
196+
, timelineplaychanged Foreign
197+
, restore Foreign
198+
, dataviewchanged Foreign
199+
, magictypechanged Foreign
200+
, pieselectchanged Foreign
201+
, pieselected Foreign
202+
, pieunselected Foreign
203+
, mapselectchanged Foreign
204+
, mapselected Foreign
205+
, mapunselected Foreign
206+
, axisareaselected Foreign
207+
, focusNodeAdjancency Foreign
208+
, unfocusNodeAdjacency Foreign
209+
, brush Foreign
210+
, brushselected Foreign
211+
)
212+
213+
214+
type EChartsEvent = V.Variant EChartsEventR

0 commit comments

Comments
 (0)