@plotdb/chart 0.0.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/README.md +3 -3
  3. package/{dist/data → data}/index.js +0 -0
  4. package/{dist/chart.css → index.css} +0 -0
  5. package/{dist/chart.js → index.js} +3 -1
  6. package/{dist/chart.min.css → index.min.css} +0 -0
  7. package/index.min.js +1 -0
  8. package/package.json +1 -89
  9. package/{dist/utils → utils}/axis.js +6 -0
  10. package/utils/axis.min.js +1 -0
  11. package/{dist/utils → utils}/config.js +0 -0
  12. package/utils/config.min.js +1 -0
  13. package/{dist/utils → utils}/data.js +0 -0
  14. package/utils/data.min.js +1 -0
  15. package/{dist/utils → utils}/format.js +0 -0
  16. package/utils/format.min.js +1 -0
  17. package/{dist/utils → utils}/legend.css +0 -0
  18. package/{dist/utils → utils}/legend.js +0 -0
  19. package/{dist/utils → utils}/legend.min.css +0 -0
  20. package/utils/legend.min.js +1 -0
  21. package/{dist/utils → utils}/tint.js +0 -0
  22. package/utils/tint.min.js +1 -0
  23. package/{dist/utils → utils}/tip.js +0 -0
  24. package/utils/tip.min.js +1 -0
  25. package/build +0 -39
  26. package/dist/chart.min.js +0 -1
  27. package/dist/utils/axis.min.js +0 -1
  28. package/dist/utils/config.min.js +0 -1
  29. package/dist/utils/data.min.js +0 -1
  30. package/dist/utils/format.min.js +0 -1
  31. package/dist/utils/legend.min.js +0 -1
  32. package/dist/utils/tint.min.js +0 -1
  33. package/dist/utils/tip.min.js +0 -1
  34. package/doc/charts.md +0 -58
  35. package/doc/config.md +0 -44
  36. package/doc/draft/chart.md +0 -146
  37. package/doc/draft/data.md +0 -8
  38. package/doc/draft/definition.md +0 -0
  39. package/doc/draft/events.md +0 -0
  40. package/doc/draft/filter.md +0 -0
  41. package/doc/draft/lifecycle.md +0 -89
  42. package/doc/spec.md +0 -89
  43. package/doc/todo.md +0 -27
  44. package/doc/utils/tip.md +0 -84
  45. package/src/chart.ls +0 -323
  46. package/src/chart.styl +0 -6
  47. package/src/data/en-US/category +0 -20
  48. package/src/data/en-US/fruit +0 -39
  49. package/src/data/en-US/movie +0 -125
  50. package/src/data/en-US/name +0 -58
  51. package/src/data/index.ls +0 -34
  52. package/src/data/zh-TW/category +0 -20
  53. package/src/data/zh-TW/fruits +0 -38
  54. package/src/data/zh-TW/movie +0 -125
  55. package/src/data/zh-TW/names +0 -105
  56. package/src/utils/axis.ls +0 -229
  57. package/src/utils/config.ls +0 -11
  58. package/src/utils/data.ls +0 -104
  59. package/src/utils/format.ls +0 -30
  60. package/src/utils/legend.ls +0 -134
  61. package/src/utils/legend.styl +0 -37
  62. package/src/utils/tint.ls +0 -66
  63. package/src/utils/tip.ls +0 -97
  64. package/web/src/pug/base.pug +0 -20
  65. package/web/src/pug/block/axis/0.0.1/index.ls +0 -38
  66. package/web/src/pug/block/axis/0.0.1/index.pug +0 -1
  67. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +0 -141
  68. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +0 -1
  69. package/web/src/pug/block/bar/0.0.1/index.ls +0 -274
  70. package/web/src/pug/block/bar/0.0.1/index.pug +0 -35
  71. package/web/src/pug/block/bar-list/0.0.1/index.ls +0 -85
  72. package/web/src/pug/block/bar-list/0.0.1/index.pug +0 -30
  73. package/web/src/pug/block/bar-race/0.0.1/index.ls +0 -83
  74. package/web/src/pug/block/bar-race/0.0.1/index.pug +0 -21
  75. package/web/src/pug/block/base/0.0.1/index.ls +0 -67
  76. package/web/src/pug/block/base/0.0.1/index.pug +0 -5
  77. package/web/src/pug/block/blank/0.0.1/index.ls +0 -25
  78. package/web/src/pug/block/blank/0.0.1/index.pug +0 -1
  79. package/web/src/pug/block/bubble/0.0.1/index.ls +0 -220
  80. package/web/src/pug/block/bubble/0.0.1/index.pug +0 -28
  81. package/web/src/pug/block/curve-bar/0.0.1/index.ls +0 -89
  82. package/web/src/pug/block/curve-bar/0.0.1/index.pug +0 -16
  83. package/web/src/pug/block/curve-bar/0.0.1/sample.js +0 -338
  84. package/web/src/pug/block/dumbbell/0.0.1/index.ls +0 -90
  85. package/web/src/pug/block/dumbbell/0.0.1/index.pug +0 -1
  86. package/web/src/pug/block/empty/0.0.1/index.ls +0 -27
  87. package/web/src/pug/block/empty/0.0.1/index.pug +0 -2
  88. package/web/src/pug/block/gauge/0.0.1/index.ls +0 -100
  89. package/web/src/pug/block/gauge/0.0.1/index.pug +0 -31
  90. package/web/src/pug/block/gauge/0.0.1/sample.js +0 -338
  91. package/web/src/pug/block/line/0.0.1/index.ls +0 -302
  92. package/web/src/pug/block/line/0.0.1/index.pug +0 -33
  93. package/web/src/pug/block/number/0.0.1/index.ls +0 -69
  94. package/web/src/pug/block/number/0.0.1/index.pug +0 -20
  95. package/web/src/pug/block/percent-list/0.0.1/index.ls +0 -167
  96. package/web/src/pug/block/percent-list/0.0.1/index.pug +0 -34
  97. package/web/src/pug/block/pie/0.0.1/index.ls +0 -125
  98. package/web/src/pug/block/pie/0.0.1/index.pug +0 -19
  99. package/web/src/pug/block/pie/0.0.1/sample.js +0 -338
  100. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +0 -185
  101. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +0 -40
  102. package/web/src/pug/block/radar/0.0.1/index.ls +0 -113
  103. package/web/src/pug/block/radar/0.0.1/index.pug +0 -1
  104. package/web/src/pug/block/radar/0.0.1/xx +0 -285
  105. package/web/src/pug/block/scatter/0.0.1/index.ls +0 -128
  106. package/web/src/pug/block/scatter/0.0.1/index.pug +0 -30
  107. package/web/src/pug/block/sheet/0.0.1/index.ls +0 -38
  108. package/web/src/pug/block/sheet/0.0.1/index.pug +0 -5
  109. package/web/src/pug/block/table/0.0.1/index.ls +0 -40
  110. package/web/src/pug/block/table/0.0.1/index.pug +0 -3
  111. package/web/src/pug/block/taiwancounty/0.0.1/index.ls +0 -74
  112. package/web/src/pug/block/taiwancounty/0.0.1/index.pug +0 -64
  113. package/web/src/pug/block/taiwantown/0.0.1/index.ls +0 -48
  114. package/web/src/pug/block/taiwantown/0.0.1/index.pug +0 -52
  115. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +0 -53
  116. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +0 -52
  117. package/web/src/pug/block/treemap/0.0.1/index.ls +0 -172
  118. package/web/src/pug/block/treemap/0.0.1/index.pug +0 -42
  119. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +0 -174
  120. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +0 -17
  121. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +0 -241
  122. package/web/src/pug/block/wordcloud/0.0.1/index.ls +0 -61
  123. package/web/src/pug/block/wordcloud/0.0.1/index.pug +0 -1
  124. package/web/src/pug/block/worldmap/0.0.1/index.ls +0 -81
  125. package/web/src/pug/block/worldmap/0.0.1/index.pug +0 -12
  126. package/web/src/pug/index.ls +0 -72
  127. package/web/src/pug/index.pug +0 -51
  128. package/web/src/styl/index.styl +0 -0
  129. package/web/static/assets/block/cache.js +0 -4
  130. package/web/static/assets/custom-lib/d3/d3-array.v2.js +0 -1182
  131. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +0 -2
  132. package/web/static/assets/custom-lib/d3/d3-array.v3.js +0 -1273
  133. package/web/static/assets/custom-lib/d3/d3-array.v3.min.js +0 -1273
  134. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +0 -2
  135. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +0 -2
  136. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +0 -2
  137. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +0 -2
  138. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +0 -2
  139. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +0 -2
  140. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +0 -2
  141. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +0 -2
  142. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +0 -2
  143. package/web/static/assets/custom-lib/d3/d3-geo.v2.js +0 -3127
  144. package/web/static/assets/custom-lib/d3/d3-geo.v2.min.js +0 -2
  145. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +0 -2
  146. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +0 -2
  147. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +0 -2
  148. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +0 -2
  149. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +0 -2
  150. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +0 -2
  151. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +0 -2
  152. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +0 -2
  153. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +0 -2
  154. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +0 -2
  155. package/web/static/assets/custom-lib/d3/d3.v4.js +0 -17178
  156. package/web/static/assets/custom-lib/d3/d3.v4.min.js +0 -2
  157. package/web/static/assets/custom-lib/d3/d3.v6.js +0 -19708
  158. package/web/static/assets/data/countrycode.json +0 -1
  159. package/web/static/assets/data/world-110m.json +0 -1
  160. package/web/static/assets/data/zh-to-alpha2.json +0 -1
  161. package/web/static/assets/img/fluid.svg +0 -16
  162. package/web/static/block/axis/0.0.1/index.html +0 -79
  163. package/web/static/block/axis-bubble/0.0.1/index.html +0 -222
  164. package/web/static/block/bar/0.0.1/index.html +0 -581
  165. package/web/static/block/bar-list/0.0.1/index.html +0 -231
  166. package/web/static/block/bar-race/0.0.1/index.html +0 -184
  167. package/web/static/block/base/0.0.1/index.html +0 -197
  168. package/web/static/block/blank/0.0.1/index.html +0 -42
  169. package/web/static/block/bubble/0.0.1/index.html +0 -402
  170. package/web/static/block/bubble/0.0.1/test.html +0 -0
  171. package/web/static/block/curve-bar/0.0.1/index.html +0 -148
  172. package/web/static/block/dumbbell/0.0.1/index.html +0 -178
  173. package/web/static/block/empty/0.0.1/index.html +0 -76
  174. package/web/static/block/gauge/0.0.1/index.html +0 -150
  175. package/web/static/block/line/0.0.1/index.html +0 -571
  176. package/web/static/block/number/0.0.1/index.html +0 -152
  177. package/web/static/block/percent-list/0.0.1/index.html +0 -316
  178. package/web/static/block/pie/0.0.1/index.html +0 -281
  179. package/web/static/block/pie-bubble/0.0.1/index.html +0 -358
  180. package/web/static/block/radar/0.0.1/index.html +0 -149
  181. package/web/static/block/scatter/0.0.1/index.html +0 -251
  182. package/web/static/block/sheet/0.0.1/index.html +0 -103
  183. package/web/static/block/table/0.0.1/index.html +0 -73
  184. package/web/static/block/taiwancounty/0.0.1/index.html +0 -202
  185. package/web/static/block/taiwantown/0.0.1/index.html +0 -210
  186. package/web/static/block/taiwanvillage/0.0.1/index.html +0 -220
  187. package/web/static/block/treemap/0.0.1/index.html +0 -360
  188. package/web/static/block/voronoi-treemap/0.0.1/index.html +0 -350
  189. package/web/static/block/wordcloud/0.0.1/index.html +0 -92
  190. package/web/static/block/worldmap/0.0.1/index.html +0 -207
  191. package/web/static/css/index.css +0 -0
  192. package/web/static/css/index.min.css +0 -0
  193. package/web/static/favicon.ico +0 -0
  194. package/web/static/index.html +0 -153
@@ -1,174 +0,0 @@
1
- <-(->it!) _
2
-
3
- block-factory =
4
- pkg:
5
- name: 'voronoi-treemap', version: '0.0.1'
6
- extend: {name: "base", version: "0.0.1"}
7
- dependencies: [
8
- {name: "@zbryikt/voronoijs", version: "main", path: "voronoi.min.js"}
9
- ]
10
- init: ({root, context, pubsub}) ->
11
- pubsub.fire \init, mod: mod {context} .then ~> it.0
12
-
13
- mod = ({context}) ->
14
- {d3,ldcolor,voronoi,chart} = context
15
- sample: ->
16
- raw: [0 to 100].map (val) ~> {val: Math.random! * 10, cat: Math.floor(1 + 10 * Math.random!), name: val}
17
- binding:
18
- name: {key: \name}
19
- area: {key: \val}
20
- category: {key: \cat}
21
- config: {}
22
- dimension:
23
- area: { type: \R, name: "area"},
24
- name: { type: \N, desc: "name" },
25
- category: { type: \N, desc: "category"},
26
-
27
- init: ->
28
- @tint = tint = new chart.utils.tint!
29
- @g = Object.fromEntries <[view legend]>.map ~> [it, d3.select(@layout.get-group it)]
30
- @layout.get-group(\view).appendChild g = (document.createElementNS "http://www.w3.org/2000/svg", "g")
31
- @g.shape = d3.select g
32
- @site-boxes = []
33
- @legend = new chart.utils.legend do
34
- layout: @layout
35
- name: \legend
36
- root: @root
37
- shape: (d) -> d3.select(@).attr \fill, tint.get d.key
38
- cfg: selectable: true
39
- @legend.on \select, ~> @bind!; @resize!; @render!
40
- @tip = new chart.utils.tip do
41
- root: @root
42
- accessor: ({evt}) ~>
43
- if !(evt.target and data = d3.select(evt.target).datum!) => return null
44
- if Array.isArray(data) =>
45
- if !@_sites => return
46
- if !(data.idx?) => return
47
- if !(data = @_sites[data.idx]) => return
48
- return {name: data.name, value: "#{(data.area).toFixed 2}#{@binding.area.unit or ''}"}
49
- range: ~> @layout.get-node \view .getBoundingClientRect!
50
-
51
- @start!
52
- parse: ->
53
- @data.map -> it <<< {key: it.name, value: it.area}
54
- @total = @data.reduce(((a,b) -> a + b.area), 0)
55
- @cats = Array.from(new Set(@data.map (d) -> d.category))
56
- @legend.data @cats.map -> {key: it, text: it}
57
- bind: ->
58
- data = @data.filter ~> @legend.is-selected(it.category )
59
- @parsed = children: d3.nest!.key(->it.category).entries(data).map -> it <<< {children: it.values}
60
- box = @box or @svg.getBoundingClientRect!
61
- [w,h] = [box.width, box.height]
62
- w = h = Math.min(w,h)
63
- @treemap = new voronoi.Treemap(@parsed, voronoi.Polygon.create(w, h, 60), w, h)
64
- sites = @treemap.getSites!
65
- @g.shape.selectAll \path.data .data @treemap.getPolygons!
66
- ..exit!remove!
67
- ..enter!append \path .attr \class, \data
68
- .each (d,i) -> d.idx = i
69
- @g.shape.selectAll \path.data .attr \class, (d,i) -> if sites[i].lv <= 0 => 'data group' else 'data'
70
- @polygons = @g.shape.selectAll \path.data
71
-
72
- @g.shape.selectAll \g.label .data sites
73
- ..exit!remove!
74
- ..enter!append \g .attr \class, \label
75
- .each (d,i) ->
76
- d3.select @
77
- ..append \text .attr \class, 'name' .attr \font-size, '.8em'
78
- ..append \text .attr \class, 'value'
79
- @sites = @g.shape.selectAll \g.label
80
- @sites.each (d,i) ->
81
- d3.select @ .selectAll \text .data [d,d]
82
- .attr \text-anchor, \middle
83
- .attr \dominant-baseline, \center
84
- resize: ->
85
- box = @layout.get-box \view
86
- [w,h] = [box.width, box.height]
87
- s = Math.min(w,h)
88
- @legend.config @cfg.legend
89
- @legend.update!
90
- @layout.update false
91
- @g.shape.attr \transform, "translate(#{w/2 - s/2},#{h/2 - s/2})"
92
- @scale =
93
- x: d3.scaleLinear!domain [0,w] .range [0, w]
94
- y: d3.scaleLinear!domain [0,h] .range [0, h]
95
- color: d3.interpolateTurbo
96
- if @cfg? and @cfg.palette =>
97
- @scale.color = d3.interpolateDiscrete @cfg.palette.colors.map -> ldcolor.web(it.value or it)
98
- @tint.set @cfg.palette
99
- sites = @treemap.getSites!
100
- @count = 0
101
- @gbox = @svg.getBoundingClientRect!
102
-
103
- render: (tick = false)->
104
- @_sites = sites = @treemap.getSites!
105
- polygons = @treemap.getPolygons!
106
- [w,h] = [@box.width, @box.height]
107
-
108
- if !tick =>
109
-
110
- @legend.render!
111
- @sites.selectAll \.name
112
- .attr \dy, \0.88em
113
- .text ->
114
- n = ("#{it.name or ''}")
115
- return n
116
- if it.lv > 0 => n.substring(0,7) + (if n.length > 7 => '...' else '') else ''
117
- .attr \fill, (d,i) ~> if ldcolor.hcl(@tint.get d.category).l > 60 => \#000 else \#eee
118
- .style \pointer-events, \none
119
- @sites.selectAll \.value
120
- .attr \dy, \-0.28em
121
- .text -> if it.lv > 0 => (it.value or 0).toFixed(2) else ''
122
- .attr \fill, (d,i) ~> if ldcolor.hcl(@tint.get d.category).l > 60 => \#000 else \#eee
123
- .style \pointer-events, \none
124
- @site-boxes = site-boxes = []
125
- @sites.each (d,i) -> site-boxes.push @getBoundingClientRect!
126
- @polygons
127
- .attr \fill, (d,i) ~> @tint.get sites[i].category
128
- .attr \stroke, \#fff
129
- .attr \stroke-width, 1
130
-
131
- site-boxes = @site-boxes
132
- boxes = []
133
-
134
- @polygons.data polygons
135
- .attr \d, (d,i) ->
136
- d.idx = i
137
- if !(d and d.length) =>
138
- boxes.push {}
139
- return ""
140
- ret = [[\M, d.0.x, d.0.y]]
141
- [min,max] = [{x: d.0.x, y: d.0.y}, {d.0.x, d.0.y}]
142
- for idx from 0 til d.length =>
143
- [x,y] = [d[idx].x, d[idx].y]
144
- if min.x > x => min.x = x
145
- if max.x < x => max.x = x
146
- if min.y > y => min.y = y
147
- if max.y < y => max.y = y
148
- ret.push [\L, x, y]
149
- ret.push [\L, d.0.x, d.0.y]
150
- boxes.push {x: min.x, y: min.y, width: max.x - min.x, height: max.y - min.y}
151
- return ret.map(->it.join(' ')).join(' ')
152
-
153
- @sites
154
- .each (d,i) ->
155
- box = boxes[i]
156
- mybox = site-boxes[i]
157
- if !mybox => mybox = @getBoundingClientRect!
158
- d3.select @
159
- .attr \transform, ->
160
- x = box.x + box.width / 2
161
- y = box.y + box.height / 2
162
- if isNaN(x) => x = -10000
163
- if isNaN(y) => y = -10000
164
- return "translate(#x, #y)"
165
- .attr \opacity, -> (1 - 6 * ((mybox.width / (box.width >? 0) - 1) >? 0)) >? 0
166
-
167
-
168
- tick: ->
169
- @count = (@count or 0) + 1
170
- if @count < 100 =>
171
- @treemap.compute!
172
- @render true
173
-
174
- return block-factory
@@ -1,17 +0,0 @@
1
- div
2
- div(plug="layout")
3
- .pdl-layout
4
- div(data-type="layout")
5
- .pdl-cell(data-name="view")
6
- .pdl-cell(data-name="legend")
7
- div(data-type="render")
8
- style(type="text/css"): :stylus
9
- .pdl-layout > div[data-type=layout]
10
- display: grid
11
- grid-template-columns: 1fr fit-content(10em)
12
- & > .pdl-cell[data-name=view]
13
- grid-column: 1
14
- & > .pdl-cell[data-name=legend]
15
- grid-column: 2
16
- padding: 0 .5em 0 .5em
17
- script(type="@plotdb/block"): include:lsc index.ls
@@ -1,241 +0,0 @@
1
- {
2
- sample: function() {
3
- var list = d3.range(20);
4
- return {
5
- value: [{name: "Score", data: list.map(function(d,i) { return Math.round(Math.random() * 90 + 10); })}],
6
- name: [{name: "Name", data: list.map(function(d,i) { return plotdb.data.sample.name.rand(); })}],
7
- category: [{name: "Dept", data: list.map(function(d,i) { return plotdb.data.sample.category.rand(); })}]
8
- };
9
- },
10
- dimension: {
11
- value: { type: [plotdb.Number], require: true, desc: "size of the block" },
12
- name: { type: [], require: false, desc: "name of the block" },
13
- category: { type: [], require: false, desc: "parent of the block"},
14
- color: { type: [], require: false, desc: "color of block. leave empty to color by category"}
15
- },
16
- config: {
17
- fontFamily: {},
18
- background: {},
19
- textFill: {},
20
- fontSize: {default: 14},
21
- stroke: {default: "#000"},
22
- strokeWidth: {default: 5},
23
- margin: {},
24
- palette: {},
25
- legendLabel: {},
26
- legendShow: {},
27
- labelShow: {},
28
- labelShowThreshold: {
29
- name: "Only Show labels over this value",
30
- desc: "this config controls the labels to show by their underlying area",
31
- default: 10,
32
- type: [plotdb.Number],
33
- min: 0, max: 1000,
34
- category: "Label"
35
- },
36
- labelShadowSize: {},
37
- popupShow: {}
38
- },
39
- init: function() {
40
- var that = this;
41
- this.svg = d3.select(this.root).append("svg");
42
- this.legendGroup = this.svg.append("g").attr({class: "legend-group"});
43
- this.tooltip = plotd3.html.tooltip(this.root).on("mousemove", function(d,i,popup) {
44
- var data = d3.select(that.sites[0][i]).datum();
45
- popup.select(".title").text(data.name + " / " + data.category);
46
- popup.select(".value").text(data.data);
47
- });
48
- requestAnimationFrame(function() { that.tickWrap(); });
49
- },
50
- tickWrap: function() {
51
- var that = this;
52
- this.tick();
53
- requestAnimationFrame(function() { that.tickWrap(); });
54
- },
55
- parse: function() {
56
- this.data.map(function(it) {
57
- it.key = it.name;
58
- it.data = it.value;
59
- });
60
- this.total = this.data.reduce(function(a,b) { return a + b.data; }, 0);
61
- this.categories = d3.map(this.data, function(d,i) { return d.category; }).keys();
62
- this.parsed = {children: d3.nest().key(function(it) { return it.category; }).entries(this.data).map(function(it) {
63
- it.children = it.values;
64
- return it;
65
- })};
66
- },
67
- bind: function() {
68
- var that = this, sel;
69
- var sites = this.treemap.getSites();
70
- sel = this.svg.selectAll("path.data").data(this.treemap.getPolygons());
71
- sel.exit().remove();
72
- sel = sel.enter().append("path").attr({"class": "data", opacity: 1});
73
- this.svg.selectAll("path.data").attr({
74
- class: function(d,i) {
75
- return (sites[i].lv <=0 ? "data group" : "data");
76
- }
77
- });
78
- if(this.config.popupShow) this.tooltip.nodes(sel);
79
- this.polygons = this.svg.selectAll("path.data");
80
- sel = this.svg.selectAll("g.label").data(sites);
81
- sel.exit().remove();
82
- sel = sel.enter().append("g").attr({"class": "label"}).each(function(it) {
83
- var node = d3.select(this);
84
- node.append("text").attr({"class": "name shadow"});
85
- node.append("text").attr({"class": "value shadow"});
86
- node.append("text").attr({"class": "name"});
87
- node.append("text").attr({"class": "value"});
88
- });
89
- this.sites = this.svg.selectAll("g.label");
90
- this.sites.each(function(d,i) {
91
- d3.select(this).selectAll("text").datum(d);
92
- });
93
- },
94
- resize: function() {
95
- var that = this;
96
- var box = this.root.getBoundingClientRect();
97
- var width = this.width = box.width;
98
- var height = this.height = box.height;
99
- this.svg.attr({
100
- width: width + "px", height: height + "px",
101
- viewBox: [0,0,width,height].join(" "),
102
- preserveAspectRatio: "xMidYMid"
103
- });
104
- this.tooltip.fontSize(this.config.fontSize);
105
- this.useColor = !!this.dimension.color.fields.length;
106
- this.cScale = plotdb.Palette.scale.auto(
107
- this.config.palette,
108
- this.useColor ? this.dimension.color.fields : this.dimension.category.fields
109
- );
110
- this.legend = plotd3.rwd.legend()
111
- .scale(this.cScale)
112
- .orient("bottom")
113
- .tickValues(this.cScale.domain())
114
- .size([this.width - 2 * this.config.margin, 100])
115
- .fontSize(this.config.fontSize);
116
- this.legend.label(this.config.legendLabel || "");
117
- this.legendGroup.call(this.legend).selectAll(".legend").on("mouseover", function(d,i) {
118
- var sites = that.treemap.getSites();
119
- that.activeGroup = d;
120
- that.polygons.transition().attr({
121
- opacity: function(d,i) {
122
- var data = sites[i];
123
- return (!that.activeGroup || that.activeGroup == data.category ? 1 : 0.1);
124
- }
125
- });
126
- }).on("mouseout", function(d,i) {
127
- that.activeGroup = null;
128
- that.polygons.transition().attr({ opacity: 1 });
129
- });
130
- this.legendSize = (this.config.legendShow ? this.legend.offset() : [0,0]);
131
- this.xScale = d3.scale.linear().domain([0,width]).range([
132
- this.config.margin,
133
- width - this.config.margin
134
- ]);
135
- this.yScale = d3.scale.linear().domain([0,height]).range([
136
- this.config.margin,
137
- height - this.config.margin - (this.config.legendShow ? this.legendSize[1] + this.config.fontSize : 0)
138
- ]);
139
- this.treemap = new Voronoi.Treemap(this.parsed, Voronoi.Polygon.create(width, height, 60), width, height);
140
- },
141
- tick: function() {
142
- this.treemap.compute();
143
- this.renderTreemap();
144
- },
145
- render: function() {
146
- var that = this;
147
- if(this.config.fontFamily) d3.select(this.root).style("font-family", this.config.fontFamily);
148
- d3.select(this.root).style("background-color", this.config.background);
149
- this.svg.selectAll("text").attr({
150
- "font-size": that.config.fontSize,
151
- "fill": that.config.textFill
152
- });
153
- this.legendGroup.attr({
154
- transform: ["translate(", (this.width - this.legendSize[0])/2, (this.height - this.legendSize[1] - this.config.margin), ")"].join(" "),
155
- display: (this.config.legendShow ? "block" : "none")
156
- });
157
- this.sites.attr({
158
- "font-size": this.config.fontSize,
159
- "font-weight": "200",
160
- "text-anchor": "middle",
161
- dy: "0.38em",
162
- display: function(d,i) {
163
- return (that.config.labelShow && (0.001 * that.config.labelShowThreshold < d.data / that.total) ? "block" : "none");
164
- }
165
- });
166
- this.sites.selectAll("text").attr({
167
- fill: function(it) {
168
- var hsl = d3.hsl(that.cScale(that.useColor ? it.color : it.category));
169
- if(hsl.l > 0.65) return "#000";
170
- return "#fff";
171
- }
172
- });
173
- this.sites.selectAll(".name").attr({
174
- dy: "-0.5em"
175
- }).text(function(it) {
176
- if(it.lv >= 1) return it.name;
177
- return "";
178
- });
179
- this.sites.selectAll(".value").attr({
180
- dy: "0.5em",
181
- "font-size": "0.8em"
182
- }).text(function(it) {
183
- if(it.lv >= 1) return Math.round(100*it.data)/100;
184
- return "";
185
- });
186
- this.sites.selectAll(".shadow").attr({
187
- stroke: function(it) {
188
- var hsl = d3.hsl(that.cScale(that.useColor ? it.color : it.category));
189
- if(hsl.l > 0.65) return "#fff";
190
- return "#000";
191
- },
192
- "stroke-width": that.config.labelShadowSize
193
- });
194
- var sites = this.treemap.getSites();
195
- this.polygons.attr({
196
- fill: function(it,i) {
197
- if(sites[i].lv == 0) return "none";
198
- return (that.useColor
199
- ? that.cScale(sites[i].color)
200
- : that.cScale(sites[i].category)
201
- );
202
- },
203
- stroke: this.config.stroke,
204
- "stroke-width": function(it,i) {
205
- if(sites[i].lv <= 0) return that.config.strokeWidth;
206
- return that.config.strokeWidth/3;
207
- }
208
- });
209
- },
210
- renderTreemap: function() {
211
- var that = this;
212
- var sites = this.treemap.getSites();
213
- var polygons = this.treemap.getPolygons();
214
- this.polygons.data(polygons).attr({
215
- d: function(it) {
216
- if(!it || !it.length) return ""
217
- ret = ["M", that.xScale(it[0].x), that.yScale(it[0].y)];
218
- for(var idx = 0; idx < it.length; idx++) {
219
- ret.push("L");
220
- ret.push(that.xScale(it[idx].x));
221
- ret.push(that.yScale(it[idx].y));
222
- }
223
- ret.push("L");
224
- ret.push(that.xScale(it[0].x));
225
- ret.push(that.yScale(it[0].y));
226
- return ret.join(" ");
227
- },
228
- });
229
- this.sites.attr({
230
- transform: function(it,i) {
231
- var x = 0, y = 0;
232
- var box = that.polygons[0][i].getBoundingClientRect();
233
- x = box.left + box.width/2;
234
- y = box.top + box.height/2;
235
- if(isNaN(x)) x = -10000;
236
- if(isNaN(y)) y = -10000;
237
- return ["translate(", x, y, ")"].join(" ");
238
- },
239
- });
240
- }
241
- }
@@ -1,61 +0,0 @@
1
- <- (->it!) _
2
-
3
- block-factory =
4
- pkg:
5
- name: 'wordcloud', version: '0.0.1'
6
- extend: {name: "base", version: "0.0.1"}
7
- dependencies: [
8
- {url: "https://unpkg.com/d3-cloud@1.2.5/build/d3.layout.cloud.js"}
9
- ]
10
-
11
- init: ({root, context, pubsub}) ->
12
- pubsub.fire \init, mod: mod {context} .then ~> it.0
13
-
14
- mod = ({context, root}) ->
15
- {d3,forceBoundary,ldColor,repeatString$} = context
16
- sample: ->
17
- raw: []
18
- binding: {}
19
- config: {}
20
- dimension: {}
21
- init: ->
22
- @dd = <[cover scandal seem consumption garbage hunter
23
- pepper west guilt conspiracy pupil boat muscle nightmare gene
24
- royalty salon difficult management brainstorm aid moving plaster
25
- cake issue realism subject speed railcar break grass collapse
26
- is leave retiree looting transaction copyright serve guard
27
- colony spell ask ranch cell sensation name default reflection
28
- ]>.map (d,i) -> { text: d, value: 1.5 * i + 10} #value: Math.pow(i,2)/50 + 10} #Math.random! * 40 + 10 }
29
- @cloud = d3.layout.cloud!
30
- @cloud
31
- #.rotate 0
32
- .font \arial
33
- .padding 2
34
- .fontSize ~> it.value
35
- .on \end, ~>
36
- @render!
37
- parse: ->
38
- resize: ->
39
- @cloud
40
- .size([@box.width, @box.height].map -> Math.round it)
41
- .words @dd
42
- .start!
43
- render: ->
44
- color = d3.interpolateTurbo
45
- if @cfg? and @cfg.palette =>
46
- color = d3.interpolateDiscrete @cfg.palette.colors.map -> ldColor.web(it.value or it)
47
- vext = d3.extent @dd.map -> it.value
48
- vscale = d3.scaleLinear!domain vext .range [0,1]
49
- d3.select @svg .selectAll \text .data @dd
50
- ..exit!remove!
51
- ..enter!append \text
52
- d3.select @svg .selectAll \text
53
- .attr \transform, ~> "translate(#{it.x + @box.width / 2} #{it.y + @box.height / 2}) rotate(#{it.rotate})"
54
- .attr \text-anchor, \middle
55
- .attr \font-size, -> it.size
56
- .attr \font-family, \arial
57
- .attr \fill, -> color vscale it.value
58
- .text -> it.text
59
- tick: ->
60
-
61
- return block-factory
@@ -1 +0,0 @@
1
- div: script(type="@plotdb/block"): include:lsc index.ls
@@ -1,81 +0,0 @@
1
- <-(->it!) _
2
-
3
- block-factory =
4
- pkg:
5
- name: 'worldmap', version: '0.0.1'
6
- extend: {name: "base", version: "0.0.1"}
7
- dependencies: [
8
- {url: "https://d3js.org/d3-geo.v2.min.js", async: false}
9
- {url: "https://d3js.org/topojson.v2.min.js", async: false}
10
- {url: "/assets/lib/@plotdb/pdmap-world/main/index.js"}
11
- ]
12
- init: ({root, context, pubsub}) ->
13
- pubsub.fire \init, {mod: mod {context}}
14
-
15
- mod = ({context}) ->
16
- {chart, d3, ldcolor, pdmap-world, topojson} = context
17
- sample: ->
18
- raw: pdmap-world.meta.alpha2.map -> {country: it, val: Math.random!}
19
- binding: do
20
- color: {key: \val}
21
- name: {key: \country}
22
- config: {}
23
- dimension:
24
- name: {type: \N, name: "國家"}
25
- color: {type: \R, name: "顏色"}
26
- init: ->
27
- @g = @layout.get-group \view
28
- @obj = new pdmap-world { root: @g }
29
- @scale = scale = {color: d3.interpolateTurbo}
30
- @legend = new chart.utils.legend do
31
- root: @root
32
- name: \legend
33
- layout: @layout
34
- shape: (d) -> d3.select(@).attr \fill, scale.color d.key
35
- @tip = new chart.utils.tip {
36
- root: @root,
37
- accessor: ({evt}) ~>
38
- if !(evt.target and data = d3.select(evt.target).datum!) => return null
39
- ret = [[k,v] for k,v of pdmap-world.meta.zhalpha2].filter(-> it.1.toLowerCase! == data.properties.alpha2).0
40
- name = if ret => ret.0
41
- else data.properties.shortname or data.data.name
42
- v = if isNaN(data.data.color) => '-' else "#{(data.data.color).toFixed(2)}#{@binding.color.unit or ''}"
43
- return {name: name, value: v}
44
- range: ~> return @layout.get-node \view .getBoundingClientRect!
45
- }
46
- @obj.init!then ~> @obj.fit!
47
-
48
- destroy: -> @tip.destroy!
49
-
50
- parse: ->
51
- geo-data = d3.select @g .selectAll \path .data!
52
- geo-data.map (d) -> d.data = null; d.properties.value = 0; d.properties.data = {}
53
- @data
54
- .map ~> {c: @obj.findCountry(it.name), v: it}
55
- .filter -> it.c
56
- .map -> it.c <<< {value: it.v.color, data: it.v}
57
- geo-data.map (d) -> d.data = d.properties.data or {}
58
- @extent = c: d3.extent(geo-data, -> it.properties.value)
59
-
60
- resize: ->
61
- @tip.toggle(if @cfg.{}tip.enabled? => @cfg.tip.enabled else true)
62
- @obj.fit @layout.get-box \view
63
- pal = if @cfg.palette => @cfg.palette.colors else <[#f00 #999 #00f]>
64
- len = pal.length
65
- @ticks = d3.quantize((~> (1 - it) * (@extent.c.1 - @extent.c.0) + @extent.c.0), len).map ~>
66
- {key: it, text: d3.format(@cfg.legend-format or '.2f')(it) + (if @binding.color.unit => that else '')}
67
- @ticks.sort (a,b) -> a.key - b.key
68
- if @cfg.palette =>
69
- @scale.color = d3.scaleLinear!
70
- .domain @ticks.map(-> it.key)
71
- .range pal.map -> ldcolor.web(it.value or it)
72
- @legend.data @ticks
73
-
74
- render: ->
75
- @legend.render!
76
- d3.select @g .selectAll \path
77
- .transition!duration 350
78
- .attr \fill, (d,i) ~> @scale.color d.properties.value
79
- .attr \fill-opacity, (d,i) ~> if @cfg.dim-empty => (if d.properties.value => 1 else 0.2) else 1
80
-
81
- return block-factory
@@ -1,12 +0,0 @@
1
- div
2
- div(plug="layout")
3
- .pdl-layout
4
- div(data-type="layout")
5
- .pdl-cell(data-name="view")
6
- .pdl-cell(data-name="legend") 123
7
- div(data-type="render")
8
- style(type="text/css"): :stylus
9
- .pdl-layout > div[data-type=layout]
10
- display: grid
11
- grid-template-columns: 1fr fit-content(5em)
12
- script(type="@plotdb/block"): include:lsc index.ls
@@ -1,72 +0,0 @@
1
- <-(->it.apply {}) _
2
- lc = @
3
-
4
-
5
- block-prepare = (name, root, data) ->
6
- if !data =>
7
- data = do
8
- config: palette: {"colors":['#b32317','#f58025','#3a6e8f','#87b2d8','#8d8b00','#c1d72f']}
9
- delay-render: false
10
-
11
- if lc.chart => lc.chart.destroy!
12
- root.innerHTML = ""
13
- console.log "[#name] loading"
14
- manager.get({name, version: "0.0.1"})
15
- .then -> it.create {data}
16
- .then (bi) ->
17
- console.log "[#name] created"
18
- bi.attach {root} .then -> bi.interface!
19
- .then (chart) ->
20
- console.log "[#name] attached"
21
- window.chart = chart
22
- lc.chart = chart
23
- chart.config {legend: selectable: true}
24
- chart.resize!
25
- chart.render!
26
- chart.on <[select hover]>, -> console.log "[select/hover] ", it
27
- console.log chart.mod.config
28
- lc.kfg.meta {meta: chart.mod.config}
29
-
30
- manager = new block.manager do
31
- registry: ({name,version,path,type}) ->
32
- if type == \block => return "/block/#name/#version/#{path or 'index.html'}"
33
- if !/^d3/.exec(name) => return "/assets/lib/#name/#version/#path"
34
- return "/assets/custom-lib/d3/#name.v#version.min.js"
35
-
36
- manager.init!
37
- .then -> manager.get({name: "base", version: "0.0.1"})
38
- .then ->
39
- pals = ldpp.get \all
40
- lc.view = new ldview do
41
- root: '[ld-scope=viewer]'
42
- action:
43
- change: choice: ({node}) -> block-prepare node.value, root
44
- click:
45
- palette: ->
46
- lc.chart.config palette: colors: pals[Math.floor(pals.length * Math.random!)]
47
- lc.chart.resize!
48
- lc.chart.render!
49
- filter: ->
50
- lc.chart.filter {name: [2,5]}
51
-
52
- .then ->
53
- query = Object.fromEntries((window.location.search or "").substring(1).split(\&).map -> it.split(\=))
54
- if !query.chart => query.chart = lc.view.get('choice').value
55
- if query.chart =>
56
- block-prepare query.chart, root
57
- lc.view.get('choice').value = query.chart
58
-
59
- .then ->
60
- lc.kfg = new konfig {
61
- root: lc.view.get('konfig'), manager: manager
62
- view: \recurse, use-bundle: true, debounce: false, autotab: true
63
- typemap: (name) -> {name: "@plotdb/konfig.widget.bootstrap", version: "master", path: name}
64
- }
65
- lc.kfg.init!then -> console.log ">", it
66
- lc.kfg.on \change, (cfg) ->
67
- lc.cfg = cfg
68
- if !lc.chart => return
69
- lc.chart.config lc.cfg
70
- lc.chart.bind!
71
- lc.chart.resize!
72
- lc.chart.render!