@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
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Logs
2
+
3
+ ## v0.0.2
4
+
5
+ - use `palette` instead of `pal` in all charts, configurations and utils
6
+ - rename `Chart` to `chart`.
7
+ - rename `Aniloop` to `aniloop`
8
+ - export to `window` only if `module` is not defined.
9
+ - add config preset.
10
+ - update pie bubble chart
11
+ - tweak init and config flow. default config is now available.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # @plotdb/chart
2
+
3
+ charting framework. In `@plotdb/chart`, charts are separated into 2 parts:
4
+
5
+ - chart framework - define how a chart works, and provide an interface for controlling charts.
6
+ - chart definition - specific chart definition and implementation.
7
+
8
+ Chart framework provides:
9
+
10
+ - chart lifecycle control - initing, resizing, rendering, destroying, etc
11
+ - animation loop control.
12
+ - rendering management for container resizing / visibility changing.
13
+ - utility modules for common charting components.
14
+
15
+ Chart Definition includes:
16
+
17
+ - the actual code for chart rendering
18
+ - definition of user configurable options
19
+ - accepted data formats
20
+ - other metadata and dependencies
21
+
22
+ While not in spec and not necessary, chart definitions can be encapsulated in `@plotdb/block` for modularization and abstraction.
23
+
24
+
25
+ ## Usage
26
+
27
+ install via `@plotdb/chart`:
28
+
29
+ npm install --save @plotdb/chart
30
+
31
+
32
+ include `@plotdb/chart` js and css files under `dist`, mainly `chart.js` and `chart.css`:
33
+
34
+ <link rel="stylesheet" type="text/css" href="path-to-dist/chart.css"/>
35
+ <script src="path-to-dist/chart.js"></script>
36
+
37
+
38
+ then, create and initialize a chart object:
39
+
40
+ c = new chart({ ... })
41
+ c.init().then(function() { ... });
42
+
43
+
44
+ For more detail about chart module object, chart object constructor option and api interface, check `doc/spec.md`.
45
+
46
+
47
+
48
+ ## License
49
+
50
+ MIT
package/build ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env bash
2
+
3
+ echo "prepare..."
4
+ rm -rf dist/utils
5
+ mkdir -p dist/utils
6
+
7
+ echo "building livescript files ... "
8
+ ./node_modules/.bin/lsc -c --no-header -o dist src
9
+
10
+ echo "building stylus files ... "
11
+ ./node_modules/.bin/stylus -p src/chart.styl > dist/chart.css
12
+ ./node_modules/.bin/stylus -p src/utils/legend.styl > dist/utils/legend.css
13
+
14
+ echo "minify chart.js -> chart.min.js ..."
15
+ ./node_modules/.bin/uglifyjs dist/chart.js > dist/chart.min.js
16
+ echo "minify src/utils/legend.js -> dist/utils/legend.min.js ..."
17
+ ./node_modules/.bin/uglifyjs dist/utils/legend.js > dist/utils/legend.min.js
18
+ echo "minify src/utils/tint.js -> dist/utils/tint.min.js ..."
19
+ ./node_modules/.bin/uglifyjs dist/utils/tint.js > dist/utils/tint.min.js
20
+ echo "minify src/utils/data.js -> dist/utils/data.min.js ..."
21
+ ./node_modules/.bin/uglifyjs dist/utils/data.js > dist/utils/data.min.js
22
+ echo "minify src/utils/axis.js -> dist/utils/axis.min.js ..."
23
+ ./node_modules/.bin/uglifyjs dist/utils/axis.js > dist/utils/axis.min.js
24
+ echo "minify src/utils/format.js -> dist/utils/format.min.js ..."
25
+ ./node_modules/.bin/uglifyjs dist/utils/format.js > dist/utils/format.min.js
26
+ echo "minify src/utils/tip.js -> dist/utils/tip.min.js ..."
27
+ ./node_modules/.bin/uglifyjs dist/utils/tip.js > dist/utils/tip.min.js
28
+ echo "minify src/utils/config.js -> dist/utils/config.min.js ..."
29
+ ./node_modules/.bin/uglifyjs dist/utils/config.js > dist/utils/config.min.js
30
+
31
+ echo "minifying dist/chart.css ..."
32
+ ./node_modules/.bin/uglifycss dist/chart.css > dist/chart.min.css
33
+ echo "minifying dist/utils/legend.css ..."
34
+ ./node_modules/.bin/uglifycss dist/utils/legend.css > dist/utils/legend.min.css
35
+
36
+ echo "copy dist to web ..."
37
+ rm -rf "web/static/assets/lib/@plotdb/chart/main/"
38
+ mkdir -p "web/static/assets/lib/@plotdb/chart/main/"
39
+ cp -R dist/* "web/static/assets/lib/@plotdb/chart/main/"
package/dist/chart.css ADDED
@@ -0,0 +1,8 @@
1
+ div[plug=layout] {
2
+ width: 100%;
3
+ height: 100%;
4
+ }
5
+ div[plug=layout] .pdl-layout {
6
+ width: 100%;
7
+ height: 100%;
8
+ }
package/dist/chart.js ADDED
@@ -0,0 +1,603 @@
1
+ (function(){
2
+ var svgns, parent, aniloop, visibilityObserver, resizeObserver, withDefault, defaultConfig, chart;
3
+ svgns = "http://www.w3.org/2000/svg";
4
+ parent = function(n, s, e){
5
+ var m;
6
+ m = n;
7
+ while (n && n !== e) {
8
+ n = n.parentNode;
9
+ }
10
+ if (n !== e) {
11
+ return null;
12
+ }
13
+ if (!s) {
14
+ return n;
15
+ }
16
+ n = m;
17
+ while (n && n !== e && (!n.matches || (n.matches && !n.matches(s)))) {
18
+ n = n.parentNode;
19
+ }
20
+ if (n === e && (!e.matches || !e.matches(s))) {
21
+ return null;
22
+ }
23
+ return n;
24
+ };
25
+ aniloop = function(){
26
+ this.running = false;
27
+ this.time = {
28
+ now: 0,
29
+ last: 0
30
+ };
31
+ this.fps(60);
32
+ this.evtHandler = {};
33
+ return this;
34
+ };
35
+ aniloop.prototype = import$(Object.create(Object.prototype), {
36
+ on: function(n, cb){
37
+ var this$ = this;
38
+ return (Array.isArray(n)
39
+ ? n
40
+ : [n]).map(function(n){
41
+ var ref$;
42
+ return ((ref$ = this$.evtHandler)[n] || (ref$[n] = [])).push(cb);
43
+ });
44
+ },
45
+ fire: function(n){
46
+ var v, res$, i$, to$, ref$, len$, cb, results$ = [];
47
+ res$ = [];
48
+ for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
49
+ res$.push(arguments[i$]);
50
+ }
51
+ v = res$;
52
+ for (i$ = 0, len$ = (ref$ = this.evtHandler[n] || []).length; i$ < len$; ++i$) {
53
+ cb = ref$[i$];
54
+ results$.push(cb.apply(this, v));
55
+ }
56
+ return results$;
57
+ },
58
+ reset: function(){
59
+ return this.time = {
60
+ now: 0
61
+ };
62
+ },
63
+ setTime: function(t){
64
+ return this.time.now = t;
65
+ },
66
+ getTime: function(){
67
+ return this.time.now;
68
+ },
69
+ isRunning: function(){
70
+ return this.running;
71
+ },
72
+ toggle: function(it){
73
+ if (it != null) {
74
+ this.running = !it;
75
+ }
76
+ if (this.running) {
77
+ return this.pause();
78
+ } else {
79
+ return this.run();
80
+ }
81
+ },
82
+ pause: function(){
83
+ return this.running = false;
84
+ },
85
+ render: function(){
86
+ return this.fire('tick', this.time.now);
87
+ },
88
+ run: function(fps){
89
+ var this$ = this;
90
+ if (fps != null) {
91
+ this.fps(fps);
92
+ }
93
+ if (this.running) {
94
+ return;
95
+ }
96
+ this.running = true;
97
+ return requestAnimationFrame(function(t){
98
+ return this$.handler(this$.time.last = t, true);
99
+ });
100
+ },
101
+ throttle: function(v){
102
+ v == null && (v = true);
103
+ return this.isThrottled = v;
104
+ },
105
+ fps: function(it){
106
+ if (!(it != null)) {
107
+ return this._fps_val;
108
+ }
109
+ this._fps_val = it > 0.01 ? it : 0.01;
110
+ return this._fps_delay = 1000 / this._fps_val;
111
+ },
112
+ handler: function(t, force){
113
+ var delay, ref$, this$ = this;
114
+ force == null && (force = false);
115
+ if (!this.running) {
116
+ return;
117
+ }
118
+ this.time.now = t;
119
+ delay = this.isThrottled
120
+ ? (ref$ = this._fps_delay) > 1000 ? ref$ : 1000
121
+ : this._fps_delay;
122
+ if (force || this.time.now - this.time.last >= delay) {
123
+ this.time.last = t;
124
+ this.render();
125
+ }
126
+ return requestAnimationFrame(function(t){
127
+ return this$.handler(t, false);
128
+ });
129
+ }
130
+ });
131
+ visibilityObserver = {
132
+ list: [],
133
+ init: function(){
134
+ var ref$, h, vc, this$ = this;
135
+ this.inited = true;
136
+ ref$ = document.hidden != null
137
+ ? ['hidden', 'visibilitychange']
138
+ : document.msHidden != null
139
+ ? ['hidden', 'visibilitychange']
140
+ : document.webkiHidden != null
141
+ ? ['webkitHidden', 'webkitvisibilitychange']
142
+ : ['hidden', 'visibilitychange'], h = ref$[0], vc = ref$[1];
143
+ return document.addEventListener(vc, debounce(150, function(){
144
+ var th;
145
+ th = !!document[h];
146
+ return this$.list.map(function(it){
147
+ return it.throttle(th);
148
+ });
149
+ }, false));
150
+ },
151
+ add: function(aniloop){
152
+ if (!this.inited) {
153
+ this.init();
154
+ }
155
+ return this.list.push(aniloop);
156
+ }
157
+ };
158
+ resizeObserver = {
159
+ wm: new WeakMap(),
160
+ ro: new ResizeObserver(function(list){
161
+ return list.map(function(n){
162
+ var ret;
163
+ ret = resizeObserver.wm.get(n.target);
164
+ return ret._resize();
165
+ });
166
+ }),
167
+ add: function(node, obj){
168
+ this.wm.set(node, obj);
169
+ return this.ro.observe(node);
170
+ },
171
+ 'delete': function(it){
172
+ this.ro.unobserve(it);
173
+ return this.wm['delete'](it);
174
+ }
175
+ };
176
+ withDefault = function(cfg, defcfg){
177
+ var _;
178
+ cfg == null && (cfg = {});
179
+ defcfg == null && (defcfg = {});
180
+ defcfg = JSON.parse(JSON.stringify(defcfg));
181
+ _ = function(cfg, defcfg){
182
+ var k, v;
183
+ for (k in defcfg) {
184
+ v = defcfg[k];
185
+ if (!(cfg[k] != null)) {
186
+ cfg[k] = v;
187
+ } else if (typeof cfg[k] === 'object' && typeof v === 'object') {
188
+ withDefault(cfg[k], defcfg[k]);
189
+ }
190
+ }
191
+ return cfg;
192
+ };
193
+ return _(cfg, defcfg);
194
+ };
195
+ defaultConfig = function(cfg){
196
+ var _;
197
+ _ = function(meta, ret){
198
+ var ctrls, that, id, v;
199
+ ret == null && (ret = {});
200
+ ctrls = (that = meta.child) ? that : meta;
201
+ for (id in meta) {
202
+ v = meta[id];
203
+ if (!v.type) {
204
+ _(v, ret[id] || (ret[id] = {}));
205
+ } else if (v['default']) {
206
+ ret[id] = v['default'];
207
+ }
208
+ }
209
+ return ret;
210
+ };
211
+ return _(cfg);
212
+ };
213
+ chart = function(opt){
214
+ var this$ = this;
215
+ opt == null && (opt = {});
216
+ this.root = typeof opt.root === 'string'
217
+ ? document.querySelector(opt.root)
218
+ : opt.root;
219
+ this.useSample = opt.useSample != null ? opt.useSample : true;
220
+ this.autoSelect = opt.autoSelect != null ? opt.autoSelect : true;
221
+ this.forceInit = opt.forceInit ? opt.forceInit : false;
222
+ this.prepareSvg = opt.prepareSvg != null ? opt.prepareSvg : true;
223
+ this.layoutOpt = opt.layout != null ? opt.layout : true;
224
+ this.delayRender = opt.delayRender || false;
225
+ this.dataAccessor = opt.dataAccessor != null
226
+ ? opt.dataAccessor
227
+ : function(it){
228
+ if (it) {
229
+ return it.data._raw;
230
+ } else {
231
+ return null;
232
+ }
233
+ };
234
+ this.raw = opt.raw || null;
235
+ this.mod = opt.mod || {};
236
+ this.cfg = opt.config || {};
237
+ this.seed = opt.seed || Math.random();
238
+ this.binding = opt.binding || {};
239
+ this.evtHandler = {};
240
+ this.init = proxise.once(function(){
241
+ return this$._init();
242
+ });
243
+ this._resize = null;
244
+ if (this.autoSelect) {
245
+ this.root.addEventListener('click', this._select = function(e){
246
+ var p;
247
+ if (!(p = parent(e.target, '.data', this$.root))) {
248
+ return;
249
+ }
250
+ return this$.fire('select', [{
251
+ data: this$.dataAccessor(p),
252
+ node: p
253
+ }]);
254
+ });
255
+ this.root.addEventListener('mouseover', this._hover = function(e){
256
+ var p;
257
+ if (!(p = ld$.parent(e.target, '.data', this$.root))) {
258
+ return;
259
+ }
260
+ return this$.fire('hover', [{
261
+ data: this$.dataAccessor(p),
262
+ node: p
263
+ }]);
264
+ });
265
+ }
266
+ return this;
267
+ };
268
+ chart.prototype = import$(Object.create(Object.prototype), {
269
+ _init: function(){
270
+ var layoutRoot, ref$, r, p, this$ = this;
271
+ if (window.getComputedStyle(this.root).position === 'static') {
272
+ this.root.style.position = 'relative';
273
+ }
274
+ layoutRoot = this.layoutOpt ? typeof this.layoutOpt !== 'object'
275
+ ? this.root.querySelector('.pdl-layout')
276
+ : typeof this.layoutOpt.root === 'string'
277
+ ? this.root.querySelector(this.layoutOpt.root)
278
+ : this.layoutOpt.root ? this.layoutOpt.root : null : null;
279
+ if (this.prepareSvg && !(this.svg = this.root.querySelector('svg'))) {
280
+ this.svg = document.createElementNS(svgns, "svg");
281
+ ref$ = this.svg.style;
282
+ ref$.width = "100%";
283
+ ref$.height = "100%";
284
+ if (this.layoutOpt) {
285
+ if (!layoutRoot) {
286
+ console.error("[@plotdb/chart] layout enabled yet layout root isn't configured properly. ");
287
+ }
288
+ r = layoutRoot.querySelector('[data-type=render]');
289
+ if (!r) {
290
+ console.warn("[@plotdb/chart] prepareSvg and layout is configured at the same time,\nyet render container for layout is not found. svg is thus appended in the root.");
291
+ }
292
+ }
293
+ (r || this.root).appendChild(this.svg);
294
+ }
295
+ this._aniloop = new aniloop();
296
+ visibilityObserver.add(this._aniloop);
297
+ this._aniloop.on('tick', function(){
298
+ return this$.tick();
299
+ });
300
+ return p = Promise.resolve().then(function(){
301
+ var ref$;
302
+ if (this$.raw && Array.isArray(this$.raw)) {
303
+ return;
304
+ }
305
+ if (this$.useSample) {
306
+ this$.raw = (ref$ = this$.mod.sample
307
+ ? this$.mod.sample() || {}
308
+ : {}).raw;
309
+ this$.binding = ref$.binding;
310
+ }
311
+ if (!this$.raw) {
312
+ return this$.raw = [];
313
+ }
314
+ }).then(function(){
315
+ var defcfg, ref$, _resizeLock;
316
+ defcfg = defaultConfig(this$.mod.config || {});
317
+ withDefault(this$.cfg, defcfg);
318
+ if (this$.layoutOpt) {
319
+ if (!(typeof layout != 'undefined' && layout !== null)) {
320
+ console.warn("[@plotdb/chart] layout-opt is set yet @plotdb/layout is not found.");
321
+ } else {
322
+ if (!layoutRoot) {
323
+ console.error("[@plotdb/chart] cannot determine root node for @plotdb/layout.");
324
+ console.error("[@plotdb/chart] config layout properly or disable layout by setting layout to false");
325
+ }
326
+ this$.layout = new layout(typeof this$.layoutOpt === 'object'
327
+ ? (ref$ = import$({}, this$.layoutOpt), ref$.watchResize = false, ref$)
328
+ : {
329
+ root: layoutRoot,
330
+ watchResize: false
331
+ });
332
+ }
333
+ }
334
+ _resizeLock = proxise(function(){
335
+ resizeObserver.add(this$.root, this$);
336
+ return null;
337
+ });
338
+ if (this$.forceInit && !this$.root.offsetParent || window.getComputedStyle(this$.root).display === 'none') {
339
+ return;
340
+ }
341
+ this$._resize = function(){
342
+ return _resizeLock.resolve();
343
+ };
344
+ return _resizeLock();
345
+ }).then(function(){
346
+ return this$._resize = function(){};
347
+ }).then(function(){
348
+ var init, layoutLock;
349
+ init = function(){
350
+ if (this$.mod.init) {
351
+ return this$.mod.init.apply(this$);
352
+ }
353
+ };
354
+ if (!this$.layout) {
355
+ return init();
356
+ }
357
+ layoutLock = proxise(function(){
358
+ Promise.resolve(this$.layout.init(init));
359
+ return null;
360
+ });
361
+ this$._layout = function(){
362
+ return layoutLock.resolve();
363
+ };
364
+ this$.layout.on('render', function(){
365
+ return this$._layout();
366
+ });
367
+ return layoutLock();
368
+ }).then(function(){
369
+ this$._layout = function(){};
370
+ Promise.resolve().then(function(){
371
+ if (!this$.delayRender) {
372
+ return;
373
+ }
374
+ this$.renderLock = proxise(function(){});
375
+ return this$.renderLock();
376
+ }).then(function(){
377
+ this$._resize = function(){
378
+ this$.resize();
379
+ return this$.render();
380
+ };
381
+ this$._layout = function(){
382
+ this$.parse();
383
+ this$.bind();
384
+ this$.resize();
385
+ return this$.render();
386
+ };
387
+ this$.parse();
388
+ this$.bind();
389
+ this$.resize();
390
+ return this$.render();
391
+ });
392
+ });
393
+ },
394
+ parse: function(){
395
+ var this$ = this;
396
+ this.data = this.raw.map(function(r, i){
397
+ var ret, k, v;
398
+ ret = {};
399
+ (function(){
400
+ var ref$, results$ = [];
401
+ for (k in ref$ = this.binding) {
402
+ v = ref$[k];
403
+ results$.push({
404
+ k: k,
405
+ v: v
406
+ });
407
+ }
408
+ return results$;
409
+ }.call(this$)).map(function(arg$){
410
+ var k, v, ref$, ref1$, t;
411
+ k = arg$.k, v = arg$.v;
412
+ if (!v) {
413
+ return;
414
+ }
415
+ ret[k] = ((ref$ = (ref1$ = this$.mod).dimension || (ref1$.dimension = {}))[k] || (ref$[k] = {})).multiple
416
+ ? v.map(function(it){
417
+ return r[it.key];
418
+ })
419
+ : r[v.key];
420
+ t = ((ref$ = (ref1$ = this$.mod).dimension || (ref1$.dimension = {}))[k] || (ref$[k] = {})).type;
421
+ if (/[RIT]/.exec(t) && !/[CN]/.exec(t)) {
422
+ return ret[k] = Array.isArray(ret[k])
423
+ ? ret[k].map(function(it){
424
+ return parseFloat(it);
425
+ })
426
+ : parseFloat(ret[k]);
427
+ }
428
+ });
429
+ ret._raw = r;
430
+ ret._idx = i;
431
+ return ret;
432
+ });
433
+ if (this.mod.parse) {
434
+ return this.mod.parse.apply(this);
435
+ }
436
+ },
437
+ bind: function(){
438
+ if (this.mod.bind) {
439
+ return this.mod.bind.apply(this);
440
+ }
441
+ },
442
+ start: function(){
443
+ this._aniloop.run();
444
+ if (this.mod.start) {
445
+ return this.mod.start.apply(this);
446
+ }
447
+ },
448
+ stop: function(){
449
+ this._aniloop.pause();
450
+ if (this.mod.stop) {
451
+ return this.mod.stop.apply(this);
452
+ }
453
+ },
454
+ resize: function(){
455
+ if (this.layout) {
456
+ this.layout.update(false);
457
+ }
458
+ this.box = this.root.getBoundingClientRect();
459
+ if (this.mod.resize) {
460
+ return this.mod.resize.apply(this);
461
+ }
462
+ },
463
+ tick: function(){
464
+ if (this.mod.tick) {
465
+ return this.mod.tick.apply(this);
466
+ }
467
+ },
468
+ render: function(){
469
+ if (this.mod.render) {
470
+ return this.mod.render.apply(this);
471
+ }
472
+ },
473
+ destroy: function(){
474
+ var this$ = this;
475
+ return Promise.resolve().then(function(){
476
+ if (this$._select) {
477
+ this$.root.removeEventListener('click', this$._select);
478
+ }
479
+ if (this$._hover) {
480
+ this$.root.removeEventListener('mouseover', this$._hover);
481
+ }
482
+ resizeObserver['delete'](this$.root);
483
+ if (this$.layout) {
484
+ this$.layout.destroy();
485
+ }
486
+ this$.stop();
487
+ if (this$.mod.destroy) {
488
+ return this$.mod.destroy.apply(this$);
489
+ }
490
+ });
491
+ },
492
+ config: function(opt){
493
+ if (!(opt != null && opt)) {
494
+ return this.cfg;
495
+ }
496
+ return import$(this.cfg, opt);
497
+ },
498
+ setBind: function(n, b){
499
+ this.binding[n] = b;
500
+ this.parse();
501
+ this.bind();
502
+ this.resize();
503
+ return this.render();
504
+ },
505
+ setRaw: function(raw, binding, reinit){
506
+ var ref$;
507
+ reinit == null && (reinit = false);
508
+ if (!Array.isArray(raw)) {
509
+ ref$ = raw, raw = ref$.raw, binding = ref$.binding, reinit = ref$.reinit;
510
+ }
511
+ if (raw != null) {
512
+ this.raw = raw;
513
+ }
514
+ if (binding != null) {
515
+ this.binding = binding;
516
+ }
517
+ if (this.renderLock) {
518
+ this.renderLock.resolve();
519
+ return this.renderLock = null;
520
+ } else {
521
+ if (reinit && this.mod.init) {
522
+ this.mod.init.apply(this);
523
+ }
524
+ this.parse();
525
+ this.bind();
526
+ this.resize();
527
+ return this.render();
528
+ }
529
+ },
530
+ on: function(n, cb){
531
+ var this$ = this;
532
+ return (Array.isArray(n)
533
+ ? n
534
+ : [n]).map(function(n){
535
+ var ref$;
536
+ return ((ref$ = this$.evtHandler)[n] || (ref$[n] = [])).push(cb);
537
+ });
538
+ },
539
+ fire: function(n){
540
+ var v, res$, i$, to$, ref$, len$, cb, results$ = [];
541
+ res$ = [];
542
+ for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
543
+ res$.push(arguments[i$]);
544
+ }
545
+ v = res$;
546
+ for (i$ = 0, len$ = (ref$ = this.evtHandler[n] || []).length; i$ < len$; ++i$) {
547
+ cb = ref$[i$];
548
+ results$.push(cb.apply(this, v));
549
+ }
550
+ return results$;
551
+ },
552
+ filter: function(filters, internal){
553
+ var bs, k, ref$, v, u;
554
+ filters == null && (filters = {});
555
+ internal == null && (internal = false);
556
+ bs = [];
557
+ for (k in ref$ = this.binding) {
558
+ v = ref$[k];
559
+ u = Array.isArray(v)
560
+ ? v
561
+ : [v];
562
+ u = u.map(fn$);
563
+ bs = bs.concat(u);
564
+ }
565
+ for (k in filters) {
566
+ v = filters[k];
567
+ bs.filter(fn1$).map(fn2$);
568
+ }
569
+ if (internal) {
570
+ this.fire('filter', filters);
571
+ }
572
+ if (this.mod.filter) {
573
+ this.mod.filter.apply(this, [filters, internal]);
574
+ }
575
+ this.parse();
576
+ this.bind();
577
+ this.resize();
578
+ return this.render();
579
+ function fn$(v){
580
+ return {
581
+ k: k,
582
+ v: v
583
+ };
584
+ }
585
+ function fn1$(it){
586
+ return it.k === k;
587
+ }
588
+ function fn2$(it){
589
+ return it.v.filter = v;
590
+ }
591
+ }
592
+ });
593
+ if (typeof module != 'undefined' && module !== null) {
594
+ module.exports = chart;
595
+ } else if (typeof window != 'undefined' && window !== null) {
596
+ window.chart = chart;
597
+ }
598
+ function import$(obj, src){
599
+ var own = {}.hasOwnProperty;
600
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
601
+ return obj;
602
+ }
603
+ }).call(this);