@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,338 +0,0 @@
1
-
2
- {
3
- sample: function() {
4
- var list = d3.range(Math.round(Math.random() * 3 + 4));
5
- var value = [{name: "Amount", data: list.map(function() { return Math.random(); })}];
6
- var name = [{name: "Fruit", data: list.map(function(it) {
7
- return plotdb.data.sample.fruit[it % plotdb.data.sample.fruit.length]
8
- })}];
9
- return {name: name, value: value};
10
- },
11
- dimension: {
12
- value: { type: [plotdb.Number], require: true, desc: "size of pie" },
13
- name: { type: [], require: false, desc: "name of pie" },
14
- },
15
- config: {
16
- fontFamily: {},
17
- background: {},
18
- textFill: {},
19
- fontSize: {},
20
- margin: {},
21
- palette: {},
22
- stroke: {default: "#fff"},
23
- strokeWidth: {},
24
- thick: { name: "thick (0~1)", type: [plotdb.Number], default: 1 },
25
- boxRoundness: {},
26
- labelShow: {},
27
- labelShadowSize: {},
28
- otherLimit: {},
29
- otherLabel: {},
30
- labelPosition: {},
31
- legendLabel: {},
32
- legendShow: {},
33
- legendPosition: {},
34
- legendInline: {
35
- name: "Show Inline Legend",
36
- type: [plotdb.Boolean],
37
- default: false,
38
- desc: "[Experiment feature] Show legend with wedges instead of a standalone legend panel",
39
- category: "Legend Inline"
40
- },
41
- legendInlineColor: {
42
- name: "Color",
43
- type: [plotdb.Color],
44
- default: "#222",
45
- desc: "Dot / Line Color",
46
- category: "Legend Inline"
47
- },
48
- legendInlineStrokeWidth: {
49
- name: "Stroke Width",
50
- type: [plotdb.Number],
51
- default: 2,
52
- desc: "Dot / line width of inline legend",
53
- category: "Legend Inline"
54
- },
55
- unit: {},
56
- sort: { name: "Sort Values", type: [plotdb.Boolean], default: true, rebindOnChange: true },
57
- showPercent: {name: "Show Percent", type: [plotdb.Boolean], default: false},
58
- popupShow: {}
59
- },
60
-
61
- init: function() {
62
- var that = this;
63
- this.svg = d3.select(this.root).append("svg");
64
- this.pieGroup = this.svg.append("g").attr("class", "pie-group");
65
- this.legendGroup = this.svg.append("g").attr({"class": "legend-group"});
66
- this.popup = plotd3.html.tooltip(this.root).on("mousemove", function(d,i,popup) {
67
- popup.select(".title").text(d.data.name || "-");
68
- popup.select(".value").html([
69
- Math.ceil(100 * d.data.value)/100 + (that.config.unit || ""),
70
- d.data.percent
71
- ].join("<br>"));
72
- });
73
- this.popup.coord(function(d,i) {
74
- var r = d.data.centralRadius;
75
- var a = (d.endAngle + d.startAngle)/2;
76
- var x = Math.sin(a) * r;
77
- var y = -Math.cos(a) * r;
78
- var cx = (that.width - that.legendOffset[0] * (that.config.legendPosition == "right" ? 1 : -1 )) / 2;
79
- var cy = (that.height - that.legendOffset[1] * (that.config.legendPosition == "bottom" ? 1 : -1 )) / 2;
80
- return [
81
- cx + x, cy + y, 1,1
82
- ];
83
- });
84
- this.pielayout = d3.layout.pie().value(function(it) { return it.value; });
85
- },
86
- parse: function() {
87
- if(!this.dimension.name.fields.length) this.data.map(function(d,i) { d.name = i; });
88
- if(!this.dimension.value.fields.length) this.data.map(function(d,i) { d.value= 1; });
89
- this.names = d3.map(this.data, function(d,i) { return d.name || ""; }).keys();
90
- },
91
- bind: function() {
92
- var that = this, sel, sel1, sel2;
93
- sel = this.pieGroup.selectAll("path.data.pie").data(this.parsed);
94
- sel.exit().attr({class: ""}).transition("exit").duration(500).attr({opacity: 0}).remove();
95
- sel1 = sel.enter().append("path").attr({class: "data pie", opacity: 0});
96
- sel = this.pieGroup.selectAll("g.label").data(this.parsed);
97
- sel.exit().attr({class: ""}).transition("exit").duration(500).attr({opacity: 0}).remove();
98
- sel2 = sel.enter().append("g").attr({class: "label", opacity: 0});
99
- this.pieGroup.selectAll("g.label").each(function(d,i) {
100
- var node = d3.select(this),sel;
101
- sel = node.selectAll("text").data([d,d]);
102
- sel.exit().remove();
103
- sel.enter().append("text").attr({
104
- class: function(d,i) { return "data label " + (i ? "value" : "shadow"); },
105
- });
106
- });
107
- sel = this.pieGroup.selectAll("g.marker").data(this.parsed);
108
- sel.exit().remove();
109
- sel.enter().append("g").attr({class: "marker"}).each(function(d,i) {
110
- var node = d3.select(this);
111
- node.append("path"); node.append("circle"); node.append("circle"); node.append("text");
112
- });
113
- this.pieGroup.selectAll("g.marker").each(function(d,i) {
114
- var node = d3.select(this);
115
- node.select("path").datum(d);node.selectAll("circle").data([d,d]);node.select("text").datum(d);
116
- });
117
- if(this.config.popupShow) this.popup.nodes(sel1).nodes(sel2);
118
- [sel1,sel2].map(function(sel) {
119
- sel.on("click", function(d,i) {
120
- that.fire("filter", {type: "value", value: d.data.name, field: "name"});
121
- });
122
- });
123
- },
124
- resize: function() {
125
- var that = this;
126
- var other = {
127
- name: that.config.otherLabel,
128
- value: this.data.filter(function(d,i) { return d.value < that.config.otherLimit; }).reduce(function(a,b) { return a + b.value; }, 0)
129
- };
130
- this.fdata = this.data.filter(function(d,i) { return d.value >= that.config.otherLimit; });
131
- if(other.value != 0) this.fdata.push(other);
132
- this.names = this.fdata.map(function(it) { return it.name; });
133
-
134
- var box = this.root.getBoundingClientRect();
135
- var svgbox = this.svg[0][0].getBoundingClientRect();
136
- var width = this.width = box.width;
137
- var height = this.height = box.height;
138
- this.svg.attr({
139
- width: width + "px", height: height + "px",
140
- viewBox: [0,0,width,height].join(" "),
141
- preserveAspectRatio: "xMidYMid"
142
- });
143
- this.popup.fontSize(this.config.fontSize);
144
- this.legendVertical = ["right","left"].indexOf(this.config.legendPosition) >= 0;
145
- this.cScale = plotdb.Palette.scale.ordinal(this.config.palette);
146
- this.legend = plotd3.rwd.legend()
147
- .size(this.legendVertical ? [220, this.height - 2 * this.config.margin] : [this.width - 2 * this.config.margin, 220])
148
- .orient(this.config.legendPosition).scale(this.cScale)
149
- .label(this.config.legendLabel || "")
150
- .tickValues(this.names).fontSize(this.config.fontSize);
151
- this.legendGroup.call(this.legend);
152
- this.legendGroup.selectAll(".legend").on("mouseover", function(d,i) {
153
- that.activeGroup = d; that.render();
154
- }).on("mouseout", function(d,i) {
155
- that.activeGroup = null; that.render();
156
- });
157
- this.legendSize = (this.config.legendShow ? this.legend.offset() : [0,0]);
158
- this.legendOffset = this.config.legendShow ?
159
- this.legendVertical ? [this.legendSize[0] + this.config.fontSize,0] : [0, this.legendSize[1] + this.config.fontSize]
160
- : [0,0];
161
- var w = this.width - this.legendOffset[0];
162
- var h = this.height - this.legendOffset[1] - (this.config.legendInline ? 60 : 0);
163
- this.radius = ( w > h ? h : w )/2 - this.config.margin
164
- - (!that.config.labelShow || (that.config.labelPosition == 'in') ? 0 : 2 * that.config.fontSize);
165
- this.pielayout.sort(this.config.sort ? function(a,b) { return b.value - a.value; } : null);
166
- var parsed = this.pielayout(this.fdata);
167
- this.parsed = parsed;
168
- var sum = d3.sum(this.fdata, function(d,i) { return d.value; });
169
- parsed.map(function(d,i) {
170
- var a = (d.startAngle + d.endAngle ) / 2;
171
- var r = that.radius;
172
- if(that.config.labelPosition != 'in') r += that.config.fontSize * 2;
173
- else r = (that.radius + that.radius * 0.9 * (1 - that.config.thick/2))/2;
174
- if(!d.data.parsed) d.data.parsed = d;
175
- d.data.width = (d.endAngle - d.startAngle) * r;
176
- d.data.centralRadius = r;
177
- d.data.innerRadius = that.radius * 0.9 * (1 - that.config.thick/2);
178
- d.data.x = Math.sin(a) * r;
179
- d.data.y = -Math.cos(a) * r;
180
- d.data.startAngle = d.startAngle;
181
- d.data.endAngle = d.endAngle;
182
- d.data.padAngle = d.padAngle;
183
- d.data.percent = (parseInt(1000 * d.data.value / sum) / 10) + "%";
184
- });
185
- if(this.config.sort) {
186
- this.parsed.sort(function(a,b) { return b.data.value - a.data.value; });
187
- } else {
188
- this.parsed.sort(function(a,b) { return parseInt(Math.random() * 2 - 1); });
189
- }
190
- if(this.config.thick>1) this.config.thick = 1;
191
- if(this.config.thick<0) this.config.thick = 0;
192
- this.arc = d3.svg.arc()
193
- .innerRadius(function(d,i) { return d.data.innerRadius; })
194
- .outerRadius(this.radius)
195
- .cornerRadius(this.config.boxRoundness);
196
- },
197
- render: function() {
198
- var that = this;
199
- if(this.config.fontFamily) d3.select(this.root).style("font-family", this.config.fontFamily);
200
- d3.select(this.root).style("background-color", this.config.background);
201
- this.svg.selectAll("g.label text, .legend text, g.marker text").attr({
202
- "font-size": that.config.fontSize,
203
- "fill": that.config.textFill
204
- });
205
- (this.pieGroup.attr("transform")
206
- ? this.pieGroup.transition("morph").duration(500)
207
- : this.pieGroup
208
- ).attr({
209
- transform: [
210
- "translate(",
211
- (that.width - this.legendOffset[0] * (this.config.legendPosition == "right" ? 1 : -1 )) / 2,
212
- (that.height - this.legendOffset[1] * (this.config.legendPosition == "bottom" ? 1 : -1 )) / 2,
213
- ")"
214
- ].join(" ")
215
- });
216
- this.pieGroup.selectAll("path.data.pie").attr({
217
- fill: function(d,i) {
218
- return that.cScale(d.data.name);
219
- },
220
- stroke: this.config.stroke,
221
- "stroke-width": this.config.strokeWidth
222
- }).transition("opacity").duration(500).attr({
223
- opacity: function(d,i) {
224
- return (!that.activeGroup || that.activeGroup == d.data.name ? 1 : 0.1);
225
- }
226
- });
227
- this.pieGroup.selectAll("path.data.pie").transition("morph").duration(500).tween("morph", function(d,i) {
228
- var oldAngles = (
229
- this.lastAngles || [d.startAngle,d.startAngle,d.data.innerRadius, d.data.innerRadius]
230
- );
231
- var curAngles = [d.startAngle, d.endAngle, that.radius, d.data.innerRadius];
232
- var node = d3.select(this);
233
- this.lastAngles = curAngles;
234
- return function(t) {
235
- node.attr({
236
- d: that.arc
237
- .startAngle((curAngles[0] - oldAngles[0]) * t + oldAngles[0])
238
- .endAngle((curAngles[1] - oldAngles[1]) * t + oldAngles[1])
239
- .outerRadius((curAngles[2] - oldAngles[2]) * t + oldAngles[2])
240
- .innerRadius((curAngles[3] - oldAngles[3]) * t + oldAngles[3])
241
- });
242
- };
243
- });
244
- var labels = this.pieGroup.selectAll("g.label");
245
- labels.filter(function(d,i) { return !d3.select(this).attr("transform"); }).attr({
246
- transform: function(d,i) {
247
- return ["translate(", d.data.x, d.data.y,")"].join(" ");
248
- }
249
- });
250
- labels.each(function(d,i) {
251
- var node = d3.select(this);
252
- node.selectAll("text").attr({
253
- fill: function(d,i) {
254
- var c = d3.hsl(that.cScale(d.data.name));
255
- return (c.l > 0.6 || (that.config.labelPosition != 'in') ? "#000":"#fff");
256
- },
257
- "font-size": that.config.fontSize,
258
- "text-anchor": "middle",
259
- dy: "0.38em"
260
- }).style({
261
- display: (that.config.labelShow?"block":"none")
262
- }).text(function(d,i) {
263
- return (that.config.showPercent ? d.data.percent : parseInt(100*d.data.value)/100);
264
- });
265
- node.select("text.label.shadow").attr({
266
- stroke: function(d,i) {
267
- var c = d3.hsl(that.cScale(d.data.name));
268
- return (c.l > 0.6 || that.config.labelPosition != 'in' ? "#fff":"#000");
269
- },
270
- "stroke-width": that.config.labelShadowSize,
271
- }).style({
272
- display: (that.config.labelShadowSize && that.config.labelShow ? "block" : "none")
273
- });
274
- if(that.config.fontSize * 2 > d.data.width * 1.5) {
275
- node.selectAll("text").style({display: "none"});
276
- }
277
- })
278
- labels.transition("move").duration(500).attr({
279
- transform: function(d,i) {
280
- return ["translate(", d.data.x, d.data.y,")"].join(" ");
281
- }
282
- });
283
- labels.transition("opacity").duration(500).attr({opacity: 1});
284
- this.pieGroup.selectAll("g.marker").attr({
285
- display: (this.config.legendInline ? "block" : "none")
286
- }).each(function(d,i) {
287
- var node = d3.select(this);
288
- var x1, y1, x2, y2, xm, ym;
289
- var a = (d.startAngle + d.endAngle)/2;
290
- x1 = Math.sin(a) * that.radius;
291
- y1 = -Math.cos(a) * that.radius;
292
- x2 = x1 + (x1 < 0 ? -100 : 100);
293
- y2 = y1 + (y1 < 0 ? -20 : 20);
294
- if(Math.abs(x1) < Math.abs(y1)) {
295
- xm = x1 + (x1 < 0 ? -20 : 20);
296
- ym = y2;
297
- } else {
298
- xm = x2 + (x1 < 0 ? 20 : -20);
299
- ym = y1;
300
- }
301
- node.select("circle").attr({
302
- cx: x1, cy: y1, fill: that.config.legendInlineColor,
303
- r: that.config.legendInlineStrokeWidth * 1.5
304
- });
305
- node.select("circle:last-of-type").attr({
306
- cx: x2, cy: y2, fill: that.config.legendInlineColor,
307
- r: that.config.legendInlineStrokeWidth * 1.5
308
- });
309
- node.select("path").attr({
310
- d: function() {
311
- return [
312
- "M", x1, y1,
313
- "L", xm, ym,
314
- "L", x2, y2
315
- ].join(" ");
316
- },
317
- fill: "none",
318
- stroke: that.config.legendInlineColor,
319
- "stroke-width": that.config.legendInlineStrokeWidth
320
- });
321
- node.select("text").attr({
322
- x: x2, y: y2,
323
- dy: "0.38em",
324
- dx: (x1<0?-0.5:0.5) + "em",
325
- "text-anchor": (x1<0?"end": "start")
326
- }).text(d.data.name);
327
- });
328
- var minus = ["left","top"].indexOf(this.config.legendPosition) >= 0;
329
- var offset = (this.legendVertical
330
- ? [this.width/2 + (this.radius + this.config.fontSize/2 - (minus?-1:1)*this.legendSize[0]/2) * (minus ? -1 : 1),(this.height - this.legendSize[1])/2]
331
- : [(this.width - this.legendSize[0])/2,this.height/2 + (this.radius + this.config.fontSize + (!minus?-this.legendSize[1]:0)) * (minus?-1:1)]
332
- );
333
- this.legendGroup.attr({
334
- transform: ["translate(",offset[0], offset[1], ")"].join(" "),
335
- display: this.config.legendShow ? "block" : "none"
336
- });
337
- }
338
- }
@@ -1,297 +0,0 @@
1
- module.exports =
2
- pkg:
3
- name: 'line', version: '0.0.1'
4
- extend: {name: "base", version: "0.0.1"}
5
- dependencies: []
6
- i18n:
7
- "zh-TW":
8
- "y axis": "Y軸"
9
- "x axis": "X軸"
10
- "rank": "順位"
11
-
12
- init: ({root, context, pubsub, t}) ->
13
- pubsub.fire \init, mod: mod {context, t}
14
-
15
- mod = ({context, t}) ->
16
- {d3,chart,axis,format} = context
17
- sample-count = 4
18
- sample: ->
19
- raw: [0 to 30].map (val) ~>
20
- ret = {}
21
- [1 to sample-count].map (i) -> ret["val#i"] = (i * Math.random! * (10 - Math.abs(10 - val)) + val) >? 0
22
- ret.order = val
23
- ret
24
- binding:
25
- value: [1 to sample-count].map -> {key: "val#it"}
26
- order: {key: \order}
27
- config:
28
- mode: type: \choice, values: <[line area streamgraph bump]>, default: \line
29
- stack: type: \boolean
30
- line: type: \choice, values: <[curve linear]>, default: \linear
31
- show-dot: type: \boolean, default: true
32
- dimension:
33
- value: {type: \R, name: "y axis", multiple: true}
34
- order: {type: \ON, name: "x axis"}
35
- init: ->
36
- svg = d3.select @svg
37
- <[view yaxis xaxis legend]>.map ~> @{}g[it] = d3.select(@layout.get-group(it))
38
- @tint = tint = new chart.utils.tint!
39
- @line = d3.line!
40
- .defined ~>
41
- !isNaN(it.y1)
42
- .x ~> @scale.x it.x
43
- .y ~> @scale.y it.y1
44
- @area = d3.area!
45
- .defined ~>
46
- !isNaN(it.y1) and !isNaN(it.y0)
47
- .x ~> @scale.x it.x
48
- .y0 ~> @scale.y it.y0
49
- .y1 ~> @scale.y it.y1
50
- @xaxis = new chart.utils.axis layout: @layout, name: \xaxis, direction: \bottom
51
- @yaxis = new chart.utils.axis layout: @layout, name: \yaxis, direction: \left
52
- @tip = new chart.utils.tip {
53
- root: @root,
54
- range: ~> return @layout.get-node \view .getBoundingClientRect!
55
- }
56
- @_evthdr = {}
57
- @root.addEventListener \mouseout, @_evthdr.out = (evt) ~> @tip.hide!now!
58
- @root.addEventListener \mousemove, @_evthdr.move = (evt) ~>
59
- x = evt.clientX - @layout.get-node(\view).getBoundingClientRect!x
60
- y = evt.clientY - @layout.get-node(\view).getBoundingClientRect!y
61
- min = {d: -1, p: null, series: null}
62
- for i from 0 til @parsed.length =>
63
- series = @parsed[i]
64
- for j from 0 til series.pts.length =>
65
- p = series.pts[j]
66
- if isNaN(p.y1) or isNaN(p.x) => continue
67
- dx = Math.abs(@scale.x(p.x) - x)
68
- dy = Math.abs(@scale.y(p.y1) - y)
69
- d = (dx ** 2) + (dy ** 2)
70
- if min.d < 0 or min.d > d => min <<< {d, p, series}
71
- if !(min.p and min.d and min.series) => return
72
- bind = min.series.bind
73
- pt = min.p
74
-
75
- data = {
76
- name: """#{if bind => bind.name or bind.key or ''} /
77
- #{pt.data.orderText or pt.data.order or pt.x}#{@binding.order.unit or ''}
78
- """
79
- value: if isNaN(pt.v) => '-' else "#{(pt.v).toFixed(2)}#{if bind => (bind.unit or '') else ''}"
80
- }
81
- box = x: @scale.x(pt.x), y: @scale.y(pt.y)
82
- @tip.render {data, evt: evt, box}
83
-
84
- @legend = new chart.utils.legend do
85
- layout: @layout
86
- root: @root
87
- name: \legend
88
- shape: (d) -> d3.select(@).attr \fill, tint.get d.text
89
- direction: \vertical
90
- cfg: selectable: true
91
- @legend.on \select, ~> @bind!; @resize!; @render!
92
- @scale = { x: d3.scaleLinear!, y: d3.scaleLinear! }
93
-
94
- destroy: ->
95
- @root.removeEventListener \mouseout, @_evthdr.out
96
- @root.removeEventListener \mousemove, @_evthdr.move
97
- @tip.destroy!
98
-
99
- parse: ->
100
- @data.map (d,i) ->
101
- d.order-text = '' + (if !(d.order?) => i else d.order)
102
- d._order = if !(d.order?) or isNaN(+d.order) => i else +d.order
103
- @data.sort (a,b) -> if a._order > b._order => 1 else if a._order == b._order => 0 else -1
104
- @legend.data @binding.value.map -> {key: it.key, text: it.key}
105
-
106
- bind: ->
107
- binds = @binding.value
108
- binds = @binding.value.map((b,i) -> {b, i}).filter (d,i) ~> @legend.is-selected d.b.key
109
-
110
- # if bump
111
- if @cfg.mode == \bump =>
112
- @parsed = []
113
- dd = @data.map (d) ~>
114
- ret = {} <<< d
115
- v = ret.value.map (d,i) ~> {i: i, v: if @legend.is-selected(@binding.value[i].key) => d else NaN}
116
- v.sort (a,b) ->
117
- if isNaN(a.v) and isNaN(b.v) => return 0
118
- else if isNaN(b.v) => return -1
119
- else if isNaN(a.v) => return 1
120
- return b.v - a.v
121
- v.map (d,i) -> d.r = i + 1
122
- v.sort (a,b) -> a.i - b.i
123
- ret.value = v.map -> if isNaN(it.v) => NaN else it.r
124
- ret.original-value = v.map -> it.v
125
- ret
126
-
127
- dd = dd or @data
128
-
129
- if @cfg.mode == \streamgraph =>
130
- sums = dd.map (d) ->
131
- sum = 0
132
- for i from 0 til d.value.length => sum += d.value[i]
133
- sum
134
- [smin, smax] = [Math.min.apply(Math, sums), Math.max.apply(Math, sums)]
135
- else
136
- [sums, smin, smax] = [dd.map(-> 0), 0, 0]
137
- @parsed = []
138
- line0 = dd.map -> 0
139
- for i from 0 til binds.length =>
140
- [p,b] = [(if i > 0 => binds[i - 1] else null), binds[i]]
141
- line1 = dd.map (d,j) -> d.value[b.i] + line0[j]
142
- @parsed.push {
143
- pts: (dd or @data).map (d,j) ->
144
- data: d
145
- y0: line0[j] - (sums[j] / 2) + (smax - smin) / 2
146
- y1: line1[j] - (sums[j] / 2) + (smax - smin) / 2
147
- x: d._order
148
- v: if d.original-value => d.original-value[i] else d.value[i]
149
- bind: b.b
150
- color: b.b.name or b.b.key
151
- }
152
- if (@cfg.stack and @cfg.mode != \bump) or (@cfg.mode in <[streamgraph area]>) => line0 = line1
153
- /*
154
- @parsed = binds.map (b,i) ~>
155
- pts: (dd or @data).map (d,j) ->
156
- data: d
157
- y0: 0
158
- y1: d.value[b.i]
159
- x: d._order
160
- v: if d.original-value => d.original-value[i] else d.value[i]
161
- bind: b.b
162
- color: b.b.name or b.b.key
163
- */
164
- # if stacked
165
- /*
166
- if @cfg.stack =>
167
- ys = @data.map -> it.value.reduce(((a,b)-> a + b),0)
168
- @parsed = []
169
- for i from 0 til binds.length =>
170
- b = binds[i].b
171
- last = @parsed[i - 1] or null
172
- @parsed.push do
173
- pts: @data.map (d,j) ->
174
- y1: (d.value[i] + if !last => 0 else last.pts[j].y1)
175
- y0: if !last => 0 else last.pts[j].y1
176
- x: d._order
177
- v: if d.original-value => d.original-value[i] else d.value[i]
178
- bind: b
179
- color: b.name or b.key
180
- */
181
- resize: ->
182
- @line.curve if @cfg.line == \curve => d3.curveCatmullRom else d3.curveLinear
183
- @area.curve if @cfg.line == \curve => d3.curveCatmullRom else d3.curveLinear
184
- @tip.toggle(if @cfg.{}tip.enabled? => @cfg.tip.enabled else true)
185
- [miny,maxy] = [0,0]
186
- for i from 0 til @parsed.length =>
187
- for j from 0 til @parsed[i].pts.length =>
188
- p = @parsed[i].pts[j]
189
- if !isNaN(p.y0) and miny > p.y0 => miny = p.y0
190
- if !isNaN(p.y1) and miny > p.y1 => miny = p.y1
191
- if !isNaN(p.y0) and maxy < p.y0 => maxy = p.y0
192
- if !isNaN(p.y1) and maxy < p.y1 => maxy = p.y1
193
-
194
- @extent =
195
- x: d3.extent @data, -> (it._order)
196
- y: [(if @cfg.mode == \bump => miny >? 1 else miny), if maxy == miny => miny + 1 else maxy]
197
-
198
- @scale.x.domain @extent.x
199
- @scale.y.domain (if @cfg.mode == \bump => [@extent.y.1, @extent.y.0] else @extent.y)
200
-
201
- [w,h] = [@box.width, @box.height]
202
- max-tick = Math.ceil(@layout.get-box \yaxis .height / 40) >? 2
203
- yticks = if @cfg.mode == \bump => [1 to ((@parsed.length or 1) >? 1)]
204
- else @scale.y.ticks((@cfg.{}yaxis.tick-count or 4) <? max-tick)
205
- yfmt = chart.utils.format.auto yticks
206
-
207
- @legend.config @cfg.legend
208
- @legend.update!
209
-
210
- @yaxis.config @cfg.yaxis
211
- @yaxis.ticks yticks
212
- @yaxis.scale @scale.y
213
- if @cfg.mode == \bump =>
214
- @yaxis.caption t \rank
215
- else
216
- if @parsed.length > 1 =>
217
- units = Array.from(new Set(@parsed.map -> it.bind.unit)).filter -> it
218
- if units.length > 1 => @yaxis.caption('')
219
- else @yaxis.caption( units.0 or '')
220
- else
221
- v = (@parsed.0 or {}).bind or {}
222
- @yaxis.caption( (v.name or v.key or '') + if v.unit => "(#{v.unit})" else '')
223
-
224
- @xaxis.config @cfg.xaxis
225
- @xaxis.ticks @data.map -> {v: it._order, t: it.order-text}
226
- @xaxis.scale @scale.x
227
- @xaxis.caption(
228
- (@binding.order.name or @binding.order.key) +
229
- if @binding.order.unit => "(#{@binding.order.unit})" else ''
230
- )
231
-
232
- # xaxis and yaxis affect each other and they all affect view.
233
- # we may need to update them until stable but for now we simply layout twice.
234
- for i from 0 til 2 =>
235
- @layout.update false
236
- box = @layout.get-box('view')
237
- [w,h] = [box.width, box.height]
238
- @tint.set @cfg.palette
239
- r = @cfg.dot-size or 3
240
- @scale.x.range [0, w - r]
241
- @scale.y.range [h, r]
242
- @xaxis.render!
243
- @yaxis.render!
244
-
245
- render: ->
246
- {scale,tint,extent} = @
247
- r = @cfg.dot-size or 3
248
- vbox = @layout.get-box \view
249
- lbox = @layout.get-box \yaxis
250
- @g.view.selectAll \path.data .data(@parsed, -> it.bind.key)
251
- ..exit!remove!
252
- ..enter!append \path .attr \class, \data
253
- .attr \fill, \none
254
- .attr \d, (d,i) ~>
255
- if @cfg.mode in <[streamgraph area]> => @area d.pts
256
- else @line d.pts
257
- .attr \stroke, (d,i) ~> @tint.get d.color
258
- .attr \stroke-width, 1
259
- @g.view.selectAll \path.data
260
- .transition!duration 150
261
- .style \opacity, (d,i) ~> if @legend.is-selected(d.bind.key) => 1 else 0.3
262
- .attr \d, (d,i) ~>
263
- if @cfg.mode in <[streamgraph area]> => @area d.pts
264
- else @line d.pts
265
- .attr \stroke, (d,i) ~> @tint.get d.color
266
- .attr \fill, (d,i) ~> if @cfg.mode in <[streamgraph area]> => @tint.get(d.color) else \none
267
- .attr \fill-opacity, ~> \0.5
268
- @g.view.selectAll \g.dot .data((if @cfg.show-dot => @parsed else []), -> it.bind.key)
269
- ..exit!remove!
270
- ..enter!append \g .attr \class, \dot
271
- @g.view.selectAll \g.dot
272
- .style \opacity, (d,i) ~> if @legend.is-selected(d.bind.key) => 1 else 0.3
273
- .each (d,i) ->
274
- d3.select(@).selectAll \circle.dot .data d.pts
275
- ..exit!remove!
276
- ..enter!append \circle .attr \class, \dot
277
- .attr \r, r
278
- .attr \fill, \#fff
279
- .attr \stroke, tint.get(d.bind.name or d.bind.key)
280
- d3.select(@).selectAll \circle.dot
281
- .filter (d,i) -> isNaN d.y1
282
- .attr \cx, (d,i) -> if isNaN(scale.x d.x) => scale.x(extent.x.0) else scale.x(d.x)
283
- .attr \cy, (d,i) -> scale.y(extent.y.0)
284
- .transition 150
285
- .attr \opacity, 0
286
- d3.select(@).selectAll \circle.dot
287
- .filter (d,i) -> !isNaN d.y1
288
- .attr \cx, (d,i) -> scale.x d.x
289
- .attr \cy, (d,i) -> scale.y d.y1
290
- .attr \r, r
291
- .attr \fill, tint.get d.color
292
- .attr \stroke, tint.get d.color
293
- .transition 150
294
- .attr \opacity, 1
295
- @legend.render!
296
- @xaxis.render!
297
- @yaxis.render!
@@ -1,33 +0,0 @@
1
- div
2
- div(plug="layout")
3
- .pdl-layout
4
- div(data-type="layout")
5
- .pdl-cell(data-name="yaxis") &nbsp;
6
- .pdl-cell(data-name="view")
7
- .pdl-cell
8
- .pdl-cell(data-name="xaxis") &nbsp;
9
- .pdl-cell(data-name="legend")
10
- div(data-type="render")
11
- style(type="text/css"): :stylus
12
- [data-name=xaxis] { font-size: 0.8em }
13
- [data-name=yaxis] { font-size: 0.8em }
14
- .pdl-layout > div[data-type=layout]
15
- display: grid
16
- grid-template-columns: fit-content(2em) 1fr fit-content(7em)
17
- grid-template-rows: 1fr fit-content(1em)
18
- /* 0.5em for axis label at the boundary */
19
- padding: 0 0.5em
20
- .pdl-cell[data-name=legend]
21
- padding-left: 1em
22
- grid-column: 3
23
- grid-row: 1 / span 2
24
-
25
- .pdl-layout.legend-below > div[data-type=layout]
26
- grid-template-columns: 2em 1fr
27
- grid-template-rows: 1fr fit-content(2em) fit-content(3em)
28
- .pdl-cell[data-name=legend]
29
- padding-top: 1em
30
- grid-column: 1 / span 2
31
- grid-row: 3
32
-
33
- script(type="@plotdb/block"): include:lsc index.ls