@plotdb/chart 3.4.0 → 3.6.0

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.
package/utils/anim.js ADDED
@@ -0,0 +1,428 @@
1
+ (function(){
2
+ var svgns, now, ease, reNum, color, interpColor, interpString, interpolate, anim, join;
3
+ svgns = "http://www.w3.org/2000/svg";
4
+ now = function(){
5
+ if (typeof performance != 'undefined' && performance !== null) {
6
+ return performance.now();
7
+ } else {
8
+ return Date.now();
9
+ }
10
+ };
11
+ ease = {
12
+ linear: function(t){
13
+ return t;
14
+ },
15
+ cubicInOut: function(t){
16
+ t = t * 2;
17
+ if (t <= 1) {
18
+ return t * t * t / 2;
19
+ } else {
20
+ return ((t -= 2) * t * t + 2) / 2;
21
+ }
22
+ },
23
+ cubicOut: function(t){
24
+ return --t * t * t + 1;
25
+ },
26
+ quadInOut: function(t){
27
+ t = t * 2;
28
+ if (t <= 1) {
29
+ return t * t / 2;
30
+ } else {
31
+ return (--t * (2 - t) + 1) / 2;
32
+ }
33
+ }
34
+ };
35
+ reNum = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
36
+ color = function(c){
37
+ var m, v;
38
+ if (typeof c !== 'string') {
39
+ return null;
40
+ }
41
+ c = c.trim();
42
+ if (m = /^#([0-9a-f]{3,4})$/i.exec(c)) {
43
+ v = m[1].split('').map(function(it){
44
+ return parseInt(it + it, 16);
45
+ });
46
+ return [v[0], v[1], v[2], v[3] != null ? v[3] / 255 : 1];
47
+ }
48
+ if (m = /^#([0-9a-f]{6})([0-9a-f]{2})?$/i.exec(c)) {
49
+ v = [0, 1, 2].map(function(i){
50
+ return parseInt(m[1].substr(i * 2, 2), 16);
51
+ });
52
+ return v.concat([m[2] ? parseInt(m[2], 16) / 255 : 1]);
53
+ }
54
+ if (m = /^rgba?\(([^)]+)\)$/i.exec(c)) {
55
+ v = m[1].split(/[\s,\/]+/).filter(function(it){
56
+ return it;
57
+ }).map(function(it){
58
+ return parseFloat(it);
59
+ });
60
+ if (v.length < 3 || v.slice(0, 3).some(function(it){
61
+ return isNaN(it);
62
+ })) {
63
+ return null;
64
+ }
65
+ return [v[0], v[1], v[2], v[3] != null && !isNaN(v[3]) ? v[3] : 1];
66
+ }
67
+ return null;
68
+ };
69
+ interpColor = function(a, b){
70
+ return function(t){
71
+ var ref$, r, g, bl, al;
72
+ ref$ = [0, 1, 2, 3].map(function(i){
73
+ return a[i] + (b[i] - a[i]) * t;
74
+ }), r = ref$[0], g = ref$[1], bl = ref$[2], al = ref$[3];
75
+ ref$ = [r, g, bl].map(function(it){
76
+ var ref$, ref1$;
77
+ return (ref$ = (ref1$ = Math.round(it)) > 0 ? ref1$ : 0) < 255 ? ref$ : 255;
78
+ }), r = ref$[0], g = ref$[1], bl = ref$[2];
79
+ if (al >= 1) {
80
+ return "rgb(" + r + ", " + g + ", " + bl + ")";
81
+ } else {
82
+ return "rgba(" + r + ", " + g + ", " + bl + ", " + al + ")";
83
+ }
84
+ };
85
+ };
86
+ interpString = function(a, b){
87
+ var an, segs, last, i, m, bv, av;
88
+ a = a + "";
89
+ b = b + "";
90
+ an = a.match(reNum) || [];
91
+ segs = [];
92
+ last = 0;
93
+ i = 0;
94
+ reNum.lastIndex = 0;
95
+ while (m = reNum.exec(b)) {
96
+ if (m.index > last) {
97
+ segs.push(b.slice(last, m.index));
98
+ }
99
+ bv = +m[0];
100
+ av = an[i] != null ? +an[i] : null;
101
+ segs.push(av != null && av !== bv
102
+ ? {
103
+ a: av,
104
+ b: bv
105
+ }
106
+ : m[0]);
107
+ last = reNum.lastIndex;
108
+ i++;
109
+ }
110
+ if (last < b.length) {
111
+ segs.push(b.slice(last));
112
+ }
113
+ if (!segs.some(function(it){
114
+ return typeof it === 'object';
115
+ })) {
116
+ return function(){
117
+ return b;
118
+ };
119
+ }
120
+ return function(t){
121
+ return segs.map(function(it){
122
+ if (typeof it === 'object') {
123
+ return it.a + (it.b - it.a) * t;
124
+ } else {
125
+ return it;
126
+ }
127
+ }).join('');
128
+ };
129
+ };
130
+ interpolate = function(a, b){
131
+ var cb, ca;
132
+ if (typeof b === 'number') {
133
+ a = parseFloat(a);
134
+ if (isNaN(a)) {
135
+ a = 0;
136
+ }
137
+ return function(t){
138
+ return a + (b - a) * t;
139
+ };
140
+ }
141
+ if (!(a != null)) {
142
+ return function(){
143
+ return b;
144
+ };
145
+ }
146
+ if (cb = color(b)) {
147
+ if (!(ca = color(a))) {
148
+ return function(){
149
+ return b;
150
+ };
151
+ }
152
+ return interpColor(ca, cb);
153
+ }
154
+ return interpString(a, b);
155
+ };
156
+ anim = function(opt){
157
+ var this$ = this;
158
+ opt == null && (opt = {});
159
+ this._manual = !!opt.manual;
160
+ this._now = 0;
161
+ this._offset = 0;
162
+ this._raf = null;
163
+ this._list = new Map();
164
+ this.evtHandler = {};
165
+ this._tick = function(t){
166
+ this$._raf = null;
167
+ if (this$._manual) {
168
+ return;
169
+ }
170
+ this$._apply(this$.time());
171
+ if (this$._list.size) {
172
+ return this$._kick();
173
+ }
174
+ };
175
+ return this;
176
+ };
177
+ anim.prototype = import$(Object.create(Object.prototype), {
178
+ on: function(n, cb){
179
+ var this$ = this;
180
+ return (Array.isArray(n)
181
+ ? n
182
+ : [n]).map(function(n){
183
+ var ref$;
184
+ return ((ref$ = this$.evtHandler)[n] || (ref$[n] = [])).push(cb);
185
+ });
186
+ },
187
+ fire: function(n){
188
+ var v, res$, i$, to$, ref$, len$, cb, results$ = [];
189
+ res$ = [];
190
+ for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
191
+ res$.push(arguments[i$]);
192
+ }
193
+ v = res$;
194
+ for (i$ = 0, len$ = (ref$ = this.evtHandler[n] || []).length; i$ < len$; ++i$) {
195
+ cb = ref$[i$];
196
+ results$.push(cb.apply(this, v));
197
+ }
198
+ return results$;
199
+ },
200
+ time: function(){
201
+ if (this._manual) {
202
+ return this._now;
203
+ } else {
204
+ return now() - this._offset;
205
+ }
206
+ },
207
+ manual: function(v){
208
+ if (!arguments.length) {
209
+ return this._manual;
210
+ }
211
+ v = !!v;
212
+ if (v === this._manual) {
213
+ return this;
214
+ }
215
+ if (v) {
216
+ this._now = this.time();
217
+ this._manual = true;
218
+ if (this._raf) {
219
+ cancelAnimationFrame(this._raf);
220
+ }
221
+ this._raf = null;
222
+ } else {
223
+ this._offset = now() - this._now;
224
+ this._manual = false;
225
+ if (this._list.size) {
226
+ this._kick();
227
+ }
228
+ }
229
+ return this;
230
+ },
231
+ step: function(dt){
232
+ dt == null && (dt = 1000 / 60);
233
+ if (!this._manual) {
234
+ this.manual(true);
235
+ }
236
+ this._now += dt;
237
+ this._apply(this._now);
238
+ this.fire('step', this._now, dt);
239
+ return this;
240
+ },
241
+ seek: function(t){
242
+ if (!this._manual) {
243
+ this.manual(true);
244
+ }
245
+ this._now = t;
246
+ this._apply(this._now);
247
+ this.fire('step', this._now, 0);
248
+ return this;
249
+ },
250
+ busy: function(){
251
+ return this._list.size > 0;
252
+ },
253
+ flush: function(){
254
+ this._apply(Infinity);
255
+ return this;
256
+ },
257
+ interrupt: function(node){
258
+ return this._list['delete'](node);
259
+ },
260
+ _kick: function(){
261
+ var this$ = this;
262
+ if (this._manual || this._raf) {
263
+ return;
264
+ }
265
+ if (!(typeof requestAnimationFrame != 'undefined' && requestAnimationFrame !== null)) {
266
+ return setTimeout(function(){
267
+ return this$._tick();
268
+ }, 16);
269
+ }
270
+ return this._raf = requestAnimationFrame(this._tick);
271
+ },
272
+ tween: function(node, attrs, opt){
273
+ var dur, delay, ez, immediate, item, start, k, v;
274
+ attrs == null && (attrs = {});
275
+ opt == null && (opt = {});
276
+ dur = opt.duration != null ? opt.duration : 350;
277
+ delay = opt.delay || 0;
278
+ ez = typeof opt.ease === 'function'
279
+ ? opt.ease
280
+ : ease[opt.ease || 'cubic-in-out'] || ease.cubicInOut;
281
+ immediate = (dur <= 0 && delay <= 0) || (!this._manual && (typeof document != 'undefined' && document !== null) && document.hidden);
282
+ item = this._list.get(node) || {
283
+ attr: {},
284
+ cb: []
285
+ };
286
+ item.remove = !!opt.remove;
287
+ if (opt.end) {
288
+ item.cb.push(opt.end);
289
+ }
290
+ start = this.time() + delay;
291
+ for (k in attrs) {
292
+ v = attrs[k];
293
+ if (!(v != null)) {
294
+ node.removeAttribute(k);
295
+ delete item.attr[k];
296
+ continue;
297
+ }
298
+ if (immediate) {
299
+ node.setAttribute(k, v);
300
+ delete item.attr[k];
301
+ } else {
302
+ item.attr[k] = {
303
+ to: v,
304
+ start: start,
305
+ dur: dur > 0 ? dur : 0,
306
+ ease: ez
307
+ };
308
+ }
309
+ }
310
+ this._list.set(node, item);
311
+ if (immediate && !(function(){
312
+ var results$ = [];
313
+ for (k in item.attr) {
314
+ results$.push(k);
315
+ }
316
+ return results$;
317
+ }()).length) {
318
+ this._done(node, item);
319
+ } else if (!this._manual) {
320
+ this._kick();
321
+ }
322
+ return this;
323
+ },
324
+ _done: function(node, item){
325
+ this._list['delete'](node);
326
+ if (item.remove && node.parentNode) {
327
+ node.parentNode.removeChild(node);
328
+ }
329
+ return item.cb.map(function(it){
330
+ return it.call(node);
331
+ });
332
+ },
333
+ _apply: function(t){
334
+ var i$, ref$, len$, ref1$, node, item, k, a, p, ref2$, results$ = [];
335
+ for (i$ = 0, len$ = (ref$ = Array.from(this._list)).length; i$ < len$; ++i$) {
336
+ ref1$ = ref$[i$], node = ref1$[0], item = ref1$[1];
337
+ if (this._list.get(node) !== item) {
338
+ continue;
339
+ }
340
+ for (k in ref1$ = item.attr) {
341
+ a = ref1$[k];
342
+ if (t < a.start) {
343
+ continue;
344
+ }
345
+ if (!a.interp) {
346
+ a.interp = interpolate(node.getAttribute(k), a.to);
347
+ }
348
+ p = a.dur ? (ref2$ = (t - a.start) / a.dur) < 1 ? ref2$ : 1 : 1;
349
+ if (p >= 1) {
350
+ node.setAttribute(k, a.to);
351
+ delete item.attr[k];
352
+ } else {
353
+ node.setAttribute(k, a.interp(a.ease(p)));
354
+ }
355
+ }
356
+ if (!(fn$()).length) {
357
+ results$.push(this._done(node, item));
358
+ }
359
+ }
360
+ return results$;
361
+ function fn$(){
362
+ var results$ = [];
363
+ for (k in item.attr) {
364
+ results$.push(k);
365
+ }
366
+ return results$;
367
+ }
368
+ }
369
+ });
370
+ join = function(arg$){
371
+ var root, tag, ref$, cls, data, key, olds, map, enter, update, nodes, exit;
372
+ root = arg$.root, tag = (ref$ = arg$.tag) != null ? ref$ : 'g', cls = arg$.cls, data = (ref$ = arg$.data) != null
373
+ ? ref$
374
+ : [], key = arg$.key;
375
+ key = key || function(d, i){
376
+ return i;
377
+ };
378
+ olds = Array.from(root.childNodes).filter(function(n){
379
+ return n.nodeType === 1 && n.tagName === tag && (!cls || n.classList.contains(cls));
380
+ });
381
+ map = new Map();
382
+ ref$ = [[], [], [], []], enter = ref$[0], update = ref$[1], nodes = ref$[2], exit = ref$[3];
383
+ olds.map(function(n, i){
384
+ var k;
385
+ k = key(n.__data__, i);
386
+ if (map.has(k)) {
387
+ return exit.push(n);
388
+ } else {
389
+ return map.set(k, n);
390
+ }
391
+ });
392
+ data.map(function(d, i){
393
+ var k, n;
394
+ k = key(d, i);
395
+ if (n = map.get(k)) {
396
+ map['delete'](k);
397
+ update.push(n);
398
+ } else {
399
+ n = document.createElementNS(svgns, tag);
400
+ if (cls) {
401
+ n.setAttribute('class', cls);
402
+ }
403
+ root.appendChild(n);
404
+ enter.push(n);
405
+ }
406
+ n.__data__ = d;
407
+ return nodes.push(n);
408
+ });
409
+ exit = exit.concat(Array.from(map.values()));
410
+ return {
411
+ enter: enter,
412
+ update: update,
413
+ exit: exit,
414
+ nodes: nodes
415
+ };
416
+ };
417
+ anim.ease = ease;
418
+ anim.interpolate = interpolate;
419
+ anim.join = join;
420
+ if (typeof chart != 'undefined' && chart !== null) {
421
+ (chart.utils || (chart.utils = {})).anim = anim;
422
+ }
423
+ function import$(obj, src){
424
+ var own = {}.hasOwnProperty;
425
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
426
+ return obj;
427
+ }
428
+ }).call(this);
@@ -0,0 +1 @@
1
+ !function(){var n,f,l,i,u,a,h,t,e;n=function(){return("undefined"!=typeof performance&&null!==performance?performance:Date).now()},f={linear:function(t){return t},cubicInOut:function(t){return(t*=2)<=1?t*t*t/2:((t-=2)*t*t+2)/2},cubicOut:function(t){return--t*t*t+1},quadInOut:function(t){return(t*=2)<=1?t*t/2:(--t*(2-t)+1)/2}},l=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,i=function(t){var n,e;return"string"!=typeof t?null:(t=t.trim(),(n=/^#([0-9a-f]{3,4})$/i.exec(t))?[(e=n[1].split("").map(function(t){return parseInt(t+t,16)}))[0],e[1],e[2],null!=e[3]?e[3]/255:1]:(n=/^#([0-9a-f]{6})([0-9a-f]{2})?$/i.exec(t))?(e=[0,1,2].map(function(t){return parseInt(n[1].substr(2*t,2),16)})).concat([n[2]?parseInt(n[2],16)/255:1]):!(n=/^rgba?\(([^)]+)\)$/i.exec(t))||(e=n[1].split(/[\s,\/]+/).filter(function(t){return t}).map(function(t){return parseFloat(t)})).length<3||e.slice(0,3).some(function(t){return isNaN(t)})?null:[e[0],e[1],e[2],null==e[3]||isNaN(e[3])?1:e[3]])},u=function(a,s){return function(n){var t=[0,1,2,3].map(function(t){return a[t]+(s[t]-a[t])*n}),e=t[0],r=t[1],i=t[2],u=t[3];return e=(t=[e,r,i].map(function(t){return(t=0<(t=Math.round(t))?t:0)<255?t:255}))[0],r=t[1],i=t[2],1<=u?"rgb("+e+", "+r+", "+i+")":"rgba("+e+", "+r+", "+i+", "+u+")"}},a=function(t,n){var e,r,i,u,a,s,o;for(n+="",e=(t+="").match(l)||[],r=[],l.lastIndex=u=i=0;a=l.exec(n);)a.index>i&&r.push(n.slice(i,a.index)),s=+a[0],o=null!=e[u]?+e[u]:null,r.push(null!=o&&o!==s?{a:o,b:s}:a[0]),i=l.lastIndex,u++;return i<n.length&&r.push(n.slice(i)),r.some(function(t){return"object"==typeof t})?function(n){return r.map(function(t){return"object"==typeof t?t.a+(t.b-t.a)*n:t}).join("")}:function(){return n}},h=function(n,e){var t,r;return"number"==typeof e?(n=parseFloat(n),isNaN(n)&&(n=0),function(t){return n+(e-n)*t}):null==n?function(){return e}:(t=i(e))?(r=i(n))?u(r,t):function(){return e}:a(n,e)},(t=function(t){var n=this;return this._manual=!!(t=null==t?{}:t).manual,this._now=0,this._offset=0,this._raf=null,this._list=new Map,this.evtHandler={},this._tick=function(t){if(n._raf=null,!n._manual)return n._apply(n.time()),n._list.size?n._kick():void 0},this}).prototype=((t,n)=>{var e,r={}.hasOwnProperty;for(e in n)r.call(n,e)&&(t[e]=n[e]);return t})(Object.create(Object.prototype),{on:function(t,e){var r=this;return(Array.isArray(t)?t:[t]).map(function(t){var n;return((n=r.evtHandler)[t]||(n[t]=[])).push(e)})},fire:function(t){for(var n,e,r,i,u=[],a=[],s=1,o=arguments.length;s<o;++s)a.push(arguments[s]);for(n=a,s=0,r=(e=this.evtHandler[t]||[]).length;s<r;++s)i=e[s],u.push(i.apply(this,n));return u},time:function(){return this._manual?this._now:n()-this._offset},manual:function(t){return arguments.length?((t=!!t)!==this._manual&&(t?(this._now=this.time(),this._manual=!0,this._raf&&cancelAnimationFrame(this._raf),this._raf=null):(this._offset=n()-this._now,this._manual=!1,this._list.size&&this._kick())),this):this._manual},step:function(t){return null==t&&(t=1e3/60),this._manual||this.manual(!0),this._now+=t,this._apply(this._now),this.fire("step",this._now,t),this},seek:function(t){return this._manual||this.manual(!0),this._now=t,this._apply(this._now),this.fire("step",this._now,0),this},busy:function(){return 0<this._list.size},flush:function(){return this._apply(1/0),this},interrupt:function(t){return this._list.delete(t)},_kick:function(){var t=this;if(!this._manual&&!this._raf)return"undefined"==typeof requestAnimationFrame||null===requestAnimationFrame?setTimeout(function(){return t._tick()},16):this._raf=requestAnimationFrame(this._tick)},tween:function(t,n,e){var r,i,u,a,s,o,l,c;for(l in null==n&&(n={}),r=null!=(e=null==e?{}:e).duration?e.duration:350,i=e.delay||0,u="function"==typeof e.ease?e.ease:f[e.ease||"cubic-in-out"]||f.cubicInOut,a=r<=0&&i<=0||!this._manual&&"undefined"!=typeof document&&null!==document&&document.hidden,(s=this._list.get(t)||{attr:{},cb:[]}).remove=!!e.remove,e.end&&s.cb.push(e.end),o=this.time()+i,n)null==(c=n[l])?(t.removeAttribute(l),delete s.attr[l]):a?(t.setAttribute(l,c),delete s.attr[l]):s.attr[l]={to:c,start:o,dur:0<r?r:0,ease:u};return this._list.set(t,s),a&&!(()=>{var t=[];for(l in s.attr)t.push(l);return t})().length?this._done(t,s):this._manual||this._kick(),this},_done:function(n,t){return this._list.delete(n),t.remove&&n.parentNode&&n.parentNode.removeChild(n),t.cb.map(function(t){return t.call(n)})},_apply:function(t){for(var n,e,r,i,u,a,s,o=[],l=0,c=(n=Array.from(this._list)).length;l<c;++l)if(r=(e=n[l])[0],i=e[1],this._list.get(r)===i){for(u in e=i.attr)t<(a=e[u]).start||(a.interp||(a.interp=h(r.getAttribute(u),a.to)),1<=(s=a.dur&&(s=(t-a.start)/a.dur)<1?s:1)?(r.setAttribute(u,a.to),delete i.attr[u]):r.setAttribute(u,a.interp(a.ease(s))));(()=>{var t=[];for(u in i.attr)t.push(u);return t})().length||o.push(this._done(r,i))}return o}}),e=function(t){var n,r,i,u,a,e,s=t.root,o=null!=(n=t.tag)?n:"g",l=t.cls,c=null!=(n=t.data)?n:[],f=t.key;return f=f||function(t,n){return n},t=Array.from(s.childNodes).filter(function(t){return 1===t.nodeType&&t.tagName===o&&(!l||t.classList.contains(l))}),r=new Map,i=(n=[[],[],[],[]])[0],u=n[1],a=n[2],e=n[3],t.map(function(t,n){n=f(t.__data__,n);return r.has(n)?e.push(t):r.set(n,t)}),c.map(function(t,n){var e,n=f(t,n);return((e=r.get(n))?(r.delete(n),u):(e=document.createElementNS("http://www.w3.org/2000/svg",o),l&&e.setAttribute("class",l),s.appendChild(e),i)).push(e),e.__data__=t,a.push(e)}),e=e.concat(Array.from(r.values())),{enter:i,update:u,exit:e,nodes:a}},t.ease=f,t.interpolate=h,t.join=e,"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).anim=t)}.call(this);