@plotdb/chart 3.6.0 → 3.8.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/scale.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function(){
2
- var e10, e5, e2, tickSpec, ticks, linear, band, scale;
2
+ var e10, e5, e2, tickSpec, ticks, identity, interpNumber, interpValue, normalize, bisectRight, piecewise, continuous, linear, transformPow, transformSqrt, transformSquare, pow, sqrt, symlog, band, point, pointish, scale;
3
3
  e10 = Math.sqrt(50);
4
4
  e5 = Math.sqrt(10);
5
5
  e2 = Math.sqrt(2);
@@ -70,58 +70,246 @@
70
70
  }
71
71
  return results$;
72
72
  };
73
- linear = function(){
74
- var ref$, d, r, s;
75
- ref$ = [[0, 1], [0, 1]], d = ref$[0], r = ref$[1];
73
+ identity = function(x){
74
+ return x;
75
+ };
76
+ interpNumber = function(a, b){
77
+ var ref$;
78
+ ref$ = [+a, +b], a = ref$[0], b = ref$[1];
79
+ return function(t){
80
+ return a * (1 - t) + b * t;
81
+ };
82
+ };
83
+ interpValue = function(a, b){
84
+ if (typeof b === 'number') {
85
+ return interpNumber(a, b);
86
+ }
87
+ if (!((typeof chart != 'undefined' && chart !== null) && chart.utils && chart.utils.anim)) {
88
+ return function(){
89
+ return b;
90
+ };
91
+ }
92
+ return chart.utils.anim.interpolate(a, b);
93
+ };
94
+ normalize = function(a, b){
95
+ a = +a;
96
+ b = b - a;
97
+ if (b) {
98
+ return function(x){
99
+ return (x - a) / b;
100
+ };
101
+ } else {
102
+ if (isNaN(b)) {
103
+ return function(){
104
+ return NaN;
105
+ };
106
+ } else {
107
+ return function(){
108
+ return 0.5;
109
+ };
110
+ }
111
+ }
112
+ };
113
+ bisectRight = function(a, x, lo, hi){
114
+ var mid;
115
+ while (lo < hi) {
116
+ mid = lo + hi >>> 1;
117
+ if (x < a[mid]) {
118
+ hi = mid;
119
+ } else {
120
+ lo = mid + 1;
121
+ }
122
+ }
123
+ return lo;
124
+ };
125
+ piecewise = function(dm, rg, ip){
126
+ var j, ref$, d0, d1, r0, r1, n, i, ns, res$, i$, ips;
127
+ j = Math.min(dm.length, rg.length) - 1;
128
+ if (j <= 1) {
129
+ ref$ = [dm[0], dm[1], rg[0], rg[1]], d0 = ref$[0], d1 = ref$[1], r0 = ref$[2], r1 = ref$[3];
130
+ ref$ = d1 < d0
131
+ ? [normalize(d1, d0), ip(r1, r0)]
132
+ : [normalize(d0, d1), ip(r0, r1)], n = ref$[0], i = ref$[1];
133
+ return function(x){
134
+ return i(n(x));
135
+ };
136
+ }
137
+ if (dm[j] < dm[0]) {
138
+ dm = dm.slice().reverse();
139
+ rg = rg.slice().reverse();
140
+ }
141
+ res$ = [];
142
+ for (i$ = 0; i$ < j; ++i$) {
143
+ i = i$;
144
+ res$.push(normalize(dm[i], dm[i + 1]));
145
+ }
146
+ ns = res$;
147
+ res$ = [];
148
+ for (i$ = 0; i$ < j; ++i$) {
149
+ i = i$;
150
+ res$.push(ip(rg[i], rg[i + 1]));
151
+ }
152
+ ips = res$;
153
+ return function(x){
154
+ var i;
155
+ i = bisectRight(dm, x, 1, j) - 1;
156
+ return ips[i](ns[i](x));
157
+ };
158
+ };
159
+ continuous = function(tf, utf){
160
+ var ref$, dm, rg, clamp, out, inp, clamper, rescale, s;
161
+ tf == null && (tf = identity);
162
+ utf == null && (utf = identity);
163
+ ref$ = [[0, 1], [0, 1], false], dm = ref$[0], rg = ref$[1], clamp = ref$[2];
164
+ ref$ = [null, null], out = ref$[0], inp = ref$[1];
165
+ clamper = function(x){
166
+ var ref$, a, b;
167
+ if (!clamp) {
168
+ return x;
169
+ }
170
+ ref$ = [dm[0], dm[Math.min(dm.length, rg.length) - 1]], a = ref$[0], b = ref$[1];
171
+ if (a > b) {
172
+ ref$ = [b, a], a = ref$[0], b = ref$[1];
173
+ }
174
+ return Math.max(a, Math.min(b, x));
175
+ };
176
+ rescale = function(){
177
+ out = null;
178
+ inp = null;
179
+ return s;
180
+ };
76
181
  s = function(x){
77
- var d0, d1, r0, r1, ref$, t, b;
78
182
  if (!(x != null) || isNaN(x = +x)) {
79
183
  return undefined;
80
184
  }
81
- d0 = d[0], d1 = d[1];
82
- r0 = r[0], r1 = r[1];
83
- if (d1 < d0) {
84
- ref$ = [d1, d0, r1, r0], d0 = ref$[0], d1 = ref$[1], r0 = ref$[2], r1 = ref$[3];
185
+ if (!out) {
186
+ out = piecewise(dm.map(tf), rg, interpValue);
187
+ }
188
+ return out(tf(clamper(x)));
189
+ };
190
+ s.invert = function(y){
191
+ if (!inp) {
192
+ inp = piecewise(rg, dm.map(tf), interpNumber);
85
193
  }
86
- t = (b = d1 - d0)
87
- ? (x - d0) / b
88
- : isNaN(b) ? NaN : 0.5;
89
- return r0 * (1 - t) + r1 * t;
194
+ return clamper(utf(inp(y)));
90
195
  };
91
196
  s.domain = function(it){
92
197
  if (!arguments.length) {
93
- return d.slice();
198
+ return dm.slice();
94
199
  }
95
- d = Array.from(it, function(v){
200
+ dm = Array.from(it, function(v){
96
201
  return +v;
97
202
  });
98
- return s;
203
+ return rescale();
99
204
  };
100
205
  s.range = function(it){
101
206
  if (!arguments.length) {
102
- return r.slice();
207
+ return rg.slice();
103
208
  }
104
- r = Array.from(it, function(v){
105
- return +v;
106
- });
107
- return s;
209
+ rg = Array.from(it);
210
+ return rescale();
108
211
  };
109
- s.invert = function(y){
110
- var d0, d1, r0, r1, t, b;
111
- d0 = d[0], d1 = d[1];
112
- r0 = r[0], r1 = r[1];
113
- t = (b = r1 - r0) ? (y - r0) / b : 0.5;
114
- return d0 * (1 - t) + d1 * t;
212
+ s.clamp = function(it){
213
+ if (!arguments.length) {
214
+ return clamp;
215
+ }
216
+ clamp = !!it;
217
+ return rescale();
115
218
  };
116
219
  s.ticks = function(count){
117
220
  count == null && (count = 10);
118
- return ticks(d[0], d[d.length - 1], count);
221
+ return ticks(dm[0], dm[dm.length - 1], count);
222
+ };
223
+ s._transform = function(t, u){
224
+ tf = t;
225
+ utf = u;
226
+ return rescale();
227
+ };
228
+ s._copy = function(c){
229
+ return c.domain(dm).range(rg).clamp(clamp);
119
230
  };
120
231
  s.copy = function(){
121
- return linear().domain(d).range(r);
232
+ return s._copy(continuous(tf, utf));
122
233
  };
123
234
  return s;
124
235
  };
236
+ linear = function(){
237
+ return continuous();
238
+ };
239
+ transformPow = function(e){
240
+ return function(x){
241
+ if (x < 0) {
242
+ return -Math.pow(-x, e);
243
+ } else {
244
+ return Math.pow(x, e);
245
+ }
246
+ };
247
+ };
248
+ transformSqrt = function(x){
249
+ if (x < 0) {
250
+ return -Math.sqrt(-x);
251
+ } else {
252
+ return Math.sqrt(x);
253
+ }
254
+ };
255
+ transformSquare = function(x){
256
+ if (x < 0) {
257
+ return -x * x;
258
+ } else {
259
+ return x * x;
260
+ }
261
+ };
262
+ pow = function(){
263
+ var s, e, update;
264
+ s = continuous();
265
+ e = 1;
266
+ update = function(){
267
+ if (e === 1) {
268
+ return s._transform(identity, identity);
269
+ } else if (e === 0.5) {
270
+ return s._transform(transformSqrt, transformSquare);
271
+ } else {
272
+ return s._transform(transformPow(e), transformPow(1 / e));
273
+ }
274
+ };
275
+ s.exponent = function(it){
276
+ if (!arguments.length) {
277
+ return e;
278
+ }
279
+ e = +it;
280
+ return update();
281
+ };
282
+ s.copy = function(){
283
+ return s._copy(pow().exponent(e));
284
+ };
285
+ return s;
286
+ };
287
+ sqrt = function(){
288
+ return pow().exponent(0.5);
289
+ };
290
+ symlog = function(){
291
+ var s, c, update;
292
+ s = continuous();
293
+ c = 1;
294
+ update = function(){
295
+ return s._transform(function(x){
296
+ return Math.sign(x) * Math.log1p(Math.abs(x / c));
297
+ }, function(x){
298
+ return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
299
+ });
300
+ };
301
+ s.constant = function(it){
302
+ if (!arguments.length) {
303
+ return c;
304
+ }
305
+ c = +it;
306
+ return update();
307
+ };
308
+ s.copy = function(){
309
+ return s._copy(symlog().constant(c));
310
+ };
311
+ return update();
312
+ };
125
313
  band = function(){
126
314
  var ref$, dm, idx, r, pi, po, al, step, bw, vals, rescale, s;
127
315
  ref$ = [[], new Map(), [0, 1], 0, 0, 0.5], dm = ref$[0], idx = ref$[1], r = ref$[2], pi = ref$[3], po = ref$[4], al = ref$[5];
@@ -217,9 +405,27 @@
217
405
  };
218
406
  return rescale();
219
407
  };
408
+ point = function(){
409
+ return pointish(band().paddingInner(1));
410
+ };
411
+ pointish = function(s){
412
+ var copy;
413
+ copy = s.copy;
414
+ s.padding = s.paddingOuter;
415
+ delete s.paddingInner;
416
+ delete s.paddingOuter;
417
+ s.copy = function(){
418
+ return pointish(copy());
419
+ };
420
+ return s;
421
+ };
220
422
  scale = {
221
423
  linear: linear,
424
+ pow: pow,
425
+ sqrt: sqrt,
426
+ symlog: symlog,
222
427
  band: band,
428
+ point: point,
223
429
  ticks: ticks
224
430
  };
225
431
  if (typeof chart != 'undefined' && chart !== null) {
@@ -1 +1 @@
1
- !function(){var f=Math.sqrt(50),h=Math.sqrt(10),c=Math.sqrt(2),g=function(n,t,r){var u,e,a,i=(t-n)/Math.max(0,r),o=Math.floor(Math.log10(i)),i=i/Math.pow(10,o),i=f<=i?10:h<=i?5:c<=i?2:1;return o<0?(u=Math.pow(10,-o)/i,(e=Math.round(n*u))/u<n&&e++,t<(a=Math.round(t*u))/u&&a--,u=-u):(u=Math.pow(10,o)*i,(e=Math.round(n/u))*u<n&&e++,t<(a=Math.round(t/u))*u&&a--),a<e&&.5<=r&&r<2?g(n,t,2*r):[e,a,u]},r=function(n,t,r){var u,e,a,i,o,f,h,c=[],l=[+n,+t,+r];if(!(0<(r=l[2])))return[];if((n=l[0])===(t=l[1]))return[n];if(e=(l=(u=t<n)?g(t,n,r):g(n,t,r))[0],i=l[2],!(e<=(a=l[1])))return[];for(o=a-e+1,f=0;f<o;++f)h=u?a-f:e+f,c.push(i<0?h/-i:h*i);return c},u=function(){var n=[[0,1],[0,1]],i=n[0],o=n[1],t=function(n){var t,r,u,e,a;if(null!=n&&!isNaN(n=+n))return t=i[0],r=i[1],e=o[0],u=o[1],r<t&&(t=(a=[r,t,u,e])[0],r=a[1],e=a[2],u=a[3]),e*(1-(e=(a=r-t)?(n-t)/a:isNaN(a)?NaN:.5))+u*e};return t.domain=function(n){return arguments.length?(i=Array.from(n,function(n){return+n}),t):i.slice()},t.range=function(n){return arguments.length?(o=Array.from(n,function(n){return+n}),t):o.slice()},t.invert=function(n){var t,r=i[0],u=i[1],e=o[0],n=(t=o[1]-e)?(n-e)/t:.5;return r*(1-n)+u*n},t.ticks=function(n){return r(i[0],i[i.length-1],n=null==n?10:n)},t.copy=function(){return u().domain(i).range(o)},t},t=function(){var f,n=[[],new Map,[0,1],0,0,.5],h=n[0],a=n[1],c=n[2],l=n[3],g=n[4],d=n[5],s=(n=[0,0,[]])[0],M=n[1],p=n[2],i=function(){var n,t,r,u=h.length,e=c[0],a=c[1],i=a<e,e=i?[a,e]:[e,a],o=e[0],a=e[1];for(o+=(a-o-(s=(a-o)/Math.max(1,u-l+2*g))*(u-l))*d,M=s*(1-l),n=[],t=0;t<u;++t)r=t,n.push(o+s*r);return p=n,i&&p.reverse(),f};return(f=function(n){if(a.has(n))return p[a.get(n)]}).domain=function(n){var t,r,u,e;if(!arguments.length)return h.slice();for(t=[[],new Map],h=t[0],a=t[1],r=0,u=n.length;r<u;++r)e=n[r],a.has(e)||a.set(e,h.push(e)-1);return i()},f.range=function(n){return arguments.length?(c=Array.from(n,function(n){return+n}),i()):c.slice()},f.bandwidth=function(){return M},f.step=function(){return s},f.paddingInner=function(n){return arguments.length?(l=Math.min(1,n),i()):l},f.paddingOuter=function(n){return arguments.length?(g=n,i()):g},f.padding=function(n){return arguments.length?(l=Math.min(1,g=n),i()):l},f.align=function(n){return arguments.length?(d=Math.max(0,Math.min(1,n)),i()):d},f.copy=function(){return t().domain(h).range(c).paddingInner(l).paddingOuter(g).align(d)},i()},n={linear:u,band:t,ticks:r};"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).scale=n)}.call(this);
1
+ !function(){var c=Math.sqrt(50),f=Math.sqrt(10),h=Math.sqrt(2),p=function(n,t,r){var u,e,i,o=(t-n)/Math.max(0,r),a=Math.floor(Math.log10(o)),o=o/Math.pow(10,a),o=c<=o?10:f<=o?5:h<=o?2:1;return a<0?(u=Math.pow(10,-a)/o,(e=Math.round(n*u))/u<n&&e++,t<(i=Math.round(t*u))/u&&i--,u=-u):(u=Math.pow(10,a)*o,(e=Math.round(n/u))*u<n&&e++,t<(i=Math.round(t/u))*u&&i--),i<e&&.5<=r&&r<2?p(n,t,2*r):[e,i,u]},l=function(n,t,r){var u,e,i,o,a,c,f,h=[],l=[+n,+t,+r];if(!(0<(r=l[2])))return[];if((n=l[0])===(t=l[1]))return[n];if(e=(l=(u=t<n)?p(t,n,r):p(n,t,r))[0],o=l[2],!(e<=(i=l[1])))return[];for(a=i-e+1,c=0;c<a;++c)f=u?i-c:e+c,h.push(o<0?f/-o:f*o);return h},s=function(n){return n},g=function(t,r){var n=[+t,+r];return t=n[0],r=n[1],function(n){return t*(1-n)+r*n}},d=function(n,t){return"number"==typeof t?g(n,t):"undefined"!=typeof chart&&null!==chart&&chart.utils&&chart.utils.anim?chart.utils.anim.interpolate(n,t):function(){return t}},M=function(t,r){return(r-=t=+t)?function(n){return(n-t)/r}:isNaN(r)?function(){return NaN}:function(){return.5}},m=function(n,t,r,u){for(var e;r<u;)t<n[e=r+u>>>1]?u=e:r=1+e;return r},v=function(r,n,t){var u,e,i,o,a,c,f,h,l,p,s,g=Math.min(r.length,n.length)-1;if(g<=1)return o=(u=[r[0],r[1],n[0],n[1]])[2],a=u[3],u=(i=u[1])<(e=u[0])?[M(i,e),t(a,o)]:[M(e,i),t(o,a)],c=u[0],f=u[1],function(n){return f(c(n))};for(r[g]<r[0]&&(r=r.slice().reverse(),n=n.slice().reverse()),l=[],p=0;p<g;++p)f=p,l.push(M(r[f],r[f+1]));for(h=l,l=[],p=0;p<g;++p)f=p,l.push(t(n[f],n[f+1]));return s=l,function(n){var t=m(r,n,1,g)-1;return s[t](h[t](n))}},y=function(r,u){var n,e,i,o,t,a,c,f,h;return null==r&&(r=s),null==u&&(u=s),e=(n=[[0,1],[0,1],!1])[0],i=n[1],o=n[2],t=(n=[null,null])[0],a=n[1],c=function(n){var t,r,u;return o?((u=(t=[e[0],e[Math.min(e.length,i.length)-1]])[1])<(r=t[0])&&(r=(t=[u,r])[0],u=t[1]),Math.max(r,Math.min(u,n))):n},f=function(){return a=t=null,h},(h=function(n){if(null!=n&&!isNaN(n=+n))return(t=t||v(e.map(r),i,d))(r(c(n)))}).invert=function(n){return a=a||v(i,e.map(r),g),c(u(a(n)))},h.domain=function(n){return arguments.length?(e=Array.from(n,function(n){return+n}),f()):e.slice()},h.range=function(n){return arguments.length?(i=Array.from(n),f()):i.slice()},h.clamp=function(n){return arguments.length?(o=!!n,f()):o},h.ticks=function(n){return l(e[0],e[e.length-1],n=null==n?10:n)},h._transform=function(n,t){return r=n,u=t,f()},h._copy=function(n){return n.domain(e).range(i).clamp(o)},h.copy=function(){return h._copy(y(r,u))},h},u=function(t){return function(n){return n<0?-Math.pow(-n,t):Math.pow(n,t)}},e=function(n){return n<0?-Math.sqrt(-n):Math.sqrt(n)},i=function(n){return n<0?-n*n:n*n},o=function(){var n=y(),t=1,r=function(){return 1===t?n._transform(s,s):.5===t?n._transform(e,i):n._transform(u(t),u(1/t))};return n.exponent=function(n){return arguments.length?(t=+n,r()):t},n.copy=function(){return n._copy(o().exponent(t))},n},a=function(){var n=y(),t=1,r=function(){return n._transform(function(n){return Math.sign(n)*Math.log1p(Math.abs(n/t))},function(n){return Math.sign(n)*Math.expm1(Math.abs(n))*t})};return n.constant=function(n){return arguments.length?(t=+n,r()):t},n.copy=function(){return n._copy(a().constant(t))},r()},t=function(){var c,n=[[],new Map,[0,1],0,0,.5],f=n[0],i=n[1],h=n[2],l=n[3],p=n[4],s=n[5],g=(n=[0,0,[]])[0],d=n[1],M=n[2],o=function(){var n,t,r,u=f.length,e=h[0],i=h[1],o=i<e,e=o?[i,e]:[e,i],a=e[0],i=e[1];for(a+=(i-a-(g=(i-a)/Math.max(1,u-l+2*p))*(u-l))*s,d=g*(1-l),n=[],t=0;t<u;++t)r=t,n.push(a+g*r);return M=n,o&&M.reverse(),c};return(c=function(n){if(i.has(n))return M[i.get(n)]}).domain=function(n){var t,r,u,e;if(!arguments.length)return f.slice();for(t=[[],new Map],f=t[0],i=t[1],r=0,u=n.length;r<u;++r)e=n[r],i.has(e)||i.set(e,f.push(e)-1);return o()},c.range=function(n){return arguments.length?(h=Array.from(n,function(n){return+n}),o()):h.slice()},c.bandwidth=function(){return d},c.step=function(){return g},c.paddingInner=function(n){return arguments.length?(l=Math.min(1,n),o()):l},c.paddingOuter=function(n){return arguments.length?(p=n,o()):p},c.padding=function(n){return arguments.length?(l=Math.min(1,p=n),o()):l},c.align=function(n){return arguments.length?(s=Math.max(0,Math.min(1,n)),o()):s},c.copy=function(){return t().domain(f).range(h).paddingInner(l).paddingOuter(p).align(s)},o()},r=function(n){var t=n.copy;return n.padding=n.paddingOuter,delete n.paddingInner,delete n.paddingOuter,n.copy=function(){return r(t())},n},n={linear:function(){return y()},pow:o,sqrt:function(){return o().exponent(.5)},symlog:a,band:t,point:function(){return r(t().paddingInner(1))},ticks:l};"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).scale=n)}.call(this);