@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,86 +0,0 @@
1
- module.exports =
2
- pkg:
3
- name: 'dumbbell', version: '0.0.1'
4
- extend: {name: "base", version: "0.0.1"}
5
- dependencies: []
6
- init: ({root, context, pubsub}) ->
7
- pubsub.fire \init, mod: mod {context}
8
-
9
- mod = ({context}) ->
10
- {d3,ldcolor,debounce,infinite} = context
11
- sample: ->
12
- raw: [0 to 10].map (val) ~>
13
- val1: Math.random! * 0.5 + 0.4
14
- val2: Math.random! * 0.5 + 0.4
15
- val3: Math.random! * 0.6 + 0.1
16
- val4: Math.random! * 0.6 + 0.1
17
- name: val
18
- binding:
19
- name: {key: \name}
20
- y1: [{key: \val1}, {key: \val2}]
21
- y2: [{key: \val3}, {key: \val4}]
22
- config: {}
23
- dimension:
24
- y1: {type: \R, multiple: true, name: "y pos"}
25
- y2: {type: \R, multiple: true, name: "y pos"}
26
- name: {type: \N, name: "dumbbell name"}
27
- init: ->
28
- @infcolor = new infinite!
29
-
30
- parse: ->
31
- @parsed = []
32
- @parsed = @data.map (d,i) ~>
33
- dumbbell = d.y1.map (e,j) ~>
34
- {y1: (d.y1[j] or 0), y2: (d.y2[j] or 0), name: [@binding.y1[j].key, @binding.y2[j].key]}
35
- {name: d.name, dumbbell}
36
- @names = @data.map -> it.name
37
-
38
-
39
- resize: ->
40
- [w,h] = [@box.width, @box.height]
41
- @extent =
42
- y: [
43
- d3.min(@data.map (d,i) -> d3.min([d3.min(d.y1), d3.min(d.y2)])),
44
- d3.max(@data.map (d,i) -> d3.max([d3.max(d.y1), d3.max(d.y2)]))
45
- ]
46
- @scale =
47
- x: d3.scaleBand!domain(@names).range [0,w] .paddingInner 0.3
48
- y: d3.scaleLinear!domain([0,@extent.y.1]).range [0,h]
49
- c: d3.scaleOrdinal(d3.schemeCategory10)
50
- if @cfg? and @cfg.palette => @scale.c = d3.scaleOrdinal(@cfg.palette.colors.map -> ldcolor.web(it.value or it))
51
- if @cfg? and @cfg.palette => @infcolor.set-colors(@cfg.palette.colors.map -> ldcolor.web(it.value or it))
52
-
53
- render: ->
54
- {scale,infcolor} = @
55
- svg = d3.select @svg
56
- svg.selectAll \g.data .data @parsed
57
- ..exit!remove!
58
- ..enter!append \g .attr \class, \data
59
- svg.selectAll \g.data
60
- .each (e,j) ->
61
- bw = scale.x.bandwidth!
62
- n = d3.select(@)
63
- n.selectAll \g.dumbbell .data e.dumbbell
64
- ..exit!remove!
65
- ..enter!append \g .attr \class, \dumbbell
66
- n.selectAll \g.dumbbell
67
- .each (f,k) ->
68
- m = d3.select(@)
69
- m.selectAll \circle .data [1,2]
70
- ..exit!remove!
71
- ..enter!append \circle
72
- m.selectAll \line .data [0]
73
- ..exit!remove!
74
- ..enter!append \line
75
- m.selectAll \circle
76
- .attr \cx, (d,i) -> scale.x(e.name) + bw * i
77
- .attr \cy, (d,i) -> scale.y f["y#d"]
78
- .attr \r, 2
79
- .attr \fill, -> infcolor.get(f.name.0)
80
- m.selectAll \line
81
- .attr \x1, (d,i) -> scale.x(e.name)
82
- .attr \x2, (d,i) -> scale.x(e.name) + bw
83
- .attr \y1, (d,i) -> scale.y f.y1
84
- .attr \y2, (d,i) -> scale.y f.y2
85
- .attr \stroke, -> infcolor.get(f.name.0)
86
- .attr \stroke-width, 1
@@ -1 +0,0 @@
1
- div: script(type="@plotdb/block"): include:lsc index.ls
@@ -1,28 +0,0 @@
1
- module.exports =
2
- pkg:
3
- name: 'empty', version: '0.0.1'
4
- dependencies: [
5
- {url: "/assets/lib/@loadingio/debounce.js/main/debounce.min.js"}
6
- {url: "/assets/lib/wrap-svg-text/main/index.min.js", async: false}
7
- {url: "/assets/lib/@plotdb/layout/main/index.min.js", async: false}
8
- {url: "/assets/lib/@plotdb/layout/main/index.min.css", type: \css}
9
- {url: "/assets/lib/ldcolor/main/ldcolor.min.js", async: false}
10
- {url: "/assets/lib/@plotdb/chart/main/chart.js", async: false}
11
- {url: "/assets/lib/@plotdb/chart/main/chart.min.css", type: \css}
12
- {url: "/assets/lib/@plotdb/chart/main/utils/legend.js", async: false}
13
- {url: "/assets/lib/@plotdb/chart/main/utils/legend.css", type: \css}
14
- {url: "/assets/lib/@plotdb/chart/main/utils/tint.js", async: false}
15
- {url: "/assets/lib/@plotdb/chart/main/utils/data.js", async: false}
16
- ]
17
-
18
- init: ({root, context, pubsub, data}) ->
19
- {chart} = context
20
- pubsub.on \init, (opt = {}) ~>
21
- opt = {root, delay-render: true} <<< opt
22
- @chart = c = new chart(opt <<< {prepare-svg: false, layout: false} <<< data)
23
- c.init!then -> c
24
- @
25
-
26
- interface: -> @chart
27
-
28
- mod: (root) -> {config: {}, dimension: {}, init: (->), resize: (->), render: (->)}
@@ -1,2 +0,0 @@
1
- div(style="width:100%;height:100%")
2
- script(type="@plotdb/block"): include:lsc index.ls
@@ -1,96 +0,0 @@
1
- module.exports =
2
- pkg:
3
- name: 'gauge', version: '0.0.1'
4
- extend: {name: "base", version: "0.0.1"}
5
- dependencies: []
6
-
7
- init: ({root, context, pubsub}) ->
8
- pubsub.fire \init, mod: mod {context}
9
-
10
- mod = ({context}) ->
11
- {d3,chart} = context
12
- sample: ->
13
- raw: [{value: Math.random!, max: 1}]
14
- binding:
15
- value: {key: \value}
16
- max: {key: \max}
17
- config: {}
18
- dimension:
19
- value: {type: \R, name: "value"}
20
- max: {type: \R, name: "max"}
21
- init: ->
22
-
23
- @tint = tint = new chart.utils.tint!
24
-
25
- @arc = d3.arc!
26
-
27
- @g =
28
- view: d3.select @layout.get-group \view
29
- number: d3.select @layout.get-group \number
30
- unit: d3.select @layout.get-group \unit
31
-
32
- parse: ->
33
- @g.view.selectAll \path.wedge .data [0,1]
34
- ..exit!remove!
35
- ..enter!append \path .attr \class, \wedge
36
- @g.view.selectAll \path.pin .data [0]
37
- ..exit!remove!
38
- ..enter!append \path .attr \class, \pin
39
- @g.view.selectAll \citcle .data [0]
40
- ..exit!remove!
41
- ..enter!append \circle
42
- @g.number.selectAll \text .data [0]
43
- ..exit!remove!
44
- ..enter!append \text
45
- @g.unit.selectAll \text .data [0]
46
- ..exit!remove!
47
- ..enter!append \text
48
-
49
- resize: ->
50
-
51
- n = @layout.get-node \view
52
- b = @layout.get-box \view
53
- n.style
54
- ..width = "#{b.height}px"
55
- @layout.update false
56
-
57
-
58
- render: ->
59
- if @cfg? and @cfg.palette => @tint.set(@cfg.palette.colors.map -> it.value or it)
60
- d = @data.0 or {}
61
- percent = ((d.value or 0) / (d.max or 1)) <? 1 >? 0
62
- angle = percent * ( Math.PI * 6 / 4 ) + Math.PI / 4
63
- start = Math.PI / 4
64
- end = Math.PI * 7 / 4
65
- box = @layout.get-box \view
66
- size = (Math.min box.width, box.height) / 2
67
- @arc
68
- .innerRadius size * 0.5
69
- .outerRadius size
70
-
71
- offset = size * (1 - (1/Math.sqrt(2))) / 2
72
-
73
- @g.view.selectAll \path.wedge
74
- .attr \transform, "translate(#{box.width/2},#{offset + box.height/2}) rotate(180)"
75
- .attr \d, (d,i) ~>
76
- @arc
77
- .startAngle if i == 0 => start else angle
78
- .endAngle if i == 0 => angle else end
79
- @arc!
80
- .attr \fill, (d,i) ~> @tint.get d
81
-
82
- @g.view.selectAll \path.pin
83
- .attr \transform, "translate(#{box.width/2} #{offset + box.height/2}) rotate(#{45 + (270 * percent)})"
84
- .attr \d, "M0 #{size * 0.4}L0 #{size}"
85
- .attr \fill, \none
86
- .attr \stroke, \#000
87
- .attr \stroke-width, 2
88
-
89
- @g.number.selectAll \text
90
- .text -> 3000
91
- .attr \font-size, 24
92
- .attr \dominant-baseline, \hanging
93
-
94
- @g.unit.selectAll \text
95
- .text -> "新臺幣"
96
- .attr \dominant-baseline, \hanging
@@ -1,31 +0,0 @@
1
- div
2
- div(plug="layout")
3
- .pdl-layout
4
- div(data-type="layout")
5
- .pdl-cell(data-name="view")
6
- div.text
7
- .pdl-cell(data-name="number") 0000
8
- .pdl-cell(data-name="unit") 0000
9
- div(data-type="render")
10
- style(type="text/css"): :stylus
11
- .pdl-layout > div[data-type=layout]
12
- display: flex
13
- justify-content: center
14
- align-items: center
15
- .text
16
- margin-left: .5em
17
- height: 100%
18
- display: flex
19
- flex-direction: column
20
- justify-content: center
21
- align-items: start
22
- [data-name=view]
23
- height: 100%
24
- [data-name=number]
25
- font-size: 24px
26
- line-height: 1em
27
- [data-name=unit]
28
- line-height: 1em
29
-
30
-
31
- script(type="@plotdb/block"): include:lsc index.ls