@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,285 @@
1
+ {
2
+ sample: function() {
3
+ var list = d3.range(9 + Math.round(Math.random() * 3));
4
+ var count = d3.range(Math.round(Math.random() * 2) + 2);
5
+ return {
6
+ order: [{name: "Month", data: list.map(function(d,i) { return plotdb.data.sample.month[i].substring(0,3); })}],
7
+ radius: count.map(function(d,i) {
8
+ return {
9
+ name: "Value " + d,
10
+ data: list.map(function(d,i) { return Math.round(Math.random() * 90 + 10); })
11
+ };
12
+ })
13
+ };
14
+ },
15
+ dimension: {
16
+ radius: { type: [plotdb.Number], require: true, multiple: true, desc: "radius of point on radar line" },
17
+ order: { type: [plotdb.Order], desc: "order of data point" }
18
+ },
19
+ config: {
20
+ fontFamily: {},
21
+ background: {},
22
+ textFill: {},
23
+ fontSize: {},
24
+ margin: {},
25
+ padding: {},
26
+ palette: {},
27
+ strokeWidth: {},
28
+ lineSmoothing: {},
29
+ legendLabel: {},
30
+ legendShow: {},
31
+ legendPosition: {},
32
+ rAxisShow: {},
33
+ rAxisLabel: {},
34
+ rAxisTickPadding: {},
35
+ rAxisTickCount: {rebindOnChange: true},
36
+ aAxisShow: {},
37
+ aAxisLabel: {},
38
+ aAxisTickPadding: {},
39
+ nodeShow: {},
40
+ nodeSize: {default: 8},
41
+ nodeStrokeWidth: {default: 2},
42
+ nodeFill: {default: "#fff"},
43
+ gridShow: {},
44
+ gridStroke: {},
45
+ gridStrokeWidth: {},
46
+ gridDashArray: {},
47
+ gridBackground: {},
48
+ popupShow: {},
49
+ unit: {}
50
+ },
51
+ init: function() {
52
+ var that = this;
53
+ this.svg = d3.select(this.root).append("svg");
54
+ this.allGroup = this.svg.append("g");
55
+ this.legendGroup = this.svg.append("g").attr({class: "legend-group"});
56
+ this.gridGroup = this.allGroup.append("g").attr({class: "grid-group"});
57
+ this.aAxisGroup = this.allGroup.append("g").attr({class: "axis angle"});
58
+ this.rAxisGroup = this.allGroup.append("g").attr({class: "axis radius"});
59
+ this.popup = plotd3.html.tooltip(this.root).on("mousemove", function(d,i,popup) {
60
+ var name = that.names[d3.select(this.parentNode).datum().idx];
61
+ var order = that.orders[i];
62
+ popup.select(".title").text(name + " @ " + order);
63
+ popup.select(".value").text(d + " " + (that.config.unit || ""));
64
+ });
65
+ this.line = d3.svg.line().tension(0.5)
66
+ .x(function(d,i) { return that.rScale(d) * Math.sin( that.aScale(that.orders[i]) ); })
67
+ .y(function(d,i) { return that.rScale(d) * -Math.cos( that.aScale(that.orders[i]) ); });
68
+ this.overlap = plotd3.rwd.overlap();
69
+ },
70
+ parse: function() {
71
+ plotdb.Order.sort(this.data, "order");
72
+ this.orders = d3.map(this.data, function(d,i) { return d.order; }).keys();
73
+ this.parsed = d3.transpose(this.data.map(function(it) { return it.radius; }));
74
+ this.parsed.map(function(d,i) { d.idx = i; });
75
+ this.names = this.dimension.radius.fieldName || ["1","2","3"];
76
+ this.radiusRange = d3.extent(this.parsed
77
+ .map(function(it) { return d3.extent(it); })
78
+ .reduce(function(a,b) { return a.concat(b); }, []));
79
+ if(this.radiusRange[0] == this.radiusRange[1]) this.radiusRange[1]++;
80
+ },
81
+ bind: function() {
82
+ var that = this, sel;
83
+ sel = this.allGroup.selectAll("path.data").data(this.parsed);
84
+ sel.exit().attr("class","").transition("exit").duration(500).attr("opacity",0).remove();
85
+ sel.enter().append("path").attr({class: "data", opacity: 0});
86
+ sel = this.allGroup.selectAll("g.data-group").data(this.parsed);
87
+ sel.exit().attr("class","").transition("exit").duration(500).attr("opacity",0).remove();
88
+ sel.enter().append("g").attr({class: "data-group", opacity: 0});
89
+ this.allGroup.selectAll("g.data-group").each(function(d,i) {
90
+ var sel = d3.select(this).selectAll("circle.node").data(d);
91
+ sel.exit().attr("class","").transition("exit").duration(500).attr("opacity",0).remove();
92
+ sel = sel.enter().append("circle").attr({class: "node", opacity: 0});
93
+ if(that.config.popupShow) that.popup.nodes(sel);
94
+ });
95
+
96
+ sel = this.gridGroup.selectAll("circle.grid.radius").data(this.rTicks);
97
+ sel.exit().attr("class","").transition("exit").duration(500).attr("opacity",0).remove();
98
+ sel.enter().append("circle").attr({class: "grid radius",opacity: 0, r: 0}).sort(d3.descending);
99
+ this.gridGroup.selectAll("circle.grid.radius").sort(function(a,b) { return b - a;});
100
+ sel = this.gridGroup.selectAll("line.grid.angle").data(this.aTicks);
101
+ sel.exit().attr("class","").transition("exit").duration(500).attr("opacity",0).remove();
102
+ sel.enter().append("line").attr({class: "grid angle",opacity: 0});
103
+ sel = this.aAxisGroup.selectAll("g").data(this.aTicks);
104
+ sel.exit().attr("class","").transition("exit").duration(500).attr("opacity",0).remove();
105
+ sel.enter().append("g").attr({class: "tick"}).each(function(d,i) {
106
+ d3.select(this).append("text").attr("opacity", 0);
107
+ });
108
+ },
109
+ resize: function() {
110
+ var that = this;
111
+ var box = this.root.getBoundingClientRect();
112
+ var width = this.width = box.width;
113
+ var height = this.height = box.height;
114
+ this.svg.attr({
115
+ width: width + "px", height: height + "px",
116
+ viewBox: [0,0,width,height].join(" "),
117
+ preserveAspectRatio: "xMidYMid"
118
+ });
119
+ this.legendVertical = ( this.config.legendPosition == "left" || this.config.legendPosition == "right" ) ? true : false;
120
+ this.line.interpolate(this.config.lineSmoothing);
121
+ this.popup.fontSize(this.config.fontSize);
122
+ this.cScale = plotdb.Palette.scale.ordinal(this.config.palette);
123
+ this.legend = plotd3.rwd.legend()
124
+ .scale(this.cScale)
125
+ .orient(this.config.legendPosition)
126
+ .size(
127
+ (this.legendVertical
128
+ ? [220,this.height - 2 * this.config.margin]
129
+ : [this.width - 2 * this.config.margin, 220]
130
+ ))
131
+ .label(this.config.legendLabel || " ")
132
+ .fontSize(this.config.fontSize);
133
+ this.legend.tickValues(this.names);
134
+ this.legendGroup.call(this.legend).selectAll(".legend").on("mouseover", function(d,i) {
135
+ that.activeGroup = i + 1; that.render();
136
+ }).on("mouseout", function(d,i) {
137
+ that.activeGroup = null; that.render();
138
+ });
139
+ this.legendSize = (this.config.legendShow ? this.legend.offset() : [0,0]);
140
+ var mh = height - (this.config.legendShow && !this.legendVertical ? this.legendSize[1] + this.config.fontSize : 0);
141
+ var mw = width - (this.config.legendShow && this.legendVertical ? this.legendSize[0] + this.config.fontSize : 0);
142
+
143
+ this.size = ((mw>mh?mh:mw) - that.config.margin * 2 - that.config.fontSize * 2)/2;
144
+ if(this.size <= 10) this.size = 10;
145
+ this.rScale = d3.scale.linear()
146
+ .domain([0,this.radiusRange[1]])
147
+ .range([0,this.size]).nice(5);
148
+ this.rTicks = this.rScale.ticks(this.config.rAxisTickCount);
149
+ this.rTicks.sort(function(a,b) { return b - a; });
150
+ this.niceRRange = this.rScale.domain();
151
+ this.rAxis = plotd3.rwd.axis()
152
+ .scale(this.rScale)
153
+ .orient("radius")
154
+ .angle(Math.PI /(this.data.length || 1))
155
+ .showGrid(false)
156
+ .tickValues(this.rTicks)
157
+ .fontSize(this.config.fontSize);
158
+ this.rAxisGroup.call(this.rAxis).select(".domain").remove();
159
+ this.aScale = d3.scale.ordinal()
160
+ .domain(this.orders.concat(""))
161
+ .rangePoints([0, 2 * Math.PI]);
162
+ this.aTicks = d3.range(this.data.length);
163
+ },
164
+ render: function() {
165
+ var that = this,sel;
166
+ if(this.config.fontFamily) d3.select(this.root).style("font-family", this.config.fontFamily);
167
+ d3.select(this.root).style("background-color", this.config.background);
168
+ this.svg.selectAll("text").attr({
169
+ "font-size": that.config.fontSize,
170
+ "fill": that.config.textFill
171
+ });
172
+ this.legendGroup.attr({
173
+ transform:
174
+ ["translate(",
175
+ (this.legendVertical
176
+ ? (this.width/2 +
177
+ (this.config.legendPosition == "left"
178
+ ? -(this.size + this.config.fontSize + this.legendSize[0])
179
+ : (this.size + this.config.fontSize)
180
+ ))
181
+ : (this.width - this.legendSize[0])/2
182
+ ),
183
+ (!this.legendVertical
184
+ ? (this.height/2 +
185
+ (this.config.legendPosition == "top"
186
+ ? -(this.size + this.config.fontSize + this.legendSize[1])
187
+ : (this.size + this.config.fontSize)
188
+ ))
189
+ : (this.height - this.legendSize[1])/2
190
+ ),
191
+ ")"].join(" "),
192
+ display: (this.config.legendShow ? "block" : "none")
193
+ });
194
+ this.allGroup.attr({
195
+ transform: [
196
+ "translate(",
197
+ ((this.width + (this.legendVertical ? (this.config.legendPosition == "left" ? 1 : -1) : 0) * (this.config.legendShow
198
+ ? this.legendSize[0] + this.config.fontSize
199
+ : 0))/2
200
+ ), (this.height + (!this.legendVertical ? (this.config.legendPosition == "top" ? 1 : -1) : 0) * (this.config.legendShow
201
+ ? this.legendSize[1] + this.config.fontSize : 0))/2,
202
+ //(this.height/2),
203
+ ")"
204
+ ].join(" ")
205
+ });
206
+ this.gridGroup.attr({
207
+ display: (this.config.gridShow ? "block" : "none")
208
+ }).selectAll("circle.grid.radius").attr({
209
+ cx: 0, cy: 0, fill: this.config.gridBackground, stroke: this.config.gridStroke,
210
+ "stroke-width": this.config.gridStrokeWidth, "stroke-dasharray": this.config.gridDashArray
211
+ }).transition("morph").duration(500).attr({
212
+ r: function(d,i) { return that.rScale(d); },
213
+ opacity: 1
214
+ });
215
+
216
+ this.gridGroup.selectAll("line.grid.angle").attr({
217
+ stroke: this.config.gridStroke,
218
+ "stroke-width": this.config.gridStrokeWidth,
219
+ "stroke-dasharray": this.config.gridDashArray
220
+ }).transition("morph").duration(500).attr({
221
+ x1: 0, y1: 0,
222
+ x2: function(d,i) {
223
+ return that.rScale(that.niceRRange[1]) * Math.sin( that.aScale(that.orders[d]) );
224
+ },
225
+ y2: function(d,i) {
226
+ return that.rScale(that.niceRRange[1]) * -Math.cos( that.aScale(that.orders[d]) );
227
+ },
228
+ opacity: 1
229
+ });
230
+ this.aAxisGroup.attr({
231
+ display: (this.config.aAxisShow ? "block" : "none")
232
+ });
233
+ this.rAxisGroup.attr({
234
+ display: (this.config.rAxisShow ? "block" : "none")
235
+ });
236
+ this.aAxisGroup.selectAll(".tick text").attr({
237
+ "font-size": that.config.fontSize,
238
+ "text-anchor": "middle",
239
+ dy: "0.38em",
240
+ }).text(function(d,i) { return that.orders[i] || i; }).transition("morph").duration(function() {
241
+ return d3.select(this).attr("transform") ? 500 : 0;
242
+ }).attr({
243
+ transform: function(d,i) {
244
+ var r = (that.rScale(that.niceRRange[1]) + 1 * that.config.fontSize);
245
+ var x = r * Math.sin( that.aScale(that.orders[d]) );
246
+ var y = r * -Math.cos( that.aScale(that.orders[d]) );
247
+ var a = (360 * i / that.data.length);
248
+ return ["translate(", x, y, ") rotate(", a, ")"].join(" ");
249
+ },
250
+ });
251
+ this.aAxisGroup.selectAll("text").transition("opacity").duration(500).attr({ opacity: 1 });
252
+ this.allGroup.selectAll("path.data").each(function(d,i) {
253
+ var strokeColor = that.cScale(that.names[i]);
254
+ var rgb = d3.rgb(strokeColor);
255
+ var fillColor = ["rgba(",rgb.r,",",rgb.g,",",rgb.b,",",0.2,")"].join("");
256
+ d3.select(this).attr({
257
+ fill: fillColor,
258
+ stroke: strokeColor,
259
+ "stroke-width": that.config.strokeWidth
260
+ }).transition("morph").duration(500).attr({
261
+ d: function(d,i) { return that.line(d,i) +"Z"; },
262
+ });
263
+ }).transition("opacity").duration(500).attr({
264
+ opacity: function(d,i) { return (!that.activeGroup || that.activeGroup == i+1 ? 1 : 0.1); }
265
+ });
266
+ this.allGroup.selectAll("g.data-group").each(function(d,i) {
267
+ var node = d3.select(this);
268
+ var strokeColor = that.cScale(that.names[i]);
269
+ var rgb = d3.rgb(strokeColor);
270
+ var fillColor = ["rgba(",rgb.r,",",rgb.g,",",rgb.b,",",0.2,")"].join("");
271
+ node.selectAll("circle.node").attr({
272
+ fill: that.config.nodeFill || "#fff", stroke: strokeColor, "stroke-width": that.config.nodeStrokeWidth,
273
+ display: (that.config.nodeShow ? "block" : "none")
274
+ }).transition("morph").duration(500).attr({
275
+ cx: function(d,i) { return that.rScale(d) * Math.sin( that.aScale(that.orders[i]) ); },
276
+ cy: function(d,i) { return that.rScale(d) * -Math.cos( that.aScale(that.orders[i]) ); },
277
+ r: that.config.nodeSize/2,
278
+ opacity: 1
279
+ });
280
+ });
281
+ this.allGroup.selectAll("g.data-group").transition("opacity").duration(500).attr({
282
+ opacity: function(d,i) { return (!that.activeGroup || that.activeGroup == i+1 ? 1 : 0.1); }
283
+ });
284
+ }
285
+ }
@@ -0,0 +1,128 @@
1
+ <-(->it!) _
2
+
3
+ block-factory =
4
+ pkg:
5
+ name: 'scatter', version: '0.0.1'
6
+ extend: {name: "base", version: "0.0.1"}
7
+ dependencies: [
8
+ { url: "http://cdn.jsdelivr.net/npm/d3-delaunay@6/dist/d3-delaunay.min.js" }
9
+ ]
10
+
11
+ init: ({root, context, pubsub}) ->
12
+ pubsub.fire \init, mod: mod {context}
13
+
14
+ mod = ({context}) ->
15
+ {d3,chart} = context
16
+ names = [
17
+ "The Glenn Miller Story",
18
+ "The Fifth Element",
19
+ "Forrest Gump",
20
+ "Finding Nemo",
21
+ "The Fly",
22
+ "First Blood",
23
+ "You Can't Take It with You",
24
+ "Man of the Year",
25
+ "From Hell",
26
+ "The Easy Rider",
27
+ "The English Patient",
28
+ "The Extra-Terrestial",
29
+ "Edward Scissorhands",
30
+ "Empire of the Sun",
31
+ "Encounters of the Third Kind",
32
+ "Elizabeth: The Golden Age",
33
+ ]
34
+ sample: ->
35
+ raw: [0 to 100].map (val) ~>
36
+ ret = x: Math.random!, y: Math.random!, name: names[Math.floor(Math.random! * names.length)]
37
+ ret
38
+ binding:
39
+ x: {key: \x}
40
+ y: {key: \y}
41
+ name: {key: \name}
42
+ config: {}
43
+ dimension:
44
+ x: {type: \R, name: "x axis"}
45
+ y: {type: \R, name: "y axis"}
46
+ radius: {type: \R, name: "radius"}
47
+ category: {type: \CN, name: "category"}
48
+ name: {type: \N, name: "name"}
49
+ init: ->
50
+ @tint = tint = new chart.utils.tint!
51
+ <[view yaxis xaxis]>.map ~> @{}g[it] = d3.select(@layout.get-group(it))
52
+ @path = d3.select @svg .append \path
53
+
54
+ parse: ->
55
+
56
+ resize: ->
57
+ [w,h] = [@box.width, @box.height]
58
+ @extent =
59
+ x: d3.extent @data.map -> it.x
60
+ y: d3.extent @data.map -> it.y
61
+ box = @layout.get-box \view
62
+ @scale =
63
+ x: d3.scaleLinear!domain @extent.x .range [0, box.width]
64
+ y: d3.scaleLinear!domain @extent.y .range [0, box.height]
65
+ @pts = @data.map (d) ~> [@scale.x(d.x), @scale.y(d.y)]
66
+ @delaunay = d3.Delaunay.from @pts
67
+ @voronoi = @delaunay.voronoi [0, 0, box.width, box.height]
68
+ @cells = @pts
69
+ .map (point,i) ~>
70
+ [x,y] = point
71
+ polygon = @voronoi.cellPolygon i
72
+ [cx,cy] = centroid = d3.polygonCentroid polygon
73
+ area = -d3.polygonArea polygon
74
+ angle = (Math.round(Math.atan2(cy - y, cx - x) / Math.PI * 2) + 4) % 4
75
+ {point, polygon, centroid, area, angle}
76
+
77
+ render: ->
78
+ {scale} = @
79
+ @g.view.selectAll \circle.data .data @data
80
+ ..exit!remove!
81
+ ..enter!append \circle .attr \class, \data
82
+ .attr \cx, (d,i) -> scale.x d.x
83
+ .attr \cy, (d,i) -> scale.y d.y
84
+ .attr \r, 3
85
+ .attr \fill, \#000
86
+ @g.view.selectAll \text .data @data
87
+ ..exit!remove!
88
+ ..enter!append \text
89
+ .text (d,i) -> d.name
90
+ .attr \x, (d,i) -> if d.nb => d.nb.x else scale.x(d.x)
91
+ .attr \y, (d,i) -> if d.nb => d.nb.y else scale.y(d.y)
92
+ .attr \text-anchor, \middle
93
+ .attr \dominant-baseline, \middle
94
+ @g.view.selectAll \text .data @data
95
+ .attr \x, (d,i) -> if d.nb => d.nb.x else scale.x(d.x)
96
+ .attr \y, (d,i) -> if d.nb => d.nb.y else scale.y(d.y) - 20
97
+ .attr \opacity, (d,i) -> if d.nb => (if d.nb.show => 1 else 0) else 1
98
+ @path
99
+ .attr \d, @voronoi.render!
100
+ .attr \stroke, \#000
101
+ .attr \transform, @g.view.node!getAttribute(\transform)
102
+ tick: ->
103
+ scale = @scale
104
+ @g.view.selectAll \text .each (d,i) -> d.box = @getBoundingClientRect!
105
+ rbox = @layout.get-box \view
106
+ for i from 0 til @data.length =>
107
+ d = @data[i].box
108
+ if !@data[i].nb => @data[i].nb = x: scale.x(@data[i].x), y: scale.y(@data[i].y) - 20
109
+ @data[i].nb <<< width: d.width, height: d.height, show: true
110
+ for r from 20 til 200 by 20
111
+ for i from 0 til @data.length =>
112
+ for j from 0 til i =>
113
+ [a,b] = [@data[i].nb, @data[j].nb]
114
+ if ((a.x >= b.x and a.x <= b.x + b.width) or (a.x + a.width >= b.x and a.x + a.width <= b.x + b.width)) and
115
+ ((a.y >= b.y and a.y <= b.y + b.height) or (a.y + a.height >= b.y and a.y + a.height <= b.y + b.height)) =>
116
+ d = Math.random! * Math.PI * 2
117
+ data = @data[i]
118
+ data.nb <<< {x: scale.x(data.x) + (Math.cos(d) * r), y: scale.y(data.y) + (Math.sin(d) * r)}
119
+ for i from 0 til @data.length =>
120
+ for j from 0 til i =>
121
+ [a,b] = [@data[i].nb, @data[j].nb]
122
+ if ((a.x >= b.x and a.x <= b.x + b.width) or (a.x + a.width >= b.x and a.x + a.width <= b.x + b.width)) and
123
+ ((a.y >= b.y and a.y <= b.y + b.height) or (a.y + a.height >= b.y and a.y + a.height <= b.y + b.height)) =>
124
+ @data[i].nb.show = false
125
+
126
+ @render!
127
+
128
+ return block-factory
@@ -0,0 +1,30 @@
1
+ div
2
+ div(plug="layout")
3
+ .pdl-layout
4
+ div(data-type="layout")
5
+ .pdl-cell(data-name="axis-left")
6
+ .pdl-cell(data-name="view")
7
+ .pdl-cell
8
+ .pdl-cell(data-name="axis-bottom")
9
+ .pdl-cell(data-name="legend")
10
+ div(data-type="render")
11
+ style(type="text/css"): :stylus
12
+ .pdl-layout > div[data-type=layout]
13
+ display: grid
14
+ grid-template-columns: 2em 1fr
15
+ grid-template-rows: 1fr 1em 3em
16
+ padding: 20px 20px 0 20px
17
+ .pdl-cell[data-name=legend]
18
+ grid-column: 1 / span 2
19
+ grid-row: 3
20
+ /*
21
+ .pdl-layout > div[data-type=layout]
22
+ display: grid
23
+ grid-template-columns: 2em 1fr 5em
24
+ grid-template-rows: 1fr 1em
25
+ padding: 20px 20px 0 20px
26
+ .pdl-cell[data-name=legend]
27
+ grid-column: 3
28
+ grid-row: 1 / span 2
29
+ */
30
+ script(type="@plotdb/block"): include:lsc index.ls
@@ -0,0 +1,38 @@
1
+ <-(->it!) _
2
+
3
+ block-factory =
4
+ pkg:
5
+ name: 'bar', version: '0.0.1'
6
+ extend: {name: "base", version: "0.0.1"}
7
+ dependencies: [
8
+ {url: "/assets/lib/@plotdb/sheet/main/index.min.js"}
9
+ {url: "/assets/lib/@plotdb/sheet/main/index.min.css"}
10
+ ]
11
+ init: ({root, context, t, pubsub}) ->
12
+ pubsub.fire \init, mod: mod({context, t}), prepareSvg: false, layout: false
13
+
14
+ mod = ({context, t}) ->
15
+ {chart,sheet} = context
16
+ sample: ->
17
+ raw: [0 to 20].map (val) ~> Object.fromEntries([1 to 5].map -> ["col#it", (Math.random! * 100).toFixed(2)])
18
+ binding: column: [1 to 5].map -> {key: "col#it"}
19
+ config: {}
20
+ dimension: column: {type: \NCOR, multiple: true, name: \column}
21
+ init: ->
22
+ @sheet = new sheet do
23
+ root: @root.querySelector('[plug=layout]')
24
+ frozen: {row: 1}
25
+ editing: false
26
+ idx: row: true, col: true
27
+ @data = [@binding.column.map(->it.name or it.key)] ++ @raw.map (r) ~> @binding.column.map (c) -> r[c.key]
28
+ @sheet.data @data
29
+
30
+ filter: (filters, internal = false) ->
31
+ parse: ->
32
+ head = @binding.column.map -> it.name or it.key
33
+ @parsed = [head] ++ (@data.map -> it.column)
34
+ @sheet.data @parsed
35
+ resize: ->
36
+ render: ->
37
+
38
+ return block-factory
@@ -0,0 +1,5 @@
1
+ div
2
+ div(plug="layout")
3
+ style(type="text/css"): :stylus
4
+
5
+ script(type="@plotdb/block"): include:lsc index.ls
@@ -0,0 +1,40 @@
1
+ <-(->it!) _
2
+
3
+ block-factory =
4
+ pkg:
5
+ name: 'table', version: '0.0.1'
6
+ extend: {name: "empty", version: "0.0.1"}
7
+ dependencies: [
8
+ {url: "/assets/lib/gridjs/main/gridjs.production.min.js"}
9
+ {url: "/assets/lib/gridjs/main/theme/mermaid.min.css"}
10
+ ]
11
+ init: ({root, context, pubsub}) ->
12
+ {gridjs} = context
13
+ pubsub.fire \init, {
14
+ layout: false
15
+ prepare-svg: false
16
+ mod: {
17
+ init: ->
18
+ @grid = grid = new gridjs.Grid do
19
+ columns: [' ',' ',' ',' ',' '],
20
+ height: "#{@root.getBoundingClientRect!height}px"
21
+ fixedHeader: true,
22
+ sort: true
23
+ search: false
24
+ resizable: true
25
+ data: [] ++ [0 to 10].map -> []
26
+ grid.render @root
27
+ parse: ->
28
+ head = [k for k of (@raw.0 or {})]
29
+ head.length
30
+ raw = @raw
31
+ console.log raw
32
+ return
33
+ @grid.updateConfig {
34
+ columns: raw.0
35
+ data: raw.slice(1) ++ [0 to (20 - raw.length) >? 0 ].map(->[])
36
+ } .forceRender!
37
+ }
38
+ }
39
+
40
+ return block-factory
@@ -0,0 +1,3 @@
1
+ div(style="height:100%")
2
+ plug(name="layout")
3
+ script(type="@plotdb/block"): include:lsc index.ls
@@ -0,0 +1,48 @@
1
+ <-(->it!) _
2
+
3
+ block-factory =
4
+ pkg:
5
+ name: 'taiwantown', version: '0.0.1'
6
+ extend: {name: "base", version: "0.0.1"}
7
+ dependencies: [
8
+ {url: "https://d3js.org/topojson.v2.min.js", async: false}
9
+ {url: "/js/work/map.list.js", async: false}
10
+ {url: "https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist/pdmaptw.min.js"}
11
+ ]
12
+
13
+ init: ({root, context, pubsub}) ->
14
+ pubsub.fire \init, mod: mod {context} .then ~> it.0
15
+
16
+ mod = ({context}) ->
17
+ {d3,forceBoundary,ldColor,repeatString$, pdmaptw, counties, towns} = context
18
+ sample: ->
19
+ val =
20
+ counties: counties.map (d,i) -> {val: Math.random!, county: d}
21
+ towns: towns.map (d,i) -> {val: Math.random!, town: d}
22
+ raw: val.towns
23
+ binding: do
24
+ color: {key: \val}
25
+ name: {key: \town}
26
+ config: {}
27
+ dimension:
28
+ name: {type: \N, name: "國家"}
29
+ color: {type: \R, name: "顏色"}
30
+ init: ->
31
+ @obj = pdmaptw.create do
32
+ root: @svg
33
+ type: \town
34
+ baseurl: 'https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist'
35
+ @obj.init!then ~> @obj.fit!
36
+ parse: ->
37
+ d3.select @svg .selectAll \path .each (d,i) ~>
38
+ d.data = @data.filter(-> it.name == d.properties.name).0 or {}
39
+ resize: -> #@obj.fit!
40
+ render: ->
41
+ @color = d3.interpolateTurbo
42
+ if @cfg? and @cfg.palette =>
43
+ @color = d3.interpolateDiscrete @cfg.palette.colors.map -> ldColor.web(it.value or it)
44
+ d3.select @svg .selectAll \path
45
+ .transition!duration 350
46
+ .attr \fill, (d,i) ~> @color d.data.color
47
+
48
+ return block-factory
@@ -0,0 +1,52 @@
1
+ div: script(type="@plotdb/block"): include:lsc index.ls
2
+
3
+ div: script(type="@plotdb/block"): :lsc
4
+ {
5
+ pkg:
6
+ name: 'taiwantown', version: '0.0.1'
7
+ dependencies: [
8
+ {url: "https://d3js.org/d3.v4.js", async: false}
9
+ "https://d3js.org/d3-format.v2.min.js"
10
+ "https://d3js.org/d3-array.v2.min.js"
11
+ "https://d3js.org/topojson.v2.min.js"
12
+ {url: "https://d3js.org/d3-color.v1.min.js", async: false}
13
+ {url: "https://d3js.org/d3-interpolate.v1.min.js", async: false}
14
+ {url: "https://d3js.org/d3-scale-chromatic.v1.min.js", async: false}
15
+ "/js/map.list.js"
16
+ "https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist/pdmaptw.min.js"
17
+ ]
18
+ init: ({root, context}) ->
19
+ counties = context.counties.map (d,i) -> {val: Math.random!, county: d}
20
+ towns = context.towns.map (d,i) -> {val: Math.random!, town: d}
21
+ c = new chart do
22
+ root: root
23
+ raw: towns
24
+ mod: @mod({context})
25
+ binding: do
26
+ color: {name: \val}
27
+ name: {name: \town}
28
+ c.init!then -> c.render!
29
+ @c = c
30
+
31
+ interface: -> @c
32
+
33
+ mod: ({context}) ->
34
+ return do
35
+ init: ->
36
+ @obj = context.pdmaptw.create do
37
+ root: @svg
38
+ type: \town
39
+ baseurl: 'https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist'
40
+ @obj.init!then ~> @obj.fit!
41
+ parse: ->
42
+ d3.select @svg .selectAll \path .each (d,i) ~>
43
+ d.data = @data.filter(-> it.name == d.properties.name).0 or {}
44
+ resize: -> #@obj.fit!
45
+ render: ->
46
+ @color = d3.interpolateTurbo
47
+ if config.pal => @color = d3.interpolateDiscrete config.pal
48
+ d3.select @svg .selectAll \path
49
+ .transition!duration 350
50
+ .attr \fill, (d,i) ~> @color d.data.color
51
+
52
+ }