@plotdb/chart 1.0.1 → 1.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 (164) hide show
  1. package/package.json +3 -1
  2. package/CHANGELOG.md +0 -29
  3. package/build +0 -45
  4. package/doc/charts.md +0 -58
  5. package/doc/config.md +0 -44
  6. package/doc/draft/chart.md +0 -146
  7. package/doc/draft/data.md +0 -8
  8. package/doc/draft/definition.md +0 -0
  9. package/doc/draft/events.md +0 -0
  10. package/doc/draft/filter.md +0 -0
  11. package/doc/draft/lifecycle.md +0 -89
  12. package/doc/spec.md +0 -89
  13. package/doc/todo.md +0 -27
  14. package/doc/utils/tip.md +0 -84
  15. package/src/data/en-US/category +0 -20
  16. package/src/data/en-US/fruit +0 -39
  17. package/src/data/en-US/movie +0 -125
  18. package/src/data/en-US/name +0 -58
  19. package/src/data/index.ls +0 -34
  20. package/src/data/zh-TW/category +0 -20
  21. package/src/data/zh-TW/fruits +0 -38
  22. package/src/data/zh-TW/movie +0 -125
  23. package/src/data/zh-TW/names +0 -105
  24. package/src/index.ls +0 -323
  25. package/src/index.styl +0 -6
  26. package/src/utils/axis.ls +0 -229
  27. package/src/utils/config.ls +0 -11
  28. package/src/utils/data.ls +0 -104
  29. package/src/utils/format.ls +0 -30
  30. package/src/utils/legend.ls +0 -134
  31. package/src/utils/legend.styl +0 -37
  32. package/src/utils/tint.ls +0 -66
  33. package/src/utils/tip.ls +0 -97
  34. package/web/src/pug/base.pug +0 -21
  35. package/web/src/pug/block/axis/0.0.1/index.ls +0 -32
  36. package/web/src/pug/block/axis/0.0.1/index.pug +0 -1
  37. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +0 -137
  38. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +0 -1
  39. package/web/src/pug/block/bar/0.0.1/index.ls +0 -270
  40. package/web/src/pug/block/bar/0.0.1/index.pug +0 -35
  41. package/web/src/pug/block/bar-list/0.0.1/index.ls +0 -81
  42. package/web/src/pug/block/bar-list/0.0.1/index.pug +0 -30
  43. package/web/src/pug/block/bar-race/0.0.1/index.ls +0 -79
  44. package/web/src/pug/block/bar-race/0.0.1/index.pug +0 -21
  45. package/web/src/pug/block/base/0.0.1/index.ls +0 -66
  46. package/web/src/pug/block/base/0.0.1/index.pug +0 -5
  47. package/web/src/pug/block/blank/0.0.1/index.ls +0 -21
  48. package/web/src/pug/block/blank/0.0.1/index.pug +0 -1
  49. package/web/src/pug/block/bubble/0.0.1/index.ls +0 -218
  50. package/web/src/pug/block/bubble/0.0.1/index.pug +0 -42
  51. package/web/src/pug/block/curve-bar/0.0.1/index.ls +0 -85
  52. package/web/src/pug/block/curve-bar/0.0.1/index.pug +0 -16
  53. package/web/src/pug/block/curve-bar/0.0.1/sample.js +0 -338
  54. package/web/src/pug/block/dumbbell/0.0.1/index.ls +0 -86
  55. package/web/src/pug/block/dumbbell/0.0.1/index.pug +0 -1
  56. package/web/src/pug/block/empty/0.0.1/index.ls +0 -28
  57. package/web/src/pug/block/empty/0.0.1/index.pug +0 -2
  58. package/web/src/pug/block/gauge/0.0.1/index.ls +0 -96
  59. package/web/src/pug/block/gauge/0.0.1/index.pug +0 -31
  60. package/web/src/pug/block/gauge/0.0.1/sample.js +0 -338
  61. package/web/src/pug/block/line/0.0.1/index.ls +0 -297
  62. package/web/src/pug/block/line/0.0.1/index.pug +0 -33
  63. package/web/src/pug/block/number/0.0.1/index.ls +0 -65
  64. package/web/src/pug/block/number/0.0.1/index.pug +0 -20
  65. package/web/src/pug/block/percent-list/0.0.1/index.ls +0 -161
  66. package/web/src/pug/block/percent-list/0.0.1/index.pug +0 -34
  67. package/web/src/pug/block/pie/0.0.1/index.ls +0 -121
  68. package/web/src/pug/block/pie/0.0.1/index.pug +0 -19
  69. package/web/src/pug/block/pie/0.0.1/sample.js +0 -338
  70. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +0 -181
  71. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +0 -40
  72. package/web/src/pug/block/radar/0.0.1/index.ls +0 -109
  73. package/web/src/pug/block/radar/0.0.1/index.pug +0 -1
  74. package/web/src/pug/block/radar/0.0.1/xx +0 -285
  75. package/web/src/pug/block/scatter/0.0.1/index.ls +0 -124
  76. package/web/src/pug/block/scatter/0.0.1/index.pug +0 -30
  77. package/web/src/pug/block/sheet/0.0.1/index.ls +0 -34
  78. package/web/src/pug/block/sheet/0.0.1/index.pug +0 -5
  79. package/web/src/pug/block/table/0.0.1/index.ls +0 -36
  80. package/web/src/pug/block/table/0.0.1/index.pug +0 -3
  81. package/web/src/pug/block/taiwancounty/0.0.1/index.ls +0 -70
  82. package/web/src/pug/block/taiwancounty/0.0.1/index.pug +0 -64
  83. package/web/src/pug/block/taiwantown/0.0.1/index.ls +0 -44
  84. package/web/src/pug/block/taiwantown/0.0.1/index.pug +0 -52
  85. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +0 -49
  86. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +0 -52
  87. package/web/src/pug/block/treemap/0.0.1/index.ls +0 -168
  88. package/web/src/pug/block/treemap/0.0.1/index.pug +0 -42
  89. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +0 -170
  90. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +0 -17
  91. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +0 -241
  92. package/web/src/pug/block/wordcloud/0.0.1/index.ls +0 -57
  93. package/web/src/pug/block/wordcloud/0.0.1/index.pug +0 -1
  94. package/web/src/pug/block/worldmap/0.0.1/index.ls +0 -77
  95. package/web/src/pug/block/worldmap/0.0.1/index.pug +0 -12
  96. package/web/src/pug/index.ls +0 -72
  97. package/web/src/pug/index.pug +0 -51
  98. package/web/src/styl/index.styl +0 -6
  99. package/web/static/assets/block/cache.js +0 -4
  100. package/web/static/assets/custom-lib/d3/d3-array.v2.js +0 -1182
  101. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +0 -2
  102. package/web/static/assets/custom-lib/d3/d3-array.v3.js +0 -1273
  103. package/web/static/assets/custom-lib/d3/d3-array.v3.min.js +0 -1273
  104. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +0 -2
  105. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +0 -2
  106. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +0 -2
  107. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +0 -2
  108. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +0 -2
  109. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +0 -2
  110. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +0 -2
  111. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +0 -2
  112. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +0 -2
  113. package/web/static/assets/custom-lib/d3/d3-geo.v2.js +0 -3127
  114. package/web/static/assets/custom-lib/d3/d3-geo.v2.min.js +0 -2
  115. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +0 -2
  116. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +0 -2
  117. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +0 -2
  118. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +0 -2
  119. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +0 -2
  120. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +0 -2
  121. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +0 -2
  122. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +0 -2
  123. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +0 -2
  124. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +0 -2
  125. package/web/static/assets/custom-lib/d3/d3.v4.js +0 -17178
  126. package/web/static/assets/custom-lib/d3/d3.v4.min.js +0 -2
  127. package/web/static/assets/custom-lib/d3/d3.v6.js +0 -19708
  128. package/web/static/assets/data/countrycode.json +0 -1
  129. package/web/static/assets/data/world-110m.json +0 -1
  130. package/web/static/assets/data/zh-to-alpha2.json +0 -1
  131. package/web/static/assets/img/fluid.svg +0 -16
  132. package/web/static/block/axis/0.0.1/index.html +0 -74
  133. package/web/static/block/axis-bubble/0.0.1/index.html +0 -217
  134. package/web/static/block/bar/0.0.1/index.html +0 -576
  135. package/web/static/block/bar-list/0.0.1/index.html +0 -226
  136. package/web/static/block/bar-race/0.0.1/index.html +0 -179
  137. package/web/static/block/base/0.0.1/index.html +0 -197
  138. package/web/static/block/blank/0.0.1/index.html +0 -37
  139. package/web/static/block/bubble/0.0.1/index.html +0 -422
  140. package/web/static/block/bubble/0.0.1/test.html +0 -0
  141. package/web/static/block/curve-bar/0.0.1/index.html +0 -143
  142. package/web/static/block/dumbbell/0.0.1/index.html +0 -173
  143. package/web/static/block/empty/0.0.1/index.html +0 -76
  144. package/web/static/block/gauge/0.0.1/index.html +0 -145
  145. package/web/static/block/line/0.0.1/index.html +0 -566
  146. package/web/static/block/number/0.0.1/index.html +0 -147
  147. package/web/static/block/percent-list/0.0.1/index.html +0 -311
  148. package/web/static/block/pie/0.0.1/index.html +0 -276
  149. package/web/static/block/pie-bubble/0.0.1/index.html +0 -353
  150. package/web/static/block/radar/0.0.1/index.html +0 -144
  151. package/web/static/block/scatter/0.0.1/index.html +0 -246
  152. package/web/static/block/sheet/0.0.1/index.html +0 -98
  153. package/web/static/block/table/0.0.1/index.html +0 -67
  154. package/web/static/block/taiwancounty/0.0.1/index.html +0 -197
  155. package/web/static/block/taiwantown/0.0.1/index.html +0 -205
  156. package/web/static/block/taiwanvillage/0.0.1/index.html +0 -215
  157. package/web/static/block/treemap/0.0.1/index.html +0 -355
  158. package/web/static/block/voronoi-treemap/0.0.1/index.html +0 -345
  159. package/web/static/block/wordcloud/0.0.1/index.html +0 -87
  160. package/web/static/block/worldmap/0.0.1/index.html +0 -202
  161. package/web/static/css/index.css +0 -6
  162. package/web/static/css/index.min.css +0 -1
  163. package/web/static/favicon.ico +0 -0
  164. package/web/static/index.html +0 -153
@@ -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,57 +0,0 @@
1
- module.exports =
2
- pkg:
3
- name: 'wordcloud', version: '0.0.1'
4
- extend: {name: "base", version: "0.0.1"}
5
- dependencies: [
6
- {url: "https://unpkg.com/d3-cloud@1.2.5/build/d3.layout.cloud.js"}
7
- ]
8
-
9
- init: ({root, context, pubsub}) ->
10
- pubsub.fire \init, mod: mod {context} .then ~> it.0
11
-
12
- mod = ({context, root}) ->
13
- {d3,forceBoundary,ldColor,repeatString$} = context
14
- sample: ->
15
- raw: []
16
- binding: {}
17
- config: {}
18
- dimension: {}
19
- init: ->
20
- @dd = <[cover scandal seem consumption garbage hunter
21
- pepper west guilt conspiracy pupil boat muscle nightmare gene
22
- royalty salon difficult management brainstorm aid moving plaster
23
- cake issue realism subject speed railcar break grass collapse
24
- is leave retiree looting transaction copyright serve guard
25
- colony spell ask ranch cell sensation name default reflection
26
- ]>.map (d,i) -> { text: d, value: 1.5 * i + 10} #value: Math.pow(i,2)/50 + 10} #Math.random! * 40 + 10 }
27
- @cloud = d3.layout.cloud!
28
- @cloud
29
- #.rotate 0
30
- .font \arial
31
- .padding 2
32
- .fontSize ~> it.value
33
- .on \end, ~>
34
- @render!
35
- parse: ->
36
- resize: ->
37
- @cloud
38
- .size([@box.width, @box.height].map -> Math.round it)
39
- .words @dd
40
- .start!
41
- render: ->
42
- color = d3.interpolateTurbo
43
- if @cfg? and @cfg.palette =>
44
- color = d3.interpolateDiscrete @cfg.palette.colors.map -> ldColor.web(it.value or it)
45
- vext = d3.extent @dd.map -> it.value
46
- vscale = d3.scaleLinear!domain vext .range [0,1]
47
- d3.select @svg .selectAll \text .data @dd
48
- ..exit!remove!
49
- ..enter!append \text
50
- d3.select @svg .selectAll \text
51
- .attr \transform, ~> "translate(#{it.x + @box.width / 2} #{it.y + @box.height / 2}) rotate(#{it.rotate})"
52
- .attr \text-anchor, \middle
53
- .attr \font-size, -> it.size
54
- .attr \font-family, \arial
55
- .attr \fill, -> color vscale it.value
56
- .text -> it.text
57
- tick: ->
@@ -1 +0,0 @@
1
- div: script(type="@plotdb/block"): include:lsc index.ls
@@ -1,77 +0,0 @@
1
- module.exports =
2
- pkg:
3
- name: 'worldmap', version: '0.0.1'
4
- extend: {name: "base", version: "0.0.1"}
5
- dependencies: [
6
- {url: "https://d3js.org/d3-geo.v2.min.js", async: false}
7
- {url: "https://d3js.org/topojson.v2.min.js", async: false}
8
- {url: "/assets/lib/@plotdb/pdmap-world/main/index.js"}
9
- ]
10
- init: ({root, context, pubsub}) ->
11
- pubsub.fire \init, {mod: mod {context}}
12
-
13
- mod = ({context}) ->
14
- {chart, d3, ldcolor, pdmap-world, topojson} = context
15
- sample: ->
16
- raw: pdmap-world.meta.alpha2.map -> {country: it, val: Math.random!}
17
- binding: do
18
- color: {key: \val}
19
- name: {key: \country}
20
- config: {}
21
- dimension:
22
- name: {type: \N, name: "國家"}
23
- color: {type: \R, name: "顏色"}
24
- init: ->
25
- @g = @layout.get-group \view
26
- @obj = new pdmap-world { root: @g }
27
- @scale = scale = {color: d3.interpolateTurbo}
28
- @legend = new chart.utils.legend do
29
- root: @root
30
- name: \legend
31
- layout: @layout
32
- shape: (d) -> d3.select(@).attr \fill, scale.color d.key
33
- @tip = new chart.utils.tip {
34
- root: @root,
35
- accessor: ({evt}) ~>
36
- if !(evt.target and data = d3.select(evt.target).datum!) => return null
37
- ret = [[k,v] for k,v of pdmap-world.meta.zhalpha2].filter(-> it.1.toLowerCase! == data.properties.alpha2).0
38
- name = if ret => ret.0
39
- else data.properties.shortname or data.data.name
40
- v = if isNaN(data.data.color) => '-' else "#{(data.data.color).toFixed(2)}#{@binding.color.unit or ''}"
41
- return {name: name, value: v}
42
- range: ~> return @layout.get-node \view .getBoundingClientRect!
43
- }
44
- @obj.init!then ~> @obj.fit!
45
-
46
- destroy: -> @tip.destroy!
47
-
48
- parse: ->
49
- geo-data = d3.select @g .selectAll \path .data!
50
- geo-data.map (d) -> d.data = null; d.properties.value = 0; d.properties.data = {}
51
- @data
52
- .map ~> {c: @obj.findCountry(it.name), v: it}
53
- .filter -> it.c
54
- .map -> it.c <<< {value: it.v.color, data: it.v}
55
- geo-data.map (d) -> d.data = d.properties.data or {}
56
- @extent = c: d3.extent(geo-data, -> it.properties.value)
57
-
58
- resize: ->
59
- @tip.toggle(if @cfg.{}tip.enabled? => @cfg.tip.enabled else true)
60
- @obj.fit @layout.get-box \view
61
- pal = if @cfg.palette => @cfg.palette.colors else <[#f00 #999 #00f]>
62
- len = pal.length
63
- @ticks = d3.quantize((~> (1 - it) * (@extent.c.1 - @extent.c.0) + @extent.c.0), len).map ~>
64
- {key: it, text: d3.format(@cfg.legend-format or '.2f')(it) + (if @binding.color.unit => that else '')}
65
- @ticks.sort (a,b) -> a.key - b.key
66
- if @cfg.palette =>
67
- @scale.color = d3.scaleLinear!
68
- .domain @ticks.map(-> it.key)
69
- .range pal.map -> ldcolor.web(it.value or it)
70
- @legend.data @ticks
71
-
72
- render: ->
73
- @legend.render!
74
- d3.select @g .selectAll \path
75
- .transition!duration 350
76
- .attr \fill, (d,i) ~> @scale.color d.properties.value
77
- .attr \fill-opacity, (d,i) ~> if @cfg.dim-empty => (if d.properties.value => 1 else 0.2) else 1
@@ -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!
@@ -1,51 +0,0 @@
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/index.min.js")
45
- +script("/assets/lib/@plotdb/rescope/main/index.min.js")
46
- +script("/assets/lib/@plotdb/block/main/index.min.js")
47
- +script("/assets/lib/@plotdb/konfig/main/index.min.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: include:lsc index.ls
@@ -1,6 +0,0 @@
1
- @font-face
2
- font-family: 'ldi'
3
- font-weight: normal
4
- font-style: normal
5
- src: url('/assets/lib/ldiconfont/main/ldif.ttf') format('truetype')
6
-