update plugin files

This commit is contained in:
REJack
2021-02-17 08:25:25 +01:00
parent 378a39ea12
commit 1c856b0d8c
16 changed files with 542 additions and 11665 deletions

View File

@@ -4,7 +4,7 @@
*
* uPlot.js (μPlot)
* A small, fast chart for time series, lines, areas, ohlc & bars
* https://github.com/leeoniya/uPlot (v1.6.4)
* https://github.com/leeoniya/uPlot (v1.6.5)
*/
'use strict';
@@ -110,6 +110,7 @@ function fixIncr(minIncr, maxIncr, minExp, maxExp) {
}
function rangeLog(min, max, base, fullMags) {
let logFn = base == 10 ? log10 : log2;
if (min == max) {
@@ -129,8 +130,8 @@ function rangeLog(min, max, base, fullMags) {
max = minMaxIncrs[1];
}
else {
minExp = floor(logFn(min));
maxExp = floor(logFn(max));
minExp = floor(logFn(abs(min)));
maxExp = floor(logFn(abs(max)));
minMaxIncrs = fixIncr(pow(base, minExp), pow(base, maxExp), minExp, maxExp);
@@ -141,6 +142,18 @@ function rangeLog(min, max, base, fullMags) {
return [min, max];
}
function rangeAsinh(min, max, base, fullMags) {
let minMax = rangeLog(min, max, base, fullMags);
if (min == 0)
minMax[0] = 0;
if (max == 0)
minMax[1] = 0;
return minMax;
}
const _eqRangePart = {
pad: 0,
soft: null,
@@ -212,6 +225,7 @@ const fmtNum = new Intl.NumberFormat(navigator.language).format;
const M = Math;
const PI = M.PI;
const abs = M.abs;
const floor = M.floor;
const round = M.round;
@@ -222,7 +236,8 @@ const pow = M.pow;
const sqrt = M.sqrt;
const log10 = M.log10;
const log2 = M.log2;
const PI = M.PI;
const sinh = (v, linthresh = 1) => M.sinh(v / linthresh);
const asinh = (v, linthresh = 1) => M.asinh(v / linthresh);
const inf = Infinity;
@@ -541,9 +556,9 @@ function slice3(str) {
return str.slice(0, 3);
}
const days3 = days.map(slice3);
const days3 = days.map(slice3);
const months3 = months.map(slice3);
const months3 = months.map(slice3);
const engNames = {
MMMM: months,
@@ -868,8 +883,8 @@ function genTimeStuffs(ms) {
];
}
const [ timeIncrsMs, _timeAxisStampsMs, timeAxisSplitsMs ] = genTimeStuffs(1);
const [ timeIncrsS, _timeAxisStampsS, timeAxisSplitsS ] = genTimeStuffs(1e-3);
const [ timeIncrsMs, _timeAxisStampsMs, timeAxisSplitsMs ] = genTimeStuffs(1);
const [ timeIncrsS, _timeAxisStampsS, timeAxisSplitsS ] = genTimeStuffs(1e-3);
// base 2
genIncrs(2, -53, 53, [1]);
@@ -1145,6 +1160,7 @@ function numAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace,
return splits;
}
// this doesnt work for sin, which needs to come off from 0 independently in pos and neg dirs
function logAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace, forceMin) {
const splits = [];
@@ -1173,6 +1189,18 @@ function logAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace,
return splits;
}
function asinhAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace, forceMin) {
let sc = self.scales[self.axes[axisIdx].scale];
let linthresh = sc.asinh;
let posSplits = scaleMax > linthresh ? logAxisSplits(self, axisIdx, max(linthresh, scaleMin), scaleMax, foundIncr) : [linthresh];
let zero = scaleMax >= 0 && scaleMin <= 0 ? [0] : [];
let negSplits = scaleMin < -linthresh ? logAxisSplits(self, axisIdx, max(linthresh, -scaleMax), -scaleMin, foundIncr): [linthresh];
return negSplits.reverse().map(v => -v).concat(zero, posSplits);
}
const RE_ALL = /./;
const RE_12357 = /[12357]/;
const RE_125 = /[125]/;
@@ -1181,8 +1209,9 @@ const RE_1 = /1/;
function logAxisValsFilt(self, splits, axisIdx, foundSpace, foundIncr) {
let axis = self.axes[axisIdx];
let scaleKey = axis.scale;
let sc = self.scales[scaleKey];
if (self.scales[scaleKey].log == 2)
if (sc.distr == 3 && sc.log == 2)
return splits;
let valToPos = self.valToPos;
@@ -1198,7 +1227,7 @@ function logAxisValsFilt(self, splits, axisIdx, foundSpace, foundIncr) {
RE_1
);
return splits.map(v => re.test(v) ? v : null);
return splits.map(v => ((sc.distr == 4 && v == 0) || re.test(v)) ? v : null);
}
function numSeriesVal(self, val) {
@@ -1292,6 +1321,7 @@ const xScaleOpts = {
auto: true,
distr: 1,
log: 10,
asinh: 1,
min: null,
max: null,
dir: 1,
@@ -1305,24 +1335,31 @@ const yScaleOpts = assign({}, xScaleOpts, {
const syncs = {};
function _sync(opts) {
let clients = [];
function _sync(key, opts) {
let s = syncs[key];
return {
sub(client) {
clients.push(client);
},
unsub(client) {
clients = clients.filter(c => c != client);
},
pub(type, self, x, y, w, h, i) {
if (clients.length > 1) {
clients.forEach(client => {
client != self && client.pub(type, self, x, y, w, h, i);
});
if (!s) {
let clients = [];
s = {
key,
sub(client) {
clients.push(client);
},
unsub(client) {
clients = clients.filter(c => c != client);
},
pub(type, self, x, y, w, h, i) {
for (let i = 0; i < clients.length; i++)
clients[i] != self && clients[i].pub(type, self, x, y, w, h, i);
}
}
};
};
if (key != null)
syncs[key] = s;
}
return s;
}
function orient(u, seriesIdx, cb) {
@@ -1981,7 +2018,7 @@ function bars(opts) {
};
}
const linearPath = linear() ;
const linearPath = linear() ;
function setDefaults(d, xo, yo, initY) {
let d2 = initY ? [d[0], d[1]].concat(d.slice(2)) : [d[0]].concat(d.slice(1));
@@ -2012,6 +2049,12 @@ function snapLogY(self, dataMin, dataMax, scale) {
const snapLogX = snapLogY;
function snapAsinhY(self, dataMin, dataMax, scale) {
return dataMin == null ? nullMinMax : rangeAsinh(dataMin, dataMax, self.scales[scale].log, false);
}
const snapAsinhX = snapAsinhY;
// dim is logical (getClientBoundingRect) pixels, not canvas pixels
function findIncr(min, max, incrs, dim, minSpace) {
let pxPerUnit = dim / (max - min);
@@ -2039,12 +2082,15 @@ function pxRatioFont(font) {
function uPlot(opts, data, then) {
const self = {};
// TODO: cache denoms & mins scale.cache = {r, min, }
function getValPct(val, scale) {
return (
scale.distr == 3
? log10((val > 0 ? val : scale.clamp(self, val, scale.min, scale.max, scale.key)) / scale.min) / log10(scale.max / scale.min)
: (val - scale.min) / (scale.max - scale.min)
let _val = (
scale.distr == 3 ? log10(val > 0 ? val : scale.clamp(self, val, scale.min, scale.max, scale.key)) :
scale.distr == 4 ? asinh(val, scale.asinh) :
val
);
return (_val - scale._min) / (scale._max - scale._min);
}
function getHPos(val, scale, dim, off) {
@@ -2133,8 +2179,7 @@ function uPlot(opts, data, then) {
sc.key = scaleKey;
let isTime = sc.time;
let isLog = sc.distr == 3;
let isTime = sc.time;
let rn = sc.range;
@@ -2144,11 +2189,17 @@ function uPlot(opts, data, then) {
rn = (self, dataMin, dataMax) => dataMin == null ? nullMinMax : rangeNum(dataMin, dataMax, cfg);
}
sc.range = fnOrSelf(rn || (isTime ? snapTimeX : scaleKey == xScaleKey ? (isLog ? snapLogX : snapNumX) : (isLog ? snapLogY : snapNumY)));
sc.range = fnOrSelf(rn || (isTime ? snapTimeX : scaleKey == xScaleKey ?
(sc.distr == 3 ? snapLogX : sc.distr == 4 ? snapAsinhX : snapNumX) :
(sc.distr == 3 ? snapLogY : sc.distr == 4 ? snapAsinhY : snapNumY)
));
sc.auto = fnOrSelf(sc.auto);
sc.clamp = fnOrSelf(sc.clamp || clampScale);
// caches for expensive ops like asinh() & log()
sc._min = sc._max = null;
}
}
}
@@ -2225,15 +2276,15 @@ function uPlot(opts, data, then) {
}
// self.tz = opts.tz || Intl.DateTimeFormat().resolvedOptions().timeZone;
const _tzDate = (opts.tzDate || (ts => new Date(ts / ms)));
const _fmtDate = (opts.fmtDate || fmtDate);
const _tzDate = (opts.tzDate || (ts => new Date(ts / ms)));
const _fmtDate = (opts.fmtDate || fmtDate);
const _timeAxisSplits = (ms == 1 ? timeAxisSplitsMs(_tzDate) : timeAxisSplitsS(_tzDate));
const _timeAxisVals = timeAxisVals(_tzDate, timeAxisStamps((ms == 1 ? _timeAxisStampsMs : _timeAxisStampsS), _fmtDate));
const _timeSeriesVal = timeSeriesVal(_tzDate, timeSeriesStamp(_timeSeriesStamp, _fmtDate));
const _timeAxisSplits = (ms == 1 ? timeAxisSplitsMs(_tzDate) : timeAxisSplitsS(_tzDate));
const _timeAxisVals = timeAxisVals(_tzDate, timeAxisStamps((ms == 1 ? _timeAxisStampsMs : _timeAxisStampsS), _fmtDate));
const _timeSeriesVal = timeSeriesVal(_tzDate, timeSeriesStamp(_timeSeriesStamp, _fmtDate));
const legend = assign({show: true, live: true}, opts.legend);
const showLegend = legend.show;
const legend = assign({show: true, live: true}, opts.legend);
const showLegend = legend.show;
{
legend.width = fnOrSelf(ifNull(legend.width, legendWidth));
@@ -2299,10 +2350,10 @@ function uPlot(opts, data, then) {
if (i > 0) {
onMouse("click", label, e => {
if ( cursor._lock)
if (cursor._lock)
return;
setSeries(series.indexOf(s), {show: !s.show}, syncOpts.setSeries);
setSeries(series.indexOf(s), {show: !s.show}, syncOpts.setSeries);
});
if (cursorFocus) {
@@ -2509,7 +2560,7 @@ function uPlot(opts, data, then) {
});
}
const cursor = (self.cursor = assign({}, cursorOpts, opts.cursor));
const cursor = (self.cursor = assign({}, cursorOpts, opts.cursor));
{
cursor._lock = false;
@@ -2523,8 +2574,8 @@ function uPlot(opts, data, then) {
points.fill = fnOrSelf(points.fill);
}
const focus = self.focus = assign({}, opts.focus || {alpha: 0.3}, cursor.focus);
const cursorFocus = focus.prox >= 0;
const focus = self.focus = assign({}, opts.focus || {alpha: 0.3}, cursor.focus);
const cursorFocus = focus.prox >= 0;
// series-intersection markers
let cursorPts = [null];
@@ -2545,7 +2596,7 @@ function uPlot(opts, data, then) {
}
function initSeries(s, i) {
let isTime = scales[s.scale].time;
let isTime = scales[s.scale].time;
let sv = s.value;
s.value = isTime ? (isStr(sv) ? timeSeriesVal(_tzDate, timeSeriesStamp(sv, _fmtDate)) : sv || _timeSeriesVal) : sv || numSeriesVal;
@@ -2578,7 +2629,7 @@ function uPlot(opts, data, then) {
if (showLegend)
legendRows.splice(i, 0, initLegendRow(s, i));
if ( cursor.show) {
if (cursor.show) {
let pt = initCursorPt(s, i);
pt && cursorPts.splice(i, 0, pt);
}
@@ -2596,8 +2647,8 @@ function uPlot(opts, data, then) {
function delSeries(i) {
series.splice(i, 1);
showLegend && legendRows.splice(i, 1)[0][0].parentNode.remove();
cursorPts.length > 1 && cursorPts.splice(i, 1)[0].remove();
showLegend && legendRows.splice(i, 1)[0][0].parentNode.remove();
cursorPts.length > 1 && cursorPts.splice(i, 1)[0].remove();
// TODO: de-init no-longer-needed scales?
}
@@ -2623,13 +2674,13 @@ function uPlot(opts, data, then) {
}
// also set defaults for incrs & values based on axis distr
let isTime = sc.time;
let isTime = sc.time;
axis.size = fnOrSelf(axis.size);
axis.space = fnOrSelf(axis.space);
axis.rotate = fnOrSelf(axis.rotate);
axis.incrs = fnOrSelf(axis.incrs || ( sc.distr == 2 ? wholeIncrs : (isTime ? (ms == 1 ? timeIncrsMs : timeIncrsS) : numIncrs)));
axis.splits = fnOrSelf(axis.splits || (isTime && sc.distr == 1 ? _timeAxisSplits : sc.distr == 3 ? logAxisSplits : numAxisSplits));
axis.splits = fnOrSelf(axis.splits || (isTime && sc.distr == 1 ? _timeAxisSplits : sc.distr == 3 ? logAxisSplits : sc.distr == 4 ? asinhAxisSplits : numAxisSplits));
axis.stroke = fnOrSelf(axis.stroke);
axis.grid.stroke = fnOrSelf(axis.grid.stroke);
@@ -2647,7 +2698,7 @@ function uPlot(opts, data, then) {
) : av || numAxisVals
);
axis.filter = fnOrSelf(axis.filter || ( sc.distr == 3 ? logAxisValsFilt : retArg1));
axis.filter = fnOrSelf(axis.filter || ( sc.distr >= 3 ? logAxisValsFilt : retArg1));
axis.font = pxRatioFont(axis.font);
axis.labelFont = pxRatioFont(axis.labelFont);
@@ -2750,6 +2801,8 @@ function uPlot(opts, data, then) {
else if (dataLen == 1) {
if (xScaleDistr == 3)
[_min, _max] = rangeLog(_min, _min, scaleX.log, false);
else if (xScaleDistr == 4)
[_min, _max] = rangeAsinh(_min, _min, scaleX.log, false);
else if (scaleX.time)
_max = _min + 86400 / ms;
else
@@ -2881,6 +2934,12 @@ function uPlot(opts, data, then) {
if (sc.min != wsc.min || sc.max != wsc.max) {
sc.min = wsc.min;
sc.max = wsc.max;
let distr = sc.distr;
sc._min = distr == 3 ? log10(sc.min) : distr == 4 ? asinh(sc.min, sc.asinh) : sc.min;
sc._max = distr == 3 ? log10(sc.max) : distr == 4 ? asinh(sc.max, sc.asinh) : sc.max;
changed[k] = anyChanged = true;
}
}
@@ -2897,7 +2956,7 @@ function uPlot(opts, data, then) {
fire("setScale", k);
}
if ( cursor.show)
if (cursor.show)
shouldSetCursor = true;
}
@@ -3012,10 +3071,10 @@ function uPlot(opts, data, then) {
series.forEach((s, i) => {
if (i > 0 && s.show) {
if (s._paths)
drawPath(i);
drawPath(i);
if (s.points.show(self, i, i0, i1))
drawPoints(i);
drawPoints(i);
fire("drawSeries", i);
}
@@ -3453,7 +3512,7 @@ function uPlot(opts, data, then) {
// shouldSetSelect = false;
// }
if ( cursor.show && shouldSetCursor) {
if (cursor.show && shouldSetCursor) {
updateCursor();
shouldSetCursor = false;
}
@@ -3553,12 +3612,12 @@ function uPlot(opts, data, then) {
let dragging = false;
const drag = cursor.drag;
const drag = cursor.drag;
let dragX = drag.x;
let dragY = drag.y;
let dragX = drag.x;
let dragY = drag.y;
if ( cursor.show) {
if (cursor.show) {
if (cursor.x)
xCursor = placeDiv(CURSOR_X, over);
if (cursor.y)
@@ -3607,7 +3666,7 @@ function uPlot(opts, data, then) {
label && remClass(label, OFF);
else {
label && addClass(label, OFF);
cursorPts.length > 1 && trans(cursorPts[i], -10, -10, plotWidCss, plotHgtCss);
cursorPts.length > 1 && trans(cursorPts[i], -10, -10, plotWidCss, plotHgtCss);
}
}
@@ -3626,7 +3685,7 @@ function uPlot(opts, data, then) {
if (opts.show != null) {
s.show = opts.show;
toggleDOM(i, opts.show);
toggleDOM(i, opts.show);
_setScale(s.scale, null, null);
commit();
@@ -3634,7 +3693,7 @@ function uPlot(opts, data, then) {
fire("setSeries", i, opts);
pub && sync.pub("setSeries", self, i, opts);
pub && sync.pub("setSeries", self, i, opts);
}
self.setSeries = setSeries;
@@ -3642,10 +3701,10 @@ function uPlot(opts, data, then) {
function _alpha(i, value) {
series[i].alpha = value;
if ( cursor.show && cursorPts[i])
if (cursor.show && cursorPts[i])
cursorPts[i].style.opacity = value;
if ( showLegend && legendRows[i])
if (showLegend && legendRows[i])
legendRows[i][0].parentNode.style.opacity = value;
}
@@ -3700,17 +3759,19 @@ function uPlot(opts, data, then) {
if (sc.dir == -1)
pos = dim - pos;
let _min = sc.min,
_max = sc.max,
let _min = sc._min,
_max = sc._max,
pct = pos / dim;
if (sc.distr == 3) {
_min = log10(_min);
_max = log10(_max);
return pow(10, _min + (_max - _min) * pct);
}
else
return _min + (_max - _min) * pct;
let sv = _min + (_max - _min) * pct;
let distr = sc.distr;
return (
distr == 3 ? pow(10, sv) :
distr == 4 ? sinh(sv, sc.asinh) :
sv
);
}
function closestIdxFromXpos(pos) {
@@ -3741,7 +3802,7 @@ function uPlot(opts, data, then) {
self.batch = batch;
(self.setCursor = opts => {
(self.setCursor = opts => {
mouseLeft1 = opts.left;
mouseTop1 = opts.top;
// assign(cursor, opts);
@@ -3792,7 +3853,7 @@ function uPlot(opts, data, then) {
for (let i = 0; i < series.length; i++) {
if (i > 0) {
cursorPts.length > 1 && trans(cursorPts[i], -10, -10, plotWidCss, plotHgtCss);
cursorPts.length > 1 && trans(cursorPts[i], -10, -10, plotWidCss, plotHgtCss);
}
if (showLegend && legend.live) {
@@ -3849,7 +3910,7 @@ function uPlot(opts, data, then) {
vPos = xPos2;
}
cursorPts.length > 1 && trans(cursorPts[i], hPos, vPos, plotWidCss, plotHgtCss);
cursorPts.length > 1 && trans(cursorPts[i], hPos, vPos, plotWidCss, plotHgtCss);
}
if (showLegend && legend.live) {
@@ -3945,7 +4006,7 @@ function uPlot(opts, data, then) {
let uni = drag.uni;
if (uni != null) {
// only calc drag status if they pass the dist thresh
// only calc drag status if they pass the dist asinh
if (dragX && dragY) {
dragX = rawDX >= uni;
dragY = rawDY >= uni;
@@ -4279,7 +4340,7 @@ function uPlot(opts, data, then) {
let deb;
if ( cursor.show) {
if (cursor.show) {
onMouse(mousedown, over, mouseDown);
onMouse(mousemove, over, mouseMove);
onMouse(mouseenter, over, syncRect);
@@ -4311,28 +4372,28 @@ function uPlot(opts, data, then) {
hooks[evName] = (hooks[evName] || []).concat(p.hooks[evName]);
});
const syncOpts = assign({
const syncOpts = assign({
key: null,
setSeries: false,
scales: [xScaleKey, null]
}, cursor.sync);
const syncKey = syncOpts.key;
const syncKey = syncOpts.key;
const sync = (syncKey != null ? (syncs[syncKey] = syncs[syncKey] || _sync()) : _sync());
const sync = _sync(syncKey);
sync.sub(self);
sync.sub(self);
function pub(type, src, x, y, w, h, i) {
events[type](null, src, x, y, w, h, i);
}
(self.pub = pub);
(self.pub = pub);
function destroy() {
sync.unsub(self);
off(resize, win, deb);
off(scroll, win, deb);
sync.unsub(self);
off(resize, win, deb);
off(scroll, win, deb);
root.remove();
fire("destroy");
}
@@ -4372,6 +4433,7 @@ uPlot.assign = assign;
uPlot.fmtNum = fmtNum;
uPlot.rangeNum = rangeNum;
uPlot.rangeLog = rangeLog;
uPlot.rangeAsinh = rangeAsinh;
uPlot.orient = orient;
{
@@ -4383,16 +4445,20 @@ uPlot.orient = orient;
uPlot.tzDate = tzDate;
}
{
uPlot.sync = _sync;
}
{
uPlot.addGap = addGap;
uPlot.clipGaps = clipGaps;
let paths = uPlot.paths = {};
(paths.linear = linear);
(paths.spline = spline);
(paths.stepped = stepped);
(paths.bars = bars);
(paths.linear = linear);
(paths.spline = spline);
(paths.stepped = stepped);
(paths.bars = bars);
}
module.exports = uPlot;