2020-11-25 07:59:41 +00:00
|
|
|
/**
|
2021-01-18 13:49:52 +00:00
|
|
|
* Copyright (c) 2021, Leon Sorokin
|
2020-11-25 07:59:41 +00:00
|
|
|
* All rights reserved. (MIT Licensed)
|
|
|
|
*
|
|
|
|
* uPlot.js (μPlot)
|
|
|
|
* A small, fast chart for time series, lines, areas, ohlc & bars
|
2021-09-17 19:28:20 +00:00
|
|
|
* https://github.com/leeoniya/uPlot (v1.6.15)
|
2020-11-25 07:59:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
var uPlot = (function () {
|
|
|
|
'use strict';
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
var FEAT_TIME = true;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
// binary search for index of closest value
|
|
|
|
function closestIdx(num, arr, lo, hi) {
|
|
|
|
var mid;
|
|
|
|
lo = lo || 0;
|
|
|
|
hi = hi || arr.length - 1;
|
|
|
|
var bitwise = hi <= 2147483647;
|
|
|
|
|
|
|
|
while (hi - lo > 1) {
|
|
|
|
mid = bitwise ? (lo + hi) >> 1 : floor((lo + hi) / 2);
|
|
|
|
|
|
|
|
if (arr[mid] < num)
|
|
|
|
{ lo = mid; }
|
|
|
|
else
|
|
|
|
{ hi = mid; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num - arr[lo] <= arr[hi] - num)
|
|
|
|
{ return lo; }
|
|
|
|
|
|
|
|
return hi;
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function nonNullIdx(data, _i0, _i1, dir) {
|
|
|
|
for (var i = dir == 1 ? _i0 : _i1; i >= _i0 && i <= _i1; i += dir) {
|
|
|
|
if (data[i] != null)
|
|
|
|
{ return i; }
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function getMinMax(data, _i0, _i1, sorted) {
|
|
|
|
// console.log("getMinMax()");
|
|
|
|
|
|
|
|
var _min = inf;
|
|
|
|
var _max = -inf;
|
|
|
|
|
|
|
|
if (sorted == 1) {
|
|
|
|
_min = data[_i0];
|
|
|
|
_max = data[_i1];
|
|
|
|
}
|
|
|
|
else if (sorted == -1) {
|
|
|
|
_min = data[_i1];
|
|
|
|
_max = data[_i0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (var i = _i0; i <= _i1; i++) {
|
|
|
|
if (data[i] != null) {
|
|
|
|
_min = min(_min, data[i]);
|
|
|
|
_max = max(_max, data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [_min, _max];
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function getMinMaxLog(data, _i0, _i1) {
|
|
|
|
// console.log("getMinMax()");
|
|
|
|
|
|
|
|
var _min = inf;
|
|
|
|
var _max = -inf;
|
|
|
|
|
|
|
|
for (var i = _i0; i <= _i1; i++) {
|
|
|
|
if (data[i] > 0) {
|
|
|
|
_min = min(_min, data[i]);
|
|
|
|
_max = max(_max, data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
_min == inf ? 1 : _min,
|
|
|
|
_max == -inf ? 10 : _max ];
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var _fixedTuple = [0, 0];
|
|
|
|
|
|
|
|
function fixIncr(minIncr, maxIncr, minExp, maxExp) {
|
|
|
|
_fixedTuple[0] = minExp < 0 ? roundDec(minIncr, -minExp) : minIncr;
|
|
|
|
_fixedTuple[1] = maxExp < 0 ? roundDec(maxIncr, -maxExp) : maxIncr;
|
|
|
|
return _fixedTuple;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rangeLog(min, max, base, fullMags) {
|
2021-09-17 19:28:20 +00:00
|
|
|
var minSign = sign(min);
|
2021-02-17 07:25:25 +00:00
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var logFn = base == 10 ? log10 : log2;
|
|
|
|
|
|
|
|
if (min == max) {
|
2021-09-17 19:28:20 +00:00
|
|
|
if (minSign == -1) {
|
|
|
|
min *= base;
|
|
|
|
max /= base;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
min /= base;
|
|
|
|
max *= base;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var minExp, maxExp, minMaxIncrs;
|
|
|
|
|
|
|
|
if (fullMags) {
|
|
|
|
minExp = floor(logFn(min));
|
|
|
|
maxExp = ceil(logFn(max));
|
|
|
|
|
|
|
|
minMaxIncrs = fixIncr(pow(base, minExp), pow(base, maxExp), minExp, maxExp);
|
|
|
|
|
|
|
|
min = minMaxIncrs[0];
|
|
|
|
max = minMaxIncrs[1];
|
|
|
|
}
|
|
|
|
else {
|
2021-02-17 07:25:25 +00:00
|
|
|
minExp = floor(logFn(abs(min)));
|
|
|
|
maxExp = floor(logFn(abs(max)));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
minMaxIncrs = fixIncr(pow(base, minExp), pow(base, maxExp), minExp, maxExp);
|
|
|
|
|
|
|
|
min = incrRoundDn(min, minMaxIncrs[0]);
|
|
|
|
max = incrRoundUp(max, minMaxIncrs[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [min, max];
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
function rangeAsinh(min, max, base, fullMags) {
|
|
|
|
var minMax = rangeLog(min, max, base, fullMags);
|
|
|
|
|
|
|
|
if (min == 0)
|
|
|
|
{ minMax[0] = 0; }
|
|
|
|
|
|
|
|
if (max == 0)
|
|
|
|
{ minMax[1] = 0; }
|
|
|
|
|
|
|
|
return minMax;
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var rangePad = 0.1;
|
|
|
|
|
|
|
|
var autoRangePart = {
|
|
|
|
mode: 3,
|
|
|
|
pad: rangePad,
|
|
|
|
};
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var _eqRangePart = {
|
|
|
|
pad: 0,
|
|
|
|
soft: null,
|
|
|
|
mode: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
var _eqRange = {
|
|
|
|
min: _eqRangePart,
|
|
|
|
max: _eqRangePart,
|
|
|
|
};
|
|
|
|
|
|
|
|
// this ensures that non-temporal/numeric y-axes get multiple-snapped padding added above/below
|
|
|
|
// TODO: also account for incrs when snapping to ensure top of axis gets a tick & value
|
|
|
|
function rangeNum(_min, _max, mult, extra) {
|
|
|
|
if (isObj(mult))
|
|
|
|
{ return _rangeNum(_min, _max, mult); }
|
|
|
|
|
|
|
|
_eqRangePart.pad = mult;
|
|
|
|
_eqRangePart.soft = extra ? 0 : null;
|
2021-01-18 13:49:52 +00:00
|
|
|
_eqRangePart.mode = extra ? 3 : 0;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
return _rangeNum(_min, _max, _eqRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nullish coalesce
|
|
|
|
function ifNull(lh, rh) {
|
|
|
|
return lh == null ? rh : lh;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _rangeNum(_min, _max, cfg) {
|
|
|
|
var cmin = cfg.min;
|
|
|
|
var cmax = cfg.max;
|
|
|
|
|
|
|
|
var padMin = ifNull(cmin.pad, 0);
|
|
|
|
var padMax = ifNull(cmax.pad, 0);
|
|
|
|
|
|
|
|
var hardMin = ifNull(cmin.hard, -inf);
|
|
|
|
var hardMax = ifNull(cmax.hard, inf);
|
|
|
|
|
|
|
|
var softMin = ifNull(cmin.soft, inf);
|
|
|
|
var softMax = ifNull(cmax.soft, -inf);
|
|
|
|
|
|
|
|
var softMinMode = ifNull(cmin.mode, 0);
|
|
|
|
var softMaxMode = ifNull(cmax.mode, 0);
|
|
|
|
|
|
|
|
var delta = _max - _min;
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
// this handles situations like 89.7, 89.69999999999999
|
|
|
|
// by assuming 0.001x deltas are precision errors
|
|
|
|
// if (delta > 0 && delta < abs(_max) / 1e3)
|
|
|
|
// delta = 0;
|
|
|
|
|
|
|
|
// treat data as flat if delta is less than 1 billionth
|
|
|
|
if (delta < 1e-9) {
|
|
|
|
delta = 0;
|
|
|
|
|
|
|
|
// if soft mode is 2 and all vals are flat at 0, avoid the 0.1 * 1e3 fallback
|
|
|
|
// this prevents 0,0,0 from ranging to -100,100 when softMin/softMax are -1,1
|
|
|
|
if (_min == 0 || _max == 0) {
|
|
|
|
delta = 1e-9;
|
|
|
|
|
|
|
|
if (softMinMode == 2 && softMin != inf)
|
|
|
|
{ padMin = 0; }
|
|
|
|
|
|
|
|
if (softMaxMode == 2 && softMax != -inf)
|
|
|
|
{ padMax = 0; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var nonZeroDelta = delta || abs(_max) || 1e3;
|
|
|
|
var mag = log10(nonZeroDelta);
|
|
|
|
var base = pow(10, floor(mag));
|
|
|
|
|
|
|
|
var _padMin = nonZeroDelta * (delta == 0 ? (_min == 0 ? .1 : 1) : padMin);
|
2021-09-17 19:28:20 +00:00
|
|
|
var _newMin = roundDec(incrRoundDn(_min - _padMin, base/10), 9);
|
2021-01-18 13:49:52 +00:00
|
|
|
var _softMin = _min >= softMin && (softMinMode == 1 || softMinMode == 3 && _newMin <= softMin || softMinMode == 2 && _newMin >= softMin) ? softMin : inf;
|
2020-11-25 07:59:41 +00:00
|
|
|
var minLim = max(hardMin, _newMin < _softMin && _min >= _softMin ? _softMin : min(_softMin, _newMin));
|
|
|
|
|
|
|
|
var _padMax = nonZeroDelta * (delta == 0 ? (_max == 0 ? .1 : 1) : padMax);
|
2021-09-17 19:28:20 +00:00
|
|
|
var _newMax = roundDec(incrRoundUp(_max + _padMax, base/10), 9);
|
2021-01-18 13:49:52 +00:00
|
|
|
var _softMax = _max <= softMax && (softMaxMode == 1 || softMaxMode == 3 && _newMax >= softMax || softMaxMode == 2 && _newMax <= softMax) ? softMax : -inf;
|
2020-11-25 07:59:41 +00:00
|
|
|
var maxLim = min(hardMax, _newMax > _softMax && _max <= _softMax ? _softMax : max(_softMax, _newMax));
|
|
|
|
|
|
|
|
if (minLim == maxLim && minLim == 0)
|
|
|
|
{ maxLim = 100; }
|
|
|
|
|
|
|
|
return [minLim, maxLim];
|
|
|
|
}
|
|
|
|
|
|
|
|
// alternative: https://stackoverflow.com/a/2254896
|
|
|
|
var fmtNum = new Intl.NumberFormat(navigator.language).format;
|
|
|
|
|
|
|
|
var M = Math;
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var PI = M.PI;
|
2020-11-25 07:59:41 +00:00
|
|
|
var abs = M.abs;
|
|
|
|
var floor = M.floor;
|
|
|
|
var round = M.round;
|
|
|
|
var ceil = M.ceil;
|
|
|
|
var min = M.min;
|
|
|
|
var max = M.max;
|
|
|
|
var pow = M.pow;
|
2021-09-17 19:28:20 +00:00
|
|
|
var sign = M.sign;
|
2020-11-25 07:59:41 +00:00
|
|
|
var log10 = M.log10;
|
|
|
|
var log2 = M.log2;
|
2021-02-17 07:25:25 +00:00
|
|
|
var sinh = (v, linthresh) => {
|
|
|
|
if ( linthresh === void 0 ) linthresh = 1;
|
|
|
|
|
|
|
|
return M.sinh(v / linthresh);
|
|
|
|
};
|
|
|
|
var asinh = (v, linthresh) => {
|
|
|
|
if ( linthresh === void 0 ) linthresh = 1;
|
|
|
|
|
|
|
|
return M.asinh(v / linthresh);
|
|
|
|
};
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var inf = Infinity;
|
|
|
|
|
|
|
|
function incrRound(num, incr) {
|
|
|
|
return round(num/incr)*incr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clamp(num, _min, _max) {
|
|
|
|
return min(max(num, _min), _max);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fnOrSelf(v) {
|
2021-01-18 13:49:52 +00:00
|
|
|
return typeof v == "function" ? v : () => v;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var retArg0 = _0 => _0;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var retArg1 = (_0, _1) => _1;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var retNull = _ => null;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
var retTrue = _ => true;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var retEq = (a, b) => a == b;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function incrRoundUp(num, incr) {
|
|
|
|
return ceil(num/incr)*incr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function incrRoundDn(num, incr) {
|
|
|
|
return floor(num/incr)*incr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function roundDec(val, dec) {
|
|
|
|
return round(val * (dec = Math.pow( 10, dec ))) / dec;
|
|
|
|
}
|
|
|
|
|
|
|
|
var fixedDec = new Map();
|
|
|
|
|
|
|
|
function guessDec(num) {
|
|
|
|
return ((""+num).split(".")[1] || "").length;
|
|
|
|
}
|
|
|
|
|
|
|
|
function genIncrs(base, minExp, maxExp, mults) {
|
|
|
|
var incrs = [];
|
|
|
|
|
|
|
|
var multDec = mults.map(guessDec);
|
|
|
|
|
|
|
|
for (var exp = minExp; exp < maxExp; exp++) {
|
|
|
|
var expa = abs(exp);
|
|
|
|
var mag = roundDec(pow(base, exp), expa);
|
|
|
|
|
|
|
|
for (var i = 0; i < mults.length; i++) {
|
|
|
|
var _incr = mults[i] * mag;
|
|
|
|
var dec = (_incr >= 0 && exp >= 0 ? 0 : expa) + (exp >= multDec[i] ? 0 : multDec[i]);
|
|
|
|
var incr = roundDec(_incr, dec);
|
|
|
|
incrs.push(incr);
|
|
|
|
fixedDec.set(incr, dec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return incrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
//export const assign = Object.assign;
|
|
|
|
|
|
|
|
var EMPTY_OBJ = {};
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var nullNullTuple = [null, null];
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var isArr = Array.isArray;
|
|
|
|
|
|
|
|
function isStr(v) {
|
2020-12-23 07:17:49 +00:00
|
|
|
return typeof v == 'string';
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isObj(v) {
|
2020-12-23 07:17:49 +00:00
|
|
|
var is = false;
|
|
|
|
|
|
|
|
if (v != null) {
|
|
|
|
var c = v.constructor;
|
|
|
|
is = c == null || c == Object;
|
|
|
|
}
|
|
|
|
|
|
|
|
return is;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
function fastIsObj(v) {
|
|
|
|
return v != null && typeof v == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
function copy(o, _isObj) {
|
|
|
|
_isObj = _isObj || isObj;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var out;
|
|
|
|
|
|
|
|
if (isArr(o))
|
2021-03-20 20:39:14 +00:00
|
|
|
{ out = o.map(v => copy(v, _isObj)); }
|
|
|
|
else if (_isObj(o)) {
|
2020-11-25 07:59:41 +00:00
|
|
|
out = {};
|
|
|
|
for (var k in o)
|
2021-03-20 20:39:14 +00:00
|
|
|
{ out[k] = copy(o[k], _isObj); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ out = o; }
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
function assign(targ) {
|
|
|
|
var args = arguments;
|
|
|
|
|
|
|
|
for (var i = 1; i < args.length; i++) {
|
|
|
|
var src = args[i];
|
|
|
|
|
|
|
|
for (var key in src) {
|
|
|
|
if (isObj(targ[key]))
|
|
|
|
{ assign(targ[key], copy(src[key])); }
|
|
|
|
else
|
|
|
|
{ targ[key] = copy(src[key]); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return targ;
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
// nullModes
|
2021-02-10 07:13:13 +00:00
|
|
|
var NULL_REMOVE = 0; // nulls are converted to undefined (e.g. for spanGaps: true)
|
|
|
|
var NULL_RETAIN = 1; // nulls are retained, with alignment artifacts set to undefined (default)
|
|
|
|
var NULL_EXPAND = 2; // nulls are expanded to include any adjacent alignment artifacts
|
2021-01-27 07:12:15 +00:00
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
// sets undefined values to nulls when adjacent to existing nulls (minesweeper)
|
2021-01-27 07:12:15 +00:00
|
|
|
function nullExpand(yVals, nullIdxs, alignedLen) {
|
2021-02-10 07:13:13 +00:00
|
|
|
for (var i = 0, xi = (void 0), lastNullIdx = -1; i < nullIdxs.length; i++) {
|
2021-01-27 07:12:15 +00:00
|
|
|
var nullIdx = nullIdxs[i];
|
|
|
|
|
|
|
|
if (nullIdx > lastNullIdx) {
|
|
|
|
xi = nullIdx - 1;
|
|
|
|
while (xi >= 0 && yVals[xi] == null)
|
|
|
|
{ yVals[xi--] = null; }
|
|
|
|
|
|
|
|
xi = nullIdx + 1;
|
|
|
|
while (xi < alignedLen && yVals[xi] == null)
|
|
|
|
{ yVals[lastNullIdx = xi++] = null; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
|
|
|
// nullModes is a tables-matched array indicating how to treat nulls in each series
|
2021-02-10 07:13:13 +00:00
|
|
|
// output is sorted ASC on the joined field (table[0]) and duplicate join values are collapsed
|
2020-12-23 07:17:49 +00:00
|
|
|
function join(tables, nullModes) {
|
|
|
|
var xVals = new Set();
|
|
|
|
|
|
|
|
for (var ti = 0; ti < tables.length; ti++) {
|
|
|
|
var t = tables[ti];
|
|
|
|
var xs = t[0];
|
|
|
|
var len = xs.length;
|
|
|
|
|
|
|
|
for (var i = 0; i < len; i++)
|
|
|
|
{ xVals.add(xs[i]); }
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var data = [Array.from(xVals).sort((a, b) => a - b)];
|
2020-12-23 07:17:49 +00:00
|
|
|
|
|
|
|
var alignedLen = data[0].length;
|
|
|
|
|
|
|
|
var xIdxs = new Map();
|
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
for (var i$1 = 0; i$1 < alignedLen; i$1++)
|
|
|
|
{ xIdxs.set(data[0][i$1], i$1); }
|
2020-12-23 07:17:49 +00:00
|
|
|
|
|
|
|
for (var ti$1 = 0; ti$1 < tables.length; ti$1++) {
|
|
|
|
var t$1 = tables[ti$1];
|
|
|
|
var xs$1 = t$1[0];
|
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
for (var si = 1; si < t$1.length; si++) {
|
|
|
|
var ys = t$1[si];
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
var yVals = Array(alignedLen).fill(undefined);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
var nullMode = nullModes ? nullModes[ti$1][si] : NULL_RETAIN;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
var nullIdxs = [];
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
for (var i$2 = 0; i$2 < ys.length; i$2++) {
|
|
|
|
var yVal = ys[i$2];
|
|
|
|
var alignedIdx = xIdxs.get(xs$1[i$2]);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (yVal === null) {
|
2021-02-10 07:13:13 +00:00
|
|
|
if (nullMode != NULL_REMOVE) {
|
2021-01-27 07:12:15 +00:00
|
|
|
yVals[alignedIdx] = yVal;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
if (nullMode == NULL_EXPAND)
|
|
|
|
{ nullIdxs.push(alignedIdx); }
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-27 07:12:15 +00:00
|
|
|
else
|
|
|
|
{ yVals[alignedIdx] = yVal; }
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
nullExpand(yVals, nullIdxs, alignedLen);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
data.push(yVals);
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
return data;
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var microTask = typeof queueMicrotask == "undefined" ? fn => Promise.resolve().then(fn) : queueMicrotask;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
var WIDTH = "width";
|
|
|
|
var HEIGHT = "height";
|
|
|
|
var TOP = "top";
|
|
|
|
var BOTTOM = "bottom";
|
|
|
|
var LEFT = "left";
|
|
|
|
var RIGHT = "right";
|
|
|
|
var hexBlack = "#000";
|
2020-11-25 07:59:41 +00:00
|
|
|
var transparent = hexBlack + "0";
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
var mousemove = "mousemove";
|
|
|
|
var mousedown = "mousedown";
|
|
|
|
var mouseup = "mouseup";
|
|
|
|
var mouseenter = "mouseenter";
|
|
|
|
var mouseleave = "mouseleave";
|
|
|
|
var dblclick = "dblclick";
|
|
|
|
var resize = "resize";
|
|
|
|
var scroll = "scroll";
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var change = "change";
|
|
|
|
var ddpxchange = "dppxchange";
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var pre = "u-";
|
|
|
|
|
|
|
|
var UPLOT = "uplot";
|
2021-01-18 13:49:52 +00:00
|
|
|
var ORI_HZ = pre + "hz";
|
|
|
|
var ORI_VT = pre + "vt";
|
2020-11-25 07:59:41 +00:00
|
|
|
var TITLE = pre + "title";
|
|
|
|
var WRAP = pre + "wrap";
|
|
|
|
var UNDER = pre + "under";
|
|
|
|
var OVER = pre + "over";
|
|
|
|
var OFF = pre + "off";
|
|
|
|
var SELECT = pre + "select";
|
|
|
|
var CURSOR_X = pre + "cursor-x";
|
|
|
|
var CURSOR_Y = pre + "cursor-y";
|
|
|
|
var CURSOR_PT = pre + "cursor-pt";
|
|
|
|
var LEGEND = pre + "legend";
|
|
|
|
var LEGEND_LIVE = pre + "live";
|
|
|
|
var LEGEND_INLINE = pre + "inline";
|
|
|
|
var LEGEND_THEAD = pre + "thead";
|
|
|
|
var LEGEND_SERIES = pre + "series";
|
|
|
|
var LEGEND_MARKER = pre + "marker";
|
|
|
|
var LEGEND_LABEL = pre + "label";
|
|
|
|
var LEGEND_VALUE = pre + "value";
|
|
|
|
|
|
|
|
var doc = document;
|
|
|
|
var win = window;
|
2021-09-17 19:28:20 +00:00
|
|
|
var pxRatio;
|
|
|
|
|
|
|
|
var query;
|
|
|
|
|
|
|
|
function setPxRatio() {
|
|
|
|
pxRatio = devicePixelRatio;
|
|
|
|
|
|
|
|
query && off(change, query, setPxRatio);
|
|
|
|
query = matchMedia(("screen and (min-resolution: " + (pxRatio - 0.001) + "dppx) and (max-resolution: " + (pxRatio + 0.001) + "dppx)"));
|
|
|
|
on(change, query, setPxRatio);
|
|
|
|
|
|
|
|
win.dispatchEvent(new CustomEvent(ddpxchange));
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
function addClass(el, c) {
|
2021-03-20 20:39:14 +00:00
|
|
|
if (c != null) {
|
|
|
|
var cl = el.classList;
|
|
|
|
!cl.contains(c) && cl.add(c);
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function remClass(el, c) {
|
2021-03-20 20:39:14 +00:00
|
|
|
var cl = el.classList;
|
|
|
|
cl.contains(c) && cl.remove(c);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setStylePx(el, name, value) {
|
|
|
|
el.style[name] = value + "px";
|
|
|
|
}
|
|
|
|
|
|
|
|
function placeTag(tag, cls, targ, refEl) {
|
2020-12-23 07:17:49 +00:00
|
|
|
var el = doc.createElement(tag);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (cls != null)
|
|
|
|
{ addClass(el, cls); }
|
|
|
|
|
|
|
|
if (targ != null)
|
|
|
|
{ targ.insertBefore(el, refEl); }
|
|
|
|
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
|
|
|
function placeDiv(cls, targ) {
|
|
|
|
return placeTag("div", cls, targ);
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var xformCache = new WeakMap();
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function trans(el, xPos, yPos, xMax, yMax) {
|
2021-09-17 19:28:20 +00:00
|
|
|
var xform = "translate(" + xPos + "px," + yPos + "px)";
|
|
|
|
var xformOld = xformCache.get(el);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (xform != xformOld) {
|
|
|
|
el.style.transform = xform;
|
|
|
|
xformCache.set(el, xform);
|
|
|
|
|
|
|
|
if (xPos < 0 || yPos < 0 || xPos > xMax || yPos > yMax)
|
|
|
|
{ addClass(el, OFF); }
|
|
|
|
else
|
|
|
|
{ remClass(el, OFF); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var colorCache = new WeakMap();
|
|
|
|
|
|
|
|
function color(el, background, borderColor) {
|
|
|
|
var newColor = background + borderColor;
|
|
|
|
var oldColor = colorCache.get(el);
|
|
|
|
|
|
|
|
if (newColor != oldColor) {
|
|
|
|
colorCache.set(el, newColor);
|
|
|
|
el.style.background = background;
|
|
|
|
el.style.borderColor = borderColor;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var evOpts = {passive: true};
|
2021-09-17 19:28:20 +00:00
|
|
|
var evOpts2 = assign({capture: true}, evOpts);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function on(ev, el, cb, capt) {
|
|
|
|
el.addEventListener(ev, cb, capt ? evOpts2 : evOpts);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function off(ev, el, cb, capt) {
|
|
|
|
el.removeEventListener(ev, cb, capt ? evOpts2 : evOpts);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
setPxRatio();
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var months = [
|
|
|
|
"January",
|
|
|
|
"February",
|
|
|
|
"March",
|
|
|
|
"April",
|
|
|
|
"May",
|
|
|
|
"June",
|
|
|
|
"July",
|
|
|
|
"August",
|
|
|
|
"September",
|
|
|
|
"October",
|
|
|
|
"November",
|
|
|
|
"December" ];
|
|
|
|
|
|
|
|
var days = [
|
|
|
|
"Sunday",
|
|
|
|
"Monday",
|
|
|
|
"Tuesday",
|
|
|
|
"Wednesday",
|
|
|
|
"Thursday",
|
|
|
|
"Friday",
|
|
|
|
"Saturday" ];
|
|
|
|
|
|
|
|
function slice3(str) {
|
|
|
|
return str.slice(0, 3);
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var days3 = days.map(slice3);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var months3 = months.map(slice3);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var engNames = {
|
|
|
|
MMMM: months,
|
|
|
|
MMM: months3,
|
|
|
|
WWWW: days,
|
|
|
|
WWW: days3,
|
|
|
|
};
|
|
|
|
|
|
|
|
function zeroPad2(int) {
|
|
|
|
return (int < 10 ? '0' : '') + int;
|
|
|
|
}
|
|
|
|
|
|
|
|
function zeroPad3(int) {
|
|
|
|
return (int < 10 ? '00' : int < 100 ? '0' : '') + int;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
function suffix(int) {
|
|
|
|
let mod10 = int % 10;
|
|
|
|
|
|
|
|
return int + (
|
|
|
|
mod10 == 1 && int != 11 ? "st" :
|
|
|
|
mod10 == 2 && int != 12 ? "nd" :
|
|
|
|
mod10 == 3 && int != 13 ? "rd" : "th"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
var subs = {
|
|
|
|
// 2019
|
2021-03-20 20:39:14 +00:00
|
|
|
YYYY: d => d.getFullYear(),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 19
|
2021-03-20 20:39:14 +00:00
|
|
|
YY: d => (d.getFullYear()+'').slice(2),
|
2020-11-25 07:59:41 +00:00
|
|
|
// July
|
2021-03-20 20:39:14 +00:00
|
|
|
MMMM: (d, names) => names.MMMM[d.getMonth()],
|
2020-11-25 07:59:41 +00:00
|
|
|
// Jul
|
2021-03-20 20:39:14 +00:00
|
|
|
MMM: (d, names) => names.MMM[d.getMonth()],
|
2020-11-25 07:59:41 +00:00
|
|
|
// 07
|
2021-03-20 20:39:14 +00:00
|
|
|
MM: d => zeroPad2(d.getMonth()+1),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 7
|
2021-03-20 20:39:14 +00:00
|
|
|
M: d => d.getMonth()+1,
|
2020-11-25 07:59:41 +00:00
|
|
|
// 09
|
2021-03-20 20:39:14 +00:00
|
|
|
DD: d => zeroPad2(d.getDate()),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 9
|
2021-03-20 20:39:14 +00:00
|
|
|
D: d => d.getDate(),
|
2020-11-25 07:59:41 +00:00
|
|
|
// Monday
|
2021-03-20 20:39:14 +00:00
|
|
|
WWWW: (d, names) => names.WWWW[d.getDay()],
|
2020-11-25 07:59:41 +00:00
|
|
|
// Mon
|
2021-03-20 20:39:14 +00:00
|
|
|
WWW: (d, names) => names.WWW[d.getDay()],
|
2020-11-25 07:59:41 +00:00
|
|
|
// 03
|
2021-03-20 20:39:14 +00:00
|
|
|
HH: d => zeroPad2(d.getHours()),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 3
|
2021-03-20 20:39:14 +00:00
|
|
|
H: d => d.getHours(),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 9 (12hr, unpadded)
|
2021-03-20 20:39:14 +00:00
|
|
|
h: d => {var h = d.getHours(); return h == 0 ? 12 : h > 12 ? h - 12 : h;},
|
2020-11-25 07:59:41 +00:00
|
|
|
// AM
|
2021-03-20 20:39:14 +00:00
|
|
|
AA: d => d.getHours() >= 12 ? 'PM' : 'AM',
|
2020-11-25 07:59:41 +00:00
|
|
|
// am
|
2021-03-20 20:39:14 +00:00
|
|
|
aa: d => d.getHours() >= 12 ? 'pm' : 'am',
|
2020-11-25 07:59:41 +00:00
|
|
|
// a
|
2021-03-20 20:39:14 +00:00
|
|
|
a: d => d.getHours() >= 12 ? 'p' : 'a',
|
2020-11-25 07:59:41 +00:00
|
|
|
// 09
|
2021-03-20 20:39:14 +00:00
|
|
|
mm: d => zeroPad2(d.getMinutes()),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 9
|
2021-03-20 20:39:14 +00:00
|
|
|
m: d => d.getMinutes(),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 09
|
2021-03-20 20:39:14 +00:00
|
|
|
ss: d => zeroPad2(d.getSeconds()),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 9
|
2021-03-20 20:39:14 +00:00
|
|
|
s: d => d.getSeconds(),
|
2020-11-25 07:59:41 +00:00
|
|
|
// 374
|
2021-03-20 20:39:14 +00:00
|
|
|
fff: d => zeroPad3(d.getMilliseconds()),
|
2020-11-25 07:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function fmtDate(tpl, names) {
|
|
|
|
names = names || engNames;
|
|
|
|
var parts = [];
|
|
|
|
|
|
|
|
var R = /\{([a-z]+)\}|[^{]+/gi, m;
|
|
|
|
|
|
|
|
while (m = R.exec(tpl))
|
|
|
|
{ parts.push(m[0][0] == '{' ? subs[m[1]] : m[0]); }
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
return d => {
|
2020-11-25 07:59:41 +00:00
|
|
|
var out = '';
|
|
|
|
|
|
|
|
for (var i = 0; i < parts.length; i++)
|
|
|
|
{ out += typeof parts[i] == "string" ? parts[i] : parts[i](d, names); }
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var localTz = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone/53652131#53652131
|
|
|
|
function tzDate(date, tz) {
|
|
|
|
var date2;
|
|
|
|
|
|
|
|
// perf optimization
|
2021-03-20 20:39:14 +00:00
|
|
|
if (tz == 'UTC' || tz == 'Etc/UTC')
|
2020-11-25 07:59:41 +00:00
|
|
|
{ date2 = new Date(+date + date.getTimezoneOffset() * 6e4); }
|
|
|
|
else if (tz == localTz)
|
|
|
|
{ date2 = date; }
|
|
|
|
else {
|
|
|
|
date2 = new Date(date.toLocaleString('en-US', {timeZone: tz}));
|
2021-03-20 20:39:14 +00:00
|
|
|
date2.setMilliseconds(date.getMilliseconds());
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return date2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//export const series = [];
|
|
|
|
|
|
|
|
// default formatters:
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var onlyWhole = v => v % 1 == 0;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var allMults = [1,2,2.5,5];
|
|
|
|
|
|
|
|
// ...0.01, 0.02, 0.025, 0.05, 0.1, 0.2, 0.25, 0.5
|
|
|
|
var decIncrs = genIncrs(10, -16, 0, allMults);
|
|
|
|
|
|
|
|
// 1, 2, 2.5, 5, 10, 20, 25, 50...
|
|
|
|
var oneIncrs = genIncrs(10, 0, 16, allMults);
|
|
|
|
|
|
|
|
// 1, 2, 5, 10, 20, 25, 50...
|
|
|
|
var wholeIncrs = oneIncrs.filter(onlyWhole);
|
|
|
|
|
|
|
|
var numIncrs = decIncrs.concat(oneIncrs);
|
|
|
|
|
2020-11-29 02:57:24 +00:00
|
|
|
var NL = "\n";
|
|
|
|
|
|
|
|
var yyyy = "{YYYY}";
|
|
|
|
var NLyyyy = NL + yyyy;
|
|
|
|
var md = "{M}/{D}";
|
|
|
|
var NLmd = NL + md;
|
|
|
|
var NLmdyy = NLmd + "/{YY}";
|
|
|
|
|
|
|
|
var aa = "{aa}";
|
|
|
|
var hmm = "{h}:{mm}";
|
|
|
|
var hmmaa = hmm + aa;
|
|
|
|
var NLhmmaa = NL + hmmaa;
|
|
|
|
var ss = ":{ss}";
|
|
|
|
|
|
|
|
var _ = null;
|
|
|
|
|
|
|
|
function genTimeStuffs(ms) {
|
|
|
|
var s = ms * 1e3,
|
|
|
|
m = s * 60,
|
|
|
|
h = m * 60,
|
|
|
|
d = h * 24,
|
|
|
|
mo = d * 30,
|
|
|
|
y = d * 365;
|
|
|
|
|
|
|
|
// min of 1e-3 prevents setting a temporal x ticks too small since Date objects cannot advance ticks smaller than 1ms
|
|
|
|
var subSecIncrs = ms == 1 ? genIncrs(10, 0, 3, allMults).filter(onlyWhole) : genIncrs(10, -3, 0, allMults);
|
|
|
|
|
|
|
|
var timeIncrs = subSecIncrs.concat([
|
|
|
|
// minute divisors (# of secs)
|
|
|
|
s,
|
|
|
|
s * 5,
|
|
|
|
s * 10,
|
|
|
|
s * 15,
|
|
|
|
s * 30,
|
|
|
|
// hour divisors (# of mins)
|
|
|
|
m,
|
|
|
|
m * 5,
|
|
|
|
m * 10,
|
|
|
|
m * 15,
|
|
|
|
m * 30,
|
|
|
|
// day divisors (# of hrs)
|
|
|
|
h,
|
|
|
|
h * 2,
|
|
|
|
h * 3,
|
|
|
|
h * 4,
|
|
|
|
h * 6,
|
|
|
|
h * 8,
|
|
|
|
h * 12,
|
|
|
|
// month divisors TODO: need more?
|
|
|
|
d,
|
|
|
|
d * 2,
|
|
|
|
d * 3,
|
|
|
|
d * 4,
|
|
|
|
d * 5,
|
|
|
|
d * 6,
|
|
|
|
d * 7,
|
|
|
|
d * 8,
|
|
|
|
d * 9,
|
|
|
|
d * 10,
|
|
|
|
d * 15,
|
|
|
|
// year divisors (# months, approx)
|
|
|
|
mo,
|
|
|
|
mo * 2,
|
|
|
|
mo * 3,
|
|
|
|
mo * 4,
|
|
|
|
mo * 6,
|
|
|
|
// century divisors
|
|
|
|
y,
|
|
|
|
y * 2,
|
|
|
|
y * 5,
|
|
|
|
y * 10,
|
|
|
|
y * 25,
|
|
|
|
y * 50,
|
|
|
|
y * 100 ]);
|
|
|
|
|
|
|
|
// [0]: minimum num secs in the tick incr
|
|
|
|
// [1]: default tick format
|
|
|
|
// [2-7]: rollover tick formats
|
|
|
|
// [8]: mode: 0: replace [1] -> [2-7], 1: concat [1] + [2-7]
|
|
|
|
var _timeAxisStamps = [
|
|
|
|
// tick incr default year month day hour min sec mode
|
|
|
|
[y, yyyy, _, _, _, _, _, _, 1],
|
|
|
|
[d * 28, "{MMM}", NLyyyy, _, _, _, _, _, 1],
|
|
|
|
[d, md, NLyyyy, _, _, _, _, _, 1],
|
|
|
|
[h, "{h}" + aa, NLmdyy, _, NLmd, _, _, _, 1],
|
|
|
|
[m, hmmaa, NLmdyy, _, NLmd, _, _, _, 1],
|
|
|
|
[s, ss, NLmdyy + " " + hmmaa, _, NLmd + " " + hmmaa, _, NLhmmaa, _, 1],
|
|
|
|
[ms, ss + ".{fff}", NLmdyy + " " + hmmaa, _, NLmd + " " + hmmaa, _, NLhmmaa, _, 1] ];
|
|
|
|
|
|
|
|
// the ensures that axis ticks, values & grid are aligned to logical temporal breakpoints and not an arbitrary timestamp
|
|
|
|
// https://www.timeanddate.com/time/dst/
|
|
|
|
// https://www.timeanddate.com/time/dst/2019.html
|
|
|
|
// https://www.epochconverter.com/timezones
|
|
|
|
function timeAxisSplits(tzDate) {
|
2021-01-18 13:49:52 +00:00
|
|
|
return (self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace) => {
|
2020-11-29 02:57:24 +00:00
|
|
|
var splits = [];
|
|
|
|
var isYr = foundIncr >= y;
|
|
|
|
var isMo = foundIncr >= mo && foundIncr < y;
|
|
|
|
|
|
|
|
// get the timezone-adjusted date
|
|
|
|
var minDate = tzDate(scaleMin);
|
2021-09-17 19:28:20 +00:00
|
|
|
var minDateTs = roundDec(minDate * ms, 3);
|
2020-11-29 02:57:24 +00:00
|
|
|
|
|
|
|
// get ts of 12am (this lands us at or before the original scaleMin)
|
2021-03-20 20:39:14 +00:00
|
|
|
var minMin = mkDate(minDate.getFullYear(), isYr ? 0 : minDate.getMonth(), isMo || isYr ? 1 : minDate.getDate());
|
2021-09-17 19:28:20 +00:00
|
|
|
var minMinTs = roundDec(minMin * ms, 3);
|
2020-11-29 02:57:24 +00:00
|
|
|
|
|
|
|
if (isMo || isYr) {
|
|
|
|
var moIncr = isMo ? foundIncr / mo : 0;
|
|
|
|
var yrIncr = isYr ? foundIncr / y : 0;
|
|
|
|
// let tzOffset = scaleMin - minDateTs; // needed?
|
2021-09-17 19:28:20 +00:00
|
|
|
var split = minDateTs == minMinTs ? minDateTs : roundDec(mkDate(minMin.getFullYear() + yrIncr, minMin.getMonth() + moIncr, 1) * ms, 3);
|
|
|
|
var splitDate = new Date(round(split / ms));
|
2021-03-20 20:39:14 +00:00
|
|
|
var baseYear = splitDate.getFullYear();
|
|
|
|
var baseMonth = splitDate.getMonth();
|
2020-11-29 02:57:24 +00:00
|
|
|
|
|
|
|
for (var i = 0; split <= scaleMax; i++) {
|
|
|
|
var next = mkDate(baseYear + yrIncr * i, baseMonth + moIncr * i, 1);
|
2021-09-17 19:28:20 +00:00
|
|
|
var offs = next - tzDate(roundDec(next * ms, 3));
|
2020-11-29 02:57:24 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
split = roundDec((+next + offs) * ms, 3);
|
2020-11-29 02:57:24 +00:00
|
|
|
|
|
|
|
if (split <= scaleMax)
|
|
|
|
{ splits.push(split); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var incr0 = foundIncr >= d ? d : foundIncr;
|
|
|
|
var tzOffset = floor(scaleMin) - floor(minDateTs);
|
|
|
|
var split$1 = minMinTs + tzOffset + incrRoundUp(minDateTs - minMinTs, incr0);
|
|
|
|
splits.push(split$1);
|
|
|
|
|
|
|
|
var date0 = tzDate(split$1);
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
var prevHour = date0.getHours() + (date0.getMinutes() / m) + (date0.getSeconds() / h);
|
2020-11-29 02:57:24 +00:00
|
|
|
var incrHours = foundIncr / h;
|
|
|
|
|
|
|
|
var minSpace = self.axes[axisIdx]._space;
|
|
|
|
var pctSpace = foundSpace / minSpace;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
split$1 = roundDec(split$1 + foundIncr, ms == 1 ? 0 : 3);
|
|
|
|
|
|
|
|
if (split$1 > scaleMax)
|
|
|
|
{ break; }
|
|
|
|
|
|
|
|
if (incrHours > 1) {
|
|
|
|
var expectedHour = floor(roundDec(prevHour + incrHours, 6)) % 24;
|
|
|
|
var splitDate$1 = tzDate(split$1);
|
|
|
|
var actualHour = splitDate$1.getHours();
|
|
|
|
|
|
|
|
var dstShift = actualHour - expectedHour;
|
|
|
|
|
|
|
|
if (dstShift > 1)
|
|
|
|
{ dstShift = -1; }
|
|
|
|
|
|
|
|
split$1 -= dstShift * h;
|
|
|
|
|
|
|
|
prevHour = (prevHour + incrHours) % 24;
|
|
|
|
|
|
|
|
// add a tick only if it's further than 70% of the min allowed label spacing
|
|
|
|
var prevSplit = splits[splits.length - 1];
|
|
|
|
var pctIncr = roundDec((split$1 - prevSplit) / foundIncr, 3);
|
|
|
|
|
|
|
|
if (pctIncr * pctSpace >= .7)
|
|
|
|
{ splits.push(split$1); }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ splits.push(split$1); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return splits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
timeIncrs,
|
|
|
|
_timeAxisStamps,
|
|
|
|
timeAxisSplits ];
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var ref = genTimeStuffs(1);
|
2020-11-29 02:57:24 +00:00
|
|
|
var timeIncrsMs = ref[0];
|
|
|
|
var _timeAxisStampsMs = ref[1];
|
|
|
|
var timeAxisSplitsMs = ref[2];
|
2021-02-17 07:25:25 +00:00
|
|
|
var ref$1 = genTimeStuffs(1e-3);
|
2020-11-29 02:57:24 +00:00
|
|
|
var timeIncrsS = ref$1[0];
|
|
|
|
var _timeAxisStampsS = ref$1[1];
|
|
|
|
var timeAxisSplitsS = ref$1[2];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// base 2
|
2021-02-10 07:13:13 +00:00
|
|
|
genIncrs(2, -53, 53, [1]);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
console.log({
|
|
|
|
decIncrs,
|
|
|
|
oneIncrs,
|
|
|
|
wholeIncrs,
|
|
|
|
numIncrs,
|
|
|
|
timeIncrs,
|
|
|
|
fixedDec,
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
|
|
|
function timeAxisStamps(stampCfg, fmtDate) {
|
2021-01-18 13:49:52 +00:00
|
|
|
return stampCfg.map(s => s.map((v, i) =>
|
|
|
|
i == 0 || i == 8 || v == null ? v : fmtDate(i == 1 || s[8] == 0 ? v : s[1] + v)
|
|
|
|
));
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: will need to accept spaces[] and pull incr into the loop when grid will be non-uniform, eg for log scales.
|
|
|
|
// currently we ignore this for months since they're *nearly* uniform and the added complexity is not worth it
|
|
|
|
function timeAxisVals(tzDate, stamps) {
|
2021-01-18 13:49:52 +00:00
|
|
|
return (self, splits, axisIdx, foundSpace, foundIncr) => {
|
|
|
|
var s = stamps.find(s => foundIncr >= s[0]) || stamps[stamps.length - 1];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// these track boundaries when a full label is needed again
|
|
|
|
var prevYear;
|
|
|
|
var prevMnth;
|
|
|
|
var prevDate;
|
|
|
|
var prevHour;
|
|
|
|
var prevMins;
|
|
|
|
var prevSecs;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
return splits.map(split => {
|
2020-11-25 07:59:41 +00:00
|
|
|
var date = tzDate(split);
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
var newYear = date.getFullYear();
|
|
|
|
var newMnth = date.getMonth();
|
|
|
|
var newDate = date.getDate();
|
|
|
|
var newHour = date.getHours();
|
|
|
|
var newMins = date.getMinutes();
|
|
|
|
var newSecs = date.getSeconds();
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var stamp = (
|
|
|
|
newYear != prevYear && s[2] ||
|
|
|
|
newMnth != prevMnth && s[3] ||
|
|
|
|
newDate != prevDate && s[4] ||
|
|
|
|
newHour != prevHour && s[5] ||
|
|
|
|
newMins != prevMins && s[6] ||
|
|
|
|
newSecs != prevSecs && s[7] ||
|
|
|
|
s[1]
|
|
|
|
);
|
|
|
|
|
|
|
|
prevYear = newYear;
|
|
|
|
prevMnth = newMnth;
|
|
|
|
prevDate = newDate;
|
|
|
|
prevHour = newHour;
|
|
|
|
prevMins = newMins;
|
|
|
|
prevSecs = newSecs;
|
|
|
|
|
|
|
|
return stamp(date);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// for when axis.values is defined as a static fmtDate template string
|
|
|
|
function timeAxisVal(tzDate, dateTpl) {
|
|
|
|
var stamp = fmtDate(dateTpl);
|
2021-01-18 13:49:52 +00:00
|
|
|
return (self, splits, axisIdx, foundSpace, foundIncr) => splits.map(split => stamp(tzDate(split)));
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mkDate(y, m, d) {
|
|
|
|
return new Date(y, m, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
function timeSeriesStamp(stampCfg, fmtDate) {
|
|
|
|
return fmtDate(stampCfg);
|
|
|
|
}
|
|
|
|
var _timeSeriesStamp = '{YYYY}-{MM}-{DD} {h}:{mm}{aa}';
|
|
|
|
|
|
|
|
function timeSeriesVal(tzDate, stamp) {
|
2021-01-18 13:49:52 +00:00
|
|
|
return (self, val) => stamp(tzDate(val));
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function legendStroke(self, seriesIdx) {
|
|
|
|
var s = self.series[seriesIdx];
|
|
|
|
return s.width ? s.stroke(self, seriesIdx) : s.points.width ? s.points.stroke(self, seriesIdx) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function legendFill(self, seriesIdx) {
|
|
|
|
return self.series[seriesIdx].fill(self, seriesIdx);
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var legendOpts = {
|
|
|
|
show: true,
|
|
|
|
live: true,
|
|
|
|
isolate: false,
|
|
|
|
markers: {
|
|
|
|
show: true,
|
|
|
|
width: 2,
|
|
|
|
stroke: legendStroke,
|
|
|
|
fill: legendFill,
|
|
|
|
dash: "solid",
|
|
|
|
},
|
|
|
|
idx: null,
|
|
|
|
idxs: null,
|
|
|
|
values: [],
|
|
|
|
};
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function cursorPointShow(self, si) {
|
|
|
|
var o = self.cursor.points;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var pt = placeDiv();
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
var size = o.size(self, si);
|
|
|
|
setStylePx(pt, WIDTH, size);
|
|
|
|
setStylePx(pt, HEIGHT, size);
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
var mar = size / -2;
|
2020-11-25 07:59:41 +00:00
|
|
|
setStylePx(pt, "marginLeft", mar);
|
|
|
|
setStylePx(pt, "marginTop", mar);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var width = o.width(self, si, size);
|
|
|
|
width && setStylePx(pt, "borderWidth", width);
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function cursorPointFill(self, si) {
|
2021-09-17 19:28:20 +00:00
|
|
|
var sp = self.series[si].points;
|
|
|
|
return sp._fill || sp._stroke;
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cursorPointStroke(self, si) {
|
2021-09-17 19:28:20 +00:00
|
|
|
var sp = self.series[si].points;
|
|
|
|
return sp._stroke || sp._fill;
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cursorPointSize(self, si) {
|
2021-09-17 19:28:20 +00:00
|
|
|
var sp = self.series[si].points;
|
|
|
|
return ptDia(sp.width, 1);
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function dataIdx(self, seriesIdx, cursorIdx) {
|
|
|
|
return cursorIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
var moveTuple = [0,0];
|
|
|
|
|
|
|
|
function cursorMove(self, mouseLeft1, mouseTop1) {
|
|
|
|
moveTuple[0] = mouseLeft1;
|
|
|
|
moveTuple[1] = mouseTop1;
|
|
|
|
return moveTuple;
|
|
|
|
}
|
|
|
|
|
|
|
|
function filtBtn0(self, targ, handle) {
|
2021-01-18 13:49:52 +00:00
|
|
|
return e => {
|
2020-11-25 07:59:41 +00:00
|
|
|
e.button == 0 && handle(e);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function passThru(self, targ, handle) {
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cursorOpts = {
|
|
|
|
show: true,
|
|
|
|
x: true,
|
|
|
|
y: true,
|
|
|
|
lock: false,
|
|
|
|
move: cursorMove,
|
|
|
|
points: {
|
2020-12-23 07:17:49 +00:00
|
|
|
show: cursorPointShow,
|
|
|
|
size: cursorPointSize,
|
|
|
|
width: 0,
|
|
|
|
stroke: cursorPointStroke,
|
|
|
|
fill: cursorPointFill,
|
2020-11-25 07:59:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
bind: {
|
|
|
|
mousedown: filtBtn0,
|
|
|
|
mouseup: filtBtn0,
|
|
|
|
click: filtBtn0,
|
|
|
|
dblclick: filtBtn0,
|
|
|
|
|
|
|
|
mousemove: passThru,
|
|
|
|
mouseleave: passThru,
|
|
|
|
mouseenter: passThru,
|
|
|
|
},
|
|
|
|
|
|
|
|
drag: {
|
|
|
|
setScale: true,
|
|
|
|
x: true,
|
|
|
|
y: false,
|
|
|
|
dist: 0,
|
|
|
|
uni: null,
|
|
|
|
_x: false,
|
|
|
|
_y: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
focus: {
|
|
|
|
prox: -1,
|
|
|
|
},
|
|
|
|
|
|
|
|
left: -10,
|
|
|
|
top: -10,
|
|
|
|
idx: null,
|
|
|
|
dataIdx: dataIdx,
|
2021-09-17 19:28:20 +00:00
|
|
|
idxs: null,
|
2020-11-25 07:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var grid = {
|
|
|
|
show: true,
|
|
|
|
stroke: "rgba(0,0,0,0.07)",
|
|
|
|
width: 2,
|
|
|
|
// dash: [],
|
|
|
|
filter: retArg1,
|
|
|
|
};
|
|
|
|
|
|
|
|
var ticks = assign({}, grid, {size: 10});
|
|
|
|
|
|
|
|
var font = '12px system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"';
|
|
|
|
var labelFont = "bold " + font;
|
|
|
|
var lineMult = 1.5; // font-size multiplier
|
|
|
|
|
|
|
|
var xAxisOpts = {
|
|
|
|
show: true,
|
|
|
|
scale: "x",
|
2021-01-27 07:12:15 +00:00
|
|
|
stroke: hexBlack,
|
2020-11-25 07:59:41 +00:00
|
|
|
space: 50,
|
|
|
|
gap: 5,
|
|
|
|
size: 50,
|
2021-09-17 19:28:20 +00:00
|
|
|
labelGap: 0,
|
2020-11-25 07:59:41 +00:00
|
|
|
labelSize: 30,
|
|
|
|
labelFont: labelFont,
|
|
|
|
side: 2,
|
|
|
|
// class: "x-vals",
|
|
|
|
// incrs: timeIncrs,
|
|
|
|
// values: timeVals,
|
|
|
|
// filter: retArg1,
|
|
|
|
grid: grid,
|
|
|
|
ticks: ticks,
|
|
|
|
font: font,
|
|
|
|
rotate: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
var numSeriesLabel = "Value";
|
|
|
|
var timeSeriesLabel = "Time";
|
|
|
|
|
|
|
|
var xSeriesOpts = {
|
|
|
|
show: true,
|
|
|
|
scale: "x",
|
|
|
|
auto: false,
|
|
|
|
sorted: 1,
|
|
|
|
// label: "Time",
|
|
|
|
// value: v => stamp(new Date(v * 1e3)),
|
|
|
|
|
|
|
|
// internal caches
|
|
|
|
min: inf,
|
|
|
|
max: -inf,
|
|
|
|
idxs: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
function numAxisVals(self, splits, axisIdx, foundSpace, foundIncr) {
|
2021-01-18 13:49:52 +00:00
|
|
|
return splits.map(v => v == null ? "" : fmtNum(v));
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function numAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace, forceMin) {
|
|
|
|
var splits = [];
|
|
|
|
|
|
|
|
var numDec = fixedDec.get(foundIncr) || 0;
|
|
|
|
|
|
|
|
scaleMin = forceMin ? scaleMin : roundDec(incrRoundUp(scaleMin, foundIncr), numDec);
|
|
|
|
|
|
|
|
for (var val = scaleMin; val <= scaleMax; val = roundDec(val + foundIncr, numDec))
|
|
|
|
{ splits.push(Object.is(val, -0) ? 0 : val); } // coalesces -0
|
|
|
|
|
|
|
|
return splits;
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
// this doesnt work for sin, which needs to come off from 0 independently in pos and neg dirs
|
2020-11-25 07:59:41 +00:00
|
|
|
function logAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace, forceMin) {
|
|
|
|
var splits = [];
|
|
|
|
|
|
|
|
var logBase = self.scales[self.axes[axisIdx].scale].log;
|
|
|
|
|
|
|
|
var logFn = logBase == 10 ? log10 : log2;
|
|
|
|
|
|
|
|
var exp = floor(logFn(scaleMin));
|
|
|
|
|
|
|
|
foundIncr = pow(logBase, exp);
|
|
|
|
|
|
|
|
if (exp < 0)
|
|
|
|
{ foundIncr = roundDec(foundIncr, -exp); }
|
|
|
|
|
|
|
|
var split = scaleMin;
|
|
|
|
|
|
|
|
do {
|
|
|
|
splits.push(split);
|
|
|
|
split = roundDec(split + foundIncr, fixedDec.get(foundIncr));
|
|
|
|
|
|
|
|
if (split >= foundIncr * logBase)
|
|
|
|
{ foundIncr = split; }
|
|
|
|
|
|
|
|
} while (split <= scaleMax);
|
|
|
|
|
|
|
|
return splits;
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
function asinhAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace, forceMin) {
|
|
|
|
var sc = self.scales[self.axes[axisIdx].scale];
|
|
|
|
|
|
|
|
var linthresh = sc.asinh;
|
|
|
|
|
|
|
|
var posSplits = scaleMax > linthresh ? logAxisSplits(self, axisIdx, max(linthresh, scaleMin), scaleMax, foundIncr) : [linthresh];
|
|
|
|
var zero = scaleMax >= 0 && scaleMin <= 0 ? [0] : [];
|
|
|
|
var negSplits = scaleMin < -linthresh ? logAxisSplits(self, axisIdx, max(linthresh, -scaleMax), -scaleMin, foundIncr): [linthresh];
|
|
|
|
|
|
|
|
return negSplits.reverse().map(v => -v).concat(zero, posSplits);
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var RE_ALL = /./;
|
|
|
|
var RE_12357 = /[12357]/;
|
|
|
|
var RE_125 = /[125]/;
|
|
|
|
var RE_1 = /1/;
|
|
|
|
|
|
|
|
function logAxisValsFilt(self, splits, axisIdx, foundSpace, foundIncr) {
|
|
|
|
var axis = self.axes[axisIdx];
|
|
|
|
var scaleKey = axis.scale;
|
2021-02-17 07:25:25 +00:00
|
|
|
var sc = self.scales[scaleKey];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
if (sc.distr == 3 && sc.log == 2)
|
2020-11-25 07:59:41 +00:00
|
|
|
{ return splits; }
|
|
|
|
|
|
|
|
var valToPos = self.valToPos;
|
|
|
|
|
|
|
|
var minSpace = axis._space;
|
|
|
|
|
|
|
|
var _10 = valToPos(10, scaleKey);
|
|
|
|
|
|
|
|
var re = (
|
|
|
|
valToPos(9, scaleKey) - _10 >= minSpace ? RE_ALL :
|
|
|
|
valToPos(7, scaleKey) - _10 >= minSpace ? RE_12357 :
|
|
|
|
valToPos(5, scaleKey) - _10 >= minSpace ? RE_125 :
|
|
|
|
RE_1
|
|
|
|
);
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
return splits.map(v => ((sc.distr == 4 && v == 0) || re.test(v)) ? v : null);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function numSeriesVal(self, val) {
|
|
|
|
return val == null ? "" : fmtNum(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
var yAxisOpts = {
|
|
|
|
show: true,
|
|
|
|
scale: "y",
|
2021-01-27 07:12:15 +00:00
|
|
|
stroke: hexBlack,
|
2020-11-25 07:59:41 +00:00
|
|
|
space: 30,
|
|
|
|
gap: 5,
|
|
|
|
size: 50,
|
2021-09-17 19:28:20 +00:00
|
|
|
labelGap: 0,
|
2020-11-25 07:59:41 +00:00
|
|
|
labelSize: 30,
|
|
|
|
labelFont: labelFont,
|
|
|
|
side: 3,
|
|
|
|
// class: "y-vals",
|
|
|
|
// incrs: numIncrs,
|
|
|
|
// values: (vals, space) => vals,
|
|
|
|
// filter: retArg1,
|
|
|
|
grid: grid,
|
|
|
|
ticks: ticks,
|
|
|
|
font: font,
|
|
|
|
rotate: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
// takes stroke width
|
|
|
|
function ptDia(width, mult) {
|
|
|
|
var dia = 3 + (width || 1) * 2;
|
|
|
|
return roundDec(dia * mult, 3);
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function seriesPointsShow(self, si) {
|
|
|
|
var ref = self.series[0];
|
|
|
|
var scale = ref.scale;
|
|
|
|
var idxs = ref.idxs;
|
|
|
|
var xData = self._data[0];
|
|
|
|
var p0 = self.valToPos(xData[idxs[0]], scale, true);
|
|
|
|
var p1 = self.valToPos(xData[idxs[1]], scale, true);
|
|
|
|
var dim = abs(p1 - p0);
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var s = self.series[si];
|
2021-01-18 13:49:52 +00:00
|
|
|
// const dia = ptDia(s.width, pxRatio);
|
|
|
|
var maxPts = dim / (s.points.space * pxRatio);
|
2020-11-25 07:59:41 +00:00
|
|
|
return idxs[1] - idxs[0] <= maxPts;
|
|
|
|
}
|
|
|
|
|
|
|
|
function seriesFillTo(self, seriesIdx, dataMin, dataMax) {
|
|
|
|
var scale = self.scales[self.series[seriesIdx].scale];
|
2021-01-27 07:12:15 +00:00
|
|
|
var isUpperBandEdge = self.bands && self.bands.some(b => b.series[0] == seriesIdx);
|
|
|
|
return scale.distr == 3 || isUpperBandEdge ? scale.min : 0;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var ySeriesOpts = {
|
|
|
|
scale: "y",
|
|
|
|
auto: true,
|
|
|
|
sorted: 0,
|
|
|
|
show: true,
|
|
|
|
spanGaps: false,
|
2021-09-17 19:28:20 +00:00
|
|
|
gaps: (self, seriesIdx, idx0, idx1, nullGaps) => nullGaps,
|
2020-11-25 07:59:41 +00:00
|
|
|
alpha: 1,
|
|
|
|
points: {
|
2021-09-17 19:28:20 +00:00
|
|
|
show: seriesPointsShow,
|
|
|
|
filter: null,
|
|
|
|
// paths:
|
2020-11-25 07:59:41 +00:00
|
|
|
// stroke: "#000",
|
|
|
|
// fill: "#fff",
|
|
|
|
// width: 1,
|
|
|
|
// size: 10,
|
|
|
|
},
|
|
|
|
// label: "Value",
|
|
|
|
// value: v => v,
|
|
|
|
values: null,
|
|
|
|
|
|
|
|
// internal caches
|
|
|
|
min: inf,
|
|
|
|
max: -inf,
|
|
|
|
idxs: [],
|
|
|
|
|
|
|
|
path: null,
|
|
|
|
clip: null,
|
|
|
|
};
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function clampScale(self, val, scaleMin, scaleMax, scaleKey) {
|
|
|
|
/*
|
|
|
|
if (val < 0) {
|
|
|
|
let cssHgt = self.bbox.height / pxRatio;
|
|
|
|
let absPos = self.valToPos(abs(val), scaleKey);
|
|
|
|
let fromBtm = cssHgt - absPos;
|
|
|
|
return self.posToVal(cssHgt + fromBtm, scaleKey);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return scaleMin / 10;
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var xScaleOpts = {
|
2020-12-23 07:17:49 +00:00
|
|
|
time: FEAT_TIME,
|
2020-11-25 07:59:41 +00:00
|
|
|
auto: true,
|
|
|
|
distr: 1,
|
|
|
|
log: 10,
|
2021-02-17 07:25:25 +00:00
|
|
|
asinh: 1,
|
2020-11-25 07:59:41 +00:00
|
|
|
min: null,
|
|
|
|
max: null,
|
2021-01-18 13:49:52 +00:00
|
|
|
dir: 1,
|
|
|
|
ori: 0,
|
2020-11-25 07:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var yScaleOpts = assign({}, xScaleOpts, {
|
|
|
|
time: false,
|
2021-01-18 13:49:52 +00:00
|
|
|
ori: 1,
|
2020-11-25 07:59:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var syncs = {};
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
function _sync(key, opts) {
|
|
|
|
var s = syncs[key];
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
s = {
|
|
|
|
key: key,
|
2021-09-17 19:28:20 +00:00
|
|
|
plots: [],
|
|
|
|
sub: function sub(plot) {
|
|
|
|
s.plots.push(plot);
|
2021-02-17 07:25:25 +00:00
|
|
|
},
|
2021-09-17 19:28:20 +00:00
|
|
|
unsub: function unsub(plot) {
|
|
|
|
s.plots = s.plots.filter(c => c != plot);
|
2021-02-17 07:25:25 +00:00
|
|
|
},
|
|
|
|
pub: function pub(type, self, x, y, w, h, i) {
|
2021-09-17 19:28:20 +00:00
|
|
|
for (var j = 0; j < s.plots.length; j++)
|
|
|
|
{ s.plots[j] != self && s.plots[j].pub(type, self, x, y, w, h, i); }
|
|
|
|
},
|
2021-02-17 07:25:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (key != null)
|
|
|
|
{ syncs[key] = s; }
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var BAND_CLIP_FILL = 1 << 0;
|
|
|
|
var BAND_CLIP_STROKE = 1 << 1;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function orient(u, seriesIdx, cb) {
|
2020-12-23 07:17:49 +00:00
|
|
|
var series = u.series[seriesIdx];
|
|
|
|
var scales = u.scales;
|
|
|
|
var bbox = u.bbox;
|
2021-01-18 13:49:52 +00:00
|
|
|
var scaleX = scales[u.series[0].scale];
|
|
|
|
|
|
|
|
var dx = u._data[0],
|
|
|
|
dy = u._data[seriesIdx],
|
|
|
|
sx = scaleX,
|
|
|
|
sy = scales[series.scale],
|
|
|
|
l = bbox.left,
|
|
|
|
t = bbox.top,
|
|
|
|
w = bbox.width,
|
|
|
|
h = bbox.height,
|
|
|
|
H = u.valToPosH,
|
|
|
|
V = u.valToPosV;
|
|
|
|
|
|
|
|
return (sx.ori == 0
|
|
|
|
? cb(
|
|
|
|
series,
|
|
|
|
dx,
|
|
|
|
dy,
|
|
|
|
sx,
|
|
|
|
sy,
|
|
|
|
H,
|
|
|
|
V,
|
|
|
|
l,
|
|
|
|
t,
|
|
|
|
w,
|
|
|
|
h,
|
|
|
|
moveToH,
|
|
|
|
lineToH,
|
|
|
|
rectH,
|
|
|
|
arcH,
|
|
|
|
bezierCurveToH
|
|
|
|
)
|
|
|
|
: cb(
|
|
|
|
series,
|
|
|
|
dx,
|
|
|
|
dy,
|
|
|
|
sx,
|
|
|
|
sy,
|
|
|
|
V,
|
|
|
|
H,
|
|
|
|
t,
|
|
|
|
l,
|
|
|
|
h,
|
|
|
|
w,
|
|
|
|
moveToV,
|
|
|
|
lineToV,
|
|
|
|
rectV,
|
|
|
|
arcV,
|
|
|
|
bezierCurveToV
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// creates inverted band clip path (towards from stroke path -> yMax)
|
|
|
|
function clipBandLine(self, seriesIdx, idx0, idx1, strokePath) {
|
|
|
|
return orient(self, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => {
|
|
|
|
var dir = scaleX.dir * (scaleX.ori == 0 ? 1 : -1);
|
|
|
|
var lineTo = scaleX.ori == 0 ? lineToH : lineToV;
|
|
|
|
|
|
|
|
var frIdx, toIdx;
|
|
|
|
|
|
|
|
if (dir == 1) {
|
|
|
|
frIdx = idx0;
|
|
|
|
toIdx = idx1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
frIdx = idx1;
|
|
|
|
toIdx = idx0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// path start
|
|
|
|
var x0 = incrRound(valToPosX(dataX[frIdx], scaleX, xDim, xOff), 0.5);
|
|
|
|
var y0 = incrRound(valToPosY(dataY[frIdx], scaleY, yDim, yOff), 0.5);
|
|
|
|
// path end x
|
|
|
|
var x1 = incrRound(valToPosX(dataX[toIdx], scaleX, xDim, xOff), 0.5);
|
|
|
|
// upper y limit
|
|
|
|
var yLimit = incrRound(valToPosY(scaleY.max, scaleY, yDim, yOff), 0.5);
|
|
|
|
|
|
|
|
var clip = new Path2D(strokePath);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
lineTo(clip, x1, yLimit);
|
|
|
|
lineTo(clip, x0, yLimit);
|
|
|
|
lineTo(clip, x0, y0);
|
|
|
|
|
|
|
|
return clip;
|
|
|
|
});
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function clipGaps(gaps, ori, plotLft, plotTop, plotWid, plotHgt) {
|
|
|
|
var clip = null;
|
|
|
|
|
|
|
|
// create clip path (invert gaps and non-gaps)
|
|
|
|
if (gaps.length > 0) {
|
|
|
|
clip = new Path2D();
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var rect = ori == 0 ? rectH : rectV;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var prevGapEnd = plotLft;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
for (var i = 0; i < gaps.length; i++) {
|
|
|
|
var g = gaps[i];
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (g[1] > g[0]) {
|
|
|
|
rect(clip, prevGapEnd, plotTop, g[0] - prevGapEnd, plotTop + plotHgt);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
prevGapEnd = g[1];
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
rect(clip, prevGapEnd, plotTop, plotLft + plotWid - prevGapEnd, plotTop + plotHgt);
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return clip;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function addGap(gaps, fromX, toX) {
|
2021-09-17 19:28:20 +00:00
|
|
|
var prevGap = gaps[gaps.length - 1];
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (prevGap && prevGap[0] == fromX) // TODO: gaps must be encoded at stroke widths?
|
|
|
|
{ prevGap[1] = toX; }
|
|
|
|
else
|
|
|
|
{ gaps.push([fromX, toX]); }
|
|
|
|
}
|
|
|
|
|
|
|
|
function pxRoundGen(pxAlign) {
|
|
|
|
return pxAlign == 0 ? retArg0 : pxAlign == 1 ? round : v => incrRound(v, pxAlign);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
// orientation-inverting canvas functions
|
|
|
|
function moveToH(p, x, y) { p.moveTo(x, y); }
|
|
|
|
function moveToV(p, y, x) { p.moveTo(x, y); }
|
|
|
|
function lineToH(p, x, y) { p.lineTo(x, y); }
|
|
|
|
function lineToV(p, y, x) { p.lineTo(x, y); }
|
|
|
|
function rectH(p, x, y, w, h) { p.rect(x, y, w, h); }
|
|
|
|
function rectV(p, y, x, h, w) { p.rect(x, y, w, h); }
|
|
|
|
function arcH(p, x, y, r, startAngle, endAngle) { p.arc(x, y, r, startAngle, endAngle); }
|
|
|
|
function arcV(p, y, x, r, startAngle, endAngle) { p.arc(x, y, r, startAngle, endAngle); }
|
|
|
|
function bezierCurveToH(p, bp1x, bp1y, bp2x, bp2y, p2x, p2y) { p.bezierCurveTo(bp1x, bp1y, bp2x, bp2y, p2x, p2y); }function bezierCurveToV(p, bp1y, bp1x, bp2y, bp2x, p2y, p2x) { p.bezierCurveTo(bp1x, bp1y, bp2x, bp2y, p2x, p2y); }
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
// TODO: drawWrap(seriesIdx, drawPoints) (save, restore, translate, clip)
|
|
|
|
function points(opts) {
|
|
|
|
return (u, seriesIdx, idx0, idx1, filtIdxs) => {
|
|
|
|
// log("drawPoints()", arguments);
|
|
|
|
|
|
|
|
return orient(u, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => {
|
|
|
|
var pxRound = series.pxRound;
|
|
|
|
var points = series.points;
|
|
|
|
|
|
|
|
var moveTo, arc;
|
|
|
|
|
|
|
|
if (scaleX.ori == 0) {
|
|
|
|
moveTo = moveToH;
|
|
|
|
arc = arcH;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
moveTo = moveToV;
|
|
|
|
arc = arcV;
|
|
|
|
}
|
|
|
|
|
|
|
|
var width = roundDec(points.width * pxRatio, 3);
|
|
|
|
|
|
|
|
var rad = (points.size - points.width) / 2 * pxRatio;
|
|
|
|
var dia = roundDec(rad * 2, 3);
|
|
|
|
|
|
|
|
var fill = new Path2D();
|
|
|
|
var clip = new Path2D();
|
|
|
|
|
|
|
|
var ref = u.bbox;
|
|
|
|
var lft = ref.left;
|
|
|
|
var top = ref.top;
|
|
|
|
var wid = ref.width;
|
|
|
|
var hgt = ref.height;
|
|
|
|
|
|
|
|
rectH(clip,
|
|
|
|
lft - dia,
|
|
|
|
top - dia,
|
|
|
|
wid + dia * 2,
|
|
|
|
hgt + dia * 2
|
|
|
|
);
|
|
|
|
|
|
|
|
var drawPoint = pi => {
|
|
|
|
if (dataY[pi] != null) {
|
|
|
|
var x = pxRound(valToPosX(dataX[pi], scaleX, xDim, xOff));
|
|
|
|
var y = pxRound(valToPosY(dataY[pi], scaleY, yDim, yOff));
|
|
|
|
|
|
|
|
moveTo(fill, x + rad, y);
|
|
|
|
arc(fill, x, y, rad, 0, PI * 2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (filtIdxs)
|
|
|
|
{ filtIdxs.forEach(drawPoint); }
|
|
|
|
else {
|
|
|
|
for (var pi = idx0; pi <= idx1; pi++)
|
|
|
|
{ drawPoint(pi); }
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
stroke: width > 0 ? fill : null,
|
|
|
|
fill: fill,
|
|
|
|
clip: clip,
|
|
|
|
flags: BAND_CLIP_FILL | BAND_CLIP_STROKE,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function _drawAcc(lineTo) {
|
2021-09-17 19:28:20 +00:00
|
|
|
return (stroke, accX, minY, maxY, inY, outY) => {
|
2021-02-10 07:13:13 +00:00
|
|
|
if (minY != maxY) {
|
2021-09-17 19:28:20 +00:00
|
|
|
if (inY != minY && outY != minY)
|
|
|
|
{ lineTo(stroke, accX, minY); }
|
|
|
|
if (inY != maxY && outY != maxY)
|
|
|
|
{ lineTo(stroke, accX, maxY); }
|
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
lineTo(stroke, accX, outY);
|
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
};
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var drawAccH = _drawAcc(lineToH);
|
|
|
|
var drawAccV = _drawAcc(lineToV);
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function linear() {
|
2021-01-18 13:49:52 +00:00
|
|
|
return (u, seriesIdx, idx0, idx1) => {
|
|
|
|
return orient(u, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => {
|
2021-09-17 19:28:20 +00:00
|
|
|
var pxRound = series.pxRound;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var lineTo, drawAcc;
|
|
|
|
|
|
|
|
if (scaleX.ori == 0) {
|
|
|
|
lineTo = lineToH;
|
|
|
|
drawAcc = drawAccH;
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-01-18 13:49:52 +00:00
|
|
|
lineTo = lineToV;
|
|
|
|
drawAcc = drawAccV;
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var dir = scaleX.dir * (scaleX.ori == 0 ? 1 : -1);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL};
|
2021-01-18 13:49:52 +00:00
|
|
|
var stroke = _paths.stroke;
|
|
|
|
|
|
|
|
var minY = inf,
|
|
|
|
maxY = -inf,
|
2021-09-17 19:28:20 +00:00
|
|
|
inY, outY, outX, drawnAtX;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var gaps = [];
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var accX = pxRound(valToPosX(dataX[dir == 1 ? idx0 : idx1], scaleX, xDim, xOff));
|
2021-01-18 13:49:52 +00:00
|
|
|
var accGaps = false;
|
2021-09-17 19:28:20 +00:00
|
|
|
var prevYNull = false;
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
// data edges
|
|
|
|
var lftIdx = nonNullIdx(dataY, idx0, idx1, 1 * dir);
|
|
|
|
var rgtIdx = nonNullIdx(dataY, idx0, idx1, -1 * dir);
|
|
|
|
var lftX = incrRound(valToPosX(dataX[lftIdx], scaleX, xDim, xOff), 0.5);
|
|
|
|
var rgtX = incrRound(valToPosX(dataX[rgtIdx], scaleX, xDim, xOff), 0.5);
|
|
|
|
|
|
|
|
if (lftX > xOff)
|
|
|
|
{ addGap(gaps, xOff, lftX); }
|
|
|
|
|
|
|
|
for (var i = dir == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += dir) {
|
2021-09-17 19:28:20 +00:00
|
|
|
var x = pxRound(valToPosX(dataX[i], scaleX, xDim, xOff));
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
if (x == accX) {
|
|
|
|
if (dataY[i] != null) {
|
2021-09-17 19:28:20 +00:00
|
|
|
outY = pxRound(valToPosY(dataY[i], scaleY, yDim, yOff));
|
2021-01-18 13:49:52 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (minY == inf) {
|
|
|
|
lineTo(stroke, x, outY);
|
|
|
|
inY = outY;
|
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
minY = min(outY, minY);
|
|
|
|
maxY = max(outY, maxY);
|
|
|
|
}
|
2021-09-17 19:28:20 +00:00
|
|
|
else if (dataY[i] === null)
|
|
|
|
{ accGaps = prevYNull = true; }
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
else {
|
|
|
|
var _addGap = false;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (minY != inf) {
|
2021-09-17 19:28:20 +00:00
|
|
|
drawAcc(stroke, accX, minY, maxY, inY, outY);
|
2021-01-18 13:49:52 +00:00
|
|
|
outX = drawnAtX = accX;
|
|
|
|
}
|
|
|
|
else if (accGaps) {
|
|
|
|
_addGap = true;
|
|
|
|
accGaps = false;
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (dataY[i] != null) {
|
2021-09-17 19:28:20 +00:00
|
|
|
outY = pxRound(valToPosY(dataY[i], scaleY, yDim, yOff));
|
2021-01-18 13:49:52 +00:00
|
|
|
lineTo(stroke, x, outY);
|
2021-09-17 19:28:20 +00:00
|
|
|
minY = maxY = inY = outY;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
// prior pixel can have data but still start a gap if ends with null
|
2021-09-17 19:28:20 +00:00
|
|
|
if (prevYNull && x - accX > 1)
|
2021-01-18 13:49:52 +00:00
|
|
|
{ _addGap = true; }
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
prevYNull = false;
|
2021-01-18 13:49:52 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
minY = inf;
|
|
|
|
maxY = -inf;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (dataY[i] === null) {
|
|
|
|
accGaps = true;
|
|
|
|
|
|
|
|
if (x - accX > 1)
|
|
|
|
{ _addGap = true; }
|
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
_addGap && addGap(gaps, outX, x);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
accX = x;
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (minY != inf && minY != maxY && drawnAtX != accX)
|
2021-09-17 19:28:20 +00:00
|
|
|
{ drawAcc(stroke, accX, minY, maxY, inY, outY); }
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (rgtX < xOff + xDim)
|
|
|
|
{ addGap(gaps, rgtX, xOff + xDim); }
|
2020-12-23 07:17:49 +00:00
|
|
|
|
|
|
|
if (series.fill != null) {
|
|
|
|
var fill = _paths.fill = new Path2D(stroke);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var fillTo = pxRound(valToPosY(series.fillTo(u, seriesIdx, series.min, series.max), scaleY, yDim, yOff));
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
lineTo(fill, rgtX, fillTo);
|
|
|
|
lineTo(fill, lftX, fillTo);
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
_paths.gaps = gaps = series.gaps(u, seriesIdx, idx0, idx1, gaps);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (!series.spanGaps)
|
|
|
|
{ _paths.clip = clipGaps(gaps, scaleX.ori, xOff, yOff, xDim, yDim); }
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (u.bands.length > 0) {
|
|
|
|
// ADDL OPT: only create band clips for series that are band lower edges
|
|
|
|
// if (b.series[1] == i && _paths.band == null)
|
|
|
|
_paths.band = clipBandLine(u, seriesIdx, idx0, idx1, stroke);
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
return _paths;
|
|
|
|
});
|
2020-12-23 07:17:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function stepped(opts) {
|
|
|
|
var align = ifNull(opts.align, 1);
|
2021-03-20 20:39:14 +00:00
|
|
|
// whether to draw ascenders/descenders at null/gap bondaries
|
|
|
|
var ascDesc = ifNull(opts.ascDesc, false);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
return (u, seriesIdx, idx0, idx1) => {
|
|
|
|
return orient(u, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => {
|
2021-09-17 19:28:20 +00:00
|
|
|
var pxRound = series.pxRound;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var lineTo = scaleX.ori == 0 ? lineToH : lineToV;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL};
|
2021-01-18 13:49:52 +00:00
|
|
|
var stroke = _paths.stroke;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var _dir = 1 * scaleX.dir * (scaleX.ori == 0 ? 1 : -1);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
idx0 = nonNullIdx(dataY, idx0, idx1, 1);
|
|
|
|
idx1 = nonNullIdx(dataY, idx0, idx1, -1);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var gaps = [];
|
|
|
|
var inGap = false;
|
2021-09-17 19:28:20 +00:00
|
|
|
var prevYPos = pxRound(valToPosY(dataY[_dir == 1 ? idx0 : idx1], scaleY, yDim, yOff));
|
|
|
|
var firstXPos = pxRound(valToPosX(dataX[_dir == 1 ? idx0 : idx1], scaleX, xDim, xOff));
|
2021-01-18 13:49:52 +00:00
|
|
|
var prevXPos = firstXPos;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
lineTo(stroke, firstXPos, prevYPos);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
for (var i = _dir == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += _dir) {
|
|
|
|
var yVal1 = dataY[i];
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var x1 = pxRound(valToPosX(dataX[i], scaleX, xDim, xOff));
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
if (yVal1 == null) {
|
2021-01-27 07:12:15 +00:00
|
|
|
if (yVal1 === null) {
|
2021-01-18 13:49:52 +00:00
|
|
|
addGap(gaps, prevXPos, x1);
|
|
|
|
inGap = true;
|
|
|
|
}
|
|
|
|
continue;
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var y1 = pxRound(valToPosY(yVal1, scaleY, yDim, yOff));
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (inGap) {
|
|
|
|
addGap(gaps, prevXPos, x1);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
// don't clip vertical extenders
|
|
|
|
if (prevYPos != y1) {
|
|
|
|
var halfStroke = (series.width * pxRatio) / 2;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var lastGap = gaps[gaps.length - 1];
|
2021-03-20 20:39:14 +00:00
|
|
|
|
|
|
|
lastGap[0] += (ascDesc || align == 1) ? halfStroke : -halfStroke;
|
|
|
|
lastGap[1] -= (ascDesc || align == -1) ? halfStroke : -halfStroke;
|
2021-01-18 13:49:52 +00:00
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
inGap = false;
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (align == 1)
|
|
|
|
{ lineTo(stroke, x1, prevYPos); }
|
|
|
|
else
|
|
|
|
{ lineTo(stroke, prevXPos, y1); }
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
lineTo(stroke, x1, y1);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
prevYPos = y1;
|
|
|
|
prevXPos = x1;
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (series.fill != null) {
|
|
|
|
var fill = _paths.fill = new Path2D(stroke);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var fillTo = series.fillTo(u, seriesIdx, series.min, series.max);
|
2021-09-17 19:28:20 +00:00
|
|
|
var minY = pxRound(valToPosY(fillTo, scaleY, yDim, yOff));
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
lineTo(fill, prevXPos, minY);
|
|
|
|
lineTo(fill, firstXPos, minY);
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
_paths.gaps = gaps = series.gaps(u, seriesIdx, idx0, idx1, gaps);
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (!series.spanGaps)
|
|
|
|
{ _paths.clip = clipGaps(gaps, scaleX.ori, xOff, yOff, xDim, yDim); }
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (u.bands.length > 0) {
|
|
|
|
// ADDL OPT: only create band clips for series that are band lower edges
|
|
|
|
// if (b.series[1] == i && _paths.band == null)
|
|
|
|
_paths.band = clipBandLine(u, seriesIdx, idx0, idx1, stroke);
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
return _paths;
|
|
|
|
});
|
2020-12-23 07:17:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function bars(opts) {
|
|
|
|
opts = opts || EMPTY_OBJ;
|
2021-09-17 19:28:20 +00:00
|
|
|
var size = ifNull(opts.size, [0.6, inf, 1]);
|
2021-01-18 13:49:52 +00:00
|
|
|
var align = opts.align || 0;
|
2021-09-17 19:28:20 +00:00
|
|
|
var extraGap = (opts.gap || 0) * pxRatio;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
|
|
|
var gapFactor = 1 - size[0];
|
|
|
|
var maxWidth = ifNull(size[1], inf) * pxRatio;
|
2021-09-17 19:28:20 +00:00
|
|
|
var minWidth = ifNull(size[2], 1) * pxRatio;
|
|
|
|
|
|
|
|
var disp = opts.disp;
|
|
|
|
var _each = ifNull(opts.each, _ => {});
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
return (u, seriesIdx, idx0, idx1) => {
|
|
|
|
return orient(u, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => {
|
2021-09-17 19:28:20 +00:00
|
|
|
var pxRound = series.pxRound;
|
2021-01-18 13:49:52 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var _dirX = scaleX.dir * (scaleX.ori == 0 ? 1 : -1);
|
|
|
|
var _dirY = scaleY.dir * (scaleY.ori == 1 ? 1 : -1);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var rect = scaleX.ori == 0 ? rectH : rectV;
|
|
|
|
|
|
|
|
var each = scaleX.ori == 0 ? _each : (u, seriesIdx, i, top, lft, hgt, wid) => {
|
|
|
|
_each(u, seriesIdx, i, lft, top, wid, hgt);
|
|
|
|
};
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var fillToY = series.fillTo(u, seriesIdx, series.min, series.max);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var y0Pos = valToPosY(fillToY, scaleY, yDim, yOff);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var xShift, barWid;
|
|
|
|
|
|
|
|
var strokeWidth = pxRound(series.width * pxRatio);
|
|
|
|
|
|
|
|
if (disp != null) {
|
|
|
|
dataX = disp.x0.values(u, seriesIdx, idx0, idx1);
|
|
|
|
|
|
|
|
if (disp.x0.unit == 2)
|
|
|
|
{ dataX = dataX.map(pct => u.posToVal(xOff + pct * xDim, scaleX.key, true)); }
|
|
|
|
|
|
|
|
// assumes uniform sizes, for now
|
|
|
|
var sizes = disp.size.values(u, seriesIdx, idx0, idx1);
|
|
|
|
|
|
|
|
if (disp.size.unit == 2)
|
|
|
|
{ barWid = sizes[0] * xDim; }
|
|
|
|
else
|
|
|
|
{ barWid = valToPosX(sizes[0], scaleX, xDim, xOff) - valToPosX(0, scaleX, xDim, xOff); } // assumes linear scale (delta from 0)
|
|
|
|
|
|
|
|
barWid = pxRound(barWid - strokeWidth);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
xShift = (_dirX == 1 ? -strokeWidth / 2 : barWid + strokeWidth / 2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var colWid = xDim;
|
|
|
|
|
|
|
|
if (dataX.length > 1) {
|
|
|
|
// scan full dataset for smallest adjacent delta
|
|
|
|
// will not work properly for non-linear x scales, since does not do expensive valToPosX calcs till end
|
|
|
|
for (var i = 1, minDelta = Infinity; i < dataX.length; i++) {
|
|
|
|
var delta = abs(dataX[i] - dataX[i-1]);
|
|
|
|
|
|
|
|
if (delta < minDelta) {
|
|
|
|
minDelta = delta;
|
|
|
|
colWid = abs(valToPosX(dataX[i], scaleX, xDim, xOff) - valToPosX(dataX[i-1], scaleX, xDim, xOff));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var gapWid = colWid * gapFactor;
|
|
|
|
|
|
|
|
barWid = pxRound(min(maxWidth, max(minWidth, colWid - gapWid)) - strokeWidth - extraGap);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
xShift = (align == 0 ? barWid / 2 : align == _dirX ? 0 : barWid) - align * _dirX * extraGap / 2;
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL | BAND_CLIP_STROKE}; // disp, geom
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var hasBands = u.bands.length > 0;
|
|
|
|
var yLimit;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (hasBands) {
|
|
|
|
// ADDL OPT: only create band clips for series that are band lower edges
|
|
|
|
// if (b.series[1] == i && _paths.band == null)
|
|
|
|
_paths.band = new Path2D();
|
|
|
|
yLimit = incrRound(valToPosY(scaleY.max, scaleY, yDim, yOff), 0.5);
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var stroke = _paths.stroke;
|
|
|
|
var band = _paths.band;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
for (var i$1 = _dirX == 1 ? idx0 : idx1; i$1 >= idx0 && i$1 <= idx1; i$1 += _dirX) {
|
|
|
|
var yVal = dataY[i$1];
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
// interpolate upwards band clips
|
|
|
|
if (yVal == null) {
|
|
|
|
if (hasBands) {
|
|
|
|
// simple, but inefficient bi-directinal linear scans on each iteration
|
2021-09-17 19:28:20 +00:00
|
|
|
var prevNonNull = nonNullIdx(dataY, _dirX == 1 ? idx0 : idx1, i$1, -_dirX);
|
|
|
|
var nextNonNull = nonNullIdx(dataY, i$1, _dirX == 1 ? idx1 : idx0, _dirX);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var prevVal = dataY[prevNonNull];
|
|
|
|
var nextVal = dataY[nextNonNull];
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
yVal = prevVal + (i$1 - prevNonNull) / (nextNonNull - prevNonNull) * (nextVal - prevVal);
|
2021-01-18 13:49:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ continue; }
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var xVal = scaleX.distr != 2 || disp != null ? dataX[i$1] : i$1;
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
// TODO: all xPos can be pre-computed once for all series in aligned set
|
|
|
|
var xPos = valToPosX(xVal, scaleX, xDim, xOff);
|
|
|
|
var yPos = valToPosY(yVal, scaleY, yDim, yOff);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var lft = pxRound(xPos - xShift);
|
|
|
|
var btm = pxRound(max(yPos, y0Pos));
|
|
|
|
var top = pxRound(min(yPos, y0Pos));
|
2021-01-18 13:49:52 +00:00
|
|
|
var barHgt = btm - top;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (dataY[i$1] != null) {
|
|
|
|
rect(stroke, lft, top, barWid, barHgt);
|
|
|
|
|
|
|
|
each(u, seriesIdx, i$1,
|
|
|
|
lft - strokeWidth / 2,
|
|
|
|
top - strokeWidth / 2,
|
|
|
|
barWid + strokeWidth,
|
|
|
|
barHgt + strokeWidth
|
|
|
|
);
|
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
if (hasBands) {
|
2021-09-17 19:28:20 +00:00
|
|
|
if (_dirY == 1) {
|
|
|
|
btm = top;
|
|
|
|
top = yLimit;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
top = btm;
|
|
|
|
btm = yLimit;
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
barHgt = btm - top;
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
rect(band, lft - strokeWidth / 2, top + strokeWidth / 2, barWid + strokeWidth, barHgt - strokeWidth);
|
2021-01-18 13:49:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (series.fill != null)
|
|
|
|
{ _paths.fill = new Path2D(stroke); }
|
|
|
|
|
|
|
|
return _paths;
|
|
|
|
});
|
2020-12-23 07:17:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function splineInterp(interp, opts) {
|
|
|
|
return (u, seriesIdx, idx0, idx1) => {
|
|
|
|
return orient(u, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => {
|
|
|
|
var pxRound = series.pxRound;
|
|
|
|
|
|
|
|
var moveTo, bezierCurveTo, lineTo;
|
|
|
|
|
|
|
|
if (scaleX.ori == 0) {
|
|
|
|
moveTo = moveToH;
|
|
|
|
lineTo = lineToH;
|
|
|
|
bezierCurveTo = bezierCurveToH;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
moveTo = moveToV;
|
|
|
|
lineTo = lineToV;
|
|
|
|
bezierCurveTo = bezierCurveToV;
|
|
|
|
}
|
|
|
|
|
|
|
|
var _dir = 1 * scaleX.dir * (scaleX.ori == 0 ? 1 : -1);
|
|
|
|
|
|
|
|
idx0 = nonNullIdx(dataY, idx0, idx1, 1);
|
|
|
|
idx1 = nonNullIdx(dataY, idx0, idx1, -1);
|
|
|
|
|
|
|
|
var gaps = [];
|
|
|
|
var inGap = false;
|
|
|
|
var firstXPos = pxRound(valToPosX(dataX[_dir == 1 ? idx0 : idx1], scaleX, xDim, xOff));
|
|
|
|
var prevXPos = firstXPos;
|
|
|
|
|
|
|
|
var xCoords = [];
|
|
|
|
var yCoords = [];
|
|
|
|
|
|
|
|
for (var i = _dir == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += _dir) {
|
|
|
|
var yVal = dataY[i];
|
|
|
|
var xVal = dataX[i];
|
|
|
|
var xPos = valToPosX(xVal, scaleX, xDim, xOff);
|
|
|
|
|
|
|
|
if (yVal == null) {
|
|
|
|
if (yVal === null) {
|
|
|
|
addGap(gaps, prevXPos, xPos);
|
|
|
|
inGap = true;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (inGap) {
|
|
|
|
addGap(gaps, prevXPos, xPos);
|
|
|
|
inGap = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
xCoords.push((prevXPos = xPos));
|
|
|
|
yCoords.push(valToPosY(dataY[i], scaleY, yDim, yOff));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _paths = {stroke: interp(xCoords, yCoords, moveTo, lineTo, bezierCurveTo, pxRound), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL};
|
|
|
|
var stroke = _paths.stroke;
|
|
|
|
|
|
|
|
if (series.fill != null && stroke != null) {
|
|
|
|
var fill = _paths.fill = new Path2D(stroke);
|
|
|
|
|
|
|
|
var fillTo = series.fillTo(u, seriesIdx, series.min, series.max);
|
|
|
|
var minY = pxRound(valToPosY(fillTo, scaleY, yDim, yOff));
|
|
|
|
|
|
|
|
lineTo(fill, prevXPos, minY);
|
|
|
|
lineTo(fill, firstXPos, minY);
|
|
|
|
}
|
|
|
|
|
|
|
|
_paths.gaps = gaps = series.gaps(u, seriesIdx, idx0, idx1, gaps);
|
|
|
|
|
|
|
|
if (!series.spanGaps)
|
|
|
|
{ _paths.clip = clipGaps(gaps, scaleX.ori, xOff, yOff, xDim, yDim); }
|
|
|
|
|
|
|
|
if (u.bands.length > 0) {
|
|
|
|
// ADDL OPT: only create band clips for series that are band lower edges
|
|
|
|
// if (b.series[1] == i && _paths.band == null)
|
|
|
|
_paths.band = clipBandLine(u, seriesIdx, idx0, idx1, stroke);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _paths;
|
|
|
|
|
|
|
|
// if FEAT_PATHS: false in rollup.config.js
|
|
|
|
// u.ctx.save();
|
|
|
|
// u.ctx.beginPath();
|
|
|
|
// u.ctx.rect(u.bbox.left, u.bbox.top, u.bbox.width, u.bbox.height);
|
|
|
|
// u.ctx.clip();
|
|
|
|
// u.ctx.strokeStyle = u.series[sidx].stroke;
|
|
|
|
// u.ctx.stroke(stroke);
|
|
|
|
// u.ctx.fillStyle = u.series[sidx].fill;
|
|
|
|
// u.ctx.fill(fill);
|
|
|
|
// u.ctx.restore();
|
|
|
|
// return null;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function monotoneCubic(opts) {
|
|
|
|
return splineInterp(_monotoneCubic);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Monotone Cubic Spline interpolation, adapted from the Chartist.js implementation:
|
|
|
|
// https://github.com/gionkunz/chartist-js/blob/e7e78201bffe9609915e5e53cfafa29a5d6c49f9/src/scripts/interpolation.js#L240-L369
|
|
|
|
function _monotoneCubic(xs, ys, moveTo, lineTo, bezierCurveTo, pxRound) {
|
|
|
|
var n = xs.length;
|
|
|
|
|
|
|
|
if (n < 2)
|
|
|
|
{ return null; }
|
|
|
|
|
|
|
|
var path = new Path2D();
|
|
|
|
|
|
|
|
moveTo(path, xs[0], ys[0]);
|
|
|
|
|
|
|
|
if (n == 2)
|
|
|
|
{ lineTo(path, xs[1], ys[1]); }
|
|
|
|
else {
|
|
|
|
var ms = Array(n),
|
|
|
|
ds = Array(n - 1),
|
|
|
|
dys = Array(n - 1),
|
|
|
|
dxs = Array(n - 1);
|
|
|
|
|
|
|
|
// calc deltas and derivative
|
|
|
|
for (var i = 0; i < n - 1; i++) {
|
|
|
|
dys[i] = ys[i + 1] - ys[i];
|
|
|
|
dxs[i] = xs[i + 1] - xs[i];
|
|
|
|
ds[i] = dys[i] / dxs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine desired slope (m) at each point using Fritsch-Carlson method
|
|
|
|
// http://math.stackexchange.com/questions/45218/implementation-of-monotone-cubic-interpolation
|
|
|
|
ms[0] = ds[0];
|
|
|
|
|
|
|
|
for (var i$1 = 1; i$1 < n - 1; i$1++) {
|
|
|
|
if (ds[i$1] === 0 || ds[i$1 - 1] === 0 || (ds[i$1 - 1] > 0) !== (ds[i$1] > 0))
|
|
|
|
{ ms[i$1] = 0; }
|
|
|
|
else {
|
|
|
|
ms[i$1] = 3 * (dxs[i$1 - 1] + dxs[i$1]) / (
|
|
|
|
(2 * dxs[i$1] + dxs[i$1 - 1]) / ds[i$1 - 1] +
|
|
|
|
(dxs[i$1] + 2 * dxs[i$1 - 1]) / ds[i$1]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!isFinite(ms[i$1]))
|
|
|
|
{ ms[i$1] = 0; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ms[n - 1] = ds[n - 2];
|
|
|
|
|
|
|
|
for (var i$2 = 0; i$2 < n - 1; i$2++) {
|
|
|
|
bezierCurveTo(
|
|
|
|
path,
|
|
|
|
xs[i$2] + dxs[i$2] / 3,
|
|
|
|
ys[i$2] + ms[i$2] * dxs[i$2] / 3,
|
|
|
|
xs[i$2 + 1] - dxs[i$2] / 3,
|
|
|
|
ys[i$2 + 1] - ms[i$2 + 1] * dxs[i$2] / 3,
|
|
|
|
xs[i$2 + 1],
|
|
|
|
ys[i$2 + 1]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cursorPlots = new Set();
|
|
|
|
|
|
|
|
function invalidateRects() {
|
|
|
|
cursorPlots.forEach(u => {
|
|
|
|
u.syncRect(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
on(resize, win, invalidateRects);
|
|
|
|
on(scroll, win, invalidateRects, true);
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var linearPath = linear() ;
|
2021-09-17 19:28:20 +00:00
|
|
|
var pointsPath = points() ;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
|
|
|
function setDefaults(d, xo, yo, initY) {
|
|
|
|
var d2 = initY ? [d[0], d[1]].concat(d.slice(2)) : [d[0]].concat(d.slice(1));
|
2021-01-18 13:49:52 +00:00
|
|
|
return d2.map((o, i) => setDefault(o, i, xo, yo));
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setDefault(o, i, xo, yo) {
|
2021-01-18 13:49:52 +00:00
|
|
|
return assign({}, (i == 0 ? xo : yo), o);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function snapNumX(self, dataMin, dataMax) {
|
2021-09-17 19:28:20 +00:00
|
|
|
return dataMin == null ? nullNullTuple : [dataMin, dataMax];
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var snapTimeX = snapNumX;
|
|
|
|
|
|
|
|
// this ensures that non-temporal/numeric y-axes get multiple-snapped padding added above/below
|
|
|
|
// TODO: also account for incrs when snapping to ensure top of axis gets a tick & value
|
|
|
|
function snapNumY(self, dataMin, dataMax) {
|
2021-09-17 19:28:20 +00:00
|
|
|
return dataMin == null ? nullNullTuple : rangeNum(dataMin, dataMax, rangePad, true);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function snapLogY(self, dataMin, dataMax, scale) {
|
2021-09-17 19:28:20 +00:00
|
|
|
return dataMin == null ? nullNullTuple : rangeLog(dataMin, dataMax, self.scales[scale].log, false);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var snapLogX = snapLogY;
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
function snapAsinhY(self, dataMin, dataMax, scale) {
|
2021-09-17 19:28:20 +00:00
|
|
|
return dataMin == null ? nullNullTuple : rangeAsinh(dataMin, dataMax, self.scales[scale].log, false);
|
2021-02-17 07:25:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var snapAsinhX = snapAsinhY;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
// dim is logical (getClientBoundingRect) pixels, not canvas pixels
|
|
|
|
function findIncr(min, max, incrs, dim, minSpace) {
|
|
|
|
var pxPerUnit = dim / (max - min);
|
|
|
|
|
|
|
|
var minDec = (""+floor(min)).length;
|
|
|
|
|
|
|
|
for (var i = 0; i < incrs.length; i++) {
|
|
|
|
var space = incrs[i] * pxPerUnit;
|
|
|
|
|
|
|
|
var incrDec = incrs[i] < 10 ? fixedDec.get(incrs[i]) : 0;
|
|
|
|
|
|
|
|
if (space >= minSpace && minDec + incrDec < 17)
|
|
|
|
{ return [incrs[i], space]; }
|
|
|
|
}
|
|
|
|
|
|
|
|
return [0, 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function pxRatioFont(font) {
|
2021-09-17 19:28:20 +00:00
|
|
|
var fontSize, fontSizeCss;
|
|
|
|
font = font.replace(/(\d+)px/, (m, p1) => (fontSize = round((fontSizeCss = +p1) * pxRatio)) + 'px');
|
|
|
|
return [font, fontSize, fontSizeCss];
|
|
|
|
}
|
|
|
|
|
|
|
|
function syncFontSize(axis) {
|
|
|
|
if (axis.show) {
|
|
|
|
[axis.font, axis.labelFont].forEach(f => {
|
|
|
|
var size = roundDec(f[2] * pxRatio, 1);
|
|
|
|
f[0] = f[0].replace(/[0-9.]+px/, size + 'px');
|
|
|
|
f[1] = size;
|
|
|
|
});
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uPlot(opts, data, then) {
|
|
|
|
var self = {};
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
// TODO: cache denoms & mins scale.cache = {r, min, }
|
2020-12-23 07:17:49 +00:00
|
|
|
function getValPct(val, scale) {
|
2021-02-17 07:25:25 +00:00
|
|
|
var _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
|
2020-12-23 07:17:49 +00:00
|
|
|
);
|
2021-02-17 07:25:25 +00:00
|
|
|
|
|
|
|
return (_val - scale._min) / (scale._max - scale._min);
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function getHPos(val, scale, dim, off) {
|
|
|
|
var pct = getValPct(val, scale);
|
|
|
|
return off + dim * (scale.dir == -1 ? (1 - pct) : pct);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVPos(val, scale, dim, off) {
|
|
|
|
var pct = getValPct(val, scale);
|
|
|
|
return off + dim * (scale.dir == -1 ? pct : (1 - pct));
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function getPos(val, scale, dim, off) {
|
|
|
|
return scale.ori == 0 ? getHPos(val, scale, dim, off) : getVPos(val, scale, dim, off);
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
self.valToPosH = getHPos;
|
|
|
|
self.valToPosV = getVPos;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var ready = false;
|
|
|
|
self.status = 0;
|
|
|
|
|
|
|
|
var root = self.root = placeDiv(UPLOT);
|
|
|
|
|
|
|
|
if (opts.id != null)
|
|
|
|
{ root.id = opts.id; }
|
|
|
|
|
|
|
|
addClass(root, opts.class);
|
|
|
|
|
|
|
|
if (opts.title) {
|
|
|
|
var title = placeDiv(TITLE, root);
|
|
|
|
title.textContent = opts.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
var can = placeTag("canvas");
|
|
|
|
var ctx = self.ctx = can.getContext("2d");
|
|
|
|
|
|
|
|
var wrap = placeDiv(WRAP, root);
|
2021-09-17 19:28:20 +00:00
|
|
|
var under = self.under = placeDiv(UNDER, wrap);
|
2020-11-25 07:59:41 +00:00
|
|
|
wrap.appendChild(can);
|
2021-09-17 19:28:20 +00:00
|
|
|
var over = self.over = placeDiv(OVER, wrap);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
opts = copy(opts);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var pxAlign = +ifNull(opts.pxAlign, 1);
|
|
|
|
|
|
|
|
var pxRound = pxRoundGen(pxAlign);
|
2021-02-10 07:13:13 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
(opts.plugins || []).forEach(p => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (p.opts)
|
|
|
|
{ opts = p.opts(self, opts) || opts; }
|
|
|
|
});
|
|
|
|
|
2020-11-29 02:57:24 +00:00
|
|
|
var ms = opts.ms || 1e-3;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var series = self.series = setDefaults(opts.series || [], xSeriesOpts, ySeriesOpts, false);
|
|
|
|
var axes = self.axes = setDefaults(opts.axes || [], xAxisOpts, yAxisOpts, true);
|
|
|
|
var scales = self.scales = {};
|
2021-01-18 13:49:52 +00:00
|
|
|
var bands = self.bands = opts.bands || [];
|
|
|
|
|
|
|
|
bands.forEach(b => {
|
|
|
|
b.fill = fnOrSelf(b.fill || null);
|
|
|
|
});
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var xScaleKey = series[0].scale;
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
var drawOrderMap = {
|
|
|
|
axes: drawAxesGrid,
|
|
|
|
series: drawSeries,
|
|
|
|
};
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var drawOrder = (opts.drawOrder || ["axes", "series"]).map(key => drawOrderMap[key]);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function initScale(scaleKey) {
|
|
|
|
var sc = scales[scaleKey];
|
|
|
|
|
|
|
|
if (sc == null) {
|
|
|
|
var scaleOpts = (opts.scales || EMPTY_OBJ)[scaleKey] || EMPTY_OBJ;
|
|
|
|
|
|
|
|
if (scaleOpts.from != null) {
|
|
|
|
// ensure parent is initialized
|
|
|
|
initScale(scaleOpts.from);
|
|
|
|
// dependent scales inherit
|
|
|
|
scales[scaleKey] = assign({}, scales[scaleOpts.from], scaleOpts);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sc = scales[scaleKey] = assign({}, (scaleKey == xScaleKey ? xScaleOpts : yScaleOpts), scaleOpts);
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
sc.key = scaleKey;
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var isTime = sc.time;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var rn = sc.range;
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
var rangeIsArr = isArr(rn);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (scaleKey != xScaleKey) {
|
|
|
|
// if range array has null limits, it should be auto
|
|
|
|
if (rangeIsArr && (rn[0] == null || rn[1] == null)) {
|
|
|
|
rn = {
|
|
|
|
min: rn[0] == null ? autoRangePart : {
|
|
|
|
mode: 1,
|
|
|
|
hard: rn[0],
|
|
|
|
soft: rn[0],
|
|
|
|
},
|
|
|
|
max: rn[1] == null ? autoRangePart : {
|
|
|
|
mode: 1,
|
|
|
|
hard: rn[1],
|
|
|
|
soft: rn[1],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
rangeIsArr = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rangeIsArr && isObj(rn)) {
|
|
|
|
var cfg = rn;
|
|
|
|
// this is similar to snapNumY
|
|
|
|
rn = (self, dataMin, dataMax) => dataMin == null ? nullNullTuple : rangeNum(dataMin, dataMax, cfg);
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
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)
|
|
|
|
));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
sc.auto = fnOrSelf(rangeIsArr ? false : sc.auto);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
|
|
|
sc.clamp = fnOrSelf(sc.clamp || clampScale);
|
2021-02-17 07:25:25 +00:00
|
|
|
|
|
|
|
// caches for expensive ops like asinh() & log()
|
|
|
|
sc._min = sc._max = null;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initScale("x");
|
|
|
|
initScale("y");
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
series.forEach(s => {
|
2020-11-25 07:59:41 +00:00
|
|
|
initScale(s.scale);
|
|
|
|
});
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
axes.forEach(a => {
|
|
|
|
initScale(a.scale);
|
|
|
|
});
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
for (var k in opts.scales)
|
|
|
|
{ initScale(k); }
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var scaleX = scales[xScaleKey];
|
|
|
|
|
|
|
|
var xScaleDistr = scaleX.distr;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var valToPosX, valToPosY;
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
if (scaleX.ori == 0) {
|
|
|
|
addClass(root, ORI_HZ);
|
|
|
|
valToPosX = getHPos;
|
|
|
|
valToPosY = getVPos;
|
|
|
|
/*
|
|
|
|
updOriDims = () => {
|
|
|
|
xDimCan = plotWid;
|
|
|
|
xOffCan = plotLft;
|
|
|
|
yDimCan = plotHgt;
|
|
|
|
yOffCan = plotTop;
|
|
|
|
|
|
|
|
xDimCss = plotWidCss;
|
|
|
|
xOffCss = plotLftCss;
|
|
|
|
yDimCss = plotHgtCss;
|
|
|
|
yOffCss = plotTopCss;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addClass(root, ORI_VT);
|
|
|
|
valToPosX = getVPos;
|
|
|
|
valToPosY = getHPos;
|
|
|
|
/*
|
|
|
|
updOriDims = () => {
|
|
|
|
xDimCan = plotHgt;
|
|
|
|
xOffCan = plotTop;
|
|
|
|
yDimCan = plotWid;
|
|
|
|
yOffCan = plotLft;
|
|
|
|
|
|
|
|
xDimCss = plotHgtCss;
|
|
|
|
xOffCss = plotTopCss;
|
|
|
|
yDimCss = plotWidCss;
|
|
|
|
yOffCss = plotLftCss;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var pendScales = {};
|
|
|
|
|
|
|
|
// explicitly-set initial scales
|
|
|
|
for (var k$1 in scales) {
|
|
|
|
var sc = scales[k$1];
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
if (sc.min != null || sc.max != null) {
|
|
|
|
pendScales[k$1] = {min: sc.min, max: sc.max};
|
|
|
|
sc.min = sc.max = null;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// self.tz = opts.tz || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
2021-09-17 19:28:20 +00:00
|
|
|
var _tzDate = (opts.tzDate || (ts => new Date(round(ts / ms))));
|
2021-02-17 07:25:25 +00:00
|
|
|
var _fmtDate = (opts.fmtDate || fmtDate);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var _timeAxisSplits = (ms == 1 ? timeAxisSplitsMs(_tzDate) : timeAxisSplitsS(_tzDate));
|
|
|
|
var _timeAxisVals = timeAxisVals(_tzDate, timeAxisStamps((ms == 1 ? _timeAxisStampsMs : _timeAxisStampsS), _fmtDate));
|
|
|
|
var _timeSeriesVal = timeSeriesVal(_tzDate, timeSeriesStamp(_timeSeriesStamp, _fmtDate));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var activeIdxs = [];
|
|
|
|
|
|
|
|
var legend = (self.legend = assign({}, legendOpts, opts.legend));
|
2021-02-17 07:25:25 +00:00
|
|
|
var showLegend = legend.show;
|
2021-09-17 19:28:20 +00:00
|
|
|
var markers = legend.markers;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
{
|
2021-09-17 19:28:20 +00:00
|
|
|
legend.idxs = activeIdxs;
|
|
|
|
|
|
|
|
markers.width = fnOrSelf(markers.width);
|
|
|
|
markers.dash = fnOrSelf(markers.dash);
|
|
|
|
markers.stroke = fnOrSelf(markers.stroke);
|
|
|
|
markers.fill = fnOrSelf(markers.fill);
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var legendEl;
|
|
|
|
var legendRows = [];
|
2021-09-17 19:28:20 +00:00
|
|
|
var legendCells = [];
|
2020-11-25 07:59:41 +00:00
|
|
|
var legendCols;
|
|
|
|
var multiValLegend = false;
|
2021-09-17 19:28:20 +00:00
|
|
|
var NULL_LEGEND_VALUES = {};
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (legend.live) {
|
2020-11-25 07:59:41 +00:00
|
|
|
var getMultiVals = series[1] ? series[1].values : null;
|
|
|
|
multiValLegend = getMultiVals != null;
|
2021-09-17 19:28:20 +00:00
|
|
|
legendCols = multiValLegend ? getMultiVals(self, 1, 0) : {_: 0};
|
|
|
|
|
|
|
|
for (var k$2 in legendCols)
|
|
|
|
{ NULL_LEGEND_VALUES[k$2] = "--"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showLegend) {
|
|
|
|
legendEl = placeTag("table", LEGEND, root);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (multiValLegend) {
|
|
|
|
var head = placeTag("tr", LEGEND_THEAD, legendEl);
|
|
|
|
placeTag("th", null, head);
|
|
|
|
|
|
|
|
for (var key in legendCols)
|
|
|
|
{ placeTag("th", LEGEND_LABEL, head).textContent = key; }
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addClass(legendEl, LEGEND_INLINE);
|
|
|
|
legend.live && addClass(legendEl, LEGEND_LIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var son = {show: true};
|
|
|
|
var soff = {show: false};
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function initLegendRow(s, i) {
|
|
|
|
if (i == 0 && (multiValLegend || !legend.live))
|
2021-09-17 19:28:20 +00:00
|
|
|
{ return nullNullTuple; }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var cells = [];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var row = placeTag("tr", LEGEND_SERIES, legendEl, legendEl.childNodes[i]);
|
|
|
|
|
|
|
|
addClass(row, s.class);
|
|
|
|
|
|
|
|
if (!s.show)
|
|
|
|
{ addClass(row, OFF); }
|
|
|
|
|
|
|
|
var label = placeTag("th", null, row);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (markers.show) {
|
|
|
|
var indic = placeDiv(LEGEND_MARKER, label);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (i > 0) {
|
|
|
|
var width = markers.width(self, i);
|
2021-01-18 13:49:52 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (width)
|
|
|
|
{ indic.style.border = width + "px " + markers.dash(self, i) + " " + markers.stroke(self, i); }
|
2021-01-18 13:49:52 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
indic.style.background = markers.fill(self, i);
|
|
|
|
}
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var text = placeDiv(LEGEND_LABEL, label);
|
|
|
|
text.textContent = s.label;
|
|
|
|
|
|
|
|
if (i > 0) {
|
2021-09-17 19:28:20 +00:00
|
|
|
if (!markers.show)
|
|
|
|
{ text.style.color = s.width > 0 ? markers.stroke(self, i) : markers.fill(self, i); }
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
onMouse("click", label, e => {
|
2021-02-17 07:25:25 +00:00
|
|
|
if (cursor._lock)
|
2020-11-25 07:59:41 +00:00
|
|
|
{ return; }
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var seriesIdx = series.indexOf(s);
|
|
|
|
|
|
|
|
if (e.ctrlKey != legend.isolate) {
|
|
|
|
// if any other series is shown, isolate this one. else show all
|
|
|
|
var isolate = series.some((s, i) => i > 0 && i != seriesIdx && s.show);
|
|
|
|
|
|
|
|
series.forEach((s, i) => {
|
|
|
|
i > 0 && setSeries(i, isolate ? (i == seriesIdx ? son : soff) : son, syncOpts.setSeries);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ setSeries(seriesIdx, {show: !s.show}, syncOpts.setSeries); }
|
2020-11-25 07:59:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (cursorFocus) {
|
2021-01-18 13:49:52 +00:00
|
|
|
onMouse(mouseenter, label, e => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (cursor._lock)
|
|
|
|
{ return; }
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
setSeries(series.indexOf(s), FOCUS_TRUE, syncOpts.setSeries);
|
2020-11-25 07:59:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var key in legendCols) {
|
|
|
|
var v = placeTag("td", LEGEND_VALUE, row);
|
|
|
|
v.textContent = "--";
|
2021-09-17 19:28:20 +00:00
|
|
|
cells.push(v);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
return [row, cells];
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var mouseListeners = new Map();
|
|
|
|
|
|
|
|
function onMouse(ev, targ, fn) {
|
|
|
|
var targListeners = mouseListeners.get(targ) || {};
|
|
|
|
var listener = cursor.bind[ev](self, targ, fn);
|
|
|
|
|
|
|
|
if (listener) {
|
|
|
|
on(ev, targ, targListeners[ev] = listener);
|
|
|
|
mouseListeners.set(targ, targListeners);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function offMouse(ev, targ, fn) {
|
|
|
|
var targListeners = mouseListeners.get(targ) || {};
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
for (var k in targListeners) {
|
|
|
|
if (ev == null || k == ev) {
|
|
|
|
off(k, targ, targListeners[k]);
|
|
|
|
delete targListeners[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev == null)
|
|
|
|
{ mouseListeners.delete(targ); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var fullWidCss = 0;
|
|
|
|
var fullHgtCss = 0;
|
|
|
|
|
|
|
|
var plotWidCss = 0;
|
|
|
|
var plotHgtCss = 0;
|
|
|
|
|
|
|
|
// plot margins to account for axes
|
|
|
|
var plotLftCss = 0;
|
|
|
|
var plotTopCss = 0;
|
|
|
|
|
|
|
|
var plotLft = 0;
|
|
|
|
var plotTop = 0;
|
|
|
|
var plotWid = 0;
|
|
|
|
var plotHgt = 0;
|
|
|
|
|
|
|
|
self.bbox = {};
|
|
|
|
|
|
|
|
var shouldSetScales = false;
|
|
|
|
var shouldSetSize = false;
|
|
|
|
var shouldConvergeSize = false;
|
|
|
|
var shouldSetCursor = false;
|
|
|
|
var shouldSetLegend = false;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function _setSize(width, height, force) {
|
|
|
|
if (force || (width != self.width || height != self.height))
|
2020-11-25 07:59:41 +00:00
|
|
|
{ calcSize(width, height); }
|
|
|
|
|
|
|
|
resetYSeries(false);
|
|
|
|
|
|
|
|
shouldConvergeSize = true;
|
|
|
|
shouldSetSize = true;
|
2021-09-17 19:28:20 +00:00
|
|
|
shouldSetCursor = shouldSetLegend = cursor.left >= 0;
|
2020-11-25 07:59:41 +00:00
|
|
|
commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function calcSize(width, height) {
|
|
|
|
// log("calcSize()", arguments);
|
|
|
|
|
|
|
|
self.width = fullWidCss = plotWidCss = width;
|
|
|
|
self.height = fullHgtCss = plotHgtCss = height;
|
|
|
|
plotLftCss = plotTopCss = 0;
|
|
|
|
|
|
|
|
calcPlotRect();
|
|
|
|
calcAxesRects();
|
|
|
|
|
|
|
|
var bb = self.bbox;
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
plotLft = bb.left = incrRound(plotLftCss * pxRatio, 0.5);
|
|
|
|
plotTop = bb.top = incrRound(plotTopCss * pxRatio, 0.5);
|
|
|
|
plotWid = bb.width = incrRound(plotWidCss * pxRatio, 0.5);
|
|
|
|
plotHgt = bb.height = incrRound(plotHgtCss * pxRatio, 0.5);
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
// updOriDims();
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
// ensures size calc convergence
|
|
|
|
var CYCLE_LIMIT = 3;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function convergeSize() {
|
|
|
|
var converged = false;
|
|
|
|
|
2020-11-29 02:57:24 +00:00
|
|
|
var cycleNum = 0;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
while (!converged) {
|
2020-11-29 02:57:24 +00:00
|
|
|
cycleNum++;
|
|
|
|
|
|
|
|
var axesConverged = axesCalc(cycleNum);
|
2020-12-23 07:17:49 +00:00
|
|
|
var paddingConverged = paddingCalc(cycleNum);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
converged = cycleNum == CYCLE_LIMIT || (axesConverged && paddingConverged);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (!converged) {
|
|
|
|
calcSize(self.width, self.height);
|
|
|
|
shouldSetSize = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSize(ref) {
|
|
|
|
var width = ref.width;
|
|
|
|
var height = ref.height;
|
|
|
|
|
|
|
|
_setSize(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.setSize = setSize;
|
|
|
|
|
|
|
|
// accumulate axis offsets, reduce canvas width
|
|
|
|
function calcPlotRect() {
|
|
|
|
// easements for edge labels
|
|
|
|
var hasTopAxis = false;
|
|
|
|
var hasBtmAxis = false;
|
|
|
|
var hasRgtAxis = false;
|
|
|
|
var hasLftAxis = false;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
axes.forEach((axis, i) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (axis.show && axis._show) {
|
|
|
|
var side = axis.side;
|
|
|
|
var _size = axis._size;
|
|
|
|
var isVt = side % 2;
|
|
|
|
var labelSize = axis.labelSize = (axis.label != null ? (axis.labelSize || 30) : 0);
|
|
|
|
|
|
|
|
var fullSize = _size + labelSize;
|
|
|
|
|
|
|
|
if (fullSize > 0) {
|
|
|
|
if (isVt) {
|
|
|
|
plotWidCss -= fullSize;
|
|
|
|
|
|
|
|
if (side == 3) {
|
|
|
|
plotLftCss += fullSize;
|
|
|
|
hasLftAxis = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ hasRgtAxis = true; }
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plotHgtCss -= fullSize;
|
|
|
|
|
|
|
|
if (side == 0) {
|
|
|
|
plotTopCss += fullSize;
|
|
|
|
hasTopAxis = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ hasBtmAxis = true; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
sidesWithAxes[0] = hasTopAxis;
|
|
|
|
sidesWithAxes[1] = hasRgtAxis;
|
|
|
|
sidesWithAxes[2] = hasBtmAxis;
|
|
|
|
sidesWithAxes[3] = hasLftAxis;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
// hz padding
|
|
|
|
plotWidCss -= _padding[1] + _padding[3];
|
|
|
|
plotLftCss += _padding[3];
|
|
|
|
|
|
|
|
// vt padding
|
|
|
|
plotHgtCss -= _padding[2] + _padding[0];
|
|
|
|
plotTopCss += _padding[0];
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function calcAxesRects() {
|
|
|
|
// will accum +
|
|
|
|
var off1 = plotLftCss + plotWidCss;
|
|
|
|
var off2 = plotTopCss + plotHgtCss;
|
|
|
|
// will accum -
|
|
|
|
var off3 = plotLftCss;
|
|
|
|
var off0 = plotTopCss;
|
|
|
|
|
|
|
|
function incrOffset(side, size) {
|
|
|
|
switch (side) {
|
|
|
|
case 1: off1 += size; return off1 - size;
|
|
|
|
case 2: off2 += size; return off2 - size;
|
|
|
|
case 3: off3 -= size; return off3 + size;
|
|
|
|
case 0: off0 -= size; return off0 + size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
axes.forEach((axis, i) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (axis.show && axis._show) {
|
|
|
|
var side = axis.side;
|
|
|
|
|
|
|
|
axis._pos = incrOffset(side, axis._size);
|
|
|
|
|
|
|
|
if (axis.label != null)
|
|
|
|
{ axis._lpos = incrOffset(side, axis.labelSize); }
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var cursor = (self.cursor = assign({}, cursorOpts, opts.cursor));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
{
|
2021-09-17 19:28:20 +00:00
|
|
|
cursor.idxs = activeIdxs;
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
cursor._lock = false;
|
|
|
|
|
|
|
|
var points = cursor.points;
|
|
|
|
|
|
|
|
points.show = fnOrSelf(points.show);
|
|
|
|
points.size = fnOrSelf(points.size);
|
|
|
|
points.stroke = fnOrSelf(points.stroke);
|
|
|
|
points.width = fnOrSelf(points.width);
|
|
|
|
points.fill = fnOrSelf(points.fill);
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var focus = self.focus = assign({}, opts.focus || {alpha: 0.3}, cursor.focus);
|
|
|
|
var cursorFocus = focus.prox >= 0;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// series-intersection markers
|
|
|
|
var cursorPts = [null];
|
|
|
|
|
|
|
|
function initCursorPt(s, si) {
|
|
|
|
if (si > 0) {
|
|
|
|
var pt = cursor.points.show(self, si);
|
|
|
|
|
|
|
|
if (pt) {
|
|
|
|
addClass(pt, CURSOR_PT);
|
|
|
|
addClass(pt, s.class);
|
|
|
|
trans(pt, -10, -10, plotWidCss, plotHgtCss);
|
|
|
|
over.insertBefore(pt, cursorPts[si]);
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initSeries(s, i) {
|
2021-02-17 07:25:25 +00:00
|
|
|
var isTime = scales[s.scale].time;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var sv = s.value;
|
|
|
|
s.value = isTime ? (isStr(sv) ? timeSeriesVal(_tzDate, timeSeriesStamp(sv, _fmtDate)) : sv || _timeSeriesVal) : sv || numSeriesVal;
|
|
|
|
s.label = s.label || (isTime ? timeSeriesLabel : numSeriesLabel);
|
|
|
|
|
|
|
|
if (i > 0) {
|
2020-12-23 07:17:49 +00:00
|
|
|
s.width = s.width == null ? 1 : s.width;
|
|
|
|
s.paths = s.paths || linearPath || retNull;
|
|
|
|
s.fillTo = fnOrSelf(s.fillTo || seriesFillTo);
|
2021-09-17 19:28:20 +00:00
|
|
|
s.pxAlign = +ifNull(s.pxAlign, pxAlign);
|
|
|
|
s.pxRound = pxRoundGen(s.pxAlign);
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
s.stroke = fnOrSelf(s.stroke || null);
|
2020-12-23 07:17:49 +00:00
|
|
|
s.fill = fnOrSelf(s.fill || null);
|
2021-02-10 07:13:13 +00:00
|
|
|
s._stroke = s._fill = s._paths = s._focus = null;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var _ptDia = ptDia(s.width, 1);
|
2020-12-23 07:17:49 +00:00
|
|
|
var points = s.points = assign({}, {
|
2020-11-25 07:59:41 +00:00
|
|
|
size: _ptDia,
|
|
|
|
width: max(1, _ptDia * .2),
|
|
|
|
stroke: s.stroke,
|
|
|
|
space: _ptDia * 2,
|
2021-09-17 19:28:20 +00:00
|
|
|
paths: pointsPath,
|
2020-12-23 07:17:49 +00:00
|
|
|
_stroke: null,
|
|
|
|
_fill: null,
|
2020-11-25 07:59:41 +00:00
|
|
|
}, s.points);
|
2020-12-23 07:17:49 +00:00
|
|
|
points.show = fnOrSelf(points.show);
|
2021-09-17 19:28:20 +00:00
|
|
|
points.filter = fnOrSelf(points.filter);
|
2020-12-23 07:17:49 +00:00
|
|
|
points.fill = fnOrSelf(points.fill);
|
|
|
|
points.stroke = fnOrSelf(points.stroke);
|
2021-09-17 19:28:20 +00:00
|
|
|
points.paths = fnOrSelf(points.paths);
|
|
|
|
points.pxAlign = s.pxAlign;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (showLegend) {
|
|
|
|
var rowCells = initLegendRow(s, i);
|
|
|
|
legendRows.splice(i, 0, rowCells[0]);
|
|
|
|
legendCells.splice(i, 0, rowCells[1]);
|
|
|
|
legend.values.push(null); // NULL_LEGEND_VALS not yet avil here :(
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
if (cursor.show) {
|
2021-09-17 19:28:20 +00:00
|
|
|
activeIdxs.splice(i, 0, null);
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var pt = initCursorPt(s, i);
|
|
|
|
pt && cursorPts.splice(i, 0, pt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSeries(opts, si) {
|
|
|
|
si = si == null ? series.length : si;
|
|
|
|
|
|
|
|
opts = setDefault(opts, si, xSeriesOpts, ySeriesOpts);
|
|
|
|
series.splice(si, 0, opts);
|
|
|
|
initSeries(series[si], si);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.addSeries = addSeries;
|
|
|
|
|
|
|
|
function delSeries(i) {
|
|
|
|
series.splice(i, 1);
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
if (showLegend) {
|
|
|
|
legend.values.splice(i, 1);
|
|
|
|
|
|
|
|
legendCells.splice(i, 1);
|
|
|
|
var tr = legendRows.splice(i, 1)[0];
|
|
|
|
offMouse(null, tr.firstChild);
|
|
|
|
tr.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursor.show) {
|
|
|
|
activeIdxs.splice(i, 1);
|
|
|
|
|
|
|
|
cursorPts.length > 1 && cursorPts.splice(i, 1)[0].remove();
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// TODO: de-init no-longer-needed scales?
|
|
|
|
}
|
|
|
|
|
|
|
|
self.delSeries = delSeries;
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
var sidesWithAxes = [false, false, false, false];
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function initAxis(axis, i) {
|
|
|
|
axis._show = axis.show;
|
|
|
|
|
|
|
|
if (axis.show) {
|
|
|
|
var isVt = axis.side % 2;
|
|
|
|
|
|
|
|
var sc = scales[axis.scale];
|
|
|
|
|
|
|
|
// this can occur if all series specify non-default scales
|
|
|
|
if (sc == null) {
|
|
|
|
axis.scale = isVt ? series[1].scale : xScaleKey;
|
|
|
|
sc = scales[axis.scale];
|
|
|
|
}
|
|
|
|
|
|
|
|
// also set defaults for incrs & values based on axis distr
|
2021-02-17 07:25:25 +00:00
|
|
|
var isTime = sc.time;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
axis.size = fnOrSelf(axis.size);
|
|
|
|
axis.space = fnOrSelf(axis.space);
|
|
|
|
axis.rotate = fnOrSelf(axis.rotate);
|
2020-11-29 02:57:24 +00:00
|
|
|
axis.incrs = fnOrSelf(axis.incrs || ( sc.distr == 2 ? wholeIncrs : (isTime ? (ms == 1 ? timeIncrsMs : timeIncrsS) : numIncrs)));
|
2021-02-17 07:25:25 +00:00
|
|
|
axis.splits = fnOrSelf(axis.splits || (isTime && sc.distr == 1 ? _timeAxisSplits : sc.distr == 3 ? logAxisSplits : sc.distr == 4 ? asinhAxisSplits : numAxisSplits));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
axis.stroke = fnOrSelf(axis.stroke);
|
|
|
|
axis.grid.stroke = fnOrSelf(axis.grid.stroke);
|
|
|
|
axis.ticks.stroke = fnOrSelf(axis.ticks.stroke);
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var av = axis.values;
|
2021-01-27 07:12:15 +00:00
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
axis.values = (
|
2021-09-17 19:28:20 +00:00
|
|
|
// static array of tick values
|
|
|
|
isArr(av) && !isArr(av[0]) ? fnOrSelf(av) :
|
|
|
|
// temporal
|
2020-11-25 07:59:41 +00:00
|
|
|
isTime ? (
|
2021-09-17 19:28:20 +00:00
|
|
|
// config array of fmtDate string tpls
|
2020-11-25 07:59:41 +00:00
|
|
|
isArr(av) ?
|
|
|
|
timeAxisVals(_tzDate, timeAxisStamps(av, _fmtDate)) :
|
2021-09-17 19:28:20 +00:00
|
|
|
// fmtDate string tpl
|
2020-11-25 07:59:41 +00:00
|
|
|
isStr(av) ?
|
|
|
|
timeAxisVal(_tzDate, av) :
|
|
|
|
av || _timeAxisVals
|
|
|
|
) : av || numAxisVals
|
|
|
|
);
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
axis.filter = fnOrSelf(axis.filter || ( sc.distr >= 3 ? logAxisValsFilt : retArg1));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
axis.font = pxRatioFont(axis.font);
|
|
|
|
axis.labelFont = pxRatioFont(axis.labelFont);
|
|
|
|
|
2020-11-29 02:57:24 +00:00
|
|
|
axis._size = axis.size(self, null, i, 0);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
axis._space =
|
|
|
|
axis._rotate =
|
|
|
|
axis._incrs =
|
|
|
|
axis._found = // foundIncrSpace
|
|
|
|
axis._splits =
|
|
|
|
axis._values = null;
|
2020-12-23 07:17:49 +00:00
|
|
|
|
|
|
|
if (axis._size > 0)
|
|
|
|
{ sidesWithAxes[i] = true; }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function autoPadSide(self, side, sidesWithAxes, cycleNum) {
|
|
|
|
var hasTopAxis = sidesWithAxes[0];
|
|
|
|
var hasRgtAxis = sidesWithAxes[1];
|
|
|
|
var hasBtmAxis = sidesWithAxes[2];
|
|
|
|
var hasLftAxis = sidesWithAxes[3];
|
|
|
|
|
|
|
|
var ori = side % 2;
|
|
|
|
var size = 0;
|
|
|
|
|
|
|
|
if (ori == 0 && (hasLftAxis || hasRgtAxis))
|
|
|
|
{ size = (side == 0 && !hasTopAxis || side == 2 && !hasBtmAxis ? round(xAxisOpts.size / 3) : 0); }
|
|
|
|
if (ori == 1 && (hasTopAxis || hasBtmAxis))
|
|
|
|
{ size = (side == 1 && !hasRgtAxis || side == 3 && !hasLftAxis ? round(yAxisOpts.size / 2) : 0); }
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var padding = self.padding = (opts.padding || [autoPadSide,autoPadSide,autoPadSide,autoPadSide]).map(p => fnOrSelf(ifNull(p, autoPadSide)));
|
|
|
|
var _padding = self._padding = padding.map((p, i) => p(self, i, sidesWithAxes, 0));
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var dataLen;
|
|
|
|
|
|
|
|
// rendered data window
|
|
|
|
var i0 = null;
|
|
|
|
var i1 = null;
|
|
|
|
var idxs = series[0].idxs;
|
|
|
|
|
|
|
|
var data0 = null;
|
|
|
|
|
|
|
|
var viaAutoScaleX = false;
|
|
|
|
|
|
|
|
function setData(_data, _resetScales) {
|
2021-09-17 19:28:20 +00:00
|
|
|
data = (_data || []).slice();
|
|
|
|
data[0] = data[0] || [];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
self.data = data.slice();
|
2020-11-25 07:59:41 +00:00
|
|
|
data0 = data[0];
|
|
|
|
dataLen = data0.length;
|
|
|
|
|
|
|
|
if (xScaleDistr == 2)
|
2021-01-18 13:49:52 +00:00
|
|
|
{ data[0] = data0.map((v, i) => i); }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
self._data = data;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
resetYSeries(true);
|
|
|
|
|
|
|
|
fire("setData");
|
|
|
|
|
|
|
|
if (_resetScales !== false) {
|
2021-01-18 13:49:52 +00:00
|
|
|
var xsc = scaleX;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (xsc.auto(self, viaAutoScaleX))
|
|
|
|
{ autoScaleX(); }
|
|
|
|
else
|
|
|
|
{ _setScale(xScaleKey, xsc.min, xsc.max); }
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
shouldSetCursor = cursor.left >= 0;
|
2020-11-25 07:59:41 +00:00
|
|
|
shouldSetLegend = true;
|
|
|
|
commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.setData = setData;
|
|
|
|
|
|
|
|
function autoScaleX() {
|
2021-02-17 07:25:25 +00:00
|
|
|
var assign, assign$1, assign$2;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
viaAutoScaleX = true;
|
|
|
|
|
|
|
|
var _min, _max;
|
|
|
|
|
|
|
|
if (dataLen > 0) {
|
|
|
|
i0 = idxs[0] = 0;
|
|
|
|
i1 = idxs[1] = dataLen - 1;
|
|
|
|
|
|
|
|
_min = data[0][i0];
|
|
|
|
_max = data[0][i1];
|
|
|
|
|
|
|
|
if (xScaleDistr == 2) {
|
|
|
|
_min = i0;
|
|
|
|
_max = i1;
|
|
|
|
}
|
|
|
|
else if (dataLen == 1) {
|
|
|
|
if (xScaleDistr == 3)
|
2021-01-18 13:49:52 +00:00
|
|
|
{ (assign = rangeLog(_min, _min, scaleX.log, false), _min = assign[0], _max = assign[1]); }
|
2021-02-17 07:25:25 +00:00
|
|
|
else if (xScaleDistr == 4)
|
|
|
|
{ (assign$1 = rangeAsinh(_min, _min, scaleX.log, false), _min = assign$1[0], _max = assign$1[1]); }
|
2021-01-18 13:49:52 +00:00
|
|
|
else if (scaleX.time)
|
2021-09-17 19:28:20 +00:00
|
|
|
{ _max = _min + round(86400 / ms); }
|
2020-11-25 07:59:41 +00:00
|
|
|
else
|
2021-09-17 19:28:20 +00:00
|
|
|
{ (assign$2 = rangeNum(_min, _max, rangePad, true), _min = assign$2[0], _max = assign$2[1]); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
i0 = idxs[0] = _min = null;
|
|
|
|
i1 = idxs[1] = _max = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
_setScale(xScaleKey, _min, _max);
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function setCtxStyle(stroke, width, dash, cap, fill) {
|
2020-11-25 07:59:41 +00:00
|
|
|
ctx.strokeStyle = stroke || transparent;
|
|
|
|
ctx.lineWidth = width;
|
|
|
|
ctx.lineJoin = "round";
|
2021-01-18 13:49:52 +00:00
|
|
|
ctx.lineCap = cap || "butt"; // (‿|‿)
|
2020-11-25 07:59:41 +00:00
|
|
|
ctx.setLineDash(dash || []);
|
|
|
|
ctx.fillStyle = fill || transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setScales() {
|
|
|
|
// log("setScales()", arguments);
|
|
|
|
|
|
|
|
// wip scales
|
2021-03-20 20:39:14 +00:00
|
|
|
var wipScales = copy(scales, fastIsObj);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
for (var k in wipScales) {
|
|
|
|
var wsc = wipScales[k];
|
|
|
|
var psc = pendScales[k];
|
|
|
|
|
|
|
|
if (psc != null && psc.min != null) {
|
|
|
|
assign(wsc, psc);
|
|
|
|
|
|
|
|
// explicitly setting the x-scale invalidates everything (acts as redraw)
|
|
|
|
if (k == xScaleKey)
|
|
|
|
{ resetYSeries(true); }
|
|
|
|
}
|
|
|
|
else if (k != xScaleKey) {
|
|
|
|
if (dataLen == 0 && wsc.from == null) {
|
|
|
|
var minMax = wsc.range(self, null, null, k);
|
|
|
|
wsc.min = minMax[0];
|
|
|
|
wsc.max = minMax[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wsc.min = inf;
|
|
|
|
wsc.max = -inf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataLen > 0) {
|
|
|
|
// pre-range y-scales from y series' data values
|
2021-01-18 13:49:52 +00:00
|
|
|
series.forEach((s, i) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
var k = s.scale;
|
|
|
|
var wsc = wipScales[k];
|
|
|
|
var psc = pendScales[k];
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
var minMax = wsc.range(self, wsc.min, wsc.max, k);
|
|
|
|
|
|
|
|
wsc.min = minMax[0];
|
|
|
|
wsc.max = minMax[1];
|
|
|
|
|
|
|
|
i0 = closestIdx(wsc.min, data[0]);
|
|
|
|
i1 = closestIdx(wsc.max, data[0]);
|
|
|
|
|
|
|
|
// closest indices can be outside of view
|
|
|
|
if (data[0][i0] < wsc.min)
|
|
|
|
{ i0++; }
|
|
|
|
if (data[0][i1] > wsc.max)
|
|
|
|
{ i1--; }
|
|
|
|
|
|
|
|
s.min = data0[i0];
|
|
|
|
s.max = data0[i1];
|
|
|
|
}
|
|
|
|
else if (s.show && s.auto && wsc.auto(self, viaAutoScaleX) && (psc == null || psc.min == null)) {
|
|
|
|
// only run getMinMax() for invalidated series data, else reuse
|
2020-12-23 07:17:49 +00:00
|
|
|
var minMax$1 = s.min == null ? (wsc.distr == 3 ? getMinMaxLog(data[i], i0, i1) : getMinMax(data[i], i0, i1, s.sorted)) : [s.min, s.max];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// initial min/max
|
|
|
|
wsc.min = min(wsc.min, s.min = minMax$1[0]);
|
|
|
|
wsc.max = max(wsc.max, s.max = minMax$1[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
s.idxs[0] = i0;
|
|
|
|
s.idxs[1] = i1;
|
|
|
|
});
|
|
|
|
|
|
|
|
// range independent scales
|
|
|
|
for (var k$1 in wipScales) {
|
|
|
|
var wsc$1 = wipScales[k$1];
|
|
|
|
var psc$1 = pendScales[k$1];
|
|
|
|
|
|
|
|
if (wsc$1.from == null && (psc$1 == null || psc$1.min == null)) {
|
|
|
|
var minMax$1 = wsc$1.range(
|
|
|
|
self,
|
|
|
|
wsc$1.min == inf ? null : wsc$1.min,
|
|
|
|
wsc$1.max == -inf ? null : wsc$1.max,
|
|
|
|
k$1
|
|
|
|
);
|
|
|
|
wsc$1.min = minMax$1[0];
|
|
|
|
wsc$1.max = minMax$1[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// range dependent scales
|
|
|
|
for (var k$2 in wipScales) {
|
|
|
|
var wsc$2 = wipScales[k$2];
|
|
|
|
|
|
|
|
if (wsc$2.from != null) {
|
|
|
|
var base = wipScales[wsc$2.from];
|
|
|
|
var minMax$2 = wsc$2.range(self, base.min, base.max, k$2);
|
|
|
|
wsc$2.min = minMax$2[0];
|
|
|
|
wsc$2.max = minMax$2[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var changed = {};
|
|
|
|
var anyChanged = false;
|
|
|
|
|
|
|
|
for (var k$3 in wipScales) {
|
|
|
|
var wsc$3 = wipScales[k$3];
|
|
|
|
var sc = scales[k$3];
|
|
|
|
|
|
|
|
if (sc.min != wsc$3.min || sc.max != wsc$3.max) {
|
|
|
|
sc.min = wsc$3.min;
|
|
|
|
sc.max = wsc$3.max;
|
2021-02-17 07:25:25 +00:00
|
|
|
|
|
|
|
var 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;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
changed[k$3] = anyChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anyChanged) {
|
|
|
|
// invalidate paths of all series on changed scales
|
2021-01-18 13:49:52 +00:00
|
|
|
series.forEach(s => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (changed[s.scale])
|
|
|
|
{ s._paths = null; }
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var k$4 in changed) {
|
|
|
|
shouldConvergeSize = true;
|
|
|
|
fire("setScale", k$4);
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
if (cursor.show)
|
2021-09-17 19:28:20 +00:00
|
|
|
{ shouldSetCursor = shouldSetLegend = cursor.left >= 0; }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var k$5 in pendScales)
|
|
|
|
{ pendScales[k$5] = null; }
|
|
|
|
}
|
|
|
|
|
|
|
|
// grabs the nearest indices with y data outside of x-scale limits
|
|
|
|
function getOuterIdxs(ydata) {
|
|
|
|
var _i0 = clamp(i0 - 1, 0, dataLen - 1);
|
|
|
|
var _i1 = clamp(i1 + 1, 0, dataLen - 1);
|
|
|
|
|
|
|
|
while (ydata[_i0] == null && _i0 > 0)
|
|
|
|
{ _i0--; }
|
|
|
|
|
|
|
|
while (ydata[_i1] == null && _i1 < dataLen - 1)
|
|
|
|
{ _i1++; }
|
|
|
|
|
|
|
|
return [_i0, _i1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawSeries() {
|
2020-12-23 07:17:49 +00:00
|
|
|
if (dataLen > 0) {
|
2021-01-18 13:49:52 +00:00
|
|
|
series.forEach((s, i) => {
|
2020-12-23 07:17:49 +00:00
|
|
|
if (i > 0 && s.show && s._paths == null) {
|
|
|
|
var _idxs = getOuterIdxs(data[i]);
|
|
|
|
s._paths = s.paths(self, i, _idxs[0], _idxs[1]);
|
|
|
|
}
|
|
|
|
});
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
series.forEach((s, i) => {
|
2020-12-23 07:17:49 +00:00
|
|
|
if (i > 0 && s.show) {
|
2021-09-17 19:28:20 +00:00
|
|
|
{
|
|
|
|
cacheStrokeFill(i, false);
|
|
|
|
s._paths && drawPath(i, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
cacheStrokeFill(i, true);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var show = s.points.show(self, i, i0, i1);
|
|
|
|
var idxs = s.points.filter(self, i, show, s._paths ? s._paths.gaps : null);
|
|
|
|
|
|
|
|
if (show || idxs) {
|
|
|
|
s.points._paths = s.points.paths(self, i, i0, i1, idxs);
|
|
|
|
drawPath(i, true);
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
fire("drawSeries", i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function cacheStrokeFill(si, _points) {
|
|
|
|
var s = _points ? series[si].points : series[si];
|
|
|
|
|
|
|
|
s._stroke = s.stroke(self, si);
|
|
|
|
s._fill = s.fill(self, si);
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawPath(si, _points) {
|
|
|
|
var s = _points ? series[si].points : series[si];
|
|
|
|
|
|
|
|
var strokeStyle = s._stroke;
|
|
|
|
var fillStyle = s._fill;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var ref = s._paths;
|
|
|
|
var stroke = ref.stroke;
|
|
|
|
var fill = ref.fill;
|
|
|
|
var clip = ref.clip;
|
2021-09-17 19:28:20 +00:00
|
|
|
var flags = ref.flags;
|
2021-01-18 13:49:52 +00:00
|
|
|
var width = roundDec(s.width * pxRatio, 3);
|
|
|
|
var offset = (width % 2) / 2;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (_points && fillStyle == null)
|
|
|
|
{ fillStyle = width > 0 ? "#fff" : strokeStyle; }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
ctx.globalAlpha = s.alpha;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var _pxAlign = s.pxAlign == 1;
|
2021-02-10 07:13:13 +00:00
|
|
|
|
|
|
|
_pxAlign && ctx.translate(offset, offset);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
ctx.save();
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (!_points) {
|
|
|
|
var lft = plotLft,
|
|
|
|
top = plotTop,
|
|
|
|
wid = plotWid,
|
|
|
|
hgt = plotHgt;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var halfWid = width * pxRatio / 2;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (s.min == 0)
|
|
|
|
{ hgt += halfWid; }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (s.max == 0) {
|
|
|
|
top -= halfWid;
|
|
|
|
hgt += halfWid;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.rect(lft, top, wid, hgt);
|
|
|
|
ctx.clip();
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-27 07:12:15 +00:00
|
|
|
clip && ctx.clip(clip);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (_points)
|
|
|
|
{ strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, null, flags); }
|
|
|
|
else
|
|
|
|
{ fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags); }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
ctx.restore();
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
_pxAlign && ctx.translate(-offset, -offset);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
ctx.globalAlpha = 1;
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags) {
|
2021-02-10 07:13:13 +00:00
|
|
|
var didStrokeFill = false;
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
// for all bands where this series is the top edge, create upwards clips using the bottom edges
|
|
|
|
// and apply clips + fill with band fill or dfltFill
|
|
|
|
bands.forEach((b, bi) => {
|
2021-02-10 07:13:13 +00:00
|
|
|
// isUpperEdge?
|
2021-01-18 13:49:52 +00:00
|
|
|
if (b.series[0] == si) {
|
|
|
|
var lowerEdge = series[b.series[1]];
|
|
|
|
|
|
|
|
var clip = (lowerEdge._paths || EMPTY_OBJ).band;
|
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
ctx.save();
|
|
|
|
|
|
|
|
var _fillStyle = null;
|
|
|
|
|
|
|
|
// hasLowerEdge?
|
2021-09-17 19:28:20 +00:00
|
|
|
if (lowerEdge.show && clip)
|
|
|
|
{ _fillStyle = b.fill(self, bi) || fillStyle; }
|
|
|
|
else
|
|
|
|
{ clip = null; }
|
2021-02-10 07:13:13 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, clip, flags);
|
2021-02-10 07:13:13 +00:00
|
|
|
|
|
|
|
ctx.restore();
|
|
|
|
|
|
|
|
didStrokeFill = true;
|
2021-01-18 13:49:52 +00:00
|
|
|
}
|
|
|
|
});
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
if (!didStrokeFill)
|
2021-09-17 19:28:20 +00:00
|
|
|
{ strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, null, flags); }
|
2021-02-10 07:13:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var CLIP_FILL_STROKE = BAND_CLIP_FILL | BAND_CLIP_STROKE;
|
|
|
|
|
|
|
|
function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, clip, flags) {
|
2021-02-10 07:13:13 +00:00
|
|
|
setCtxStyle(strokeStyle, lineWidth, lineDash, lineCap, fillStyle);
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
if (clip) {
|
|
|
|
if ((flags & CLIP_FILL_STROKE) == CLIP_FILL_STROKE) {
|
|
|
|
ctx.clip(clip);
|
|
|
|
doFill(fillStyle, fillPath);
|
|
|
|
doStroke(strokeStyle, strokePath, lineWidth);
|
|
|
|
}
|
|
|
|
else if (flags & BAND_CLIP_STROKE) {
|
|
|
|
doFill(fillStyle, fillPath);
|
|
|
|
ctx.clip(clip);
|
|
|
|
doStroke(strokeStyle, strokePath, lineWidth);
|
|
|
|
}
|
|
|
|
else if (flags & BAND_CLIP_FILL) {
|
|
|
|
ctx.save();
|
|
|
|
ctx.clip(clip);
|
|
|
|
doFill(fillStyle, fillPath);
|
|
|
|
ctx.restore();
|
|
|
|
doStroke(strokeStyle, strokePath, lineWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
doFill(fillStyle, fillPath);
|
|
|
|
doStroke(strokeStyle, strokePath, lineWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function doStroke(strokeStyle, strokePath, lineWidth) {
|
2021-02-10 07:13:13 +00:00
|
|
|
strokeStyle && strokePath && lineWidth && ctx.stroke(strokePath);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function doFill(fillStyle, fillPath) {
|
|
|
|
fillStyle && fillPath && ctx.fill(fillPath);
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
function getIncrSpace(axisIdx, min, max, fullDim) {
|
|
|
|
var axis = axes[axisIdx];
|
|
|
|
|
|
|
|
var incrSpace;
|
|
|
|
|
|
|
|
if (fullDim <= 0)
|
|
|
|
{ incrSpace = [0, 0]; }
|
|
|
|
else {
|
|
|
|
var minSpace = axis._space = axis.space(self, axisIdx, min, max, fullDim);
|
|
|
|
var incrs = axis._incrs = axis.incrs(self, axisIdx, min, max, fullDim, minSpace);
|
|
|
|
incrSpace = axis._found = findIncr(min, max, incrs, fullDim, minSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
return incrSpace;
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function drawOrthoLines(offs, filts, ori, side, pos0, len, width, stroke, dash, cap) {
|
2020-11-25 07:59:41 +00:00
|
|
|
var offset = (width % 2) / 2;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
pxAlign == 1 && ctx.translate(offset, offset);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
setCtxStyle(stroke, width, dash, cap);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
|
|
|
|
var x0, y0, x1, y1, pos1 = pos0 + (side == 0 || side == 3 ? -len : len);
|
|
|
|
|
|
|
|
if (ori == 0) {
|
|
|
|
y0 = pos0;
|
|
|
|
y1 = pos1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x0 = pos0;
|
|
|
|
x1 = pos1;
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
offs.forEach((off, i) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (filts[i] == null)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
if (ori == 0)
|
|
|
|
{ x0 = x1 = off; }
|
|
|
|
else
|
|
|
|
{ y0 = y1 = off; }
|
|
|
|
|
|
|
|
ctx.moveTo(x0, y0);
|
|
|
|
ctx.lineTo(x1, y1);
|
|
|
|
});
|
|
|
|
|
|
|
|
ctx.stroke();
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
pxAlign == 1 && ctx.translate(-offset, -offset);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 02:57:24 +00:00
|
|
|
function axesCalc(cycleNum) {
|
2020-11-25 07:59:41 +00:00
|
|
|
// log("axesCalc()", arguments);
|
|
|
|
|
|
|
|
var converged = true;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
axes.forEach((axis, i) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (!axis.show)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
var scale = scales[axis.scale];
|
|
|
|
|
|
|
|
if (scale.min == null) {
|
|
|
|
if (axis._show) {
|
|
|
|
converged = false;
|
|
|
|
axis._show = false;
|
|
|
|
resetYSeries(false);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!axis._show) {
|
|
|
|
converged = false;
|
|
|
|
axis._show = true;
|
|
|
|
resetYSeries(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var side = axis.side;
|
|
|
|
var ori = side % 2;
|
|
|
|
|
|
|
|
var min = scale.min;
|
|
|
|
var max = scale.max; // // should this toggle them ._show = false
|
|
|
|
|
|
|
|
var ref = getIncrSpace(i, min, max, ori == 0 ? plotWidCss : plotHgtCss);
|
|
|
|
var _incr = ref[0];
|
|
|
|
var _space = ref[1];
|
|
|
|
|
|
|
|
if (_space == 0)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
// if we're using index positions, force first tick to match passed index
|
|
|
|
var forceMin = scale.distr == 2;
|
|
|
|
|
|
|
|
var _splits = axis._splits = axis.splits(self, i, min, max, _incr, _space, forceMin);
|
|
|
|
|
|
|
|
// tick labels
|
|
|
|
// BOO this assumes a specific data/series
|
2021-01-18 13:49:52 +00:00
|
|
|
var splits = scale.distr == 2 ? _splits.map(i => data0[i]) : _splits;
|
2020-11-25 07:59:41 +00:00
|
|
|
var incr = scale.distr == 2 ? data0[_splits[1]] - data0[_splits[0]] : _incr;
|
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
var values = axis._values = axis.values(self, axis.filter(self, splits, i, _space, incr), i, _space, incr);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// rotating of labels only supported on bottom x axis
|
|
|
|
axis._rotate = side == 2 ? axis.rotate(self, values, i, _space) : 0;
|
|
|
|
|
|
|
|
var oldSize = axis._size;
|
|
|
|
|
2020-11-29 02:57:24 +00:00
|
|
|
axis._size = ceil(axis.size(self, values, i, cycleNum));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (oldSize != null && axis._size != oldSize) // ready && ?
|
|
|
|
{ converged = false; }
|
|
|
|
});
|
|
|
|
|
|
|
|
return converged;
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
function paddingCalc(cycleNum) {
|
2020-11-25 07:59:41 +00:00
|
|
|
var converged = true;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
padding.forEach((p, i) => {
|
2020-12-23 07:17:49 +00:00
|
|
|
var _p = p(self, i, sidesWithAxes, cycleNum);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
if (_p != _padding[i])
|
|
|
|
{ converged = false; }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
_padding[i] = _p;
|
|
|
|
});
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
return converged;
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawAxesGrid() {
|
2021-01-18 13:49:52 +00:00
|
|
|
axes.forEach((axis, i) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (!axis.show || !axis._show)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
var side = axis.side;
|
|
|
|
var ori = side % 2;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var x, y;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var fillStyle = axis.stroke(self, i);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var shiftDir = side == 0 || side == 3 ? -1 : 1;
|
|
|
|
|
|
|
|
// axis label
|
|
|
|
if (axis.label) {
|
|
|
|
var shiftAmt$1 = axis.labelGap * shiftDir;
|
|
|
|
var baseLpos = round((axis._lpos + shiftAmt$1) * pxRatio);
|
|
|
|
|
|
|
|
ctx.save();
|
|
|
|
|
|
|
|
if (ori == 1) {
|
|
|
|
x = y = 0;
|
|
|
|
|
|
|
|
ctx.translate(
|
|
|
|
baseLpos,
|
|
|
|
round(plotTop + plotHgt / 2)
|
|
|
|
);
|
|
|
|
ctx.rotate((side == 3 ? -PI : PI) / 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x = round(plotLft + plotWid / 2);
|
|
|
|
y = baseLpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.font = axis.labelFont[0];
|
|
|
|
ctx.fillStyle = fillStyle;
|
|
|
|
ctx.textAlign = "center";
|
|
|
|
ctx.textBaseline = side == 2 ? TOP : BOTTOM;
|
|
|
|
|
|
|
|
ctx.fillText(axis.label, x, y);
|
|
|
|
|
|
|
|
ctx.restore();
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
var ref = axis._found;
|
|
|
|
var _incr = ref[0];
|
|
|
|
var _space = ref[1];
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
if (_space == 0)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
var scale = scales[axis.scale];
|
|
|
|
|
|
|
|
var plotDim = ori == 0 ? plotWid : plotHgt;
|
|
|
|
var plotOff = ori == 0 ? plotLft : plotTop;
|
|
|
|
|
|
|
|
var axisGap = round(axis.gap * pxRatio);
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var _splits = axis._splits;
|
|
|
|
|
|
|
|
// tick labels
|
|
|
|
// BOO this assumes a specific data/series
|
2021-01-18 13:49:52 +00:00
|
|
|
var splits = scale.distr == 2 ? _splits.map(i => data0[i]) : _splits;
|
2020-11-25 07:59:41 +00:00
|
|
|
var incr = scale.distr == 2 ? data0[_splits[1]] - data0[_splits[0]] : _incr;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var ticks = axis.ticks;
|
|
|
|
var tickSize = ticks.show ? round(ticks.size * pxRatio) : 0;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
// rotating of labels only supported on bottom x axis
|
|
|
|
var angle = axis._rotate * -PI/180;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var basePos = pxRound(axis._pos * pxRatio);
|
|
|
|
var shiftAmt = (tickSize + axisGap) * shiftDir;
|
|
|
|
var finalPos = basePos + shiftAmt;
|
|
|
|
y = ori == 0 ? finalPos : 0;
|
|
|
|
x = ori == 1 ? finalPos : 0;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
ctx.font = axis.font[0];
|
2021-09-17 19:28:20 +00:00
|
|
|
ctx.fillStyle = fillStyle;
|
2020-11-25 07:59:41 +00:00
|
|
|
ctx.textAlign = axis.align == 1 ? LEFT :
|
|
|
|
axis.align == 2 ? RIGHT :
|
|
|
|
angle > 0 ? LEFT :
|
|
|
|
angle < 0 ? RIGHT :
|
|
|
|
ori == 0 ? "center" : side == 3 ? RIGHT : LEFT;
|
|
|
|
ctx.textBaseline = angle ||
|
|
|
|
ori == 1 ? "middle" : side == 2 ? TOP : BOTTOM;
|
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
var lineHeight = axis.font[1] * lineMult;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var canOffs = _splits.map(val => pxRound(getPos(val, scale, plotDim, plotOff)));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
axis._values.forEach((val, i) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (val == null)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
if (ori == 0)
|
|
|
|
{ x = canOffs[i]; }
|
|
|
|
else
|
|
|
|
{ y = canOffs[i]; }
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
(""+val).split(/\n/gm).forEach((text, j) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (angle) {
|
|
|
|
ctx.save();
|
|
|
|
ctx.translate(x, y + j * lineHeight);
|
|
|
|
ctx.rotate(angle);
|
|
|
|
ctx.fillText(text, 0, 0);
|
|
|
|
ctx.restore();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ ctx.fillText(text, x, y + j * lineHeight); }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ticks
|
|
|
|
if (ticks.show) {
|
|
|
|
drawOrthoLines(
|
|
|
|
canOffs,
|
|
|
|
ticks.filter(self, splits, i, _space, incr),
|
|
|
|
ori,
|
|
|
|
side,
|
|
|
|
basePos,
|
|
|
|
tickSize,
|
2020-12-23 07:17:49 +00:00
|
|
|
roundDec(ticks.width * pxRatio, 3),
|
2021-01-27 07:12:15 +00:00
|
|
|
ticks.stroke(self, i),
|
2021-01-18 13:49:52 +00:00
|
|
|
ticks.dash,
|
|
|
|
ticks.cap
|
2020-11-25 07:59:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// grid
|
|
|
|
var grid = axis.grid;
|
|
|
|
|
|
|
|
if (grid.show) {
|
|
|
|
drawOrthoLines(
|
|
|
|
canOffs,
|
|
|
|
grid.filter(self, splits, i, _space, incr),
|
|
|
|
ori,
|
|
|
|
ori == 0 ? 2 : 1,
|
|
|
|
ori == 0 ? plotTop : plotLft,
|
|
|
|
ori == 0 ? plotHgt : plotWid,
|
2020-12-23 07:17:49 +00:00
|
|
|
roundDec(grid.width * pxRatio, 3),
|
2021-01-27 07:12:15 +00:00
|
|
|
grid.stroke(self, i),
|
2021-01-18 13:49:52 +00:00
|
|
|
grid.dash,
|
|
|
|
grid.cap
|
2020-11-25 07:59:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
fire("drawAxes");
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetYSeries(minMax) {
|
|
|
|
// log("resetYSeries()", arguments);
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
series.forEach((s, i) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (i > 0) {
|
|
|
|
s._paths = null;
|
|
|
|
|
|
|
|
if (minMax) {
|
|
|
|
s.min = null;
|
|
|
|
s.max = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var queuedCommit = false;
|
|
|
|
|
|
|
|
function commit() {
|
|
|
|
if (!queuedCommit) {
|
|
|
|
microTask(_commit);
|
|
|
|
queuedCommit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _commit() {
|
|
|
|
// log("_commit()", arguments);
|
|
|
|
|
|
|
|
if (shouldSetScales) {
|
|
|
|
setScales();
|
|
|
|
shouldSetScales = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldConvergeSize) {
|
|
|
|
convergeSize();
|
|
|
|
shouldConvergeSize = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldSetSize) {
|
|
|
|
setStylePx(under, LEFT, plotLftCss);
|
|
|
|
setStylePx(under, TOP, plotTopCss);
|
|
|
|
setStylePx(under, WIDTH, plotWidCss);
|
|
|
|
setStylePx(under, HEIGHT, plotHgtCss);
|
|
|
|
|
|
|
|
setStylePx(over, LEFT, plotLftCss);
|
|
|
|
setStylePx(over, TOP, plotTopCss);
|
|
|
|
setStylePx(over, WIDTH, plotWidCss);
|
|
|
|
setStylePx(over, HEIGHT, plotHgtCss);
|
|
|
|
|
|
|
|
setStylePx(wrap, WIDTH, fullWidCss);
|
|
|
|
setStylePx(wrap, HEIGHT, fullHgtCss);
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
can.width = round(fullWidCss * pxRatio);
|
|
|
|
can.height = round(fullHgtCss * pxRatio);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
syncRect(false);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
fire("setSize");
|
|
|
|
|
|
|
|
shouldSetSize = false;
|
|
|
|
}
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
if (fullWidCss > 0 && fullHgtCss > 0) {
|
|
|
|
ctx.clearRect(0, 0, can.width, can.height);
|
|
|
|
fire("drawClear");
|
|
|
|
drawOrder.forEach(fn => fn());
|
|
|
|
fire("draw");
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
// if (shouldSetSelect) {
|
|
|
|
// TODO: update .u-select metrics (if visible)
|
2020-12-23 07:17:49 +00:00
|
|
|
// setStylePx(selectDiv, TOP, select.top = 0);
|
|
|
|
// setStylePx(selectDiv, LEFT, select.left = 0);
|
|
|
|
// setStylePx(selectDiv, WIDTH, select.width = 0);
|
|
|
|
// setStylePx(selectDiv, HEIGHT, select.height = 0);
|
2020-11-25 07:59:41 +00:00
|
|
|
// shouldSetSelect = false;
|
|
|
|
// }
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
if (cursor.show && shouldSetCursor) {
|
2020-11-25 07:59:41 +00:00
|
|
|
updateCursor();
|
|
|
|
shouldSetCursor = false;
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
// if (FEAT_LEGEND && legend.show && legend.live && shouldSetLegend) {}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (!ready) {
|
|
|
|
ready = true;
|
|
|
|
self.status = 1;
|
|
|
|
|
|
|
|
fire("ready");
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
viaAutoScaleX = false;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
queuedCommit = false;
|
|
|
|
}
|
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
self.redraw = (rebuildPaths, recalcAxes) => {
|
|
|
|
shouldConvergeSize = recalcAxes || false;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
if (rebuildPaths !== false)
|
2021-01-18 13:49:52 +00:00
|
|
|
{ _setScale(xScaleKey, scaleX.min, scaleX.max); }
|
2020-11-25 07:59:41 +00:00
|
|
|
else
|
|
|
|
{ commit(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
// redraw() => setScale('x', scales.x.min, scales.x.max);
|
|
|
|
|
|
|
|
// explicit, never re-ranged (is this actually true? for x and y)
|
|
|
|
function setScale(key, opts) {
|
|
|
|
var sc = scales[key];
|
|
|
|
|
|
|
|
if (sc.from == null) {
|
|
|
|
if (dataLen == 0) {
|
|
|
|
var minMax = sc.range(self, opts.min, opts.max, key);
|
|
|
|
opts.min = minMax[0];
|
|
|
|
opts.max = minMax[1];
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (opts.min > opts.max) {
|
|
|
|
var _min = opts.min;
|
|
|
|
opts.min = opts.max;
|
|
|
|
opts.max = _min;
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
if (dataLen > 1 && opts.min != null && opts.max != null && opts.max - opts.min < 1e-16)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
if (key == xScaleKey) {
|
|
|
|
if (sc.distr == 2 && dataLen > 0) {
|
|
|
|
opts.min = closestIdx(opts.min, data[0]);
|
|
|
|
opts.max = closestIdx(opts.max, data[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// log("setScale()", arguments);
|
|
|
|
|
|
|
|
pendScales[key] = opts;
|
|
|
|
|
|
|
|
shouldSetScales = true;
|
|
|
|
commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.setScale = setScale;
|
|
|
|
|
|
|
|
// INTERACTION
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var xCursor;
|
|
|
|
var yCursor;
|
|
|
|
var vCursor;
|
|
|
|
var hCursor;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// starting position before cursor.move
|
|
|
|
var rawMouseLeft0;
|
|
|
|
var rawMouseTop0;
|
|
|
|
|
|
|
|
// starting position
|
|
|
|
var mouseLeft0;
|
|
|
|
var mouseTop0;
|
|
|
|
|
|
|
|
// current position before cursor.move
|
|
|
|
var rawMouseLeft1;
|
|
|
|
var rawMouseTop1;
|
|
|
|
|
|
|
|
// current position
|
|
|
|
var mouseLeft1;
|
|
|
|
var mouseTop1;
|
|
|
|
|
|
|
|
var dragging = false;
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var drag = cursor.drag;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var dragX = drag.x;
|
|
|
|
var dragY = drag.y;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
if (cursor.show) {
|
2021-01-18 13:49:52 +00:00
|
|
|
if (cursor.x)
|
|
|
|
{ xCursor = placeDiv(CURSOR_X, over); }
|
|
|
|
if (cursor.y)
|
|
|
|
{ yCursor = placeDiv(CURSOR_Y, over); }
|
|
|
|
|
|
|
|
if (scaleX.ori == 0) {
|
|
|
|
vCursor = xCursor;
|
|
|
|
hCursor = yCursor;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
else {
|
|
|
|
vCursor = yCursor;
|
|
|
|
hCursor = xCursor;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
|
|
|
|
mouseLeft1 = cursor.left;
|
|
|
|
mouseTop1 = cursor.top;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var select = self.select = assign({
|
|
|
|
show: true,
|
|
|
|
over: true,
|
2021-02-10 07:13:13 +00:00
|
|
|
left: 0,
|
|
|
|
width: 0,
|
|
|
|
top: 0,
|
|
|
|
height: 0,
|
2020-11-25 07:59:41 +00:00
|
|
|
}, opts.select);
|
|
|
|
|
|
|
|
var selectDiv = select.show ? placeDiv(SELECT, select.over ? over : under) : null;
|
|
|
|
|
|
|
|
function setSelect(opts, _fire) {
|
|
|
|
if (select.show) {
|
|
|
|
for (var prop in opts)
|
|
|
|
{ setStylePx(selectDiv, prop, select[prop] = opts[prop]); }
|
|
|
|
|
|
|
|
_fire !== false && fire("setSelect");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.setSelect = setSelect;
|
|
|
|
|
|
|
|
function toggleDOM(i, onOff) {
|
|
|
|
var s = series[i];
|
2021-09-17 19:28:20 +00:00
|
|
|
var label = showLegend ? legendRows[i] : null;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (s.show)
|
|
|
|
{ label && remClass(label, OFF); }
|
|
|
|
else {
|
|
|
|
label && addClass(label, OFF);
|
2021-02-17 07:25:25 +00:00
|
|
|
cursorPts.length > 1 && trans(cursorPts[i], -10, -10, plotWidCss, plotHgtCss);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _setScale(key, min, max) {
|
|
|
|
setScale(key, {min: min, max: max});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSeries(i, opts, pub) {
|
|
|
|
// log("setSeries()", arguments);
|
|
|
|
|
|
|
|
var s = series[i];
|
|
|
|
|
|
|
|
if (opts.focus != null)
|
|
|
|
{ setFocus(i); }
|
|
|
|
|
|
|
|
if (opts.show != null) {
|
|
|
|
s.show = opts.show;
|
2021-02-17 07:25:25 +00:00
|
|
|
toggleDOM(i, opts.show);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
_setScale(s.scale, null, null);
|
|
|
|
commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
fire("setSeries", i, opts);
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
pub && pubSync("setSeries", self, i, opts);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.setSeries = setSeries;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function setBand(bi, opts) {
|
|
|
|
assign(bands[bi], opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addBand(opts, bi) {
|
|
|
|
opts.fill = fnOrSelf(opts.fill || null);
|
|
|
|
bi = bi == null ? bands.length : bi;
|
|
|
|
bands.splice(bi, 0, opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
function delBand(bi) {
|
|
|
|
if (bi == null)
|
|
|
|
{ bands.length = 0; }
|
|
|
|
else
|
|
|
|
{ bands.splice(bi, 1); }
|
|
|
|
}
|
|
|
|
|
|
|
|
self.addBand = addBand;
|
|
|
|
self.setBand = setBand;
|
|
|
|
self.delBand = delBand;
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
function setAlpha(i, value) {
|
2020-11-25 07:59:41 +00:00
|
|
|
series[i].alpha = value;
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
if (cursor.show && cursorPts[i])
|
2020-11-25 07:59:41 +00:00
|
|
|
{ cursorPts[i].style.opacity = value; }
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
if (showLegend && legendRows[i])
|
2021-09-17 19:28:20 +00:00
|
|
|
{ legendRows[i].style.opacity = value; }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// y-distance
|
|
|
|
var closestDist;
|
|
|
|
var closestSeries;
|
|
|
|
var focusedSeries;
|
2021-01-18 13:49:52 +00:00
|
|
|
var FOCUS_TRUE = {focus: true};
|
|
|
|
var FOCUS_FALSE = {focus: false};
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
function setFocus(i) {
|
|
|
|
if (i != focusedSeries) {
|
|
|
|
// log("setFocus()", arguments);
|
|
|
|
|
2021-02-10 07:13:13 +00:00
|
|
|
var allFocused = i == null;
|
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
var _setAlpha = focus.alpha != 1;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
series.forEach((s, i2) => {
|
2021-02-10 07:13:13 +00:00
|
|
|
var isFocused = allFocused || i2 == 0 || i2 == i;
|
|
|
|
s._focus = allFocused ? null : isFocused;
|
2021-03-20 20:39:14 +00:00
|
|
|
_setAlpha && setAlpha(i2, isFocused ? 1 : focus.alpha);
|
2020-11-25 07:59:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
focusedSeries = i;
|
2021-03-20 20:39:14 +00:00
|
|
|
_setAlpha && commit();
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showLegend && cursorFocus) {
|
2021-01-18 13:49:52 +00:00
|
|
|
on(mouseleave, legendEl, e => {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (cursor._lock)
|
|
|
|
{ return; }
|
2021-01-18 13:49:52 +00:00
|
|
|
setSeries(null, FOCUS_FALSE, syncOpts.setSeries);
|
2020-11-25 07:59:41 +00:00
|
|
|
updateCursor();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function posToVal(pos, scale, can) {
|
2021-01-18 13:49:52 +00:00
|
|
|
var sc = scales[scale];
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (can)
|
|
|
|
{ pos = pos / pxRatio - (sc.ori == 1 ? plotTopCss : plotLftCss); }
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
var dim = plotWidCss;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (sc.ori == 1) {
|
2020-11-25 07:59:41 +00:00
|
|
|
dim = plotHgtCss;
|
|
|
|
pos = dim - pos;
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (sc.dir == -1)
|
|
|
|
{ pos = dim - pos; }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var _min = sc._min,
|
|
|
|
_max = sc._max,
|
2021-01-18 13:49:52 +00:00
|
|
|
pct = pos / dim;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var sv = _min + (_max - _min) * pct;
|
|
|
|
|
|
|
|
var distr = sc.distr;
|
|
|
|
|
|
|
|
return (
|
|
|
|
distr == 3 ? pow(10, sv) :
|
|
|
|
distr == 4 ? sinh(sv, sc.asinh) :
|
|
|
|
sv
|
|
|
|
);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function closestIdxFromXpos(pos, can) {
|
|
|
|
var v = posToVal(pos, xScaleKey, can);
|
2020-11-25 07:59:41 +00:00
|
|
|
return closestIdx(v, data[0], i0, i1);
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
self.valToIdx = val => closestIdx(val, data[0]);
|
2020-11-25 07:59:41 +00:00
|
|
|
self.posToIdx = closestIdxFromXpos;
|
2021-01-18 13:49:52 +00:00
|
|
|
self.posToVal = posToVal;
|
|
|
|
self.valToPos = (val, scale, can) => (
|
|
|
|
scales[scale].ori == 0 ?
|
|
|
|
getHPos(val, scales[scale],
|
2020-11-25 07:59:41 +00:00
|
|
|
can ? plotWid : plotWidCss,
|
|
|
|
can ? plotLft : 0
|
|
|
|
) :
|
2021-01-18 13:49:52 +00:00
|
|
|
getVPos(val, scales[scale],
|
2020-11-25 07:59:41 +00:00
|
|
|
can ? plotHgt : plotHgtCss,
|
|
|
|
can ? plotTop : 0
|
|
|
|
)
|
2021-01-18 13:49:52 +00:00
|
|
|
);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// defers calling expensive functions
|
|
|
|
function batch(fn) {
|
|
|
|
fn(self);
|
|
|
|
commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
self.batch = batch;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
(self.setCursor = (opts, _fire) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
mouseLeft1 = opts.left;
|
|
|
|
mouseTop1 = opts.top;
|
|
|
|
// assign(cursor, opts);
|
2021-09-17 19:28:20 +00:00
|
|
|
updateCursor(null, null, _fire);
|
2020-11-25 07:59:41 +00:00
|
|
|
});
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function setSelH(off, dim) {
|
|
|
|
setStylePx(selectDiv, LEFT, select.left = off);
|
|
|
|
setStylePx(selectDiv, WIDTH, select.width = dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSelV(off, dim) {
|
|
|
|
setStylePx(selectDiv, TOP, select.top = off);
|
|
|
|
setStylePx(selectDiv, HEIGHT, select.height = dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
var setSelX = scaleX.ori == 0 ? setSelH : setSelV;
|
|
|
|
var setSelY = scaleX.ori == 1 ? setSelH : setSelV;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function syncLegend() {
|
|
|
|
if (showLegend && legend.live) {
|
|
|
|
for (var i = 0; i < series.length; i++) {
|
|
|
|
if (i == 0 && multiValLegend)
|
|
|
|
{ continue; }
|
|
|
|
|
|
|
|
var vals = legend.values[i];
|
|
|
|
|
|
|
|
var j = 0;
|
|
|
|
|
|
|
|
for (var k in vals)
|
|
|
|
{ legendCells[i][j++].firstChild.nodeValue = vals[k]; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setLegend(opts, _fire) {
|
|
|
|
if (opts != null) {
|
|
|
|
var idx = opts.idx;
|
|
|
|
|
|
|
|
legend.idx = idx;
|
|
|
|
series.forEach((s, sidx) => {
|
|
|
|
(sidx > 0 || !multiValLegend) && setLegendValues(sidx, idx);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showLegend && legend.live)
|
|
|
|
{ syncLegend(); }
|
|
|
|
|
|
|
|
shouldSetLegend = false;
|
|
|
|
|
|
|
|
_fire !== false && fire("setLegend");
|
|
|
|
}
|
|
|
|
|
|
|
|
self.setLegend = setLegend;
|
|
|
|
|
|
|
|
function setLegendValues(sidx, idx) {
|
|
|
|
var val;
|
|
|
|
|
|
|
|
if (idx == null)
|
|
|
|
{ val = NULL_LEGEND_VALUES; }
|
|
|
|
else {
|
|
|
|
var s = series[sidx];
|
|
|
|
var src = sidx == 0 && xScaleDistr == 2 ? data0 : data[sidx];
|
|
|
|
val = multiValLegend ? s.values(self, sidx, idx) : {_: s.value(self, src[idx], sidx, idx)};
|
|
|
|
}
|
|
|
|
|
|
|
|
legend.values[sidx] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCursor(ts, src, _fire) {
|
2020-11-25 07:59:41 +00:00
|
|
|
var assign;
|
|
|
|
|
|
|
|
// ts == null && log("updateCursor()", arguments);
|
|
|
|
|
|
|
|
rawMouseLeft1 = mouseLeft1;
|
|
|
|
rawMouseTop1 = mouseTop1;
|
|
|
|
|
|
|
|
(assign = cursor.move(self, mouseLeft1, mouseTop1), mouseLeft1 = assign[0], mouseTop1 = assign[1]);
|
|
|
|
|
|
|
|
if (cursor.show) {
|
2021-01-18 13:49:52 +00:00
|
|
|
vCursor && trans(vCursor, round(mouseLeft1), 0, plotWidCss, plotHgtCss);
|
|
|
|
hCursor && trans(hCursor, 0, round(mouseTop1), plotWidCss, plotHgtCss);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var idx;
|
|
|
|
|
|
|
|
// when zooming to an x scale range between datapoints the binary search
|
|
|
|
// for nearest min/max indices results in this condition. cheap hack :D
|
|
|
|
var noDataInRange = i0 > i1;
|
|
|
|
|
|
|
|
closestDist = inf;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
// TODO: extract
|
|
|
|
var xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss;
|
|
|
|
var yDim = scaleX.ori == 1 ? plotWidCss : plotHgtCss;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
// if cursor hidden, hide points & clear legend vals
|
|
|
|
if (mouseLeft1 < 0 || dataLen == 0 || noDataInRange) {
|
|
|
|
idx = null;
|
|
|
|
|
|
|
|
for (var i = 0; i < series.length; i++) {
|
|
|
|
if (i > 0) {
|
2021-02-17 07:25:25 +00:00
|
|
|
cursorPts.length > 1 && trans(cursorPts[i], -10, -10, plotWidCss, plotHgtCss);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursorFocus)
|
2021-01-18 13:49:52 +00:00
|
|
|
{ setSeries(null, FOCUS_TRUE, syncOpts.setSeries); }
|
2021-09-17 19:28:20 +00:00
|
|
|
|
|
|
|
if (legend.live) {
|
|
|
|
activeIdxs.fill(null);
|
|
|
|
shouldSetLegend = true;
|
|
|
|
|
|
|
|
for (var i$1 = 0; i$1 < series.length; i$1++)
|
|
|
|
{ legend.values[i$1] = NULL_LEGEND_VALUES; }
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-12-23 07:17:49 +00:00
|
|
|
// let pctY = 1 - (y / rect.height);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var mouseXPos = scaleX.ori == 0 ? mouseLeft1 : mouseTop1;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var valAtPosX = posToVal(mouseXPos, xScaleKey);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
idx = closestIdx(valAtPosX, data[0], i0, i1);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var xPos = incrRoundUp(valToPosX(data[0][idx], scaleX, xDim, 0), 0.5);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
for (var i$2 = 0; i$2 < series.length; i$2++) {
|
|
|
|
var s = series[i$2];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var idx2 = cursor.dataIdx(self, i$2, idx, valAtPosX);
|
|
|
|
|
|
|
|
var yVal2 = data[i$2][idx2];
|
|
|
|
|
|
|
|
shouldSetLegend = shouldSetLegend || yVal2 != data[i$2][activeIdxs[i$2]];
|
|
|
|
|
|
|
|
activeIdxs[i$2] = idx2;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var xPos2 = idx2 == idx ? xPos : incrRoundUp(valToPosX(data[0][idx2], scaleX, xDim, 0), 0.5);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (i$2 > 0 && s.show) {
|
|
|
|
var yPos = yVal2 == null ? -10 : incrRoundUp(valToPosY(yVal2, scales[s.scale], yDim, 0), 0.5);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (yPos > 0) {
|
|
|
|
var dist = abs(yPos - mouseTop1);
|
|
|
|
|
|
|
|
if (dist <= closestDist) {
|
|
|
|
closestDist = dist;
|
2021-09-17 19:28:20 +00:00
|
|
|
closestSeries = i$2;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var hPos = (void 0), vPos = (void 0);
|
|
|
|
|
|
|
|
if (scaleX.ori == 0) {
|
|
|
|
hPos = xPos2;
|
|
|
|
vPos = yPos;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hPos = yPos;
|
|
|
|
vPos = xPos2;
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (shouldSetLegend && cursorPts.length > 1) {
|
|
|
|
trans(cursorPts[i$2], hPos, vPos, plotWidCss, plotHgtCss);
|
|
|
|
color(cursorPts[i$2], cursor.points.fill(self, i$2), cursor.points.stroke(self, i$2));
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (legend.live) {
|
|
|
|
if (!shouldSetLegend || i$2 == 0 && multiValLegend)
|
2020-11-25 07:59:41 +00:00
|
|
|
{ continue; }
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
setLegendValues(i$2, idx2);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-17 19:28:20 +00:00
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (shouldSetLegend) {
|
|
|
|
legend.idx = idx;
|
|
|
|
setLegend();
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nit: cursor.drag.setSelect is assumed always true
|
|
|
|
if (select.show && dragging) {
|
|
|
|
if (src != null) {
|
|
|
|
var ref = syncOpts.scales;
|
|
|
|
var xKey = ref[0];
|
|
|
|
var yKey = ref[1];
|
2021-09-17 19:28:20 +00:00
|
|
|
var ref$1 = syncOpts.match;
|
|
|
|
var matchXKeys = ref$1[0];
|
|
|
|
var matchYKeys = ref$1[1];
|
|
|
|
var ref$2 = src.cursor.sync.scales;
|
|
|
|
var xKeySrc = ref$2[0];
|
|
|
|
var yKeySrc = ref$2[1];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
// match the dragX/dragY implicitness/explicitness of src
|
|
|
|
var sdrag = src.cursor.drag;
|
|
|
|
dragX = sdrag._x;
|
|
|
|
dragY = sdrag._y;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var ref$3 = src.select;
|
|
|
|
var left = ref$3.left;
|
|
|
|
var top = ref$3.top;
|
|
|
|
var width = ref$3.width;
|
|
|
|
var height = ref$3.height;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var sori = src.scales[xKey].ori;
|
|
|
|
var sPosToVal = src.posToVal;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var sOff, sDim, sc, a, b;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var matchingX = xKey != null && matchXKeys(xKey, xKeySrc);
|
|
|
|
var matchingY = yKey != null && matchYKeys(yKey, yKeySrc);
|
|
|
|
|
|
|
|
if (matchingX) {
|
2021-01-18 13:49:52 +00:00
|
|
|
if (sori == 0) {
|
|
|
|
sOff = left;
|
|
|
|
sDim = width;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
2021-01-18 13:49:52 +00:00
|
|
|
else {
|
|
|
|
sOff = top;
|
|
|
|
sDim = height;
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (dragX) {
|
|
|
|
sc = scales[xKey];
|
2021-01-18 13:49:52 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
a = valToPosX(sPosToVal(sOff, xKeySrc), sc, xDim, 0);
|
|
|
|
b = valToPosX(sPosToVal(sOff + sDim, xKeySrc), sc, xDim, 0);
|
2021-01-18 13:49:52 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
setSelX(min(a,b), abs(b-a));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ setSelX(0, xDim); }
|
2021-01-18 13:49:52 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (!matchingY)
|
2021-01-18 13:49:52 +00:00
|
|
|
{ setSelY(0, yDim); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (matchingY) {
|
2021-01-18 13:49:52 +00:00
|
|
|
if (sori == 1) {
|
|
|
|
sOff = left;
|
|
|
|
sDim = width;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sOff = top;
|
|
|
|
sDim = height;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (dragY) {
|
|
|
|
sc = scales[yKey];
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
a = valToPosY(sPosToVal(sOff, yKeySrc), sc, yDim, 0);
|
|
|
|
b = valToPosY(sPosToVal(sOff + sDim, yKeySrc), sc, yDim, 0);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
setSelY(min(a,b), abs(b-a));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ setSelY(0, yDim); }
|
2021-01-18 13:49:52 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (!matchingX)
|
2021-01-18 13:49:52 +00:00
|
|
|
{ setSelX(0, xDim); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var rawDX = abs(rawMouseLeft1 - rawMouseLeft0);
|
|
|
|
var rawDY = abs(rawMouseTop1 - rawMouseTop0);
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (scaleX.ori == 1) {
|
|
|
|
var _rawDX = rawDX;
|
|
|
|
rawDX = rawDY;
|
|
|
|
rawDY = _rawDX;
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
dragX = drag.x && rawDX >= drag.dist;
|
|
|
|
dragY = drag.y && rawDY >= drag.dist;
|
|
|
|
|
|
|
|
var uni = drag.uni;
|
|
|
|
|
|
|
|
if (uni != null) {
|
2021-03-20 20:39:14 +00:00
|
|
|
// only calc drag status if they pass the dist thresh
|
2020-11-25 07:59:41 +00:00
|
|
|
if (dragX && dragY) {
|
|
|
|
dragX = rawDX >= uni;
|
|
|
|
dragY = rawDY >= uni;
|
|
|
|
|
|
|
|
// force unidirectionality when both are under uni limit
|
|
|
|
if (!dragX && !dragY) {
|
|
|
|
if (rawDY > rawDX)
|
|
|
|
{ dragY = true; }
|
|
|
|
else
|
|
|
|
{ dragX = true; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (drag.x && drag.y && (dragX || dragY))
|
|
|
|
// if omni with no uni then both dragX / dragY should be true if either is true
|
|
|
|
{ dragX = dragY = true; }
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var p0, p1;
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
if (dragX) {
|
2021-01-18 13:49:52 +00:00
|
|
|
if (scaleX.ori == 0) {
|
|
|
|
p0 = mouseLeft0;
|
|
|
|
p1 = mouseLeft1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p0 = mouseTop0;
|
|
|
|
p1 = mouseTop1;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
setSelX(min(p0, p1), abs(p1 - p0));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (!dragY)
|
|
|
|
{ setSelY(0, yDim); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dragY) {
|
2021-01-18 13:49:52 +00:00
|
|
|
if (scaleX.ori == 1) {
|
|
|
|
p0 = mouseLeft0;
|
|
|
|
p1 = mouseLeft1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p0 = mouseTop0;
|
|
|
|
p1 = mouseTop1;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
setSelY(min(p0, p1), abs(p1 - p0));
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (!dragX)
|
|
|
|
{ setSelX(0, xDim); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
// the drag didn't pass the dist requirement
|
2020-11-25 07:59:41 +00:00
|
|
|
if (!dragX && !dragY) {
|
2021-01-18 13:49:52 +00:00
|
|
|
setSelX(0, 0);
|
|
|
|
setSelY(0, 0);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.idx = idx;
|
|
|
|
cursor.left = mouseLeft1;
|
|
|
|
cursor.top = mouseTop1;
|
|
|
|
drag._x = dragX;
|
|
|
|
drag._y = dragY;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
// if ts is present, means we're implicitly syncing own cursor
|
2020-11-25 07:59:41 +00:00
|
|
|
if (ts != null) {
|
2021-09-17 19:28:20 +00:00
|
|
|
if (syncKey != null) {
|
|
|
|
var ref$4 = syncOpts.scales;
|
|
|
|
var xSyncKey = ref$4[0];
|
|
|
|
var ySyncKey = ref$4[1];
|
|
|
|
|
|
|
|
syncOpts.values[0] = xSyncKey != null ? posToVal(scaleX.ori == 0 ? mouseLeft1 : mouseTop1, xSyncKey) : null;
|
|
|
|
syncOpts.values[1] = ySyncKey != null ? posToVal(scaleX.ori == 1 ? mouseLeft1 : mouseTop1, ySyncKey) : null;
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
// this is not technically a "mousemove" event, since it's debounced, rename to setCursor?
|
|
|
|
// since this is internal, we can tweak it later
|
2021-09-17 19:28:20 +00:00
|
|
|
pubSync(mousemove, self, mouseLeft1, mouseTop1, plotWidCss, plotHgtCss, idx);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (cursorFocus) {
|
2021-01-18 13:49:52 +00:00
|
|
|
var o = syncOpts.setSeries;
|
|
|
|
var p = focus.prox;
|
|
|
|
|
|
|
|
if (focusedSeries == null) {
|
|
|
|
if (closestDist <= p)
|
|
|
|
{ setSeries(closestSeries, FOCUS_TRUE, o); }
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (closestDist > p)
|
|
|
|
{ setSeries(null, FOCUS_TRUE, o); }
|
|
|
|
else if (closestSeries != focusedSeries)
|
|
|
|
{ setSeries(closestSeries, FOCUS_TRUE, o); }
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
ready && _fire !== false && fire("setCursor");
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var rect = null;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function syncRect(defer) {
|
|
|
|
if (defer === true)
|
|
|
|
{ rect = null; }
|
|
|
|
else {
|
|
|
|
rect = over.getBoundingClientRect();
|
|
|
|
fire("syncRect", rect);
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function mouseMove(e, src, _l, _t, _w, _h, _i) {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (cursor._lock)
|
|
|
|
{ return; }
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
cacheMouse(e, src, _l, _t, _w, _h, _i, false, e != null);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (e != null)
|
|
|
|
{ updateCursor(1); }
|
2020-11-25 07:59:41 +00:00
|
|
|
else
|
|
|
|
{ updateCursor(null, src); }
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function cacheMouse(e, src, _l, _t, _w, _h, _i, initial, snap) {
|
2020-11-25 07:59:41 +00:00
|
|
|
var assign;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (rect == null)
|
|
|
|
{ syncRect(false); }
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
if (e != null) {
|
2021-01-18 13:49:52 +00:00
|
|
|
_l = e.clientX - rect.left;
|
|
|
|
_t = e.clientY - rect.top;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-01-18 13:49:52 +00:00
|
|
|
if (_l < 0 || _t < 0) {
|
2020-11-25 07:59:41 +00:00
|
|
|
mouseLeft1 = -10;
|
|
|
|
mouseTop1 = -10;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ref = syncOpts.scales;
|
|
|
|
var xKey = ref[0];
|
|
|
|
var yKey = ref[1];
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var syncOptsSrc = src.cursor.sync;
|
|
|
|
var ref$1 = syncOptsSrc.values;
|
|
|
|
var xValSrc = ref$1[0];
|
|
|
|
var yValSrc = ref$1[1];
|
|
|
|
var ref$2 = syncOptsSrc.scales;
|
|
|
|
var xKeySrc = ref$2[0];
|
|
|
|
var yKeySrc = ref$2[1];
|
|
|
|
var ref$3 = syncOpts.match;
|
|
|
|
var matchXKeys = ref$3[0];
|
|
|
|
var matchYKeys = ref$3[1];
|
|
|
|
|
|
|
|
var rotSrc = src.scales[xKeySrc].ori == 1;
|
|
|
|
|
|
|
|
var xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss,
|
|
|
|
yDim = scaleX.ori == 1 ? plotWidCss : plotHgtCss,
|
|
|
|
_xDim = rotSrc ? _h : _w,
|
|
|
|
_yDim = rotSrc ? _w : _h,
|
|
|
|
_xPos = rotSrc ? _t : _l,
|
|
|
|
_yPos = rotSrc ? _l : _t;
|
|
|
|
|
|
|
|
if (xKeySrc != null)
|
|
|
|
{ _l = matchXKeys(xKey, xKeySrc) ? getPos(xValSrc, scales[xKey], xDim, 0) : -10; }
|
2020-11-25 07:59:41 +00:00
|
|
|
else
|
2021-01-18 13:49:52 +00:00
|
|
|
{ _l = xDim * (_xPos/_xDim); }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
if (yKeySrc != null)
|
|
|
|
{ _t = matchYKeys(yKey, yKeySrc) ? getPos(yValSrc, scales[yKey], yDim, 0) : -10; }
|
2020-11-25 07:59:41 +00:00
|
|
|
else
|
2021-01-18 13:49:52 +00:00
|
|
|
{ _t = yDim * (_yPos/_yDim); }
|
|
|
|
|
|
|
|
if (scaleX.ori == 1) {
|
|
|
|
var _l$1 = _l;
|
|
|
|
_l = _t;
|
|
|
|
_t = _l$1;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (snap) {
|
2021-01-18 13:49:52 +00:00
|
|
|
if (_l <= 1 || _l >= plotWidCss - 1)
|
|
|
|
{ _l = incrRound(_l, plotWidCss); }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (_t <= 1 || _t >= plotHgtCss - 1)
|
|
|
|
{ _t = incrRound(_t, plotHgtCss); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (initial) {
|
2021-01-18 13:49:52 +00:00
|
|
|
rawMouseLeft0 = _l;
|
|
|
|
rawMouseTop0 = _t;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
(assign = cursor.move(self, _l, _t), mouseLeft0 = assign[0], mouseTop0 = assign[1]);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-01-18 13:49:52 +00:00
|
|
|
mouseLeft1 = _l;
|
|
|
|
mouseTop1 = _t;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideSelect() {
|
|
|
|
setSelect({
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function mouseDown(e, src, _l, _t, _w, _h, _i) {
|
2020-11-25 07:59:41 +00:00
|
|
|
dragging = true;
|
|
|
|
dragX = dragY = drag._x = drag._y = false;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
cacheMouse(e, src, _l, _t, _w, _h, _i, true, false);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
if (e != null) {
|
|
|
|
onMouse(mouseup, doc, mouseUp);
|
2021-03-20 20:39:14 +00:00
|
|
|
pubSync(mousedown, self, mouseLeft0, mouseTop0, plotWidCss, plotHgtCss, null);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function mouseUp(e, src, _l, _t, _w, _h, _i) {
|
2020-11-25 07:59:41 +00:00
|
|
|
dragging = drag._x = drag._y = false;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
cacheMouse(e, src, _l, _t, _w, _h, _i, false, true);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var left = select.left;
|
|
|
|
var top = select.top;
|
|
|
|
var width = select.width;
|
|
|
|
var height = select.height;
|
|
|
|
|
|
|
|
var hasSelect = width > 0 || height > 0;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
hasSelect && setSelect(select);
|
|
|
|
|
|
|
|
if (drag.setScale && hasSelect) {
|
|
|
|
// if (syncKey != null) {
|
|
|
|
// dragX = drag.x;
|
|
|
|
// dragY = drag.y;
|
|
|
|
// }
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var xOff = left,
|
|
|
|
xDim = width,
|
|
|
|
yOff = top,
|
|
|
|
yDim = height;
|
|
|
|
|
|
|
|
if (scaleX.ori == 1) {
|
|
|
|
xOff = top,
|
|
|
|
xDim = height,
|
|
|
|
yOff = left,
|
|
|
|
yDim = width;
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
if (dragX) {
|
|
|
|
_setScale(xScaleKey,
|
2021-01-18 13:49:52 +00:00
|
|
|
posToVal(xOff, xScaleKey),
|
|
|
|
posToVal(xOff + xDim, xScaleKey)
|
2020-11-25 07:59:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dragY) {
|
|
|
|
for (var k in scales) {
|
|
|
|
var sc = scales[k];
|
|
|
|
|
|
|
|
if (k != xScaleKey && sc.from == null && sc.min != inf) {
|
|
|
|
_setScale(k,
|
2021-01-18 13:49:52 +00:00
|
|
|
posToVal(yOff + yDim, k),
|
|
|
|
posToVal(yOff, k)
|
2020-11-25 07:59:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hideSelect();
|
|
|
|
}
|
|
|
|
else if (cursor.lock) {
|
|
|
|
cursor._lock = !cursor._lock;
|
|
|
|
|
|
|
|
if (!cursor._lock)
|
|
|
|
{ updateCursor(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e != null) {
|
|
|
|
offMouse(mouseup, doc);
|
2021-03-20 20:39:14 +00:00
|
|
|
pubSync(mouseup, self, mouseLeft1, mouseTop1, plotWidCss, plotHgtCss, null);
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function mouseLeave(e, src, _l, _t, _w, _h, _i) {
|
2020-11-25 07:59:41 +00:00
|
|
|
if (!cursor._lock) {
|
|
|
|
var _dragging = dragging;
|
|
|
|
|
|
|
|
if (dragging) {
|
|
|
|
// handle case when mousemove aren't fired all the way to edges by browser
|
2021-01-18 13:49:52 +00:00
|
|
|
var snapH = true;
|
|
|
|
var snapV = true;
|
2020-11-25 07:59:41 +00:00
|
|
|
var snapProx = 10;
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
var dragH, dragV;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (scaleX.ori == 0) {
|
|
|
|
dragH = dragX;
|
|
|
|
dragV = dragY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dragH = dragY;
|
|
|
|
dragV = dragX;
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (dragH && dragV) {
|
|
|
|
// maybe omni corner snap
|
|
|
|
snapH = mouseLeft1 <= snapProx || mouseLeft1 >= plotWidCss - snapProx;
|
|
|
|
snapV = mouseTop1 <= snapProx || mouseTop1 >= plotHgtCss - snapProx;
|
|
|
|
}
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (dragH && snapH)
|
|
|
|
{ mouseLeft1 = mouseLeft1 < mouseLeft0 ? 0 : plotWidCss; }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
if (dragV && snapV)
|
|
|
|
{ mouseTop1 = mouseTop1 < mouseTop0 ? 0 : plotHgtCss; }
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
updateCursor(1);
|
|
|
|
|
|
|
|
dragging = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mouseLeft1 = -10;
|
|
|
|
mouseTop1 = -10;
|
|
|
|
|
|
|
|
// passing a non-null timestamp to force sync/mousemove event
|
|
|
|
updateCursor(1);
|
|
|
|
|
|
|
|
if (_dragging)
|
|
|
|
{ dragging = _dragging; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
function dblClick(e, src, _l, _t, _w, _h, _i) {
|
2020-11-25 07:59:41 +00:00
|
|
|
autoScaleX();
|
|
|
|
|
|
|
|
hideSelect();
|
|
|
|
|
|
|
|
if (e != null)
|
2021-03-20 20:39:14 +00:00
|
|
|
{ pubSync(dblclick, self, mouseLeft1, mouseTop1, plotWidCss, plotHgtCss, null); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
function syncPxRatio() {
|
|
|
|
axes.forEach(syncFontSize);
|
|
|
|
_setSize(self.width, self.height, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
on(ddpxchange, win, syncPxRatio);
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
// internal pub/sub
|
|
|
|
var events = {};
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
events.mousedown = mouseDown;
|
|
|
|
events.mousemove = mouseMove;
|
|
|
|
events.mouseup = mouseUp;
|
|
|
|
events.dblclick = dblClick;
|
2021-01-18 13:49:52 +00:00
|
|
|
events["setSeries"] = (e, src, idx, opts) => {
|
2020-11-25 07:59:41 +00:00
|
|
|
setSeries(idx, opts);
|
|
|
|
};
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
if (cursor.show) {
|
2021-01-18 13:49:52 +00:00
|
|
|
onMouse(mousedown, over, mouseDown);
|
|
|
|
onMouse(mousemove, over, mouseMove);
|
2020-11-25 07:59:41 +00:00
|
|
|
onMouse(mouseenter, over, syncRect);
|
2021-01-18 13:49:52 +00:00
|
|
|
onMouse(mouseleave, over, mouseLeave);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
onMouse(dblclick, over, dblClick);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
cursorPlots.add(self);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
self.syncRect = syncRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
// external on/off
|
|
|
|
var hooks = self.hooks = opts.hooks || {};
|
|
|
|
|
|
|
|
function fire(evName, a1, a2) {
|
|
|
|
if (evName in hooks) {
|
2021-01-18 13:49:52 +00:00
|
|
|
hooks[evName].forEach(fn => {
|
2020-11-25 07:59:41 +00:00
|
|
|
fn.call(null, self, a1, a2);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:49:52 +00:00
|
|
|
(opts.plugins || []).forEach(p => {
|
2020-11-25 07:59:41 +00:00
|
|
|
for (var evName in p.hooks)
|
|
|
|
{ hooks[evName] = (hooks[evName] || []).concat(p.hooks[evName]); }
|
|
|
|
});
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var syncOpts = assign({
|
2020-11-25 07:59:41 +00:00
|
|
|
key: null,
|
|
|
|
setSeries: false,
|
2021-03-20 20:39:14 +00:00
|
|
|
filters: {
|
|
|
|
pub: retTrue,
|
|
|
|
sub: retTrue,
|
|
|
|
},
|
2021-09-17 19:28:20 +00:00
|
|
|
scales: [xScaleKey, series[1] ? series[1].scale : null],
|
|
|
|
match: [retEq, retEq],
|
|
|
|
values: [null, null],
|
2020-11-25 07:59:41 +00:00
|
|
|
}, cursor.sync);
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
(cursor.sync = syncOpts);
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var syncKey = syncOpts.key;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
var sync = _sync(syncKey);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
function pubSync(type, src, x, y, w, h, i) {
|
|
|
|
if (syncOpts.filters.pub(type, src, x, y, w, h, i))
|
|
|
|
{ sync.pub(type, src, x, y, w, h, i); }
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
sync.sub(self);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
function pub(type, src, x, y, w, h, i) {
|
2021-03-20 20:39:14 +00:00
|
|
|
if (syncOpts.filters.sub(type, src, x, y, w, h, i))
|
|
|
|
{ events[type](null, src, x, y, w, h, i); }
|
2020-11-25 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
(self.pub = pub);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
|
|
|
function destroy() {
|
2021-02-17 07:25:25 +00:00
|
|
|
sync.unsub(self);
|
2021-09-17 19:28:20 +00:00
|
|
|
cursorPlots.delete(self);
|
|
|
|
mouseListeners.clear();
|
|
|
|
off(ddpxchange, win, syncPxRatio);
|
2020-11-25 07:59:41 +00:00
|
|
|
root.remove();
|
|
|
|
fire("destroy");
|
|
|
|
}
|
|
|
|
|
|
|
|
self.destroy = destroy;
|
|
|
|
|
|
|
|
function _init() {
|
|
|
|
fire("init", opts, data);
|
|
|
|
|
|
|
|
setData(data || opts.data, false);
|
|
|
|
|
|
|
|
if (pendScales[xScaleKey])
|
|
|
|
{ setScale(xScaleKey, pendScales[xScaleKey]); }
|
|
|
|
else
|
|
|
|
{ autoScaleX(); }
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
_setSize(opts.width, opts.height);
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2021-03-20 20:39:14 +00:00
|
|
|
updateCursor();
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
setSelect(select, false);
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
series.forEach(initSeries);
|
|
|
|
|
|
|
|
axes.forEach(initAxis);
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
if (then) {
|
|
|
|
if (then instanceof HTMLElement) {
|
|
|
|
then.appendChild(root);
|
|
|
|
_init();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ then(self, _init); }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ _init(); }
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
uPlot.assign = assign;
|
|
|
|
uPlot.fmtNum = fmtNum;
|
|
|
|
uPlot.rangeNum = rangeNum;
|
|
|
|
uPlot.rangeLog = rangeLog;
|
2021-02-17 07:25:25 +00:00
|
|
|
uPlot.rangeAsinh = rangeAsinh;
|
2021-01-18 13:49:52 +00:00
|
|
|
uPlot.orient = orient;
|
2020-11-25 07:59:41 +00:00
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
{
|
|
|
|
uPlot.join = join;
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
{
|
|
|
|
uPlot.fmtDate = fmtDate;
|
|
|
|
uPlot.tzDate = tzDate;
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
{
|
|
|
|
uPlot.sync = _sync;
|
|
|
|
}
|
|
|
|
|
2020-12-23 07:17:49 +00:00
|
|
|
{
|
|
|
|
uPlot.addGap = addGap;
|
|
|
|
uPlot.clipGaps = clipGaps;
|
|
|
|
|
2021-09-17 19:28:20 +00:00
|
|
|
var paths = uPlot.paths = {
|
|
|
|
points: points,
|
|
|
|
};
|
2020-12-23 07:17:49 +00:00
|
|
|
|
2021-02-17 07:25:25 +00:00
|
|
|
(paths.linear = linear);
|
|
|
|
(paths.stepped = stepped);
|
|
|
|
(paths.bars = bars);
|
2021-09-17 19:28:20 +00:00
|
|
|
(paths.spline = monotoneCubic);
|
2020-12-23 07:17:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 07:59:41 +00:00
|
|
|
return uPlot;
|
|
|
|
|
|
|
|
}());
|