@plotdb/chart 3.9.1 → 3.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Change Logs
2
2
 
3
+ ## v3.10.0
4
+
5
+ - bin: `utils.bin` groups raw values into bins ( histogram ), no d3. `edges` / `index` / `range` / `label` /
6
+ `count` are pure; `bin.parse` is called from a chart's `parse` ( `bin.parse.call @, opt` ) - it parses
7
+ `@raw` with the current binding, bins subset rows with the same edges and, with dataframes, computes
8
+ edges from all frames. `bin.filter` / `bin.select` convert between bins and range filters.
9
+ rules: auto width is 1 / 2 / 5 x 10^k ( Sturges for the bin count ), edges at `anchor + k * width`,
10
+ `[a, b)` or `(a, b]`, integer data is treated as discrete ( `10–19`, or `5` with width 1 ).
11
+ - config: add `preset.bin` ( `enabled`, `width`, `count`, `anchor`, `closed`, `label`, `format`, `empty` ).
12
+ charts opt in; `enabled` defaults to false since hosts may auto-bind numeric fields to every R dimension.
13
+ - subset: allow configuring the color that unselected parts fade toward
14
+ via `common.subset.background`. defaults to `cfg.background`, then white.
15
+
16
+
3
17
  ## v3.9.1
4
18
 
5
19
  - anim: check "computed style already at target" before writing immediately, so immediate tweens
package/bundle.js CHANGED
@@ -1385,6 +1385,10 @@ var module = {exports: {}};
1385
1385
  min: 0,
1386
1386
  max: 1,
1387
1387
  step: 0.01
1388
+ },
1389
+ background: {
1390
+ type: 'color',
1391
+ 'default': 'transparent'
1388
1392
  }
1389
1393
  }
1390
1394
  }
@@ -1472,17 +1476,21 @@ var module = {exports: {}};
1472
1476
  }
1473
1477
  },
1474
1478
  color: function(color, fade){
1475
- var rgb, g, f, v;
1479
+ var rgb, g, sub, f, bg, v;
1476
1480
  if (!(rgb = _rgb(color))) {
1477
1481
  return color;
1478
1482
  }
1479
1483
  g = 0.3 * rgb[0] + 0.59 * rgb[1] + 0.11 * rgb[2];
1484
+ sub = ((this.cfg || {}).common || {}).subset || {};
1480
1485
  f = fade != null
1481
1486
  ? fade
1482
- : (((this.cfg || {}).common || {}).subset || {}).fade;
1487
+ : sub.fade;
1483
1488
  f = f != null ? f : 0.72;
1484
- v = Math.round(g + (255 - g) * f);
1485
- return "rgb(" + v + "," + v + "," + v + ")";
1489
+ bg = _rgb(sub.background) || _rgb((this.cfg || {}).background) || [255, 255, 255];
1490
+ v = [0, 1, 2].map(function(i){
1491
+ return Math.round(g + (bg[i] - g) * f);
1492
+ });
1493
+ return "rgb(" + v.join(',') + ")";
1486
1494
  }
1487
1495
  }
1488
1496
  };
@@ -4634,6 +4642,51 @@ var chart = module.exports;
4634
4642
  'default': false
4635
4643
  }
4636
4644
  },
4645
+ bin: {
4646
+ enabled: {
4647
+ type: 'boolean',
4648
+ 'default': false
4649
+ },
4650
+ width: {
4651
+ type: 'number',
4652
+ 'default': 0,
4653
+ min: 0,
4654
+ max: 1000000,
4655
+ step: 0.01
4656
+ },
4657
+ count: {
4658
+ type: 'number',
4659
+ 'default': 0,
4660
+ min: 0,
4661
+ max: 100,
4662
+ step: 1
4663
+ },
4664
+ anchor: {
4665
+ type: 'number',
4666
+ 'default': 0,
4667
+ min: -1000000,
4668
+ max: 1000000,
4669
+ step: 0.01
4670
+ },
4671
+ closed: {
4672
+ type: 'choice',
4673
+ values: ['left', 'right'],
4674
+ 'default': 'left'
4675
+ },
4676
+ label: {
4677
+ type: 'choice',
4678
+ values: ['range', 'start', 'center'],
4679
+ 'default': 'range'
4680
+ },
4681
+ format: {
4682
+ type: 'format',
4683
+ 'default': ''
4684
+ },
4685
+ empty: {
4686
+ type: 'boolean',
4687
+ 'default': true
4688
+ }
4689
+ },
4637
4690
  axis: {
4638
4691
  enabled: {
4639
4692
  type: 'boolean',
@@ -6182,6 +6235,340 @@ var chart = module.exports;
6182
6235
  (chart.utils || (chart.utils = {})).tip = tip;
6183
6236
  }
6184
6237
  }).call(this);
6238
+ (function(){
6239
+ var eps, clean, isInt, niceStep, autoWidth, rawIndex, bin;
6240
+ eps = 1e-9;
6241
+ clean = function(v){
6242
+ return +(+v).toPrecision(12);
6243
+ };
6244
+ isInt = function(v){
6245
+ return Math.abs(v - Math.round(v)) < eps;
6246
+ };
6247
+ niceStep = function(span, count){
6248
+ var raw, p, e, m;
6249
+ raw = span / (count > 1 ? count : 1);
6250
+ if (!(raw > 0)) {
6251
+ return 1;
6252
+ }
6253
+ p = Math.pow(10, Math.floor(Math.log10(raw)));
6254
+ e = raw / p;
6255
+ m = e >= Math.sqrt(50)
6256
+ ? 10
6257
+ : e >= Math.sqrt(10)
6258
+ ? 5
6259
+ : e >= Math.sqrt(2) ? 2 : 1;
6260
+ return clean(m * p);
6261
+ };
6262
+ autoWidth = function(vs, lo, hi, opt){
6263
+ var count, ref$, span, w;
6264
+ count = opt.count > 0
6265
+ ? opt.count
6266
+ : Math.ceil(Math.log2((ref$ = vs.length) > 1 ? ref$ : 1)) + 1;
6267
+ if (hi === lo && isInt(lo)) {
6268
+ return 1;
6269
+ }
6270
+ span = hi > lo
6271
+ ? hi - lo
6272
+ : Math.abs(lo) || 1;
6273
+ w = niceStep(span, count);
6274
+ if (vs.every(isInt) && w < 1) {
6275
+ w = 1;
6276
+ }
6277
+ return w;
6278
+ };
6279
+ rawIndex = function(v, info){
6280
+ var k;
6281
+ k = (v - info.start) / info.width;
6282
+ if (Math.abs(k - Math.round(k)) < eps) {
6283
+ k = Math.round(k);
6284
+ }
6285
+ if (info.closed === 'right') {
6286
+ return Math.ceil(k) - 1;
6287
+ } else {
6288
+ return Math.floor(k);
6289
+ }
6290
+ };
6291
+ bin = {
6292
+ edges: function(values, opt){
6293
+ var vs, closed, anchor, max, ref$, lo, hi, width, discrete, info, k, last, res$, i$, to$, i;
6294
+ values == null && (values = []);
6295
+ opt == null && (opt = {});
6296
+ vs = values.filter(function(it){
6297
+ return typeof it === 'number' && isFinite(it);
6298
+ });
6299
+ closed = opt.closed === 'right' ? 'right' : 'left';
6300
+ anchor = isFinite(+opt.anchor) ? +opt.anchor : 0;
6301
+ max = opt.max || 500;
6302
+ if (!vs.length) {
6303
+ return {
6304
+ start: anchor,
6305
+ width: +opt.width || 1,
6306
+ anchor: anchor,
6307
+ closed: closed,
6308
+ discrete: false,
6309
+ n: 0,
6310
+ edges: []
6311
+ };
6312
+ }
6313
+ ref$ = [Math.min.apply(Math, vs), Math.max.apply(Math, vs)], lo = ref$[0], hi = ref$[1];
6314
+ width = +opt.width > 0
6315
+ ? +opt.width
6316
+ : autoWidth(vs, lo, hi, opt);
6317
+ if ((hi - lo) / width > max) {
6318
+ width = autoWidth(vs, lo, hi, {
6319
+ count: opt.count
6320
+ });
6321
+ }
6322
+ discrete = isInt(width) && isInt(anchor) && vs.every(isInt);
6323
+ info = {
6324
+ width: width,
6325
+ anchor: anchor,
6326
+ closed: closed,
6327
+ discrete: discrete
6328
+ };
6329
+ k = (lo - anchor) / width;
6330
+ if (Math.abs(k - Math.round(k)) < eps) {
6331
+ k = Math.round(k);
6332
+ }
6333
+ info.start = clean(anchor + width * (closed === 'left'
6334
+ ? Math.floor(k)
6335
+ : !discrete && isInt(k)
6336
+ ? k
6337
+ : Math.ceil(k) - 1));
6338
+ last = rawIndex(hi, info);
6339
+ if (!discrete && closed === 'left' && last > 0 && isInt((hi - info.start) / width)) {
6340
+ last = last - 1;
6341
+ }
6342
+ info.n = (ref$ = last + 1) > 1 ? ref$ : 1;
6343
+ res$ = [];
6344
+ for (i$ = 0, to$ = info.n; i$ <= to$; ++i$) {
6345
+ i = i$;
6346
+ res$.push(clean(info.start + width * i));
6347
+ }
6348
+ info.edges = res$;
6349
+ return info;
6350
+ },
6351
+ index: function(v, info){
6352
+ var i;
6353
+ if (!(typeof v === 'number' && isFinite(v)) || !info.n) {
6354
+ return -1;
6355
+ }
6356
+ i = rawIndex(v, info);
6357
+ if (!info.discrete) {
6358
+ if (i === info.n && info.closed === 'left' && Math.abs(v - info.edges[info.n]) < eps * info.width) {
6359
+ i = info.n - 1;
6360
+ }
6361
+ if (i === -1 && info.closed === 'right' && Math.abs(v - info.edges[0]) < eps * info.width) {
6362
+ i = 0;
6363
+ }
6364
+ }
6365
+ if (i < 0 || i >= info.n) {
6366
+ return -1;
6367
+ } else {
6368
+ return i;
6369
+ }
6370
+ },
6371
+ range: function(i, info){
6372
+ var ref$, a, b;
6373
+ ref$ = [info.edges[i], info.edges[i + 1]], a = ref$[0], b = ref$[1];
6374
+ if (!info.discrete) {
6375
+ return [a, b];
6376
+ }
6377
+ if (info.closed === 'right') {
6378
+ return [clean(a + 1), b];
6379
+ } else {
6380
+ return [a, clean(b - 1)];
6381
+ }
6382
+ },
6383
+ label: function(i, info, opt){
6384
+ var f, ref$, ref1$, a, b;
6385
+ opt == null && (opt = {});
6386
+ f = opt.format && ((typeof chart != 'undefined' && chart !== null) && ((ref$ = chart.utils) != null && ref$.format))
6387
+ ? chart.utils.format.from(opt.format)
6388
+ : function(it){
6389
+ return clean(it) + "";
6390
+ };
6391
+ ref1$ = bin.range(i, info), a = ref1$[0], b = ref1$[1];
6392
+ switch (opt.label) {
6393
+ case 'start':
6394
+ return f(a);
6395
+ case 'center':
6396
+ return f(clean((info.edges[i] + info.edges[i + 1]) / 2));
6397
+ default:
6398
+ if (a === b) {
6399
+ return f(a);
6400
+ } else {
6401
+ return f(a) + "–" + f(b);
6402
+ }
6403
+ }
6404
+ },
6405
+ count: function(values, info, weights){
6406
+ var m, ref$, ret, res$, i$, to$, i, len$, j, v, j$, k, w;
6407
+ values == null && (values = []);
6408
+ m = weights ? (ref$ = (weights[0] || []).length) > 1 ? ref$ : 1 : 1;
6409
+ res$ = [];
6410
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6411
+ i = i$;
6412
+ res$.push(repeatArray$([0], m));
6413
+ }
6414
+ ret = res$;
6415
+ for (i$ = 0, len$ = values.length; i$ < len$; ++i$) {
6416
+ j = i$;
6417
+ v = values[i$];
6418
+ if ((i = bin.index(v, info)) < 0) {
6419
+ continue;
6420
+ }
6421
+ if (!weights) {
6422
+ ret[i][0] += 1;
6423
+ continue;
6424
+ }
6425
+ for (j$ = 0; j$ < m; ++j$) {
6426
+ k = j$;
6427
+ w = +(weights[j] || [])[k];
6428
+ if (isFinite(w)) {
6429
+ ret[i][k] += w;
6430
+ }
6431
+ }
6432
+ }
6433
+ return ret;
6434
+ },
6435
+ parse: function(opt){
6436
+ var ref$, kv, ks, kn, cfg, sb, series, rows, all, info, vals, wts, counts, sub, shrink, labels, res$, i$, to$, i, data, d, ref1$, x0, x1;
6437
+ opt == null && (opt = {});
6438
+ ref$ = [opt.value || 'value', opt.size || 'size', opt.name || 'name'], kv = ref$[0], ks = ref$[1], kn = ref$[2];
6439
+ cfg = opt.config || (this.cfg || {}).bin || {};
6440
+ sb = this.binding[ks];
6441
+ series = !sb
6442
+ ? 0
6443
+ : Array.isArray(sb) ? sb.length : 1;
6444
+ rows = this._parseRows(this.raw || []);
6445
+ all = this._frames && ((typeof chart != 'undefined' && chart !== null) && ((ref$ = chart.scopes) != null && ref$.frame)) ? chart.scopes.frame.all.call(this) : rows;
6446
+ info = bin.edges(all.map(function(it){
6447
+ return it[kv];
6448
+ }), cfg);
6449
+ vals = function(rs){
6450
+ return rs.map(function(it){
6451
+ return it[kv];
6452
+ });
6453
+ };
6454
+ wts = function(rs){
6455
+ if (!series) {
6456
+ return null;
6457
+ } else {
6458
+ return rs.map(function(it){
6459
+ return [].concat(it[ks]);
6460
+ });
6461
+ }
6462
+ };
6463
+ counts = bin.count(vals(rows), info, wts(rows));
6464
+ sub = !this._subset
6465
+ ? null
6466
+ : bin.count(vals(this._parseRows(this._subset)), info, wts(this._parseRows(this._subset)));
6467
+ shrink = (((this.cfg || {}).common || {}).subset || {}).mode === 'shrink';
6468
+ res$ = [];
6469
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6470
+ i = i$;
6471
+ res$.push(bin.label(i, info, cfg));
6472
+ }
6473
+ labels = res$;
6474
+ if (new Set(labels).size !== labels.length) {
6475
+ res$ = [];
6476
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6477
+ i = i$;
6478
+ res$.push(bin.label(i, info, {
6479
+ label: cfg.label
6480
+ }));
6481
+ }
6482
+ labels = res$;
6483
+ }
6484
+ data = [];
6485
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6486
+ i = i$;
6487
+ if (cfg.empty === false && counts[i].every(fn$)) {
6488
+ continue;
6489
+ }
6490
+ d = {};
6491
+ d[kn] = labels[i];
6492
+ d[ks] = counts[i];
6493
+ ref1$ = [info.edges[i], info.edges[i + 1]], x0 = ref1$[0], x1 = ref1$[1];
6494
+ d.bin = {
6495
+ x0: x0,
6496
+ x1: x1,
6497
+ index: i
6498
+ };
6499
+ if (sub) {
6500
+ d.subset = {};
6501
+ d.subset[ks] = sub[i];
6502
+ if (shrink) {
6503
+ d[ks] = sub[i];
6504
+ }
6505
+ }
6506
+ d._idx = data.length;
6507
+ d._raw = (ref1$ = import$({}, d.bin), ref1$.count = counts[i], ref1$);
6508
+ data.push(d);
6509
+ }
6510
+ return {
6511
+ data: data,
6512
+ info: info,
6513
+ series: series || 1
6514
+ };
6515
+ function fn$(it){
6516
+ return !it;
6517
+ }
6518
+ },
6519
+ filter: function(a, b, info){
6520
+ var ref$, x0, x1, closed;
6521
+ ref$ = [info.edges[a], info.edges[b + 1]], x0 = ref$[0], x1 = ref$[1];
6522
+ closed = info.closed;
6523
+ if (!info.discrete) {
6524
+ if (closed === 'left' && b === info.n - 1) {
6525
+ closed = 'both';
6526
+ }
6527
+ if (closed === 'right' && a === 0) {
6528
+ closed = 'both';
6529
+ }
6530
+ }
6531
+ return {
6532
+ type: 'range',
6533
+ value: [x0, x1],
6534
+ closed: closed
6535
+ };
6536
+ },
6537
+ select: function(f, info){
6538
+ var ref$, lo, hi, idx, res$, i$, to$, i;
6539
+ if (!(f && f.type === 'range' && Array.isArray(f.value)) || !info.n) {
6540
+ return null;
6541
+ }
6542
+ ref$ = f.value, lo = ref$[0], hi = ref$[1];
6543
+ res$ = [];
6544
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6545
+ i = i$;
6546
+ if (info.edges[i + 1] > lo && info.edges[i] < hi) {
6547
+ res$.push(i);
6548
+ }
6549
+ }
6550
+ idx = res$;
6551
+ if (!idx.length) {
6552
+ return null;
6553
+ } else {
6554
+ return [idx[0], idx[idx.length - 1]];
6555
+ }
6556
+ }
6557
+ };
6558
+ if (typeof chart != 'undefined' && chart !== null) {
6559
+ (chart.utils || (chart.utils = {})).bin = bin;
6560
+ }
6561
+ function repeatArray$(arr, n){
6562
+ for (var r = []; n > 0; (n >>= 1) && (arr = arr.concat(arr)))
6563
+ if (n & 1) r.push.apply(r, arr);
6564
+ return r;
6565
+ }
6566
+ function import$(obj, src){
6567
+ var own = {}.hasOwnProperty;
6568
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
6569
+ return obj;
6570
+ }
6571
+ }).call(this);
6185
6572
  chart.utils.debounce = debounce;
6186
6573
  if (typeof window != 'undefined' && window !== null) { window.chart = chart; }
6187
6574
  })();