@plotdb/chart 3.7.0 → 3.8.1

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 CHANGED
@@ -182,13 +182,18 @@
182
182
  opt == null && (opt = {});
183
183
  this._manual = !!opt.manual;
184
184
  this._now = 0;
185
- this._offset = 0;
185
+ this._base = 0;
186
+ this._since = now();
187
+ this._speed = 1;
188
+ this._frozen = false;
189
+ this._dur = 350;
190
+ this._back = 0;
186
191
  this._raf = null;
187
192
  this._list = new Map();
188
193
  this.evtHandler = {};
189
194
  this._tick = function(t){
190
195
  this$._raf = null;
191
- if (this$._manual) {
196
+ if (this$._manual || this$._frozen) {
192
197
  return;
193
198
  }
194
199
  this$._apply(this$.time());
@@ -224,10 +229,81 @@
224
229
  time: function(){
225
230
  if (this._manual) {
226
231
  return this._now;
232
+ } else if (this._frozen) {
233
+ return this._base;
227
234
  } else {
228
- return now() - this._offset;
235
+ return this._base + (now() - this._since) * this._speed;
229
236
  }
230
237
  },
238
+ _rebase: function(){
239
+ this._base = this.time();
240
+ return this._since = now();
241
+ },
242
+ duration: function(v){
243
+ if (!arguments.length) {
244
+ return this._dur;
245
+ }
246
+ v = +v;
247
+ this._dur = isNaN(v) || v < 0 ? 350 : v;
248
+ return this;
249
+ },
250
+ speed: function(v){
251
+ if (!arguments.length) {
252
+ return this._speed;
253
+ }
254
+ v = +v;
255
+ if (isNaN(v) || v <= 0) {
256
+ v = 1;
257
+ }
258
+ if (v === this._speed) {
259
+ return this;
260
+ }
261
+ if (!this._manual) {
262
+ this._rebase();
263
+ }
264
+ this._speed = v;
265
+ return this;
266
+ },
267
+ paused: function(){
268
+ return this._frozen;
269
+ },
270
+ pause: function(){
271
+ if (this._frozen) {
272
+ return this;
273
+ }
274
+ if (!this._manual) {
275
+ this._rebase();
276
+ }
277
+ this._frozen = true;
278
+ if (this._raf) {
279
+ cancelAnimationFrame(this._raf);
280
+ }
281
+ this._raf = null;
282
+ return this;
283
+ },
284
+ resume: function(){
285
+ if (!this._frozen) {
286
+ return this;
287
+ }
288
+ this._since = now();
289
+ this._frozen = false;
290
+ if (this._list.size) {
291
+ this._kick();
292
+ }
293
+ return this;
294
+ },
295
+ ago: function(ms, fn){
296
+ this._back = ms || 0;
297
+ try {
298
+ fn();
299
+ } finally {
300
+ this._back = 0;
301
+ }
302
+ if (ms) {
303
+ this._apply(this.time());
304
+ }
305
+ return this;
306
+ },
231
307
  manual: function(v){
232
308
  if (!arguments.length) {
233
309
  return this._manual;
@@ -244,7 +320,8 @@
244
320
  }
245
321
  this._raf = null;
246
322
  } else {
247
- this._offset = now() - this._now;
323
+ this._base = this._now;
324
+ this._since = now();
248
325
  this._manual = false;
249
326
  if (this._list.size) {
250
327
  this._kick();
@@ -257,6 +334,7 @@
257
334
  if (!this._manual) {
258
335
  this.manual(true);
259
336
  }
337
+ dt = dt * this._speed;
260
338
  this._now += dt;
261
339
  this._apply(this._now);
262
340
  this.fire('step', this._now, dt);
@@ -283,7 +361,7 @@
283
361
  },
284
362
  _kick: function(){
285
363
  var this$ = this;
286
- if (this._manual || this._raf) {
364
+ if (this._manual || this._frozen || this._raf) {
287
365
  return;
288
366
  }
289
367
  if (!(typeof requestAnimationFrame != 'undefined' && requestAnimationFrame !== null)) {
@@ -294,11 +372,12 @@
294
372
  return this._raf = requestAnimationFrame(this._tick);
295
373
  },
296
374
  tween: function(node, attrs, opt){
297
- var dur, delay, ez, immediate, item, start, k, v;
375
+ var r, dur, delay, ez, immediate, item, start, k, v;
298
376
  attrs == null && (attrs = {});
299
377
  opt == null && (opt = {});
300
- dur = opt.duration != null ? opt.duration : 350;
301
- delay = opt.delay || 0;
378
+ r = this._dur / 350;
379
+ dur = (opt.duration != null ? opt.duration : 350) * r;
380
+ delay = (opt.delay || 0) * r;
302
381
  ez = typeof opt.ease === 'function'
303
382
  ? opt.ease
304
383
  : ease[opt.ease || 'cubic-in-out'] || ease.cubicInOut;
@@ -311,7 +390,7 @@
311
390
  if (opt.end) {
312
391
  item.cb.push(opt.end);
313
392
  }
314
- start = this.time() + delay;
393
+ start = this.time() - this._back + delay;
315
394
  for (k in attrs) {
316
395
  v = attrs[k];
317
396
  if (!(v != null)) {
package/utils/anim.min.js CHANGED
@@ -1 +1 @@
1
- !function(){var n,f,l,i,u,a,h,p,_,d,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=!isNaN(u)&&(t=0<u?u:0)<1?t:1)?"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)},p=function(t,n){return n.startsWith("style:")?t.style.getPropertyValue(n.slice(6)):t.getAttribute(n)},_=function(t,n,e){return n.startsWith("style:")?t.style.setProperty(n.slice(6),e):t.setAttribute(n,e)},d=function(t,n){return n.startsWith("style:")?t.style.removeProperty(n.slice(6)):t.removeAttribute(n)},(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])?(d(t,l),delete s.attr[l]):a?(_(t,l,"function"==typeof c?c(1):c),delete s.attr[l]):l.startsWith("style:")&&!t.style.getPropertyValue(l.slice(6))&&window.getComputedStyle(t).getPropertyValue(l.slice(6))===c+""?delete s.attr[l]:s.attr[l]="function"==typeof c?{fn:c,start:o,dur:0<r?r:0,ease:u}:{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=[],c=0,f=(n=Array.from(this._list)).length;c<f;++c)if(r=(e=n[c])[0],i=e[1],this._list.get(r)===i){for(u in e=i.attr)t<(a=e[u]).start||(a.fn?(s=a.dur&&(o=(t-a.start)/a.dur)<1?o:1,_(r,u,a.fn(1<=s?1:a.ease(s))),1<=s&&delete i.attr[u]):(a.interp||(a.interp=h(p(r,u),a.to)),1<=(s=a.dur&&(o=(t-a.start)/a.dur)<1?o:1)?(_(r,u,a.to),delete i.attr[u]):_(r,u,a.interp(a.ease(s)))));(()=>{var t=[];for(u in i.attr)t.push(u);return t})().length||l.push(this._done(r,i))}return l}}),e=function(t){var n,r,i,u,a,e,s,o,l,c=t.root,f=null!=(n=t.tag)?n:"g",h=t.cls,p=null!=(n=t.data)?n:[],_=t.key;for(_=_||function(t,n){return n},t=Array.from(c.childNodes).filter(function(t){return 1===t.nodeType&&t.tagName===f&&(!h||t.classList.contains(h))}),r=new Map,i=(n=[[],[],[],[]])[0],u=n[1],a=n[2],e=n[3],t.map(function(t,n){n=_(t.__data__,n);return r.has(n)?e.push(t):r.set(n,t)}),p.map(function(t,n){var e,n=_(t,n);return((e=r.get(n))?(r.delete(n),u):(e=document.createElementNS("http://www.w3.org/2000/svg",f),h&&e.setAttribute("class",h),e._entering=!0,i)).push(e),e.__data__=t,a.push(e)}),s=null,o=a.length-1;0<=o;--o)s=((l=a[o])._entering&&(delete l._entering,c.insertBefore(l,s)),l);return 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);
1
+ !function(){var n,c,l,r,s,u,f,_,p,d,t,e;n=function(){return("undefined"!=typeof performance&&null!==performance?performance:Date).now()},c={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,r=function(t){var e,n;return"string"!=typeof t?null:(t=t.trim(),(e=/^#([0-9a-f]{3,4})$/i.exec(t))?[(n=e[1].split("").map(function(t){return parseInt(t+t,16)}))[0],n[1],n[2],null!=n[3]?n[3]/255:1]:(e=/^#([0-9a-f]{6})([0-9a-f]{2})?$/i.exec(t))?(n=[0,1,2].map(function(t){return parseInt(e[1].substr(2*t,2),16)})).concat([e[2]?parseInt(e[2],16)/255:1]):!(e=/^rgba?\(([^)]+)\)$/i.exec(t))||(n=e[1].split(/[\s,\/]+/).filter(function(t){return t}).map(function(t){return parseFloat(t)})).length<3||n.slice(0,3).some(function(t){return isNaN(t)})?null:[n[0],n[1],n[2],null==n[3]||isNaN(n[3])?1:n[3]])},s=function(u,a){return function(e){var t=[0,1,2,3].map(function(t){return u[t]+(a[t]-u[t])*e}),n=t[0],i=t[1],r=t[2],s=t[3];return n=(t=[n,i,r].map(function(t){return(t=0<(t=Math.round(t))?t:0)<255?t:255}))[0],i=t[1],r=t[2],1===(s=!isNaN(s)&&(t=0<s?s:0)<1?t:1)?"rgb("+n+", "+i+", "+r+")":"rgba("+n+", "+i+", "+r+", "+s+")"}},u=function(t,e){var n,i,r,s,u,a,o;for(e+="",n=(t+="").match(l)||[],i=[],l.lastIndex=s=r=0;u=l.exec(e);)u.index>r&&i.push(e.slice(r,u.index)),a=+u[0],o=null!=n[s]?+n[s]:null,i.push(null!=o&&o!==a?{a:o,b:a}:u[0]),r=l.lastIndex,s++;return r<e.length&&i.push(e.slice(r)),i.some(function(t){return"object"==typeof t})?function(e){return i.map(function(t){return"object"==typeof t?t.a+(t.b-t.a)*e:t}).join("")}:function(){return e}},f=function(e,n){var t,i;return"number"==typeof n?(e=parseFloat(e),isNaN(e)&&(e=0),function(t){return e+(n-e)*t}):null==e?function(){return n}:(t=r(n))?(i=r(e))?s(i,t):function(){return n}:u(e,n)},_=function(t,e){return e.startsWith("style:")?t.style.getPropertyValue(e.slice(6)):t.getAttribute(e)},p=function(t,e,n){return e.startsWith("style:")?t.style.setProperty(e.slice(6),n):t.setAttribute(e,n)},d=function(t,e){return e.startsWith("style:")?t.style.removeProperty(e.slice(6)):t.removeAttribute(e)},(t=function(t){var e=this;return this._manual=!!(t=null==t?{}:t).manual,this._now=0,this._base=0,this._since=n(),this._speed=1,this._frozen=!1,this._dur=350,this._back=0,this._raf=null,this._list=new Map,this.evtHandler={},this._tick=function(t){if(e._raf=null,!e._manual&&!e._frozen)return e._apply(e.time()),e._list.size?e._kick():void 0},this}).prototype=((t,e)=>{var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t})(Object.create(Object.prototype),{on:function(t,n){var i=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=i.evtHandler)[t]||(e[t]=[])).push(n)})},fire:function(t){for(var e,n,i,r,s=[],u=[],a=1,o=arguments.length;a<o;++a)u.push(arguments[a]);for(e=u,a=0,i=(n=this.evtHandler[t]||[]).length;a<i;++a)r=n[a],s.push(r.apply(this,e));return s},time:function(){return this._manual?this._now:this._frozen?this._base:this._base+(n()-this._since)*this._speed},_rebase:function(){return this._base=this.time(),this._since=n()},duration:function(t){return arguments.length?(t=+t,this._dur=isNaN(t)||t<0?350:t,this):this._dur},speed:function(t){return arguments.length?(t=+t,(t=isNaN(t)||t<=0?1:t)!==this._speed&&(this._manual||this._rebase(),this._speed=t),this):this._speed},paused:function(){return this._frozen},pause:function(){return this._frozen||(this._manual||this._rebase(),this._frozen=!0,this._raf&&cancelAnimationFrame(this._raf),this._raf=null),this},resume:function(){return this._frozen&&(this._since=n(),this._frozen=!1,this._list.size)&&this._kick(),this},ago:function(t,e){this._back=t||0;try{e()}finally{this._back=0}return t&&this._apply(this.time()),this},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._base=this._now,this._since=n(),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),t*=this._speed,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._frozen||this._raf))return"undefined"==typeof requestAnimationFrame||null===requestAnimationFrame?setTimeout(function(){return t._tick()},16):this._raf=requestAnimationFrame(this._tick)},tween:function(t,e,n){var i,r,s,u,a,o,l,h;for(l in null==e&&(e={}),r=this._dur/350,i=(null!=(n=null==n?{}:n).duration?n.duration:350)*r,r=(n.delay||0)*r,s="function"==typeof n.ease?n.ease:c[n.ease||"cubic-in-out"]||c.cubicInOut,u=i<=0&&r<=0||!this._manual&&"undefined"!=typeof document&&null!==document&&document.hidden,(a=this._list.get(t)||{attr:{},cb:[]}).remove=!!n.remove,n.end&&a.cb.push(n.end),o=this.time()-this._back+r,e)null==(h=e[l])?(d(t,l),delete a.attr[l]):u?(p(t,l,"function"==typeof h?h(1):h),delete a.attr[l]):l.startsWith("style:")&&!t.style.getPropertyValue(l.slice(6))&&window.getComputedStyle(t).getPropertyValue(l.slice(6))===h+""?delete a.attr[l]:a.attr[l]="function"==typeof h?{fn:h,start:o,dur:0<i?i:0,ease:s}:{to:h,start:o,dur:0<i?i:0,ease:s};return this._list.set(t,a),u&&!(()=>{var t=[];for(l in a.attr)t.push(l);return t})().length?this._done(t,a):this._manual||this._kick(),this},_done:function(e,t){return this._list.delete(e),t.remove&&e.parentNode&&e.parentNode.removeChild(e),t.cb.map(function(t){return t.call(e)})},_apply:function(t){for(var e,n,i,r,s,u,a,o,l=[],h=0,c=(e=Array.from(this._list)).length;h<c;++h)if(i=(n=e[h])[0],r=n[1],this._list.get(i)===r){for(s in n=r.attr)t<(u=n[s]).start||(u.fn?(a=u.dur&&(o=(t-u.start)/u.dur)<1?o:1,p(i,s,u.fn(1<=a?1:u.ease(a))),1<=a&&delete r.attr[s]):(u.interp||(u.interp=f(_(i,s),u.to)),1<=(a=u.dur&&(o=(t-u.start)/u.dur)<1?o:1)?(p(i,s,u.to),delete r.attr[s]):p(i,s,u.interp(u.ease(a)))));(()=>{var t=[];for(s in r.attr)t.push(s);return t})().length||l.push(this._done(i,r))}return l}}),e=function(t){var e,i,r,s,u,n,a,o,l,h=t.root,c=null!=(e=t.tag)?e:"g",f=t.cls,_=null!=(e=t.data)?e:[],p=t.key;for(p=p||function(t,e){return e},t=Array.from(h.childNodes).filter(function(t){return 1===t.nodeType&&t.tagName===c&&(!f||t.classList.contains(f))}),i=new Map,r=(e=[[],[],[],[]])[0],s=e[1],u=e[2],n=e[3],t.map(function(t,e){e=p(t.__data__,e);return i.has(e)?n.push(t):i.set(e,t)}),_.map(function(t,e){var n,e=p(t,e);return((n=i.get(e))?(i.delete(e),s):(n=document.createElementNS("http://www.w3.org/2000/svg",c),f&&n.setAttribute("class",f),n._entering=!0,r)).push(n),n.__data__=t,u.push(n)}),a=null,o=u.length-1;0<=o;--o)a=((l=u[o])._entering&&(delete l._entering,h.insertBefore(l,a)),l);return n=n.concat(Array.from(i.values())),{enter:r,update:s,exit:n,nodes:u}},t.ease=c,t.interpolate=f,t.join=e,"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).anim=t)}.call(this);