@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,138 @@
1
+ (function(){
2
+ var tint;
3
+ tint = function(opt){
4
+ opt == null && (opt = {});
5
+ this.isUnique = opt.unique != null ? opt.unique : true;
6
+ this.map = {};
7
+ this.nmap = [];
8
+ this.wm = new WeakMap();
9
+ this.count = 0;
10
+ this.set(opt.palette) || opt.colors;
11
+ return this;
12
+ };
13
+ tint['default'] = ['#e15c64', '#f7b26a', '#f3ed9d', '#a4bd81', '#a0d7d2', '#8db1da', '#daaedb'];
14
+ tint.prototype = import$(Object.create(Object.prototype), {
15
+ set: function(pal, reset){
16
+ var ref$, this$ = this;
17
+ pal == null && (pal = []);
18
+ reset == null && (reset = false);
19
+ this.colors = Array.isArray(pal) && pal.length
20
+ ? pal
21
+ : pal.colors && Array.isArray(pal.colors)
22
+ ? pal.colors
23
+ : tint['default'];
24
+ this.nmap = pal.maps || [];
25
+ this.colors = this.colors.map(function(it){
26
+ return it.value || it;
27
+ });
28
+ if (this.colors.length === 1) {
29
+ this.colors.push(ldcolor.complement(this.colors[0]));
30
+ }
31
+ this.colors = this.colors.map(function(it){
32
+ return ldcolor.hsl(it);
33
+ });
34
+ this.len = (ref$ = this.colors.length) > 2 ? ref$ : 2;
35
+ if (reset) {
36
+ return this.reset();
37
+ } else {
38
+ return this.nmap.map(function(d, i){
39
+ return (Array.isArray(d)
40
+ ? d
41
+ : [d]).map(function(it){
42
+ return this$.get(it, 0, i);
43
+ });
44
+ });
45
+ }
46
+ },
47
+ unique: function(it){
48
+ return it != null
49
+ ? this.isUnique = !!it
50
+ : this.isUnique;
51
+ },
52
+ reset: function(){
53
+ var this$ = this;
54
+ this.map = {};
55
+ this.wm = new WeakMap();
56
+ this.count = 0;
57
+ return (this.nmap || []).map(function(d, i){
58
+ return (Array.isArray(d)
59
+ ? d
60
+ : [d]).map(function(it){
61
+ return this$.get(it, 0, i);
62
+ });
63
+ });
64
+ },
65
+ get: function(data, variant, idx){
66
+ var val, seg, pos, ref$, fz, fm, c1, c2, h, s, l, ret;
67
+ variant == null && (variant = 0);
68
+ if (idx != null) {
69
+ if (this.count < idx) {
70
+ this.count = idx + 1;
71
+ }
72
+ val = idx % this.len;
73
+ if (typeof data === 'object') {
74
+ this.wm.set(data, val);
75
+ } else {
76
+ this.map[data] = val;
77
+ }
78
+ } else {
79
+ if (typeof data === 'object') {
80
+ if ((val = this.wm.get(data)) == null) {
81
+ this.wm.set(data, val = this.count++);
82
+ }
83
+ } else if ((val = this.map[data]) == null) {
84
+ this.map[data] = val = this.count++;
85
+ }
86
+ if (!this.isUnique) {
87
+ val = val % this.len;
88
+ }
89
+ }
90
+ if (val >= this.len) {
91
+ seg = val % (this.len - 1);
92
+ pos = Math.floor(val / (this.len - 1));
93
+ ref$ = [0, 1], fz = ref$[0], fm = ref$[1];
94
+ while (pos > 0) {
95
+ ref$ = [fz * 2, fm * 2], fz = ref$[0], fm = ref$[1];
96
+ if (pos % 2) {
97
+ fz += 1;
98
+ }
99
+ pos = pos >> 1;
100
+ }
101
+ pos = fz / fm;
102
+ ref$ = [this.colors[seg], this.colors[seg + 1]], c1 = ref$[0], c2 = ref$[1];
103
+ ref$ = ['h', 's', 'l'].map(function(k){
104
+ return pos * (c2[k] - c1[k]) + c1[k];
105
+ }), h = ref$[0], s = ref$[1], l = ref$[2];
106
+ ret = {
107
+ h: h,
108
+ s: s,
109
+ l: l
110
+ };
111
+ } else {
112
+ ret = this.colors[val];
113
+ }
114
+ if (variant > 0) {
115
+ ret = ldcolor.lighter(ret, variant);
116
+ } else if (variant < 0) {
117
+ ret = ldcolor.darker(ret, -variant);
118
+ }
119
+ return ldcolor.web(ret);
120
+ },
121
+ text: function(v, opt){
122
+ var hcl;
123
+ opt == null && (opt = {});
124
+ hcl = ldcolor.hcl(this.get(v));
125
+ return ldcolor.web(hcl.l > 50
126
+ ? opt.textDark || '#000'
127
+ : opt.textLight || '#fff');
128
+ }
129
+ });
130
+ if (typeof chart != 'undefined' && chart !== null) {
131
+ (chart.utils || (chart.utils = {})).tint = tint;
132
+ }
133
+ function import$(obj, src){
134
+ var own = {}.hasOwnProperty;
135
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
136
+ return obj;
137
+ }
138
+ }).call(this);
@@ -0,0 +1 @@
1
+ (function(){var tint;tint=function(opt){opt==null&&(opt={});this.isUnique=opt.unique!=null?opt.unique:true;this.map={};this.nmap=[];this.wm=new WeakMap;this.count=0;this.set(opt.palette)||opt.colors;return this};tint["default"]=["#e15c64","#f7b26a","#f3ed9d","#a4bd81","#a0d7d2","#8db1da","#daaedb"];tint.prototype=import$(Object.create(Object.prototype),{set:function(pal,reset){var ref$,this$=this;pal==null&&(pal=[]);reset==null&&(reset=false);this.colors=Array.isArray(pal)&&pal.length?pal:pal.colors&&Array.isArray(pal.colors)?pal.colors:tint["default"];this.nmap=pal.maps||[];this.colors=this.colors.map(function(it){return it.value||it});if(this.colors.length===1){this.colors.push(ldcolor.complement(this.colors[0]))}this.colors=this.colors.map(function(it){return ldcolor.hsl(it)});this.len=(ref$=this.colors.length)>2?ref$:2;if(reset){return this.reset()}else{return this.nmap.map(function(d,i){return(Array.isArray(d)?d:[d]).map(function(it){return this$.get(it,0,i)})})}},unique:function(it){return it!=null?this.isUnique=!!it:this.isUnique},reset:function(){var this$=this;this.map={};this.wm=new WeakMap;this.count=0;return(this.nmap||[]).map(function(d,i){return(Array.isArray(d)?d:[d]).map(function(it){return this$.get(it,0,i)})})},get:function(data,variant,idx){var val,seg,pos,ref$,fz,fm,c1,c2,h,s,l,ret;variant==null&&(variant=0);if(idx!=null){if(this.count<idx){this.count=idx+1}val=idx%this.len;if(typeof data==="object"){this.wm.set(data,val)}else{this.map[data]=val}}else{if(typeof data==="object"){if((val=this.wm.get(data))==null){this.wm.set(data,val=this.count++)}}else if((val=this.map[data])==null){this.map[data]=val=this.count++}if(!this.isUnique){val=val%this.len}}if(val>=this.len){seg=val%(this.len-1);pos=Math.floor(val/(this.len-1));ref$=[0,1],fz=ref$[0],fm=ref$[1];while(pos>0){ref$=[fz*2,fm*2],fz=ref$[0],fm=ref$[1];if(pos%2){fz+=1}pos=pos>>1}pos=fz/fm;ref$=[this.colors[seg],this.colors[seg+1]],c1=ref$[0],c2=ref$[1];ref$=["h","s","l"].map(function(k){return pos*(c2[k]-c1[k])+c1[k]}),h=ref$[0],s=ref$[1],l=ref$[2];ret={h:h,s:s,l:l}}else{ret=this.colors[val]}if(variant>0){ret=ldcolor.lighter(ret,variant)}else if(variant<0){ret=ldcolor.darker(ret,-variant)}return ldcolor.web(ret)},text:function(v,opt){var hcl;opt==null&&(opt={});hcl=ldcolor.hcl(this.get(v));return ldcolor.web(hcl.l>50?opt.textDark||"#000":opt.textLight||"#fff")}});if(typeof chart!="undefined"&&chart!==null){(chart.utils||(chart.utils={})).tint=tint}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}}).call(this);
@@ -0,0 +1,148 @@
1
+ (function(){
2
+ var tip, ref$;
3
+ tip = function(opt){
4
+ var ref$, this$ = this;
5
+ opt == null && (opt = {});
6
+ this.root = typeof opt.root === 'string'
7
+ ? document.querySelector(opt.root)
8
+ : opt.root;
9
+ this.tip = typeof opt.node === 'string'
10
+ ? this.root.querySelector(opt.node)
11
+ : opt.node;
12
+ this.margin = opt.margin != null ? opt.margin : 10;
13
+ this.type = opt.type === 'over' ? 'over' : 'move';
14
+ this.accessor = opt.accessor;
15
+ this.range = opt.range;
16
+ this.zmgr = opt.zmgr;
17
+ this._z = 0;
18
+ this.enabled = true;
19
+ if (!this.tip) {
20
+ this.tip = document.createElement('div');
21
+ this.tip.innerHTML = "<div ld=\"name\" style=\"font-size:.85em\"></div>\n<div ld=\"value\" style=\"font-weight:bold;font-size:1.1em;line-height:1.2em\"></div>";
22
+ this.root.appendChild(this.tip);
23
+ ref$ = this.tip.style;
24
+ ref$.padding = '.4em .5em';
25
+ ref$.background = '#13171a';
26
+ ref$.color = '#fff';
27
+ ref$.borderRadius = '3px';
28
+ ref$.boxShadow = '0 2px 4px rgba(0,0,0,.3)';
29
+ ref$.lineHeight = '1.2em';
30
+ ref$.fontSize = '.9em';
31
+ ref$.maxWidth = "10em";
32
+ ref$.wordBreak = "break-all";
33
+ }
34
+ ref$ = this.tip.style;
35
+ ref$.position = 'absolute';
36
+ ref$.zIndex = 1;
37
+ ref$.top = 0;
38
+ ref$.left = 0;
39
+ ref$.pointerEvents = 'none';
40
+ ref$.userSelect = 'none';
41
+ ref$.opacity = 0;
42
+ ref$.transition = 'opacity .15s ease-in-out' + (this.type === 'over' ? ', transform .15s ease-in-out' : '');
43
+ this.view = new ldview({
44
+ root: this.tip,
45
+ text: opt.view || {
46
+ name: function(arg$){
47
+ var ctx;
48
+ ctx = arg$.ctx;
49
+ if (ctx) {
50
+ return ctx.name;
51
+ } else {
52
+ return '';
53
+ }
54
+ },
55
+ value: function(arg$){
56
+ var ctx;
57
+ ctx = arg$.ctx;
58
+ if (ctx) {
59
+ return ctx.value;
60
+ } else {
61
+ return '';
62
+ }
63
+ }
64
+ }
65
+ });
66
+ this.hide = debounce(3000, function(){
67
+ this.tip.style.opacity = 0;
68
+ if (this.zmgr) {
69
+ return this.zmgr.remove(this._z);
70
+ }
71
+ });
72
+ this._evthdr = {};
73
+ if (this.accessor) {
74
+ this.root.addEventListener(this.type === 'over' ? 'mouseover' : 'mousemove', this._evthdr.over = function(e){
75
+ var data;
76
+ if (!(e.target && (data = this$.accessor({
77
+ evt: e
78
+ })))) {
79
+ return;
80
+ }
81
+ return this$.render({
82
+ data: data,
83
+ node: e.target,
84
+ evt: e
85
+ });
86
+ });
87
+ this.root.addEventListener('mouseout', this._evthdr.out = function(){
88
+ return this$.hide().now();
89
+ });
90
+ }
91
+ return this;
92
+ };
93
+ tip.prototype = (ref$ = Object.create(Object.prototype), ref$.destroy = function(){
94
+ if (this._evthdr.over) {
95
+ this.root.removeEventListener(this.type === 'over' ? 'mouseover' : 'mousemove', this._evthdr.over);
96
+ }
97
+ if (this._evthdr.out) {
98
+ return this.root.removeEventListener('mouseout', this._evthdr.out);
99
+ }
100
+ }, ref$.toggle = function(it){
101
+ return !(it != null)
102
+ ? this.enabled
103
+ : this.enabled = it;
104
+ }, ref$.render = function(opt){
105
+ var rbox, nbox, ret, tbox, ref$, mx, my, m, nx, ny, tx, ty, rangeBox, ref1$, ref2$;
106
+ opt == null && (opt = {});
107
+ if (!this.enabled) {
108
+ return;
109
+ }
110
+ this.view.setCtx(opt.data);
111
+ this.view.render();
112
+ rbox = this.root.getBoundingClientRect();
113
+ nbox = opt.node != null
114
+ ? (ret = opt.node.getBoundingClientRect(), ret.x = ret.x - rbox.x, ret.y = ret.y - rbox.y, ret)
115
+ : opt.box != null
116
+ ? opt.box
117
+ : {
118
+ x: opt.x,
119
+ y: opt.y,
120
+ width: opt.width,
121
+ height: opt.height
122
+ };
123
+ tbox = this.tip.getBoundingClientRect();
124
+ ref$ = [opt.evt.clientX - rbox.x, opt.evt.clientY - rbox.y], mx = ref$[0], my = ref$[1];
125
+ m = this.margin;
126
+ ref$ = [nbox.x + (nbox.width != null ? nbox.width / 2 : 0), nbox.y + (nbox.height != null ? nbox.height / 2 : 0)], nx = ref$[0], ny = ref$[1];
127
+ ref$ = [mx - tbox.width / 2, my - tbox.height / 2], tx = ref$[0], ty = ref$[1];
128
+ ref$ = [
129
+ tx + (nx < mx
130
+ ? 1
131
+ : -1) * (m + tbox.width / 2), ty + (ny < my
132
+ ? 1
133
+ : -1) * (m + tbox.height / 2)
134
+ ], tx = ref$[0], ty = ref$[1];
135
+ rangeBox = this.range ? rangeBox = this.range() : rbox;
136
+ ref$ = [((ref$ = (tx > (ref2$ = rangeBox.x - rbox.x) ? tx : ref2$) + tbox.width) < (ref1$ = rangeBox.width + rangeBox.x - rbox.x) ? ref$ : ref1$) - tbox.width, ((ref$ = (ty > (ref2$ = rangeBox.y - rbox.y) ? ty : ref2$) + tbox.height) < (ref1$ = rangeBox.height + rangeBox.y - rbox.y) ? ref$ : ref1$) - tbox.height], tx = ref$[0], ty = ref$[1];
137
+ ref$ = this.tip.style;
138
+ ref$.transform = "translate(" + tx + "px," + ty + "px)";
139
+ ref$.opacity = 1;
140
+ ref$.zIndex = this._z = !this.zmgr
141
+ ? 10
142
+ : this.zmgr.add(10);
143
+ return this.hide();
144
+ }, ref$);
145
+ if (typeof chart != 'undefined' && chart !== null) {
146
+ (chart.utils || (chart.utils = {})).tip = tip;
147
+ }
148
+ }).call(this);
@@ -0,0 +1 @@
1
+ (function(){var tip,ref$;tip=function(opt){var ref$,this$=this;opt==null&&(opt={});this.root=typeof opt.root==="string"?document.querySelector(opt.root):opt.root;this.tip=typeof opt.node==="string"?this.root.querySelector(opt.node):opt.node;this.margin=opt.margin!=null?opt.margin:10;this.type=opt.type==="over"?"over":"move";this.accessor=opt.accessor;this.range=opt.range;this.zmgr=opt.zmgr;this._z=0;this.enabled=true;if(!this.tip){this.tip=document.createElement("div");this.tip.innerHTML='<div ld="name" style="font-size:.85em"></div>\n<div ld="value" style="font-weight:bold;font-size:1.1em;line-height:1.2em"></div>';this.root.appendChild(this.tip);ref$=this.tip.style;ref$.padding=".4em .5em";ref$.background="#13171a";ref$.color="#fff";ref$.borderRadius="3px";ref$.boxShadow="0 2px 4px rgba(0,0,0,.3)";ref$.lineHeight="1.2em";ref$.fontSize=".9em";ref$.maxWidth="10em";ref$.wordBreak="break-all"}ref$=this.tip.style;ref$.position="absolute";ref$.zIndex=1;ref$.top=0;ref$.left=0;ref$.pointerEvents="none";ref$.userSelect="none";ref$.opacity=0;ref$.transition="opacity .15s ease-in-out"+(this.type==="over"?", transform .15s ease-in-out":"");this.view=new ldview({root:this.tip,text:opt.view||{name:function(arg$){var ctx;ctx=arg$.ctx;if(ctx){return ctx.name}else{return""}},value:function(arg$){var ctx;ctx=arg$.ctx;if(ctx){return ctx.value}else{return""}}}});this.hide=debounce(3e3,function(){this.tip.style.opacity=0;if(this.zmgr){return this.zmgr.remove(this._z)}});this._evthdr={};if(this.accessor){this.root.addEventListener(this.type==="over"?"mouseover":"mousemove",this._evthdr.over=function(e){var data;if(!(e.target&&(data=this$.accessor({evt:e})))){return}return this$.render({data:data,node:e.target,evt:e})});this.root.addEventListener("mouseout",this._evthdr.out=function(){return this$.hide().now()})}return this};tip.prototype=(ref$=Object.create(Object.prototype),ref$.destroy=function(){if(this._evthdr.over){this.root.removeEventListener(this.type==="over"?"mouseover":"mousemove",this._evthdr.over)}if(this._evthdr.out){return this.root.removeEventListener("mouseout",this._evthdr.out)}},ref$.toggle=function(it){return!(it!=null)?this.enabled:this.enabled=it},ref$.render=function(opt){var rbox,nbox,ret,tbox,ref$,mx,my,m,nx,ny,tx,ty,rangeBox,ref1$,ref2$;opt==null&&(opt={});if(!this.enabled){return}this.view.setCtx(opt.data);this.view.render();rbox=this.root.getBoundingClientRect();nbox=opt.node!=null?(ret=opt.node.getBoundingClientRect(),ret.x=ret.x-rbox.x,ret.y=ret.y-rbox.y,ret):opt.box!=null?opt.box:{x:opt.x,y:opt.y,width:opt.width,height:opt.height};tbox=this.tip.getBoundingClientRect();ref$=[opt.evt.clientX-rbox.x,opt.evt.clientY-rbox.y],mx=ref$[0],my=ref$[1];m=this.margin;ref$=[nbox.x+(nbox.width!=null?nbox.width/2:0),nbox.y+(nbox.height!=null?nbox.height/2:0)],nx=ref$[0],ny=ref$[1];ref$=[mx-tbox.width/2,my-tbox.height/2],tx=ref$[0],ty=ref$[1];ref$=[tx+(nx<mx?1:-1)*(m+tbox.width/2),ty+(ny<my?1:-1)*(m+tbox.height/2)],tx=ref$[0],ty=ref$[1];rangeBox=this.range?rangeBox=this.range():rbox;ref$=[((ref$=(tx>(ref2$=rangeBox.x-rbox.x)?tx:ref2$)+tbox.width)<(ref1$=rangeBox.width+rangeBox.x-rbox.x)?ref$:ref1$)-tbox.width,((ref$=(ty>(ref2$=rangeBox.y-rbox.y)?ty:ref2$)+tbox.height)<(ref1$=rangeBox.height+rangeBox.y-rbox.y)?ref$:ref1$)-tbox.height],tx=ref$[0],ty=ref$[1];ref$=this.tip.style;ref$.transform="translate("+tx+"px,"+ty+"px)";ref$.opacity=1;ref$.zIndex=this._z=!this.zmgr?10:this.zmgr.add(10);return this.hide()},ref$);if(typeof chart!="undefined"&&chart!==null){(chart.utils||(chart.utils={})).tip=tip}}).call(this);
package/doc/charts.md ADDED
@@ -0,0 +1,58 @@
1
+ # Charts to be implemented
2
+
3
+ Here we list some charts that we expected to support:
4
+
5
+ - bar types
6
+ - bar
7
+ - stacked bar
8
+ - dancing stacked bar
9
+ - grouped bar
10
+ - 100% stacked bar
11
+ - split bar
12
+ - column chart variation for all above bars
13
+ - line types
14
+ - line
15
+ - stacked area
16
+ - overlapped area
17
+ - parallel coordinates
18
+ - bump
19
+ - map types
20
+ - taiwantown ( choropleth )
21
+ - taiwanvillage ( choropleth )
22
+ - worldmap ( choropleth )
23
+ - 3d global ( choropleth )
24
+ - event based chart for above charts
25
+ - cartogram / dorling cartogram for above charts
26
+ - bubble types
27
+ - bubble
28
+ - axis-bubble
29
+ - pie-bubble
30
+ - pie types
31
+ - pie
32
+ - donut
33
+ - sunburst
34
+ - treemap type
35
+ - voronoi-treemap
36
+ - treemap
37
+ - length type
38
+ - dumbbell
39
+ - vertical dumbbell
40
+ - horizontal dumbbell
41
+ - slopegraph
42
+ - grouped slopegraph
43
+ - sankey type
44
+ - sankey chart
45
+ - chord chart
46
+ - sankey chord
47
+ - radial type
48
+ - radar chart
49
+ - curve bar
50
+ - other types
51
+ - themeriver
52
+ - wordcloud
53
+ - violin chart
54
+ - combo chart
55
+ - scatter type
56
+ - scatter chart
57
+ - voronoi diagram
58
+ - hexagonal bining
package/doc/config.md ADDED
@@ -0,0 +1,44 @@
1
+ # configuration
2
+
3
+ common configurations for charts.
4
+
5
+ ## common / generic ( consider align with common CSS styles? )
6
+
7
+ - margin
8
+ - font-size
9
+ - font-family
10
+ - background-color
11
+ - color
12
+ - palette
13
+
14
+
15
+ ## font
16
+
17
+ - size
18
+ - family
19
+
20
+
21
+ ## axis
22
+
23
+ - axis-tick
24
+ - axis-tick-size-inner
25
+ - axis-tick-size-outer
26
+ - axis-tick-padding
27
+ - axis-tick-count
28
+ - axis-tick-format
29
+
30
+ ## legend
31
+
32
+ - enabled
33
+ - selectable
34
+
35
+
36
+ ## axis
37
+
38
+ - enabled
39
+
40
+
41
+ ## tip
42
+
43
+ - enabled
44
+
@@ -0,0 +1,146 @@
1
+ # Chart Object
2
+
3
+ To use a chart definition, construct it with `chart` constructor:
4
+
5
+ mychart = new chart({
6
+ root: containerElement
7
+ mod: myChartDefinition
8
+ })
9
+
10
+ By above code, `@plotdb/chart` will construct a chart object with mod defined by `myChartDefinition`, and render it in `containerElement`. Further operations and chart controls are all throught the returned `mychart` object.
11
+
12
+
13
+ ## Constructor Options
14
+
15
+ - `root`: chart container
16
+ - `mod`: the chart definition object. see `definition.md` section.
17
+ - `config`: config definition in `@plotdb/konfig` spec.
18
+ - Config object constructed according this is available as `this.cfg` in chart definition functions.
19
+ - `raw`: raw data. optional and can be set later. see `data.md` section.
20
+ - `binding`: an object that maps between dimensions of a chart and data. see `data.md` section.
21
+ - `hash key`: chart dimension
22
+ - `hash val`: mapping data, either a single object or an array of objects which is defined as:
23
+ - `key`: field key of data in `raw`
24
+ - `name`: field name corresponding to the key. optional
25
+ - `unit`: unit of this field. optional
26
+ - `dataAccessor(node)`: data accessor function. return `node.data._raw` by default, if omitted.
27
+ - `node`: DOM element ( focused, clicked, or any reason when we need the data for certain element )
28
+ - should return the raw data object bound to this element, if any, otherwise null.
29
+ - used to get data set by chart definition, making it easier to communicate between charts and application.
30
+ - see `autoSelect` option for more information.
31
+ - `layout`: add a `@plotdb/layout` object if set to true. default true.
32
+ - can be either true, false or a layout object.
33
+ - false: don't create a layout object automatically.
34
+ - true: automatically create a layout object with default options.
35
+ - constructued layout looks up `.pdb-layout` under `root` of this chart for the root of layout.
36
+ - object: create a `@plotdb/layout` object with this object as custom options
37
+ - `prepareSvg`: when true, automatically add an SVG object, if none is available under `root`. default true.
38
+ - `delayRender`: set true to prevent chart from rendering until `setRaw` is called. default false
39
+ - `useSample`: use sample data if no data provided. default true.
40
+ - `autoSelect`: whether to automatically fire `select` / `hover` events. default true.
41
+ - when true, it automatically handles select related events with following steps:
42
+ - watch hovered / selected events from users' interaction with elements having `data` class.
43
+ - when triggered, pass the target node to `dataAccessor` to get bound data.
44
+ - pass data through `select` and `hover` events.
45
+ - `forceInit`: default false.
46
+ - by default, `init` only called after the first `resize` call. set true to force `init` before `resize`.
47
+ - sometimes `resize` won't be called until root is visible. `forceInit` can be used to bypass this limitation.
48
+
49
+
50
+ Here is a sample chart construction code, with chart definition:
51
+
52
+ mychart = new chart({
53
+ root: document.body,
54
+ data: [{name: "hello"}],
55
+ binding: {name: {key: "name"}}
56
+ mod: {
57
+ render: function() {
58
+ this.root.innerText = this.data[0].name;
59
+ }
60
+ }
61
+ });
62
+ mychart.render();
63
+
64
+
65
+ ## API
66
+
67
+ once constructed, the chart object provides following members internally to chart definition:
68
+
69
+ - `root`: root element
70
+ - `svg`: main svg under root element.
71
+ - `box`: {x,y,widht,height} dimension info for `svg` node. update when resize.
72
+ - `raw`: raw data from user.
73
+ - `binding`: definition of how raw data should be bound to chart.
74
+ - `data`: mapped data from `raw` for rendering according to `binding`, with:
75
+ - basic format normalization
76
+ - additional fields `_idx` and `_raw`:
77
+ - `_idx`: order of this item in the list
78
+ - `_raw`: original item in raw data
79
+ - `seed`: (TBD) a seed for random number generator.
80
+
81
+ and following members externally for user:
82
+
83
+ - `init()`: init this chart. guaranteed to be executed only once even with multiple calls.
84
+ - the overall init process involves following methods and will be taken care by `Chart.init`:
85
+ - `init` → `parse` → `bind` → `resize` → `render`
86
+ - `destroy()`: destroy this chart.
87
+ - `parse()`: parse `raw` into `data`. call `mod.parse` in turn.
88
+ - `bind()`: bind data. call `mod.bind` in turn.
89
+ - `resize()`: update layout ( if available ), then call `mod.resize` in turn.
90
+ - `render()`: render chart by calling `mod.render`.
91
+ - `tick()`: called by internal animation loop. call `mod.tick` in turn.
92
+ - `start()`: start animation loop.
93
+ - `stop()`: stop animation loop.
94
+ - `config(opt)`: update config with `opt`. return current configuration if `opt` is omitted.
95
+ - `setRaw(raw, binding, reinit)`: set data to `raw`.
96
+ - `raw`: data to set.
97
+ - `binding`: binding to use. optional.
98
+ - `reinit`: default false. true to call `mod.init` again, if already initied.
99
+ - `fire(event, payload)`: fire `event` with optional `payload` parameters.
100
+ - `on(event, cb)`: handle `event` with `cb` callback.
101
+ - `filter(filters, internal)`: filter data based on `filters` config.
102
+ - `filters`: object with `key` / `value` pairs for `data field name` / `filter` map.
103
+ - `internal`: true if this is called internally.
104
+
105
+ Some methods may interact with interfaces from `mod`. For more information, check `lifecycle.md`.
106
+
107
+
108
+ ## Chart Definition
109
+
110
+ a chart definition is an object with following members:
111
+
112
+ - `name`: name of this chart.
113
+ - `version`: version of this chart.
114
+ - `meta`: additional chart information such as tags, description, author, etc. optional.
115
+ - `config`: configuration following `@plotdb/konfig` spec for user interaction and config default values.
116
+ - `dimension`: chart dimension definition object.
117
+ - `hash key`: dimension name
118
+ - `hash val`: object for dimension definition with following members:
119
+ - `name`: dimension display name.
120
+ - `type`: supported data type, including:
121
+ - `N`: Nominal
122
+ - `C`: Category
123
+ - `O`: Ordinal
124
+ - `T`: Ordinal but explicitly declared as time series.
125
+ - `R`: Ratio
126
+ - `I`: Ratio but explicitly declared as interval type.
127
+ - `priority`: number, small is higher. default 100. The priority for binding data automatically.
128
+ - `multiple`: true if this dimension support multi-value mapping ( such as y-axis of a line chart )
129
+ - `passive`: true if this dimension shouldn't be auto-fitted. default false.
130
+ - `i18n`: optional i18n data for translating content.
131
+ - chart also provide some common term translation as fallback.
132
+ - example:
133
+
134
+ { "zh-TW": "some-text": "某些字" }
135
+
136
+ - `init()`: called when initialization.
137
+ - `destroy()`: called when destroying chart.
138
+ - `parse()`: called when data is updated.
139
+ - `resize()`: called when container of this chart is resized.
140
+ - `bind()`: if parse() is called. this will be called after that. ( TBD )
141
+ - `render()`: for rendeing chart.
142
+ - `start()`: called when `chart.start` is called.
143
+ - `pause()`: called when `chart.pause` is called.
144
+ - `tick()`: called periodically if animation loop is started ( by `chart.start` ).
145
+ - `mod.tick` should be lightweight as possible. leave heavy work to `render.`
146
+ - `render` should be called manually in `tick`, but only if needed.
@@ -0,0 +1,8 @@
1
+
2
+ list of object with keys are field name to corresponding values. For example:
3
+ [
4
+ {name: "john", score: 85},
5
+ {name: "silvia", score: 76},
6
+ ...
7
+ ]
8
+
File without changes
File without changes
File without changes
@@ -0,0 +1,89 @@
1
+ # Chart Life Cycle
2
+
3
+ Once created, user should `init` the created chart before using it:
4
+
5
+ mychart = new char({ ... });
6
+ mychart
7
+ .init()
8
+ .then( ... );
9
+
10
+ And should always `destroy` it when no longer need it:
11
+
12
+ mychart.destroy();
13
+
14
+
15
+ After initialized usually a chart is also rendered based on the update flow defined by chart definitions. An update flow includes following methods from chart definitions:
16
+
17
+ - `init`: initialize object that only have to be initialized one time
18
+ - `parse`: parse input raw data on demand.
19
+ - `bind`: bind data (TBD)
20
+ - `resize`: necessary update for dimensional information changes.
21
+ - `render`: render chart.
22
+ - `tick`: code run periodically for animation.
23
+ - `destroy`: recycle and release resources ( such as timer )
24
+
25
+ Above interface methods are expected to be implemented by a chart definition, and there are also counterparts of these methods in `chart` object; these counterparts may do additional works for taking care of the chart lifecycle.
26
+
27
+ Different methods may have different update flows. Except `init`, there are some additional functions that may trigger an update flow:
28
+
29
+ - `init`
30
+ - `setBind`
31
+ - `setRaw`
32
+ - container / window resized
33
+ - layout object re-rendering ( may also be triggered by resizing )
34
+
35
+ User should be responsible for lifecycle management for updates from any other types. ( e.g., `config` )
36
+
37
+
38
+ ## init
39
+
40
+ When calling `init`, it returns a promise which resolves when everything is setup and the chart is rendered. `init` undergoes the following steps:
41
+
42
+ - wait for resizeObserver triggers the first resize event, or skip this step if forceInit i true.
43
+ - wait until `mod.init` finished. ( if `mod.init` returns a promise )
44
+ - wait until `layout.init` finished.
45
+ - if `delayRender` is true, wait until `setRaw` is called.
46
+ - call `mod.parse`
47
+ - call `mod.bind`
48
+ - call `mod.resize`
49
+ - call `mod.render`
50
+
51
+
52
+ ## setRaw
53
+
54
+ when `setRaw` is called, data is updated and thus we need a full update:
55
+
56
+ - `mod.init`, if `reinit` functional option is true or `delayInit` constructor option is true.
57
+ - `mod.parse`
58
+ - `mod.bind`
59
+ - `mod.resize`
60
+ - `mod.render`
61
+
62
+ Also resolves the very first `init` function call if `delayInit` is true.
63
+
64
+
65
+ ## container resize
66
+
67
+ when container resizes, there are only changes in dimension, thus we only need to resize and render:
68
+
69
+ - `mod.resize`
70
+ - `mod.render`
71
+
72
+ ## layout render event
73
+ ( TBD why parse and bind )
74
+
75
+ when layout `render` event is fired:
76
+
77
+ - `mod.parse`
78
+ - `mod.bind`
79
+ - `mod.resize`
80
+ - `mod.render`
81
+
82
+ `render` event can be suppressed when calling `layout.update` with additional parameter.
83
+
84
+
85
+ ## Additional works in counterpart methods
86
+
87
+ - `parse`: inject additional information `_raw` and `_idx` before calling `mod.parse`
88
+ - `resize`: update layout ( suppress `render` event ), before calling `mod.resize`
89
+