@plotdb/chart 3.10.1 → 3.11.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 +24 -0
- package/bundle.js +239 -30
- package/bundle.min.js +1 -1
- package/index.js +165 -1
- package/index.min.js +1 -1
- package/package.json +1 -1
- package/utils/axis.js +56 -25
- package/utils/axis.min.js +1 -1
- package/utils/config.js +12 -1
- package/utils/config.min.js +1 -1
- package/utils/legend.js +6 -3
- package/utils/legend.min.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v3.11.0
|
|
4
|
+
|
|
5
|
+
- axis: `label.direction` gains `angled` and `auto`, plus `label.angle` ( degrees, default 45 ).
|
|
6
|
+
`angled` anchors each label's end at its tick and trails it down-left, the usual d3 convention;
|
|
7
|
+
the overlap test uses the label's projection along the axis ( `w·cos + h·sin` ) rather than its
|
|
8
|
+
width. `auto` tries horizontal, then angled, then vertical, and only falls back to thinning when
|
|
9
|
+
none of them fit - labels that don't fit horizontally used to be dropped outright, with no way
|
|
10
|
+
to ask for a rotation first. default stays `horizontal`, so nothing moves unless asked
|
|
11
|
+
- annotation: `common.annotation` draws notes and reference lines over the plot area, in two
|
|
12
|
+
deliberately separate coordinate spaces. `notes` are view-space - `{x, y}` are 0..1 of the plot
|
|
13
|
+
area, so they survive a resize and need nothing from the chart. `reference` is data-space -
|
|
14
|
+
`{axis, value, label}` asks the new `space` scope where that value lands, and a chart that
|
|
15
|
+
hasn't implemented the scope simply draws nothing. a reference line outside the current domain
|
|
16
|
+
is skipped rather than drawn over the axis. the two arrays are not in the config schema ( that
|
|
17
|
+
describes scalars, for konfig to build forms from ); only the styling is
|
|
18
|
+
- new `space` scope: `space.x(v)` / `space.y(v)` map a data value to plot-area coordinates, and
|
|
19
|
+
return null by default. the core does not own the scales - every chart builds its own - so this
|
|
20
|
+
is the only general way to ask. charts opt in with `mod.space`. `@makechart/line` implements it
|
|
21
|
+
- legend: new `actions` ( default true ) controls the "select all / none" shortcuts on their own.
|
|
22
|
+
`selectable` used to gate both whether items could be clicked and whether those two buttons
|
|
23
|
+
showed, so "clickable legend without the buttons" was impossible - in a small card the buttons
|
|
24
|
+
wrap and break the layout. `selectable` now only governs clicking
|
|
25
|
+
|
|
26
|
+
|
|
3
27
|
## v3.10.1
|
|
4
28
|
|
|
5
29
|
- bin: `bin.parse` skips `size` bindings that use the same field as `value` ( summing the binned field
|
package/bundle.js
CHANGED
|
@@ -899,7 +899,134 @@ var module = {exports: {}};
|
|
|
899
899
|
}
|
|
900
900
|
this._syncAnim();
|
|
901
901
|
if (this.mod.render) {
|
|
902
|
-
|
|
902
|
+
this.mod.render.apply(this);
|
|
903
|
+
}
|
|
904
|
+
return this._anno();
|
|
905
|
+
},
|
|
906
|
+
_annoBox: function(){
|
|
907
|
+
var b;
|
|
908
|
+
if (this.layout) {
|
|
909
|
+
try {
|
|
910
|
+
b = this.layout.getBox('view');
|
|
911
|
+
if (b && b.width && b.height) {
|
|
912
|
+
return b;
|
|
913
|
+
}
|
|
914
|
+
} catch (e$) {}
|
|
915
|
+
}
|
|
916
|
+
return {
|
|
917
|
+
x: 0,
|
|
918
|
+
y: 0,
|
|
919
|
+
width: (this.box || {}).width || 0,
|
|
920
|
+
height: (this.box || {}).height || 0
|
|
921
|
+
};
|
|
922
|
+
},
|
|
923
|
+
_anno: function(){
|
|
924
|
+
var cfg, enabled, notes, refs, box, font, textOf, i$, len$, n, x, y, r, dir, v, e, ln, ref$, x1, y1, x2, y2, lx, ly, anchor, baseline, this$ = this, results$ = [];
|
|
925
|
+
cfg = ((this.cfg || {}).common || {}).annotation || {};
|
|
926
|
+
enabled = cfg.enabled != null ? !!cfg.enabled : true;
|
|
927
|
+
notes = enabled
|
|
928
|
+
? cfg.notes || []
|
|
929
|
+
: [];
|
|
930
|
+
refs = enabled
|
|
931
|
+
? cfg.reference || []
|
|
932
|
+
: [];
|
|
933
|
+
if (!this.svg) {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
if (!(notes.length || refs.length)) {
|
|
937
|
+
if (this._annoG && this._annoG.parentNode) {
|
|
938
|
+
this._annoG.parentNode.removeChild(this._annoG);
|
|
939
|
+
}
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (!this._annoG) {
|
|
943
|
+
this._annoG = document.createElementNS(svgns, 'g');
|
|
944
|
+
this._annoG.setAttribute('data-type', 'annotation');
|
|
945
|
+
this._annoG.style.pointerEvents = 'none';
|
|
946
|
+
}
|
|
947
|
+
this.svg.appendChild(this._annoG);
|
|
948
|
+
this._annoG.textContent = '';
|
|
949
|
+
box = this._annoBox();
|
|
950
|
+
font = cfg.font || {};
|
|
951
|
+
textOf = function(o, x, y, anchor, baseline){
|
|
952
|
+
var t;
|
|
953
|
+
t = document.createElementNS(svgns, 'text');
|
|
954
|
+
t.setAttribute('x', x);
|
|
955
|
+
t.setAttribute('y', y);
|
|
956
|
+
t.setAttribute('text-anchor', anchor);
|
|
957
|
+
t.setAttribute('dominant-baseline', baseline);
|
|
958
|
+
t.style.fill = o.color || cfg.color || 'currentColor';
|
|
959
|
+
if (o.size || font.size) {
|
|
960
|
+
t.style.fontSize = (o.size || font.size) + "";
|
|
961
|
+
}
|
|
962
|
+
t.style.opacity = o.opacity != null
|
|
963
|
+
? o.opacity
|
|
964
|
+
: cfg.opacity != null ? cfg.opacity : 1;
|
|
965
|
+
t.textContent = o.text + "";
|
|
966
|
+
this$._annoG.appendChild(t);
|
|
967
|
+
return t;
|
|
968
|
+
};
|
|
969
|
+
for (i$ = 0, len$ = notes.length; i$ < len$; ++i$) {
|
|
970
|
+
n = notes[i$];
|
|
971
|
+
if (!(n && n.text != null)) {
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
x = box.x + box.width * (n.x != null ? n.x : 0.5);
|
|
975
|
+
y = box.y + box.height * (n.y != null ? n.y : 0.5);
|
|
976
|
+
textOf(n, x, y, n.align || 'middle', n.baseline || 'middle');
|
|
977
|
+
}
|
|
978
|
+
for (i$ = 0, len$ = refs.length; i$ < len$; ++i$) {
|
|
979
|
+
r = refs[i$];
|
|
980
|
+
if (!r) {
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
dir = r.axis === 'x' ? 'x' : 'y';
|
|
984
|
+
v = (fn$.call(this));
|
|
985
|
+
if (!(v != null) || isNaN(v)) {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
if (v < 0 || v > (dir === 'y'
|
|
989
|
+
? box.height
|
|
990
|
+
: box.width)) {
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
ln = document.createElementNS(svgns, 'line');
|
|
994
|
+
ref$ = dir === 'y'
|
|
995
|
+
? [box.x, box.y + v, box.x + box.width, box.y + v]
|
|
996
|
+
: [box.x + v, box.y, box.x + v, box.y + box.height], x1 = ref$[0], y1 = ref$[1], x2 = ref$[2], y2 = ref$[3];
|
|
997
|
+
ln.setAttribute('x1', x1);
|
|
998
|
+
ln.setAttribute('y1', y1);
|
|
999
|
+
ln.setAttribute('x2', x2);
|
|
1000
|
+
ln.setAttribute('y2', y2);
|
|
1001
|
+
import$(ln.style, {
|
|
1002
|
+
stroke: r.color || cfg.color || 'currentColor',
|
|
1003
|
+
strokeWidth: r.width != null ? r.width : 1,
|
|
1004
|
+
strokeDasharray: r.dash != null ? r.dash : '4 3',
|
|
1005
|
+
opacity: r.opacity != null
|
|
1006
|
+
? r.opacity
|
|
1007
|
+
: cfg.opacity != null ? cfg.opacity : 0.6
|
|
1008
|
+
});
|
|
1009
|
+
this._annoG.appendChild(ln);
|
|
1010
|
+
if (r.label != null) {
|
|
1011
|
+
ref$ = dir === 'y'
|
|
1012
|
+
? [box.x + box.width - 2, box.y + v - 3, 'end', 'auto']
|
|
1013
|
+
: [box.x + v + 3, box.y + 2, 'start', 'hanging'], lx = ref$[0], ly = ref$[1], anchor = ref$[2], baseline = ref$[3];
|
|
1014
|
+
results$.push(textOf({
|
|
1015
|
+
text: r.label,
|
|
1016
|
+
color: r.color,
|
|
1017
|
+
size: r.size,
|
|
1018
|
+
opacity: r.opacity
|
|
1019
|
+
}, lx, ly, anchor, baseline));
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return results$;
|
|
1023
|
+
function fn$(){
|
|
1024
|
+
try {
|
|
1025
|
+
return this.space[dir](r.value);
|
|
1026
|
+
} catch (e$) {
|
|
1027
|
+
e = e$;
|
|
1028
|
+
return null;
|
|
1029
|
+
}
|
|
903
1030
|
}
|
|
904
1031
|
},
|
|
905
1032
|
destroy: function(){
|
|
@@ -1390,10 +1517,47 @@ var module = {exports: {}};
|
|
|
1390
1517
|
type: 'color',
|
|
1391
1518
|
'default': 'transparent'
|
|
1392
1519
|
}
|
|
1520
|
+
},
|
|
1521
|
+
annotation: {
|
|
1522
|
+
enabled: {
|
|
1523
|
+
type: 'boolean',
|
|
1524
|
+
'default': true
|
|
1525
|
+
},
|
|
1526
|
+
color: {
|
|
1527
|
+
type: 'color',
|
|
1528
|
+
'default': 'currentColor'
|
|
1529
|
+
},
|
|
1530
|
+
opacity: {
|
|
1531
|
+
type: 'number',
|
|
1532
|
+
'default': 1,
|
|
1533
|
+
min: 0,
|
|
1534
|
+
max: 1,
|
|
1535
|
+
step: 0.05
|
|
1536
|
+
},
|
|
1537
|
+
font: {
|
|
1538
|
+
size: {
|
|
1539
|
+
type: 'quantity',
|
|
1540
|
+
'default': '.8em',
|
|
1541
|
+
units: [{
|
|
1542
|
+
name: 'em',
|
|
1543
|
+
max: 10,
|
|
1544
|
+
step: 0.01,
|
|
1545
|
+
'default': 0.8
|
|
1546
|
+
}]
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1393
1549
|
}
|
|
1394
1550
|
}
|
|
1395
1551
|
};
|
|
1396
1552
|
chart.scopes = {
|
|
1553
|
+
space: {
|
|
1554
|
+
x: function(v){
|
|
1555
|
+
return null;
|
|
1556
|
+
},
|
|
1557
|
+
y: function(v){
|
|
1558
|
+
return null;
|
|
1559
|
+
}
|
|
1560
|
+
},
|
|
1397
1561
|
frame: {
|
|
1398
1562
|
active: function(){
|
|
1399
1563
|
return !!this._frames;
|
|
@@ -4602,6 +4766,10 @@ var chart = module.exports;
|
|
|
4602
4766
|
type: 'boolean',
|
|
4603
4767
|
'default': true
|
|
4604
4768
|
},
|
|
4769
|
+
actions: {
|
|
4770
|
+
type: 'boolean',
|
|
4771
|
+
'default': true
|
|
4772
|
+
},
|
|
4605
4773
|
enabled: {
|
|
4606
4774
|
type: 'boolean',
|
|
4607
4775
|
'default': true
|
|
@@ -4742,7 +4910,14 @@ var chart = module.exports;
|
|
|
4742
4910
|
direction: {
|
|
4743
4911
|
type: 'choice',
|
|
4744
4912
|
'default': 'horizontal',
|
|
4745
|
-
values: ['horizontal', 'vertical']
|
|
4913
|
+
values: ['horizontal', 'angled', 'vertical', 'auto']
|
|
4914
|
+
},
|
|
4915
|
+
angle: {
|
|
4916
|
+
type: 'number',
|
|
4917
|
+
'default': 45,
|
|
4918
|
+
min: 0,
|
|
4919
|
+
max: 90,
|
|
4920
|
+
step: 1
|
|
4746
4921
|
},
|
|
4747
4922
|
gap: {
|
|
4748
4923
|
type: 'number',
|
|
@@ -5236,7 +5411,7 @@ var chart = module.exports;
|
|
|
5236
5411
|
: a.text > b.text ? -1 : 0);
|
|
5237
5412
|
});
|
|
5238
5413
|
}
|
|
5239
|
-
return ret.concat(this$.
|
|
5414
|
+
return ret.concat(this$._actions()
|
|
5240
5415
|
? this$._func
|
|
5241
5416
|
: []);
|
|
5242
5417
|
},
|
|
@@ -5267,7 +5442,7 @@ var chart = module.exports;
|
|
|
5267
5442
|
handler: {
|
|
5268
5443
|
legend: {
|
|
5269
5444
|
list: function(){
|
|
5270
|
-
return this$._data.concat(this$.
|
|
5445
|
+
return this$._data.concat(this$._actions()
|
|
5271
5446
|
? this$._func
|
|
5272
5447
|
: []);
|
|
5273
5448
|
},
|
|
@@ -5384,7 +5559,7 @@ var chart = module.exports;
|
|
|
5384
5559
|
this._func.map(function(f){
|
|
5385
5560
|
return f.text = this$._text(f.key);
|
|
5386
5561
|
});
|
|
5387
|
-
if (!this.
|
|
5562
|
+
if (!this._actions()) {
|
|
5388
5563
|
return;
|
|
5389
5564
|
}
|
|
5390
5565
|
this.view.layout.render('legend');
|
|
@@ -5397,6 +5572,9 @@ var chart = module.exports;
|
|
|
5397
5572
|
}
|
|
5398
5573
|
return this._lngHandler = null;
|
|
5399
5574
|
},
|
|
5575
|
+
_actions: function(){
|
|
5576
|
+
return !!(this.cfg.selectable && (this.cfg.actions != null ? this.cfg.actions : true));
|
|
5577
|
+
},
|
|
5400
5578
|
_name: function(ctx, type){
|
|
5401
5579
|
type == null && (type = "s");
|
|
5402
5580
|
return "pdlg-" + type + "-" + this.id + "-" + (ctx.type || '') + "-" + ctx.key;
|
|
@@ -5715,7 +5893,7 @@ var chart = module.exports;
|
|
|
5715
5893
|
var map, size, unit, count, itr, ref$, ends, k, v, this$ = this;
|
|
5716
5894
|
map = {};
|
|
5717
5895
|
size = this._n.layout.getBoundingClientRect()[this.dir < 2 ? 'width' : 'height'];
|
|
5718
|
-
unit = this.dir < 2 && this.cfg.label.direction
|
|
5896
|
+
unit = this.dir < 2 && this.cfg.label.direction !== 'horizontal' ? 12 : 25;
|
|
5719
5897
|
count = Math.round(size / unit);
|
|
5720
5898
|
itr = (ref$ = Math.round(ticks.length / (count > 1 ? count : 1))) > 1 ? ref$ : 1;
|
|
5721
5899
|
ends = this.cfg.label.strategy === 'ends';
|
|
@@ -5858,13 +6036,30 @@ var chart = module.exports;
|
|
|
5858
6036
|
return this.adjust();
|
|
5859
6037
|
},
|
|
5860
6038
|
adjust: function(){
|
|
5861
|
-
var ticks, isHorizon,
|
|
6039
|
+
var ticks, isHorizon, em, gap, fits, place, modes, allIdx, res$, i$, to$, i, len$, mode, sel, k, tol, ref$, lo, hi, pick, even, p, idx, picked, shown, mm3, md3, size, delta, box, xoff, yoff, this$ = this;
|
|
5862
6040
|
ticks = this._ticks;
|
|
5863
6041
|
isHorizon = this.dir < 2;
|
|
5864
|
-
vertical = isHorizon && this.cfg.label.direction === 'vertical';
|
|
5865
6042
|
em = parseFloat(getComputedStyle(this._n.wrap).fontSize) || 16;
|
|
5866
|
-
|
|
5867
|
-
|
|
6043
|
+
gap = em * (this.cfg.label.gap != null ? this.cfg.label.gap : 1.5);
|
|
6044
|
+
fits = function(idx){
|
|
6045
|
+
var prev, i$, len$, i, tick;
|
|
6046
|
+
prev = null;
|
|
6047
|
+
for (i$ = 0, len$ = idx.length; i$ < len$; ++i$) {
|
|
6048
|
+
i = idx[i$];
|
|
6049
|
+
tick = ticks[i];
|
|
6050
|
+
if (prev != null && tick._start - (prev._start + prev._size) < gap) {
|
|
6051
|
+
return false;
|
|
6052
|
+
}
|
|
6053
|
+
prev = tick;
|
|
6054
|
+
}
|
|
6055
|
+
return true;
|
|
6056
|
+
};
|
|
6057
|
+
place = function(tick, idx, mode){
|
|
6058
|
+
var vertical, angled, ang, ref$, cos, sin, pos, coord, box, offset, doOffset, r, toff;
|
|
6059
|
+
vertical = isHorizon && mode === 'vertical';
|
|
6060
|
+
angled = isHorizon && mode === 'angled';
|
|
6061
|
+
ang = this$.cfg.label.angle != null ? this$.cfg.label.angle : 45;
|
|
6062
|
+
ref$ = [Math.cos(ang * Math.PI / 180), Math.sin(ang * Math.PI / 180)], cos = ref$[0], sin = ref$[1];
|
|
5868
6063
|
pos = !idx
|
|
5869
6064
|
? 0
|
|
5870
6065
|
: idx === ticks.length - 1 ? 2 : 1;
|
|
@@ -5887,6 +6082,8 @@ var chart = module.exports;
|
|
|
5887
6082
|
if (vertical) {
|
|
5888
6083
|
offset.x -= box.width;
|
|
5889
6084
|
offset.y -= box.height * r;
|
|
6085
|
+
} else if (angled) {
|
|
6086
|
+
offset.x -= box.width;
|
|
5890
6087
|
} else if (isHorizon) {
|
|
5891
6088
|
offset.x -= box.width * r;
|
|
5892
6089
|
} else {
|
|
@@ -5895,16 +6092,24 @@ var chart = module.exports;
|
|
|
5895
6092
|
tick.n.tt.setAttribute('transform', "translate(" + offset.x + "," + offset.y + ")");
|
|
5896
6093
|
tick._size = vertical
|
|
5897
6094
|
? box.height
|
|
5898
|
-
:
|
|
6095
|
+
: angled
|
|
6096
|
+
? box.width * cos + box.height * sin
|
|
6097
|
+
: box[isHorizon ? 'width' : 'height'];
|
|
5899
6098
|
tick._sizeAlt = vertical
|
|
5900
6099
|
? box.width
|
|
5901
|
-
:
|
|
5902
|
-
|
|
6100
|
+
: angled
|
|
6101
|
+
? box.width * sin + box.height * cos
|
|
6102
|
+
: box[isHorizon ? 'height' : 'width'];
|
|
6103
|
+
tick._start = angled
|
|
6104
|
+
? coord - box.width * cos
|
|
6105
|
+
: coord - tick._size * r;
|
|
5903
6106
|
if (isHorizon) {
|
|
5904
6107
|
tick.n.g.setAttribute('transform', "translate(" + coord + ",0)");
|
|
5905
6108
|
tick.n.p.setAttribute('d', "M0 0L0 " + this$.cfg.tick.inner);
|
|
5906
6109
|
toff = this$.cfg.tick.inner + this$.cfg.label.padding;
|
|
5907
|
-
tick.n.t.setAttribute('transform', ("translate(0," + toff + ")") + (vertical
|
|
6110
|
+
tick.n.t.setAttribute('transform', ("translate(0," + toff + ")") + (vertical
|
|
6111
|
+
? " rotate(-90)"
|
|
6112
|
+
: angled ? " rotate(" + (-ang) + ")" : ""));
|
|
5908
6113
|
} else {
|
|
5909
6114
|
tick.n.g.setAttribute('transform', "translate(0," + coord + ")");
|
|
5910
6115
|
tick.n.p.setAttribute('d', "M0 0L-" + this$.cfg.tick.inner + " 0");
|
|
@@ -5912,26 +6117,27 @@ var chart = module.exports;
|
|
|
5912
6117
|
}
|
|
5913
6118
|
return tick.n.p.style.stroke = this$.cfg.tick.color || '';
|
|
5914
6119
|
};
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
6120
|
+
modes = isHorizon && this.cfg.label.direction === 'auto'
|
|
6121
|
+
? ['horizontal', 'angled', 'vertical']
|
|
6122
|
+
: [this.cfg.label.direction || 'horizontal'];
|
|
6123
|
+
res$ = [];
|
|
6124
|
+
for (i$ = 0, to$ = ticks.length; i$ < to$; ++i$) {
|
|
6125
|
+
i = i$;
|
|
6126
|
+
res$.push(i);
|
|
6127
|
+
}
|
|
6128
|
+
allIdx = res$;
|
|
6129
|
+
for (i$ = 0, len$ = modes.length; i$ < len$; ++i$) {
|
|
6130
|
+
mode = modes[i$];
|
|
6131
|
+
ticks.map(fn$);
|
|
6132
|
+
if (fits(allIdx)) {
|
|
6133
|
+
break;
|
|
5927
6134
|
}
|
|
5928
|
-
|
|
5929
|
-
};
|
|
6135
|
+
}
|
|
5930
6136
|
sel = [0];
|
|
5931
6137
|
if (ticks.length > 1) {
|
|
5932
6138
|
if (this.cfg.label.strategy !== 'ends') {
|
|
5933
6139
|
k = 1;
|
|
5934
|
-
while (k < ticks.length && !fits((
|
|
6140
|
+
while (k < ticks.length && !fits((fn1$()))) {
|
|
5935
6141
|
k++;
|
|
5936
6142
|
}
|
|
5937
6143
|
res$ = [];
|
|
@@ -6050,7 +6256,10 @@ var chart = module.exports;
|
|
|
6050
6256
|
return n.setAttribute('transform', "translate(" + xoff + "," + yoff + ") rotate(90)");
|
|
6051
6257
|
});
|
|
6052
6258
|
}
|
|
6053
|
-
function fn$(){
|
|
6259
|
+
function fn$(tick, i){
|
|
6260
|
+
return place(tick, i, mode);
|
|
6261
|
+
}
|
|
6262
|
+
function fn1$(){
|
|
6054
6263
|
var i$, step$, to$, results$ = [];
|
|
6055
6264
|
for (i$ = 0, to$ = ticks.length, step$ = k; step$ < 0 ? i$ > to$ : i$ < to$; i$ += step$) {
|
|
6056
6265
|
i = i$;
|