@plotdb/chart 0.0.2

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 (177) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +50 -0
  3. package/build +39 -0
  4. package/dist/chart.css +8 -0
  5. package/dist/chart.js +603 -0
  6. package/dist/chart.min.css +1 -0
  7. package/dist/chart.min.js +1 -0
  8. package/dist/data/index.js +73 -0
  9. package/dist/utils/axis.js +357 -0
  10. package/dist/utils/axis.min.js +1 -0
  11. package/dist/utils/config.js +33 -0
  12. package/dist/utils/config.min.js +1 -0
  13. package/dist/utils/data.js +238 -0
  14. package/dist/utils/data.min.js +1 -0
  15. package/dist/utils/format.js +70 -0
  16. package/dist/utils/format.min.js +1 -0
  17. package/dist/utils/legend.css +40 -0
  18. package/dist/utils/legend.js +263 -0
  19. package/dist/utils/legend.min.css +1 -0
  20. package/dist/utils/legend.min.js +1 -0
  21. package/dist/utils/tint.js +138 -0
  22. package/dist/utils/tint.min.js +1 -0
  23. package/dist/utils/tip.js +148 -0
  24. package/dist/utils/tip.min.js +1 -0
  25. package/doc/charts.md +58 -0
  26. package/doc/config.md +44 -0
  27. package/doc/draft/chart.md +146 -0
  28. package/doc/draft/data.md +8 -0
  29. package/doc/draft/definition.md +0 -0
  30. package/doc/draft/events.md +0 -0
  31. package/doc/draft/filter.md +0 -0
  32. package/doc/draft/lifecycle.md +89 -0
  33. package/doc/spec.md +89 -0
  34. package/doc/todo.md +27 -0
  35. package/doc/utils/tip.md +84 -0
  36. package/package.json +83 -0
  37. package/src/chart.ls +320 -0
  38. package/src/chart.styl +6 -0
  39. package/src/data/en-US/category +20 -0
  40. package/src/data/en-US/fruit +39 -0
  41. package/src/data/en-US/movie +125 -0
  42. package/src/data/en-US/name +58 -0
  43. package/src/data/index.ls +34 -0
  44. package/src/data/zh-TW/category +20 -0
  45. package/src/data/zh-TW/fruits +38 -0
  46. package/src/data/zh-TW/movie +125 -0
  47. package/src/data/zh-TW/names +105 -0
  48. package/src/utils/axis.ls +229 -0
  49. package/src/utils/config.ls +11 -0
  50. package/src/utils/data.ls +104 -0
  51. package/src/utils/format.ls +30 -0
  52. package/src/utils/legend.ls +134 -0
  53. package/src/utils/legend.styl +37 -0
  54. package/src/utils/tint.ls +66 -0
  55. package/src/utils/tip.ls +97 -0
  56. package/web/src/pug/base.pug +19 -0
  57. package/web/src/pug/block/axis/0.0.1/index.ls +38 -0
  58. package/web/src/pug/block/axis/0.0.1/index.pug +1 -0
  59. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +141 -0
  60. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +1 -0
  61. package/web/src/pug/block/bar/0.0.1/index.ls +274 -0
  62. package/web/src/pug/block/bar/0.0.1/index.pug +35 -0
  63. package/web/src/pug/block/bar-list/0.0.1/index.ls +85 -0
  64. package/web/src/pug/block/bar-list/0.0.1/index.pug +30 -0
  65. package/web/src/pug/block/bar-race/0.0.1/index.ls +83 -0
  66. package/web/src/pug/block/bar-race/0.0.1/index.pug +21 -0
  67. package/web/src/pug/block/base/0.0.1/index.ls +67 -0
  68. package/web/src/pug/block/base/0.0.1/index.pug +5 -0
  69. package/web/src/pug/block/blank/0.0.1/index.ls +25 -0
  70. package/web/src/pug/block/blank/0.0.1/index.pug +1 -0
  71. package/web/src/pug/block/bubble/0.0.1/index.ls +220 -0
  72. package/web/src/pug/block/bubble/0.0.1/index.pug +28 -0
  73. package/web/src/pug/block/curve-bar/0.0.1/index.ls +89 -0
  74. package/web/src/pug/block/curve-bar/0.0.1/index.pug +16 -0
  75. package/web/src/pug/block/curve-bar/0.0.1/sample.js +338 -0
  76. package/web/src/pug/block/dumbbell/0.0.1/index.ls +90 -0
  77. package/web/src/pug/block/dumbbell/0.0.1/index.pug +1 -0
  78. package/web/src/pug/block/empty/0.0.1/index.ls +27 -0
  79. package/web/src/pug/block/empty/0.0.1/index.pug +2 -0
  80. package/web/src/pug/block/gauge/0.0.1/index.ls +100 -0
  81. package/web/src/pug/block/gauge/0.0.1/index.pug +31 -0
  82. package/web/src/pug/block/gauge/0.0.1/sample.js +338 -0
  83. package/web/src/pug/block/line/0.0.1/index.ls +265 -0
  84. package/web/src/pug/block/line/0.0.1/index.pug +33 -0
  85. package/web/src/pug/block/number/0.0.1/index.ls +69 -0
  86. package/web/src/pug/block/number/0.0.1/index.pug +20 -0
  87. package/web/src/pug/block/percent-list/0.0.1/index.ls +167 -0
  88. package/web/src/pug/block/percent-list/0.0.1/index.pug +34 -0
  89. package/web/src/pug/block/pie/0.0.1/index.ls +125 -0
  90. package/web/src/pug/block/pie/0.0.1/index.pug +19 -0
  91. package/web/src/pug/block/pie/0.0.1/sample.js +338 -0
  92. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +185 -0
  93. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +40 -0
  94. package/web/src/pug/block/radar/0.0.1/index.ls +113 -0
  95. package/web/src/pug/block/radar/0.0.1/index.pug +1 -0
  96. package/web/src/pug/block/radar/0.0.1/xx +285 -0
  97. package/web/src/pug/block/scatter/0.0.1/index.ls +128 -0
  98. package/web/src/pug/block/scatter/0.0.1/index.pug +30 -0
  99. package/web/src/pug/block/sheet/0.0.1/index.ls +38 -0
  100. package/web/src/pug/block/sheet/0.0.1/index.pug +5 -0
  101. package/web/src/pug/block/table/0.0.1/index.ls +40 -0
  102. package/web/src/pug/block/table/0.0.1/index.pug +3 -0
  103. package/web/src/pug/block/taiwantown/0.0.1/index.ls +48 -0
  104. package/web/src/pug/block/taiwantown/0.0.1/index.pug +52 -0
  105. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +53 -0
  106. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +52 -0
  107. package/web/src/pug/block/treemap/0.0.1/index.ls +172 -0
  108. package/web/src/pug/block/treemap/0.0.1/index.pug +42 -0
  109. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +174 -0
  110. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +17 -0
  111. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +241 -0
  112. package/web/src/pug/block/wordcloud/0.0.1/index.ls +61 -0
  113. package/web/src/pug/block/wordcloud/0.0.1/index.pug +1 -0
  114. package/web/src/pug/block/worldmap/0.0.1/index.ls +83 -0
  115. package/web/src/pug/block/worldmap/0.0.1/index.pug +12 -0
  116. package/web/src/pug/index.ls +72 -0
  117. package/web/src/pug/index.pug +52 -0
  118. package/web/src/styl/index.styl +0 -0
  119. package/web/static/assets/block/cache.js +4 -0
  120. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +2 -0
  121. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +2 -0
  122. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +2 -0
  123. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +2 -0
  124. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +2 -0
  125. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +2 -0
  126. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +2 -0
  127. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +2 -0
  128. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +2 -0
  129. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +2 -0
  130. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +2 -0
  131. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +2 -0
  132. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +2 -0
  133. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +2 -0
  134. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +2 -0
  135. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +2 -0
  136. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +2 -0
  137. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +2 -0
  138. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +2 -0
  139. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +2 -0
  140. package/web/static/assets/custom-lib/d3/d3.v4.js +17178 -0
  141. package/web/static/assets/custom-lib/d3/d3.v4.min.js +2 -0
  142. package/web/static/assets/data/countrycode.json +1 -0
  143. package/web/static/assets/data/world-110m.json +1 -0
  144. package/web/static/assets/data/zh-to-alpha2.json +1 -0
  145. package/web/static/assets/img/fluid.svg +16 -0
  146. package/web/static/block/axis/0.0.1/index.html +79 -0
  147. package/web/static/block/axis-bubble/0.0.1/index.html +222 -0
  148. package/web/static/block/bar/0.0.1/index.html +581 -0
  149. package/web/static/block/bar-list/0.0.1/index.html +231 -0
  150. package/web/static/block/bar-race/0.0.1/index.html +184 -0
  151. package/web/static/block/base/0.0.1/index.html +197 -0
  152. package/web/static/block/blank/0.0.1/index.html +42 -0
  153. package/web/static/block/bubble/0.0.1/index.html +402 -0
  154. package/web/static/block/bubble/0.0.1/test.html +0 -0
  155. package/web/static/block/curve-bar/0.0.1/index.html +148 -0
  156. package/web/static/block/dumbbell/0.0.1/index.html +178 -0
  157. package/web/static/block/empty/0.0.1/index.html +76 -0
  158. package/web/static/block/gauge/0.0.1/index.html +150 -0
  159. package/web/static/block/line/0.0.1/index.html +540 -0
  160. package/web/static/block/number/0.0.1/index.html +152 -0
  161. package/web/static/block/percent-list/0.0.1/index.html +316 -0
  162. package/web/static/block/pie/0.0.1/index.html +281 -0
  163. package/web/static/block/pie-bubble/0.0.1/index.html +358 -0
  164. package/web/static/block/radar/0.0.1/index.html +149 -0
  165. package/web/static/block/scatter/0.0.1/index.html +251 -0
  166. package/web/static/block/sheet/0.0.1/index.html +103 -0
  167. package/web/static/block/table/0.0.1/index.html +73 -0
  168. package/web/static/block/taiwantown/0.0.1/index.html +210 -0
  169. package/web/static/block/taiwanvillage/0.0.1/index.html +220 -0
  170. package/web/static/block/treemap/0.0.1/index.html +360 -0
  171. package/web/static/block/voronoi-treemap/0.0.1/index.html +350 -0
  172. package/web/static/block/wordcloud/0.0.1/index.html +92 -0
  173. package/web/static/block/worldmap/0.0.1/index.html +207 -0
  174. package/web/static/css/index.css +0 -0
  175. package/web/static/css/index.min.css +0 -0
  176. package/web/static/favicon.ico +0 -0
  177. package/web/static/index.html +153 -0
@@ -0,0 +1,241 @@
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
+ }
@@ -0,0 +1,61 @@
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
@@ -0,0 +1 @@
1
+ div: script(type="@plotdb/block"): include:lsc index.ls
@@ -0,0 +1,83 @@
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
+
59
+ @extent = c: d3.extent(geo-data, -> it.properties.value)
60
+
61
+ resize: ->
62
+ @tip.toggle(if @cfg.{}tip.enabled? => @cfg.tip.enabled else true)
63
+ @obj.fit @layout.get-box \view
64
+ pal = if @cfg.palette => @cfg.palette.colors else <[#f00 #999 #00f]>
65
+ len = pal.length
66
+ @ticks = d3.quantize((~> (1 - it) * (@extent.c.1 - @extent.c.0) + @extent.c.0), len).map ~>
67
+ {key: it, text: d3.format(@cfg.legend-format or '.2f')(it) + (if @binding.color.unit => that else '')}
68
+ @ticks.sort (a,b) -> a.key - b.key
69
+ if @cfg.palette =>
70
+ @scale.color = d3.scaleLinear!
71
+ .domain @ticks.map(-> it.key)
72
+ .range pal.map -> ldcolor.web(it.value or it)
73
+ @legend.data @ticks
74
+
75
+ render: ->
76
+ @legend.render!
77
+
78
+ d3.select @g .selectAll \path
79
+ .transition!duration 350
80
+ .attr \fill, (d,i) ~> @scale.color d.properties.value
81
+ .attr \fill-opacity, (d,i) ~> if @cfg.dim-empty => (if d.properties.value => 1 else 0.2) else 1
82
+
83
+ return block-factory
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,72 @@
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!
@@ -0,0 +1,52 @@
1
+ extends /base.pug
2
+ block vars
3
+ -
4
+ var charts = [
5
+ "bar-race","bar-list", "sheet",
6
+ "percent-list", "table","scatter", "gauge", "number", "curve-bar", "dumbbell",
7
+ "pie", "axis", "wordcloud", "axis-bubble", "bubble", "treemap",
8
+ "worldmap", "taiwantown", "taiwanvillage", "pie-bubble",
9
+ "bar", "voronoi-treemap", "radar", "line"
10
+ ]
11
+
12
+ block head
13
+ +css("/assets/lib/ldpalettepicker/main/index.min.css")
14
+ style(type="text/css"): :stylus
15
+ html,body
16
+ width: 100%
17
+ height: 100%
18
+ color: #345
19
+ block body
20
+ include @/ldpalettepicker/dist/ldpp.pug
21
+ +scope("viewer").w-100.h-100
22
+ .w-100.h-100.p-4.d-flex.flex-column
23
+ div
24
+ h5 Chart Testing Suite
25
+ .d-flex.flex-grow-1.mb-4
26
+ select.form-control(ld="choice")
27
+ option(value="",disabled,selected) 選擇圖表 ...
28
+ each name in charts
29
+ option(value=name)= name
30
+ .ml-2.btn.btn-outline-secondary(ld="palette") Palette
31
+ .ml-2.btn.btn-outline-secondary(ld="filter") Filter
32
+ .flex-grow-1.d-flex.overflow-hidden
33
+ .w-100.h-100.bg-light.border.shadow-sm.rounded: #root.w-100.h-100.rounded
34
+ .border.ml-4.bg-light.border.shadow-sm.rounded.p-4(
35
+ style="width:320px;font-size:14px;overflow-y:scroll",ld="konfig")
36
+ .d-none: +scope()(ld="template")
37
+ .font-weight-bold.text-lg.mb-2(ld="name")
38
+ .mb-3(ld-each="ctrl")
39
+ .mb-4(ld-each="tab")
40
+ block script
41
+ +script("https://polyfill.io/v3/polyfill.min.js?features=ResizeObserver")
42
+ +script("/assets/lib/proxise/main/proxise.js")
43
+ +script("/assets/lib/@loadingio/debounce.js/main/debounce.min.js")
44
+ +script("/assets/lib/@plotdb/csscope/main/csscope.js")
45
+ +script("/assets/lib/@plotdb/rescope/main/rescope.js")
46
+ +script("/assets/lib/@plotdb/block/main/block.js")
47
+ +script("/assets/lib/@plotdb/konfig/main/konfig.js")
48
+ +script("/assets/lib/@plotdb/konfig/main/konfig.widget.bootstrap.js")
49
+ +script("/assets/lib/ldpalettepicker/main/ldpp.min.js")
50
+ +script("/assets/lib/ldpalettepicker/main/all.palettes.js")
51
+ //+script("/assets/block/cache.js")
52
+ script: include:lsc index.ls
File without changes