@plotdb/chart 3.9.1 → 3.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Change Logs
2
2
 
3
+ ## v3.10.1
4
+
5
+ - bin: `bin.parse` skips `size` bindings that use the same field as `value` ( summing the binned field
6
+ itself is meaningless ) and counts instead - editors often auto-bind the only numeric column to `size`
7
+ before the user binds it to `value`. returns `keep`, the indices of the size bindings actually used.
8
+
9
+
10
+ ## v3.10.0
11
+
12
+ - bin: `utils.bin` groups raw values into bins ( histogram ), no d3. `edges` / `index` / `range` / `label` /
13
+ `count` are pure; `bin.parse` is called from a chart's `parse` ( `bin.parse.call @, opt` ) - it parses
14
+ `@raw` with the current binding, bins subset rows with the same edges and, with dataframes, computes
15
+ edges from all frames. `bin.filter` / `bin.select` convert between bins and range filters.
16
+ rules: auto width is 1 / 2 / 5 x 10^k ( Sturges for the bin count ), edges at `anchor + k * width`,
17
+ `[a, b)` or `(a, b]`, integer data is treated as discrete ( `10–19`, or `5` with width 1 ).
18
+ - config: add `preset.bin` ( `enabled`, `width`, `count`, `anchor`, `closed`, `label`, `format`, `empty` ).
19
+ charts opt in; `enabled` defaults to false since hosts may auto-bind numeric fields to every R dimension.
20
+ - subset: allow configuring the color that unselected parts fade toward
21
+ via `common.subset.background`. defaults to `cfg.background`, then white.
22
+
23
+
3
24
  ## v3.9.1
4
25
 
5
26
  - 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,358 @@ 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, vk, keep, res$, i$, len$, i, b, series, rows, all, info, vals, wts, counts, sub, shrink, labels, to$, 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
+ sb = !sb
6442
+ ? []
6443
+ : Array.isArray(sb)
6444
+ ? sb
6445
+ : [sb];
6446
+ vk = (this.binding[kv] || {}).key;
6447
+ res$ = [];
6448
+ for (i$ = 0, len$ = sb.length; i$ < len$; ++i$) {
6449
+ i = i$;
6450
+ b = sb[i$];
6451
+ if (!(b && b.key === vk)) {
6452
+ res$.push(i);
6453
+ }
6454
+ }
6455
+ keep = res$;
6456
+ series = keep.length;
6457
+ rows = this._parseRows(this.raw || []);
6458
+ all = this._frames && ((typeof chart != 'undefined' && chart !== null) && ((ref$ = chart.scopes) != null && ref$.frame)) ? chart.scopes.frame.all.call(this) : rows;
6459
+ info = bin.edges(all.map(function(it){
6460
+ return it[kv];
6461
+ }), cfg);
6462
+ vals = function(rs){
6463
+ return rs.map(function(it){
6464
+ return it[kv];
6465
+ });
6466
+ };
6467
+ wts = function(rs){
6468
+ if (!series) {
6469
+ return null;
6470
+ } else {
6471
+ return rs.map(function(r){
6472
+ var s;
6473
+ s = [].concat(r[ks]);
6474
+ return keep.map(function(it){
6475
+ return s[it];
6476
+ });
6477
+ });
6478
+ }
6479
+ };
6480
+ counts = bin.count(vals(rows), info, wts(rows));
6481
+ sub = !this._subset
6482
+ ? null
6483
+ : bin.count(vals(this._parseRows(this._subset)), info, wts(this._parseRows(this._subset)));
6484
+ shrink = (((this.cfg || {}).common || {}).subset || {}).mode === 'shrink';
6485
+ res$ = [];
6486
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6487
+ i = i$;
6488
+ res$.push(bin.label(i, info, cfg));
6489
+ }
6490
+ labels = res$;
6491
+ if (new Set(labels).size !== labels.length) {
6492
+ res$ = [];
6493
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6494
+ i = i$;
6495
+ res$.push(bin.label(i, info, {
6496
+ label: cfg.label
6497
+ }));
6498
+ }
6499
+ labels = res$;
6500
+ }
6501
+ data = [];
6502
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6503
+ i = i$;
6504
+ if (cfg.empty === false && counts[i].every(fn$)) {
6505
+ continue;
6506
+ }
6507
+ d = {};
6508
+ d[kn] = labels[i];
6509
+ d[ks] = counts[i];
6510
+ ref1$ = [info.edges[i], info.edges[i + 1]], x0 = ref1$[0], x1 = ref1$[1];
6511
+ d.bin = {
6512
+ x0: x0,
6513
+ x1: x1,
6514
+ index: i
6515
+ };
6516
+ if (sub) {
6517
+ d.subset = {};
6518
+ d.subset[ks] = sub[i];
6519
+ if (shrink) {
6520
+ d[ks] = sub[i];
6521
+ }
6522
+ }
6523
+ d._idx = data.length;
6524
+ d._raw = (ref1$ = import$({}, d.bin), ref1$.count = counts[i], ref1$);
6525
+ data.push(d);
6526
+ }
6527
+ return {
6528
+ data: data,
6529
+ info: info,
6530
+ series: series || 1,
6531
+ keep: keep
6532
+ };
6533
+ function fn$(it){
6534
+ return !it;
6535
+ }
6536
+ },
6537
+ filter: function(a, b, info){
6538
+ var ref$, x0, x1, closed;
6539
+ ref$ = [info.edges[a], info.edges[b + 1]], x0 = ref$[0], x1 = ref$[1];
6540
+ closed = info.closed;
6541
+ if (!info.discrete) {
6542
+ if (closed === 'left' && b === info.n - 1) {
6543
+ closed = 'both';
6544
+ }
6545
+ if (closed === 'right' && a === 0) {
6546
+ closed = 'both';
6547
+ }
6548
+ }
6549
+ return {
6550
+ type: 'range',
6551
+ value: [x0, x1],
6552
+ closed: closed
6553
+ };
6554
+ },
6555
+ select: function(f, info){
6556
+ var ref$, lo, hi, idx, res$, i$, to$, i;
6557
+ if (!(f && f.type === 'range' && Array.isArray(f.value)) || !info.n) {
6558
+ return null;
6559
+ }
6560
+ ref$ = f.value, lo = ref$[0], hi = ref$[1];
6561
+ res$ = [];
6562
+ for (i$ = 0, to$ = info.n; i$ < to$; ++i$) {
6563
+ i = i$;
6564
+ if (info.edges[i + 1] > lo && info.edges[i] < hi) {
6565
+ res$.push(i);
6566
+ }
6567
+ }
6568
+ idx = res$;
6569
+ if (!idx.length) {
6570
+ return null;
6571
+ } else {
6572
+ return [idx[0], idx[idx.length - 1]];
6573
+ }
6574
+ }
6575
+ };
6576
+ if (typeof chart != 'undefined' && chart !== null) {
6577
+ (chart.utils || (chart.utils = {})).bin = bin;
6578
+ }
6579
+ function repeatArray$(arr, n){
6580
+ for (var r = []; n > 0; (n >>= 1) && (arr = arr.concat(arr)))
6581
+ if (n & 1) r.push.apply(r, arr);
6582
+ return r;
6583
+ }
6584
+ function import$(obj, src){
6585
+ var own = {}.hasOwnProperty;
6586
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
6587
+ return obj;
6588
+ }
6589
+ }).call(this);
6185
6590
  chart.utils.debounce = debounce;
6186
6591
  if (typeof window != 'undefined' && window !== null) { window.chart = chart; }
6187
6592
  })();