From 9344e3faa8668777860f5a0edbcc1ebce59a7468 Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Sat, 21 Aug 2021 15:28:42 -0500 Subject: [PATCH] reduce ctx mutation --- dist/uPlot.cjs.js | 189 ++-- dist/uPlot.esm.js | 189 ++-- dist/uPlot.iife.js | 2373 ++++++++++++++++++++-------------------- dist/uPlot.iife.min.js | 2 +- package.json | 1 - rollup.config.js | 3 - src/uPlot.js | 189 ++-- src/utils.js | 1 + 8 files changed, 1504 insertions(+), 1443 deletions(-) diff --git a/dist/uPlot.cjs.js b/dist/uPlot.cjs.js index 634907d0..482757d6 100644 --- a/dist/uPlot.cjs.js +++ b/dist/uPlot.cjs.js @@ -328,6 +328,7 @@ function genIncrs(base, minExp, maxExp, mults) { //export const assign = Object.assign; const EMPTY_OBJ = {}; +const EMPTY_ARR = []; const nullNullTuple = [null, null]; @@ -3116,13 +3117,33 @@ function uPlot(opts, data, then) { _setScale(xScaleKey, _min, _max); } - function setCtxStyle(stroke, width, dash, cap, fill) { - ctx.strokeStyle = stroke || transparent; - ctx.lineWidth = width; - ctx.lineJoin = "round"; - ctx.lineCap = cap || "butt"; // (‿|‿) - ctx.setLineDash(dash || []); - ctx.fillStyle = fill || transparent; + let ctxStroke, ctxFill, ctxWidth, ctxDash, ctxJoin, ctxCap, ctxFont, ctxAlign, ctxBaseline; + let ctxAlpha; + + function setCtxStyle(stroke = transparent, width, dash = EMPTY_ARR, cap = "butt", fill = transparent, join = "round") { + if (stroke != ctxStroke) + ctx.strokeStyle = ctxStroke = stroke; + if (fill != ctxFill) + ctx.fillStyle = ctxFill = fill; + if (width != ctxWidth) + ctx.lineWidth = ctxWidth = width; + if (join != ctxJoin) + ctx.lineJoin = ctxJoin = join; + if (cap != ctxCap) + ctx.lineCap = ctxCap = cap; // (‿|‿) + if (dash != ctxDash) + ctx.setLineDash(ctxDash = dash); + } + + function setFontStyle(font, fill, align, baseline) { + if (fill != ctxFill) + ctx.fillStyle = ctxFill = fill; + if (font != ctxFont) + ctx.font = ctxFont = font; + if (align != ctxAlign) + ctx.textAlign = ctxAlign = align; + if (baseline != ctxBaseline) + ctx.textBaseline = ctxBaseline = baseline; } function setScales() { @@ -3324,21 +3345,21 @@ function uPlot(opts, data, then) { let strokeStyle = s._stroke; let fillStyle = s._fill; - let { stroke, fill, clip, flags } = s._paths; + let { stroke, fill, clip: gapsClip, flags } = s._paths; + let boundsClip = null; let width = roundDec(s.width * pxRatio, 3); let offset = (width % 2) / 2; if (_points && fillStyle == null) fillStyle = width > 0 ? "#fff" : strokeStyle; - ctx.globalAlpha = s.alpha; + if (ctxAlpha != s.alpha) + ctx.globalAlpha = ctxAlpha = s.alpha; let _pxAlign = s.pxAlign == 1; _pxAlign && ctx.translate(offset, offset); - ctx.save(); - if (!_points) { let lft = plotLft, top = plotTop, @@ -3355,26 +3376,23 @@ function uPlot(opts, data, then) { hgt += halfWid; } - ctx.beginPath(); - ctx.rect(lft, top, wid, hgt); - ctx.clip(); + boundsClip = new Path2D(); + boundsClip.rect(lft, top, wid, hgt); } - clip && ctx.clip(clip); - + // the points pathbuilder's gapsClip is its boundsClip, since points dont need gaps clipping, and bounds depend on point size if (_points) - strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, null, flags); + strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags, gapsClip, null, null); else - fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags); - - ctx.restore(); + fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags, boundsClip, gapsClip); _pxAlign && ctx.translate(-offset, -offset); - ctx.globalAlpha = 1; + if (ctxAlpha != 1) + ctx.globalAlpha = ctxAlpha = 1; } - function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags) { + function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip) { let didStrokeFill = false; // for all bands where this series is the top edge, create upwards clips using the bottom edges @@ -3384,49 +3402,51 @@ function uPlot(opts, data, then) { if (b.series[0] == si) { let lowerEdge = series[b.series[1]]; - let clip = (lowerEdge._paths || EMPTY_OBJ).band; - - ctx.save(); + let bandClip = (lowerEdge._paths || EMPTY_OBJ).band; let _fillStyle = null; // hasLowerEdge? - if (lowerEdge.show && clip) + if (lowerEdge.show && bandClip) _fillStyle = b.fill(self, bi) || fillStyle; else - clip = null; - - strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, clip, flags); + bandClip = null; - ctx.restore(); + strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, bandClip); didStrokeFill = true; } }); if (!didStrokeFill) - strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, null, flags); + strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, null); } const CLIP_FILL_STROKE = BAND_CLIP_FILL | BAND_CLIP_STROKE; - function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, clip, flags) { + function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, bandClip) { setCtxStyle(strokeStyle, lineWidth, lineDash, lineCap, fillStyle); - if (clip) { + if (boundsClip || gapsClip || bandClip) { + ctx.save(); + boundsClip && ctx.clip(boundsClip); + gapsClip && ctx.clip(gapsClip); + } + + if (bandClip) { if ((flags & CLIP_FILL_STROKE) == CLIP_FILL_STROKE) { - ctx.clip(clip); + ctx.clip(bandClip); doFill(fillStyle, fillPath); doStroke(strokeStyle, strokePath, lineWidth); } else if (flags & BAND_CLIP_STROKE) { doFill(fillStyle, fillPath); - ctx.clip(clip); + ctx.clip(bandClip); doStroke(strokeStyle, strokePath, lineWidth); } else if (flags & BAND_CLIP_FILL) { ctx.save(); - ctx.clip(clip); + ctx.clip(bandClip); doFill(fillStyle, fillPath); ctx.restore(); doStroke(strokeStyle, strokePath, lineWidth); @@ -3436,6 +3456,9 @@ function uPlot(opts, data, then) { doFill(fillStyle, fillPath); doStroke(strokeStyle, strokePath, lineWidth); } + + if (boundsClip || gapsClip || bandClip) + ctx.restore(); } function doStroke(strokeStyle, strokePath, lineWidth) { @@ -3443,7 +3466,7 @@ function uPlot(opts, data, then) { } function doFill(fillStyle, fillPath) { - fillStyle && fillPath && ctx.fill(fillPath); + fillStyle && fillPath && ctx.fill(fillPath); } function getIncrSpace(axisIdx, min, max, fullDim) { @@ -3467,7 +3490,7 @@ function uPlot(opts, data, then) { pxAlign == 1 && ctx.translate(offset, offset); - setCtxStyle(stroke, width, dash, cap); + setCtxStyle(stroke, width, dash, cap, stroke); ctx.beginPath(); @@ -3482,18 +3505,17 @@ function uPlot(opts, data, then) { x1 = pos1; } - offs.forEach((off, i) => { - if (filts[i] == null) - return; - - if (ori == 0) - x0 = x1 = off; - else - y0 = y1 = off; + for (let i = 0; i < offs.length; i++) { + if (filts[i] != null) { + if (ori == 0) + x0 = x1 = offs[i]; + else + y0 = y1 = offs[i]; - ctx.moveTo(x0, y0); - ctx.lineTo(x1, y1); - }); + ctx.moveTo(x0, y0); + ctx.lineTo(x1, y1); + } + } ctx.stroke(); @@ -3579,7 +3601,9 @@ function uPlot(opts, data, then) { } function drawAxesGrid() { - axes.forEach((axis, i) => { + for (let i = 0; i < axes.length; i++) { + let axis = axes[i]; + if (!axis.show || !axis._show) return; @@ -3597,6 +3621,8 @@ function uPlot(opts, data, then) { let shiftAmt = axis.labelGap * shiftDir; let baseLpos = round((axis._lpos + shiftAmt) * pxRatio); + setFontStyle(axis.labelFont[0], fillStyle, "center", side == 2 ? TOP : BOTTOM); + ctx.save(); if (ori == 1) { @@ -3614,11 +3640,6 @@ function uPlot(opts, data, then) { 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(); @@ -3655,41 +3676,51 @@ function uPlot(opts, data, then) { y = ori == 0 ? finalPos : 0; x = ori == 1 ? finalPos : 0; - ctx.font = axis.font[0]; - ctx.fillStyle = fillStyle; - ctx.textAlign = axis.align == 1 ? LEFT : + let font = axis.font[0]; + let 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 || + let textBaseline = angle || ori == 1 ? "middle" : side == 2 ? TOP : BOTTOM; + setFontStyle(font, fillStyle, textAlign, textBaseline); + let lineHeight = axis.font[1] * lineMult; let canOffs = _splits.map(val => pxRound(getPos(val, scale, plotDim, plotOff))); - axis._values.forEach((val, i) => { - if (val == null) - return; + let _values = axis._values; - if (ori == 0) - x = canOffs[i]; - else - y = canOffs[i]; - - (""+val).split(/\n/gm).forEach((text, j) => { - if (angle) { - ctx.save(); - ctx.translate(x, y + j * lineHeight); - ctx.rotate(angle); - ctx.fillText(text, 0, 0); - ctx.restore(); - } + for (let i = 0; i < _values.length; i++) { + let val = _values[i]; + + if (val != null) { + if (ori == 0) + x = canOffs[i]; else - ctx.fillText(text, x, y + j * lineHeight); - }); - }); + y = canOffs[i]; + + val = "" + val; + + let _parts = val.indexOf("\n") == -1 ? [val] : val.split(/\n/gm); + + for (let j = 0; j < _parts.length; j++) { + let text = _parts[j]; + + if (angle) { + ctx.save(); + ctx.translate(x, y + j * lineHeight); // can this be replaced with position math? + ctx.rotate(angle); // can this be done once? + ctx.fillText(text, 0, 0); + ctx.restore(); + } + else + ctx.fillText(text, x, y + j * lineHeight); + } + } + } // ticks if (ticks.show) { @@ -3724,7 +3755,7 @@ function uPlot(opts, data, then) { grid.cap, ); } - }); + } fire("drawAxes"); } diff --git a/dist/uPlot.esm.js b/dist/uPlot.esm.js index e5e411cb..adcb66fd 100644 --- a/dist/uPlot.esm.js +++ b/dist/uPlot.esm.js @@ -326,6 +326,7 @@ function genIncrs(base, minExp, maxExp, mults) { //export const assign = Object.assign; const EMPTY_OBJ = {}; +const EMPTY_ARR = []; const nullNullTuple = [null, null]; @@ -3114,13 +3115,33 @@ function uPlot(opts, data, then) { _setScale(xScaleKey, _min, _max); } - function setCtxStyle(stroke, width, dash, cap, fill) { - ctx.strokeStyle = stroke || transparent; - ctx.lineWidth = width; - ctx.lineJoin = "round"; - ctx.lineCap = cap || "butt"; // (‿|‿) - ctx.setLineDash(dash || []); - ctx.fillStyle = fill || transparent; + let ctxStroke, ctxFill, ctxWidth, ctxDash, ctxJoin, ctxCap, ctxFont, ctxAlign, ctxBaseline; + let ctxAlpha; + + function setCtxStyle(stroke = transparent, width, dash = EMPTY_ARR, cap = "butt", fill = transparent, join = "round") { + if (stroke != ctxStroke) + ctx.strokeStyle = ctxStroke = stroke; + if (fill != ctxFill) + ctx.fillStyle = ctxFill = fill; + if (width != ctxWidth) + ctx.lineWidth = ctxWidth = width; + if (join != ctxJoin) + ctx.lineJoin = ctxJoin = join; + if (cap != ctxCap) + ctx.lineCap = ctxCap = cap; // (‿|‿) + if (dash != ctxDash) + ctx.setLineDash(ctxDash = dash); + } + + function setFontStyle(font, fill, align, baseline) { + if (fill != ctxFill) + ctx.fillStyle = ctxFill = fill; + if (font != ctxFont) + ctx.font = ctxFont = font; + if (align != ctxAlign) + ctx.textAlign = ctxAlign = align; + if (baseline != ctxBaseline) + ctx.textBaseline = ctxBaseline = baseline; } function setScales() { @@ -3322,21 +3343,21 @@ function uPlot(opts, data, then) { let strokeStyle = s._stroke; let fillStyle = s._fill; - let { stroke, fill, clip, flags } = s._paths; + let { stroke, fill, clip: gapsClip, flags } = s._paths; + let boundsClip = null; let width = roundDec(s.width * pxRatio, 3); let offset = (width % 2) / 2; if (_points && fillStyle == null) fillStyle = width > 0 ? "#fff" : strokeStyle; - ctx.globalAlpha = s.alpha; + if (ctxAlpha != s.alpha) + ctx.globalAlpha = ctxAlpha = s.alpha; let _pxAlign = s.pxAlign == 1; _pxAlign && ctx.translate(offset, offset); - ctx.save(); - if (!_points) { let lft = plotLft, top = plotTop, @@ -3353,26 +3374,23 @@ function uPlot(opts, data, then) { hgt += halfWid; } - ctx.beginPath(); - ctx.rect(lft, top, wid, hgt); - ctx.clip(); + boundsClip = new Path2D(); + boundsClip.rect(lft, top, wid, hgt); } - clip && ctx.clip(clip); - + // the points pathbuilder's gapsClip is its boundsClip, since points dont need gaps clipping, and bounds depend on point size if (_points) - strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, null, flags); + strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags, gapsClip, null, null); else - fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags); - - ctx.restore(); + fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags, boundsClip, gapsClip); _pxAlign && ctx.translate(-offset, -offset); - ctx.globalAlpha = 1; + if (ctxAlpha != 1) + ctx.globalAlpha = ctxAlpha = 1; } - function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags) { + function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip) { let didStrokeFill = false; // for all bands where this series is the top edge, create upwards clips using the bottom edges @@ -3382,49 +3400,51 @@ function uPlot(opts, data, then) { if (b.series[0] == si) { let lowerEdge = series[b.series[1]]; - let clip = (lowerEdge._paths || EMPTY_OBJ).band; - - ctx.save(); + let bandClip = (lowerEdge._paths || EMPTY_OBJ).band; let _fillStyle = null; // hasLowerEdge? - if (lowerEdge.show && clip) + if (lowerEdge.show && bandClip) _fillStyle = b.fill(self, bi) || fillStyle; else - clip = null; - - strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, clip, flags); + bandClip = null; - ctx.restore(); + strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, bandClip); didStrokeFill = true; } }); if (!didStrokeFill) - strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, null, flags); + strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, null); } const CLIP_FILL_STROKE = BAND_CLIP_FILL | BAND_CLIP_STROKE; - function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, clip, flags) { + function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, bandClip) { setCtxStyle(strokeStyle, lineWidth, lineDash, lineCap, fillStyle); - if (clip) { + if (boundsClip || gapsClip || bandClip) { + ctx.save(); + boundsClip && ctx.clip(boundsClip); + gapsClip && ctx.clip(gapsClip); + } + + if (bandClip) { if ((flags & CLIP_FILL_STROKE) == CLIP_FILL_STROKE) { - ctx.clip(clip); + ctx.clip(bandClip); doFill(fillStyle, fillPath); doStroke(strokeStyle, strokePath, lineWidth); } else if (flags & BAND_CLIP_STROKE) { doFill(fillStyle, fillPath); - ctx.clip(clip); + ctx.clip(bandClip); doStroke(strokeStyle, strokePath, lineWidth); } else if (flags & BAND_CLIP_FILL) { ctx.save(); - ctx.clip(clip); + ctx.clip(bandClip); doFill(fillStyle, fillPath); ctx.restore(); doStroke(strokeStyle, strokePath, lineWidth); @@ -3434,6 +3454,9 @@ function uPlot(opts, data, then) { doFill(fillStyle, fillPath); doStroke(strokeStyle, strokePath, lineWidth); } + + if (boundsClip || gapsClip || bandClip) + ctx.restore(); } function doStroke(strokeStyle, strokePath, lineWidth) { @@ -3441,7 +3464,7 @@ function uPlot(opts, data, then) { } function doFill(fillStyle, fillPath) { - fillStyle && fillPath && ctx.fill(fillPath); + fillStyle && fillPath && ctx.fill(fillPath); } function getIncrSpace(axisIdx, min, max, fullDim) { @@ -3465,7 +3488,7 @@ function uPlot(opts, data, then) { pxAlign == 1 && ctx.translate(offset, offset); - setCtxStyle(stroke, width, dash, cap); + setCtxStyle(stroke, width, dash, cap, stroke); ctx.beginPath(); @@ -3480,18 +3503,17 @@ function uPlot(opts, data, then) { x1 = pos1; } - offs.forEach((off, i) => { - if (filts[i] == null) - return; - - if (ori == 0) - x0 = x1 = off; - else - y0 = y1 = off; + for (let i = 0; i < offs.length; i++) { + if (filts[i] != null) { + if (ori == 0) + x0 = x1 = offs[i]; + else + y0 = y1 = offs[i]; - ctx.moveTo(x0, y0); - ctx.lineTo(x1, y1); - }); + ctx.moveTo(x0, y0); + ctx.lineTo(x1, y1); + } + } ctx.stroke(); @@ -3577,7 +3599,9 @@ function uPlot(opts, data, then) { } function drawAxesGrid() { - axes.forEach((axis, i) => { + for (let i = 0; i < axes.length; i++) { + let axis = axes[i]; + if (!axis.show || !axis._show) return; @@ -3595,6 +3619,8 @@ function uPlot(opts, data, then) { let shiftAmt = axis.labelGap * shiftDir; let baseLpos = round((axis._lpos + shiftAmt) * pxRatio); + setFontStyle(axis.labelFont[0], fillStyle, "center", side == 2 ? TOP : BOTTOM); + ctx.save(); if (ori == 1) { @@ -3612,11 +3638,6 @@ function uPlot(opts, data, then) { 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(); @@ -3653,41 +3674,51 @@ function uPlot(opts, data, then) { y = ori == 0 ? finalPos : 0; x = ori == 1 ? finalPos : 0; - ctx.font = axis.font[0]; - ctx.fillStyle = fillStyle; - ctx.textAlign = axis.align == 1 ? LEFT : + let font = axis.font[0]; + let 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 || + let textBaseline = angle || ori == 1 ? "middle" : side == 2 ? TOP : BOTTOM; + setFontStyle(font, fillStyle, textAlign, textBaseline); + let lineHeight = axis.font[1] * lineMult; let canOffs = _splits.map(val => pxRound(getPos(val, scale, plotDim, plotOff))); - axis._values.forEach((val, i) => { - if (val == null) - return; + let _values = axis._values; - if (ori == 0) - x = canOffs[i]; - else - y = canOffs[i]; - - (""+val).split(/\n/gm).forEach((text, j) => { - if (angle) { - ctx.save(); - ctx.translate(x, y + j * lineHeight); - ctx.rotate(angle); - ctx.fillText(text, 0, 0); - ctx.restore(); - } + for (let i = 0; i < _values.length; i++) { + let val = _values[i]; + + if (val != null) { + if (ori == 0) + x = canOffs[i]; else - ctx.fillText(text, x, y + j * lineHeight); - }); - }); + y = canOffs[i]; + + val = "" + val; + + let _parts = val.indexOf("\n") == -1 ? [val] : val.split(/\n/gm); + + for (let j = 0; j < _parts.length; j++) { + let text = _parts[j]; + + if (angle) { + ctx.save(); + ctx.translate(x, y + j * lineHeight); // can this be replaced with position math? + ctx.rotate(angle); // can this be done once? + ctx.fillText(text, 0, 0); + ctx.restore(); + } + else + ctx.fillText(text, x, y + j * lineHeight); + } + } + } // ticks if (ticks.show) { @@ -3722,7 +3753,7 @@ function uPlot(opts, data, then) { grid.cap, ); } - }); + } fire("drawAxes"); } diff --git a/dist/uPlot.iife.js b/dist/uPlot.iife.js index 9f7a3325..2586efa8 100644 --- a/dist/uPlot.iife.js +++ b/dist/uPlot.iife.js @@ -10,34 +10,34 @@ var uPlot = (function () { 'use strict'; - var FEAT_TIME = true; + const FEAT_TIME = true; // binary search for index of closest value function closestIdx(num, arr, lo, hi) { - var mid; + let mid; lo = lo || 0; hi = hi || arr.length - 1; - var bitwise = hi <= 2147483647; + let bitwise = hi <= 2147483647; while (hi - lo > 1) { mid = bitwise ? (lo + hi) >> 1 : floor((lo + hi) / 2); if (arr[mid] < num) - { lo = mid; } + lo = mid; else - { hi = mid; } + hi = mid; } if (num - arr[lo] <= arr[hi] - num) - { return lo; } + return lo; return hi; } function nonNullIdx(data, _i0, _i1, dir) { - for (var i = dir == 1 ? _i0 : _i1; i >= _i0 && i <= _i1; i += dir) { + for (let i = dir == 1 ? _i0 : _i1; i >= _i0 && i <= _i1; i += dir) { if (data[i] != null) - { return i; } + return i; } return -1; @@ -46,8 +46,8 @@ var uPlot = (function () { function getMinMax(data, _i0, _i1, sorted) { // console.log("getMinMax()"); - var _min = inf; - var _max = -inf; + let _min = inf; + let _max = -inf; if (sorted == 1) { _min = data[_i0]; @@ -58,7 +58,7 @@ var uPlot = (function () { _max = data[_i0]; } else { - for (var i = _i0; i <= _i1; i++) { + for (let i = _i0; i <= _i1; i++) { if (data[i] != null) { _min = min(_min, data[i]); _max = max(_max, data[i]); @@ -72,10 +72,10 @@ var uPlot = (function () { function getMinMaxLog(data, _i0, _i1) { // console.log("getMinMax()"); - var _min = inf; - var _max = -inf; + let _min = inf; + let _max = -inf; - for (var i = _i0; i <= _i1; i++) { + for (let i = _i0; i <= _i1; i++) { if (data[i] > 0) { _min = min(_min, data[i]); _max = max(_max, data[i]); @@ -84,10 +84,11 @@ var uPlot = (function () { return [ _min == inf ? 1 : _min, - _max == -inf ? 10 : _max ]; + _max == -inf ? 10 : _max, + ]; } - var _fixedTuple = [0, 0]; + const _fixedTuple = [0, 0]; function fixIncr(minIncr, maxIncr, minExp, maxExp) { _fixedTuple[0] = minExp < 0 ? roundDec(minIncr, -minExp) : minIncr; @@ -96,9 +97,9 @@ var uPlot = (function () { } function rangeLog(min, max, base, fullMags) { - var minSign = sign(min); + let minSign = sign(min); - var logFn = base == 10 ? log10 : log2; + let logFn = base == 10 ? log10 : log2; if (min == max) { if (minSign == -1) { @@ -111,7 +112,7 @@ var uPlot = (function () { } } - var minExp, maxExp, minMaxIncrs; + let minExp, maxExp, minMaxIncrs; if (fullMags) { minExp = floor(logFn(min)); @@ -136,31 +137,31 @@ var uPlot = (function () { } function rangeAsinh(min, max, base, fullMags) { - var minMax = rangeLog(min, max, base, fullMags); + let minMax = rangeLog(min, max, base, fullMags); if (min == 0) - { minMax[0] = 0; } + minMax[0] = 0; if (max == 0) - { minMax[1] = 0; } + minMax[1] = 0; return minMax; } - var rangePad = 0.1; + const rangePad = 0.1; - var autoRangePart = { + const autoRangePart = { mode: 3, pad: rangePad, }; - var _eqRangePart = { + const _eqRangePart = { pad: 0, soft: null, mode: 0, }; - var _eqRange = { + const _eqRange = { min: _eqRangePart, max: _eqRangePart, }; @@ -169,7 +170,7 @@ var uPlot = (function () { // 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); } + return _rangeNum(_min, _max, mult); _eqRangePart.pad = mult; _eqRangePart.soft = extra ? 0 : null; @@ -184,22 +185,22 @@ var uPlot = (function () { } function _rangeNum(_min, _max, cfg) { - var cmin = cfg.min; - var cmax = cfg.max; + let cmin = cfg.min; + let cmax = cfg.max; - var padMin = ifNull(cmin.pad, 0); - var padMax = ifNull(cmax.pad, 0); + let padMin = ifNull(cmin.pad, 0); + let padMax = ifNull(cmax.pad, 0); - var hardMin = ifNull(cmin.hard, -inf); - var hardMax = ifNull(cmax.hard, inf); + let hardMin = ifNull(cmin.hard, -inf); + let hardMax = ifNull(cmax.hard, inf); - var softMin = ifNull(cmin.soft, inf); - var softMax = ifNull(cmax.soft, -inf); + let softMin = ifNull(cmin.soft, inf); + let softMax = ifNull(cmax.soft, -inf); - var softMinMode = ifNull(cmin.mode, 0); - var softMaxMode = ifNull(cmax.mode, 0); + let softMinMode = ifNull(cmin.mode, 0); + let softMaxMode = ifNull(cmax.mode, 0); - var delta = _max - _min; + let delta = _max - _min; // this handles situations like 89.7, 89.69999999999999 // by assuming 0.001x deltas are precision errors @@ -216,61 +217,53 @@ var uPlot = (function () { delta = 1e-9; if (softMinMode == 2 && softMin != inf) - { padMin = 0; } + padMin = 0; if (softMaxMode == 2 && softMax != -inf) - { padMax = 0; } + padMax = 0; } } - var nonZeroDelta = delta || abs(_max) || 1e3; - var mag = log10(nonZeroDelta); - var base = pow(10, floor(mag)); + let nonZeroDelta = delta || abs(_max) || 1e3; + let mag = log10(nonZeroDelta); + let base = pow(10, floor(mag)); - var _padMin = nonZeroDelta * (delta == 0 ? (_min == 0 ? .1 : 1) : padMin); - var _newMin = roundDec(incrRoundDn(_min - _padMin, base/10), 9); - var _softMin = _min >= softMin && (softMinMode == 1 || softMinMode == 3 && _newMin <= softMin || softMinMode == 2 && _newMin >= softMin) ? softMin : inf; - var minLim = max(hardMin, _newMin < _softMin && _min >= _softMin ? _softMin : min(_softMin, _newMin)); + let _padMin = nonZeroDelta * (delta == 0 ? (_min == 0 ? .1 : 1) : padMin); + let _newMin = roundDec(incrRoundDn(_min - _padMin, base/10), 9); + let _softMin = _min >= softMin && (softMinMode == 1 || softMinMode == 3 && _newMin <= softMin || softMinMode == 2 && _newMin >= softMin) ? softMin : inf; + let minLim = max(hardMin, _newMin < _softMin && _min >= _softMin ? _softMin : min(_softMin, _newMin)); - var _padMax = nonZeroDelta * (delta == 0 ? (_max == 0 ? .1 : 1) : padMax); - var _newMax = roundDec(incrRoundUp(_max + _padMax, base/10), 9); - var _softMax = _max <= softMax && (softMaxMode == 1 || softMaxMode == 3 && _newMax >= softMax || softMaxMode == 2 && _newMax <= softMax) ? softMax : -inf; - var maxLim = min(hardMax, _newMax > _softMax && _max <= _softMax ? _softMax : max(_softMax, _newMax)); + let _padMax = nonZeroDelta * (delta == 0 ? (_max == 0 ? .1 : 1) : padMax); + let _newMax = roundDec(incrRoundUp(_max + _padMax, base/10), 9); + let _softMax = _max <= softMax && (softMaxMode == 1 || softMaxMode == 3 && _newMax >= softMax || softMaxMode == 2 && _newMax <= softMax) ? softMax : -inf; + let maxLim = min(hardMax, _newMax > _softMax && _max <= _softMax ? _softMax : max(_softMax, _newMax)); if (minLim == maxLim && minLim == 0) - { maxLim = 100; } + maxLim = 100; return [minLim, maxLim]; } // alternative: https://stackoverflow.com/a/2254896 - var fmtNum = new Intl.NumberFormat(navigator.language).format; - - var M = Math; - - var PI = M.PI; - 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; - var sign = M.sign; - var log10 = M.log10; - var log2 = M.log2; - 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); - }; - - var inf = Infinity; + const fmtNum = new Intl.NumberFormat(navigator.language).format; + + const M = Math; + + const PI = M.PI; + const abs = M.abs; + const floor = M.floor; + const round = M.round; + const ceil = M.ceil; + const min = M.min; + const max = M.max; + const pow = M.pow; + const sign = M.sign; + const log10 = M.log10; + const log2 = M.log2; + const sinh = (v, linthresh = 1) => M.sinh(v / linthresh); + const asinh = (v, linthresh = 1) => M.asinh(v / linthresh); + + const inf = Infinity; function incrRound(num, incr) { return round(num/incr)*incr; @@ -284,15 +277,15 @@ var uPlot = (function () { return typeof v == "function" ? v : () => v; } - var retArg0 = _0 => _0; + const retArg0 = _0 => _0; - var retArg1 = (_0, _1) => _1; + const retArg1 = (_0, _1) => _1; - var retNull = _ => null; + const retNull = _ => null; - var retTrue = _ => true; + const retTrue = _ => true; - var retEq = (a, b) => a == b; + const retEq = (a, b) => a == b; function incrRoundUp(num, incr) { return ceil(num/incr)*incr; @@ -303,28 +296,28 @@ var uPlot = (function () { } function roundDec(val, dec) { - return round(val * (dec = Math.pow( 10, dec ))) / dec; + return round(val * (dec = 10**dec)) / dec; } - var fixedDec = new Map(); + const fixedDec = new Map(); function guessDec(num) { return ((""+num).split(".")[1] || "").length; } function genIncrs(base, minExp, maxExp, mults) { - var incrs = []; + let incrs = []; - var multDec = mults.map(guessDec); + let multDec = mults.map(guessDec); - for (var exp = minExp; exp < maxExp; exp++) { - var expa = abs(exp); - var mag = roundDec(pow(base, exp), expa); + for (let exp = minExp; exp < maxExp; exp++) { + let expa = abs(exp); + let 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); + for (let i = 0; i < mults.length; i++) { + let _incr = mults[i] * mag; + let dec = (_incr >= 0 && exp >= 0 ? 0 : expa) + (exp >= multDec[i] ? 0 : multDec[i]); + let incr = roundDec(_incr, dec); incrs.push(incr); fixedDec.set(incr, dec); } @@ -335,21 +328,22 @@ var uPlot = (function () { //export const assign = Object.assign; - var EMPTY_OBJ = {}; + const EMPTY_OBJ = {}; + const EMPTY_ARR = []; - var nullNullTuple = [null, null]; + const nullNullTuple = [null, null]; - var isArr = Array.isArray; + const isArr = Array.isArray; function isStr(v) { return typeof v == 'string'; } function isObj(v) { - var is = false; + let is = false; if (v != null) { - var c = v.constructor; + let c = v.constructor; is = c == null || c == Object; } @@ -363,32 +357,32 @@ var uPlot = (function () { function copy(o, _isObj) { _isObj = _isObj || isObj; - var out; + let out; if (isArr(o)) - { out = o.map(v => copy(v, _isObj)); } + out = o.map(v => copy(v, _isObj)); else if (_isObj(o)) { out = {}; for (var k in o) - { out[k] = copy(o[k], _isObj); } + out[k] = copy(o[k], _isObj); } else - { out = o; } + out = o; return out; } function assign(targ) { - var args = arguments; + let args = arguments; - for (var i = 1; i < args.length; i++) { - var src = args[i]; + for (let i = 1; i < args.length; i++) { + let src = args[i]; - for (var key in src) { + for (let key in src) { if (isObj(targ[key])) - { assign(targ[key], copy(src[key])); } + assign(targ[key], copy(src[key])); else - { targ[key] = copy(src[key]); } + targ[key] = copy(src[key]); } } @@ -396,23 +390,23 @@ var uPlot = (function () { } // nullModes - 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 + const NULL_REMOVE = 0; // nulls are converted to undefined (e.g. for spanGaps: true) + const NULL_RETAIN = 1; // nulls are retained, with alignment artifacts set to undefined (default) + const NULL_EXPAND = 2; // nulls are expanded to include any adjacent alignment artifacts // sets undefined values to nulls when adjacent to existing nulls (minesweeper) function nullExpand(yVals, nullIdxs, alignedLen) { - for (var i = 0, xi = (void 0), lastNullIdx = -1; i < nullIdxs.length; i++) { - var nullIdx = nullIdxs[i]; + for (let i = 0, xi, lastNullIdx = -1; i < nullIdxs.length; i++) { + let nullIdx = nullIdxs[i]; if (nullIdx > lastNullIdx) { xi = nullIdx - 1; while (xi >= 0 && yVals[xi] == null) - { yVals[xi--] = null; } + yVals[xi--] = null; xi = nullIdx + 1; while (xi < alignedLen && yVals[xi] == null) - { yVals[lastNullIdx = xi++] = null; } + yVals[lastNullIdx = xi++] = null; } } } @@ -420,53 +414,53 @@ var uPlot = (function () { // nullModes is a tables-matched array indicating how to treat nulls in each series // output is sorted ASC on the joined field (table[0]) and duplicate join values are collapsed function join(tables, nullModes) { - var xVals = new Set(); + let xVals = new Set(); - for (var ti = 0; ti < tables.length; ti++) { - var t = tables[ti]; - var xs = t[0]; - var len = xs.length; + for (let ti = 0; ti < tables.length; ti++) { + let t = tables[ti]; + let xs = t[0]; + let len = xs.length; - for (var i = 0; i < len; i++) - { xVals.add(xs[i]); } + for (let i = 0; i < len; i++) + xVals.add(xs[i]); } - var data = [Array.from(xVals).sort((a, b) => a - b)]; + let data = [Array.from(xVals).sort((a, b) => a - b)]; - var alignedLen = data[0].length; + let alignedLen = data[0].length; - var xIdxs = new Map(); + let xIdxs = new Map(); - for (var i$1 = 0; i$1 < alignedLen; i$1++) - { xIdxs.set(data[0][i$1], i$1); } + for (let i = 0; i < alignedLen; i++) + xIdxs.set(data[0][i], i); - for (var ti$1 = 0; ti$1 < tables.length; ti$1++) { - var t$1 = tables[ti$1]; - var xs$1 = t$1[0]; + for (let ti = 0; ti < tables.length; ti++) { + let t = tables[ti]; + let xs = t[0]; - for (var si = 1; si < t$1.length; si++) { - var ys = t$1[si]; + for (let si = 1; si < t.length; si++) { + let ys = t[si]; - var yVals = Array(alignedLen).fill(undefined); + let yVals = Array(alignedLen).fill(undefined); - var nullMode = nullModes ? nullModes[ti$1][si] : NULL_RETAIN; + let nullMode = nullModes ? nullModes[ti][si] : NULL_RETAIN; - var nullIdxs = []; + let nullIdxs = []; - for (var i$2 = 0; i$2 < ys.length; i$2++) { - var yVal = ys[i$2]; - var alignedIdx = xIdxs.get(xs$1[i$2]); + for (let i = 0; i < ys.length; i++) { + let yVal = ys[i]; + let alignedIdx = xIdxs.get(xs[i]); if (yVal === null) { if (nullMode != NULL_REMOVE) { yVals[alignedIdx] = yVal; if (nullMode == NULL_EXPAND) - { nullIdxs.push(alignedIdx); } + nullIdxs.push(alignedIdx); } } else - { yVals[alignedIdx] = yVal; } + yVals[alignedIdx] = yVal; } nullExpand(yVals, nullIdxs, alignedLen); @@ -478,63 +472,63 @@ var uPlot = (function () { return data; } - var microTask = typeof queueMicrotask == "undefined" ? fn => Promise.resolve().then(fn) : queueMicrotask; - - var WIDTH = "width"; - var HEIGHT = "height"; - var TOP = "top"; - var BOTTOM = "bottom"; - var LEFT = "left"; - var RIGHT = "right"; - var hexBlack = "#000"; - var transparent = hexBlack + "0"; - - var mousemove = "mousemove"; - var mousedown = "mousedown"; - var mouseup = "mouseup"; - var mouseenter = "mouseenter"; - var mouseleave = "mouseleave"; - var dblclick = "dblclick"; - var resize = "resize"; - var scroll = "scroll"; - - var change = "change"; - var ddpxchange = "dppxchange"; - - var pre = "u-"; - - var UPLOT = "uplot"; - var ORI_HZ = pre + "hz"; - var ORI_VT = pre + "vt"; - 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; - var pxRatio; - - var query; + const microTask = typeof queueMicrotask == "undefined" ? fn => Promise.resolve().then(fn) : queueMicrotask; + + const WIDTH = "width"; + const HEIGHT = "height"; + const TOP = "top"; + const BOTTOM = "bottom"; + const LEFT = "left"; + const RIGHT = "right"; + const hexBlack = "#000"; + const transparent = hexBlack + "0"; + + const mousemove = "mousemove"; + const mousedown = "mousedown"; + const mouseup = "mouseup"; + const mouseenter = "mouseenter"; + const mouseleave = "mouseleave"; + const dblclick = "dblclick"; + const resize = "resize"; + const scroll = "scroll"; + + const change = "change"; + const ddpxchange = "dppxchange"; + + const pre = "u-"; + + const UPLOT = "uplot"; + const ORI_HZ = pre + "hz"; + const ORI_VT = pre + "vt"; + const TITLE = pre + "title"; + const WRAP = pre + "wrap"; + const UNDER = pre + "under"; + const OVER = pre + "over"; + const OFF = pre + "off"; + const SELECT = pre + "select"; + const CURSOR_X = pre + "cursor-x"; + const CURSOR_Y = pre + "cursor-y"; + const CURSOR_PT = pre + "cursor-pt"; + const LEGEND = pre + "legend"; + const LEGEND_LIVE = pre + "live"; + const LEGEND_INLINE = pre + "inline"; + const LEGEND_THEAD = pre + "thead"; + const LEGEND_SERIES = pre + "series"; + const LEGEND_MARKER = pre + "marker"; + const LEGEND_LABEL = pre + "label"; + const LEGEND_VALUE = pre + "value"; + + const doc = document; + const win = window; + let pxRatio; + + let 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)")); + 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)); @@ -542,13 +536,13 @@ var uPlot = (function () { function addClass(el, c) { if (c != null) { - var cl = el.classList; + let cl = el.classList; !cl.contains(c) && cl.add(c); } } function remClass(el, c) { - var cl = el.classList; + let cl = el.classList; cl.contains(c) && cl.remove(c); } @@ -557,13 +551,13 @@ var uPlot = (function () { } function placeTag(tag, cls, targ, refEl) { - var el = doc.createElement(tag); + let el = doc.createElement(tag); if (cls != null) - { addClass(el, cls); } + addClass(el, cls); if (targ != null) - { targ.insertBefore(el, refEl); } + targ.insertBefore(el, refEl); return el; } @@ -572,28 +566,28 @@ var uPlot = (function () { return placeTag("div", cls, targ); } - var xformCache = new WeakMap(); + const xformCache = new WeakMap(); function trans(el, xPos, yPos, xMax, yMax) { - var xform = "translate(" + xPos + "px," + yPos + "px)"; - var xformOld = xformCache.get(el); + let xform = "translate(" + xPos + "px," + yPos + "px)"; + let xformOld = xformCache.get(el); if (xform != xformOld) { el.style.transform = xform; xformCache.set(el, xform); if (xPos < 0 || yPos < 0 || xPos > xMax || yPos > yMax) - { addClass(el, OFF); } + addClass(el, OFF); else - { remClass(el, OFF); } + remClass(el, OFF); } } - var colorCache = new WeakMap(); + const colorCache = new WeakMap(); function color(el, background, borderColor) { - var newColor = background + borderColor; - var oldColor = colorCache.get(el); + let newColor = background + borderColor; + let oldColor = colorCache.get(el); if (newColor != oldColor) { colorCache.set(el, newColor); @@ -602,8 +596,8 @@ var uPlot = (function () { } } - var evOpts = {passive: true}; - var evOpts2 = assign({capture: true}, evOpts); + const evOpts = {passive: true}; + const evOpts2 = assign({capture: true}, evOpts); function on(ev, el, cb, capt) { el.addEventListener(ev, cb, capt ? evOpts2 : evOpts); @@ -615,7 +609,7 @@ var uPlot = (function () { setPxRatio(); - var months = [ + const months = [ "January", "February", "March", @@ -627,26 +621,28 @@ var uPlot = (function () { "September", "October", "November", - "December" ]; + "December", + ]; - var days = [ + const days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", - "Saturday" ]; + "Saturday", + ]; function slice3(str) { return str.slice(0, 3); } - var days3 = days.map(slice3); + const days3 = days.map(slice3); - var months3 = months.map(slice3); + const months3 = months.map(slice3); - var engNames = { + const engNames = { MMMM: months, MMM: months3, WWWW: days, @@ -673,7 +669,7 @@ var uPlot = (function () { } */ - var subs = { + const subs = { // 2019 YYYY: d => d.getFullYear(), // 19 @@ -699,7 +695,7 @@ var uPlot = (function () { // 3 H: d => d.getHours(), // 9 (12hr, unpadded) - h: d => {var h = d.getHours(); return h == 0 ? 12 : h > 12 ? h - 12 : h;}, + h: d => {let h = d.getHours(); return h == 0 ? 12 : h > 12 ? h - 12 : h;}, // AM AA: d => d.getHours() >= 12 ? 'PM' : 'AM', // am @@ -720,34 +716,34 @@ var uPlot = (function () { function fmtDate(tpl, names) { names = names || engNames; - var parts = []; + let parts = []; - var R = /\{([a-z]+)\}|[^{]+/gi, m; + let R = /\{([a-z]+)\}|[^{]+/gi, m; while (m = R.exec(tpl)) - { parts.push(m[0][0] == '{' ? subs[m[1]] : m[0]); } + parts.push(m[0][0] == '{' ? subs[m[1]] : m[0]); return d => { - var out = ''; + let out = ''; - for (var i = 0; i < parts.length; i++) - { out += typeof parts[i] == "string" ? parts[i] : parts[i](d, names); } + for (let 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; + const 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; + let date2; // perf optimization if (tz == 'UTC' || tz == 'Etc/UTC') - { date2 = new Date(+date + date.getTimezoneOffset() * 6e4); } + date2 = new Date(+date + date.getTimezoneOffset() * 6e4); else if (tz == localTz) - { date2 = date; } + date2 = date; else { date2 = new Date(date.toLocaleString('en-US', {timeZone: tz})); date2.setMilliseconds(date.getMilliseconds()); @@ -760,39 +756,39 @@ var uPlot = (function () { // default formatters: - var onlyWhole = v => v % 1 == 0; + const onlyWhole = v => v % 1 == 0; - var allMults = [1,2,2.5,5]; + const 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); + const decIncrs = genIncrs(10, -16, 0, allMults); // 1, 2, 2.5, 5, 10, 20, 25, 50... - var oneIncrs = genIncrs(10, 0, 16, allMults); + const oneIncrs = genIncrs(10, 0, 16, allMults); // 1, 2, 5, 10, 20, 25, 50... - var wholeIncrs = oneIncrs.filter(onlyWhole); + const wholeIncrs = oneIncrs.filter(onlyWhole); - var numIncrs = decIncrs.concat(oneIncrs); + const numIncrs = decIncrs.concat(oneIncrs); - var NL = "\n"; + const NL = "\n"; - var yyyy = "{YYYY}"; - var NLyyyy = NL + yyyy; - var md = "{M}/{D}"; - var NLmd = NL + md; - var NLmdyy = NLmd + "/{YY}"; + const yyyy = "{YYYY}"; + const NLyyyy = NL + yyyy; + const md = "{M}/{D}"; + const NLmd = NL + md; + const NLmdyy = NLmd + "/{YY}"; - var aa = "{aa}"; - var hmm = "{h}:{mm}"; - var hmmaa = hmm + aa; - var NLhmmaa = NL + hmmaa; - var ss = ":{ss}"; + const aa = "{aa}"; + const hmm = "{h}:{mm}"; + const hmmaa = hmm + aa; + const NLhmmaa = NL + hmmaa; + const ss = ":{ss}"; - var _ = null; + const _ = null; function genTimeStuffs(ms) { - var s = ms * 1e3, + let s = ms * 1e3, m = s * 60, h = m * 60, d = h * 24, @@ -800,9 +796,9 @@ var uPlot = (function () { 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); + let subSecIncrs = ms == 1 ? genIncrs(10, 0, 3, allMults).filter(onlyWhole) : genIncrs(10, -3, 0, allMults); - var timeIncrs = subSecIncrs.concat([ + let timeIncrs = subSecIncrs.concat([ // minute divisors (# of secs) s, s * 5, @@ -848,13 +844,14 @@ var uPlot = (function () { y * 10, y * 25, y * 50, - y * 100 ]); + 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 = [ + const _timeAxisStamps = [ // tick incr default year month day hour min sec mode [y, yyyy, _, _, _, _, _, _, 1], [d * 28, "{MMM}", NLyyyy, _, _, _, _, _, 1], @@ -862,7 +859,8 @@ var uPlot = (function () { [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] ]; + [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/ @@ -870,80 +868,80 @@ var uPlot = (function () { // https://www.epochconverter.com/timezones function timeAxisSplits(tzDate) { return (self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace) => { - var splits = []; - var isYr = foundIncr >= y; - var isMo = foundIncr >= mo && foundIncr < y; + let splits = []; + let isYr = foundIncr >= y; + let isMo = foundIncr >= mo && foundIncr < y; // get the timezone-adjusted date - var minDate = tzDate(scaleMin); - var minDateTs = roundDec(minDate * ms, 3); + let minDate = tzDate(scaleMin); + let minDateTs = roundDec(minDate * ms, 3); // get ts of 12am (this lands us at or before the original scaleMin) - var minMin = mkDate(minDate.getFullYear(), isYr ? 0 : minDate.getMonth(), isMo || isYr ? 1 : minDate.getDate()); - var minMinTs = roundDec(minMin * ms, 3); + let minMin = mkDate(minDate.getFullYear(), isYr ? 0 : minDate.getMonth(), isMo || isYr ? 1 : minDate.getDate()); + let minMinTs = roundDec(minMin * ms, 3); if (isMo || isYr) { - var moIncr = isMo ? foundIncr / mo : 0; - var yrIncr = isYr ? foundIncr / y : 0; + let moIncr = isMo ? foundIncr / mo : 0; + let yrIncr = isYr ? foundIncr / y : 0; // let tzOffset = scaleMin - minDateTs; // needed? - var split = minDateTs == minMinTs ? minDateTs : roundDec(mkDate(minMin.getFullYear() + yrIncr, minMin.getMonth() + moIncr, 1) * ms, 3); - var splitDate = new Date(round(split / ms)); - var baseYear = splitDate.getFullYear(); - var baseMonth = splitDate.getMonth(); + let split = minDateTs == minMinTs ? minDateTs : roundDec(mkDate(minMin.getFullYear() + yrIncr, minMin.getMonth() + moIncr, 1) * ms, 3); + let splitDate = new Date(round(split / ms)); + let baseYear = splitDate.getFullYear(); + let baseMonth = splitDate.getMonth(); - for (var i = 0; split <= scaleMax; i++) { - var next = mkDate(baseYear + yrIncr * i, baseMonth + moIncr * i, 1); - var offs = next - tzDate(roundDec(next * ms, 3)); + for (let i = 0; split <= scaleMax; i++) { + let next = mkDate(baseYear + yrIncr * i, baseMonth + moIncr * i, 1); + let offs = next - tzDate(roundDec(next * ms, 3)); split = roundDec((+next + offs) * ms, 3); if (split <= scaleMax) - { splits.push(split); } + 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); + let incr0 = foundIncr >= d ? d : foundIncr; + let tzOffset = floor(scaleMin) - floor(minDateTs); + let split = minMinTs + tzOffset + incrRoundUp(minDateTs - minMinTs, incr0); + splits.push(split); - var date0 = tzDate(split$1); + let date0 = tzDate(split); - var prevHour = date0.getHours() + (date0.getMinutes() / m) + (date0.getSeconds() / h); - var incrHours = foundIncr / h; + let prevHour = date0.getHours() + (date0.getMinutes() / m) + (date0.getSeconds() / h); + let incrHours = foundIncr / h; - var minSpace = self.axes[axisIdx]._space; - var pctSpace = foundSpace / minSpace; + let minSpace = self.axes[axisIdx]._space; + let pctSpace = foundSpace / minSpace; while (1) { - split$1 = roundDec(split$1 + foundIncr, ms == 1 ? 0 : 3); + split = roundDec(split + foundIncr, ms == 1 ? 0 : 3); - if (split$1 > scaleMax) - { break; } + if (split > scaleMax) + break; if (incrHours > 1) { - var expectedHour = floor(roundDec(prevHour + incrHours, 6)) % 24; - var splitDate$1 = tzDate(split$1); - var actualHour = splitDate$1.getHours(); + let expectedHour = floor(roundDec(prevHour + incrHours, 6)) % 24; + let splitDate = tzDate(split); + let actualHour = splitDate.getHours(); - var dstShift = actualHour - expectedHour; + let dstShift = actualHour - expectedHour; if (dstShift > 1) - { dstShift = -1; } + dstShift = -1; - split$1 -= dstShift * h; + split -= 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); + let prevSplit = splits[splits.length - 1]; + let pctIncr = roundDec((split - prevSplit) / foundIncr, 3); if (pctIncr * pctSpace >= .7) - { splits.push(split$1); } + splits.push(split); } else - { splits.push(split$1); } + splits.push(split); } } @@ -954,17 +952,12 @@ var uPlot = (function () { return [ timeIncrs, _timeAxisStamps, - timeAxisSplits ]; + timeAxisSplits, + ]; } - var ref = genTimeStuffs(1); - var timeIncrsMs = ref[0]; - var _timeAxisStampsMs = ref[1]; - var timeAxisSplitsMs = ref[2]; - var ref$1 = genTimeStuffs(1e-3); - var timeIncrsS = ref$1[0]; - var _timeAxisStampsS = ref$1[1]; - var timeAxisSplitsS = ref$1[2]; + const [ timeIncrsMs, _timeAxisStampsMs, timeAxisSplitsMs ] = genTimeStuffs(1); + const [ timeIncrsS, _timeAxisStampsS, timeAxisSplitsS ] = genTimeStuffs(1e-3); // base 2 genIncrs(2, -53, 53, [1]); @@ -990,27 +983,27 @@ var uPlot = (function () { // currently we ignore this for months since they're *nearly* uniform and the added complexity is not worth it function timeAxisVals(tzDate, stamps) { return (self, splits, axisIdx, foundSpace, foundIncr) => { - var s = stamps.find(s => foundIncr >= s[0]) || stamps[stamps.length - 1]; + let s = stamps.find(s => foundIncr >= s[0]) || stamps[stamps.length - 1]; // these track boundaries when a full label is needed again - var prevYear; - var prevMnth; - var prevDate; - var prevHour; - var prevMins; - var prevSecs; + let prevYear; + let prevMnth; + let prevDate; + let prevHour; + let prevMins; + let prevSecs; return splits.map(split => { - var date = tzDate(split); + let date = tzDate(split); - var newYear = date.getFullYear(); - var newMnth = date.getMonth(); - var newDate = date.getDate(); - var newHour = date.getHours(); - var newMins = date.getMinutes(); - var newSecs = date.getSeconds(); + let newYear = date.getFullYear(); + let newMnth = date.getMonth(); + let newDate = date.getDate(); + let newHour = date.getHours(); + let newMins = date.getMinutes(); + let newSecs = date.getSeconds(); - var stamp = ( + let stamp = ( newYear != prevYear && s[2] || newMnth != prevMnth && s[3] || newDate != prevDate && s[4] || @@ -1034,7 +1027,7 @@ var uPlot = (function () { // for when axis.values is defined as a static fmtDate template string function timeAxisVal(tzDate, dateTpl) { - var stamp = fmtDate(dateTpl); + let stamp = fmtDate(dateTpl); return (self, splits, axisIdx, foundSpace, foundIncr) => splits.map(split => stamp(tzDate(split))); } @@ -1045,14 +1038,14 @@ var uPlot = (function () { function timeSeriesStamp(stampCfg, fmtDate) { return fmtDate(stampCfg); } - var _timeSeriesStamp = '{YYYY}-{MM}-{DD} {h}:{mm}{aa}'; + const _timeSeriesStamp = '{YYYY}-{MM}-{DD} {h}:{mm}{aa}'; function timeSeriesVal(tzDate, stamp) { return (self, val) => stamp(tzDate(val)); } function legendStroke(self, seriesIdx) { - var s = self.series[seriesIdx]; + let s = self.series[seriesIdx]; return s.width ? s.stroke(self, seriesIdx) : s.points.width ? s.points.stroke(self, seriesIdx) : null; } @@ -1060,7 +1053,7 @@ var uPlot = (function () { return self.series[seriesIdx].fill(self, seriesIdx); } - var legendOpts = { + const legendOpts = { show: true, live: true, isolate: false, @@ -1077,36 +1070,36 @@ var uPlot = (function () { }; function cursorPointShow(self, si) { - var o = self.cursor.points; + let o = self.cursor.points; - var pt = placeDiv(); + let pt = placeDiv(); - var size = o.size(self, si); + let size = o.size(self, si); setStylePx(pt, WIDTH, size); setStylePx(pt, HEIGHT, size); - var mar = size / -2; + let mar = size / -2; setStylePx(pt, "marginLeft", mar); setStylePx(pt, "marginTop", mar); - var width = o.width(self, si, size); + let width = o.width(self, si, size); width && setStylePx(pt, "borderWidth", width); return pt; } function cursorPointFill(self, si) { - var sp = self.series[si].points; + let sp = self.series[si].points; return sp._fill || sp._stroke; } function cursorPointStroke(self, si) { - var sp = self.series[si].points; + let sp = self.series[si].points; return sp._stroke || sp._fill; } function cursorPointSize(self, si) { - var sp = self.series[si].points; + let sp = self.series[si].points; return ptDia(sp.width, 1); } @@ -1114,7 +1107,7 @@ var uPlot = (function () { return cursorIdx; } - var moveTuple = [0,0]; + const moveTuple = [0,0]; function cursorMove(self, mouseLeft1, mouseTop1) { moveTuple[0] = mouseLeft1; @@ -1132,7 +1125,7 @@ var uPlot = (function () { return handle; } - var cursorOpts = { + const cursorOpts = { show: true, x: true, y: true, @@ -1174,11 +1167,11 @@ var uPlot = (function () { left: -10, top: -10, idx: null, - dataIdx: dataIdx, + dataIdx, idxs: null, }; - var grid = { + const grid = { show: true, stroke: "rgba(0,0,0,0.07)", width: 2, @@ -1186,13 +1179,13 @@ var uPlot = (function () { filter: retArg1, }; - var ticks = assign({}, grid, {size: 10}); + const 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 + const 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"'; + const labelFont = "bold " + font; + const lineMult = 1.5; // font-size multiplier - var xAxisOpts = { + const xAxisOpts = { show: true, scale: "x", stroke: hexBlack, @@ -1201,22 +1194,22 @@ var uPlot = (function () { size: 50, labelGap: 0, labelSize: 30, - labelFont: labelFont, + labelFont, side: 2, // class: "x-vals", // incrs: timeIncrs, // values: timeVals, // filter: retArg1, - grid: grid, - ticks: ticks, - font: font, + grid, + ticks, + font, rotate: 0, }; - var numSeriesLabel = "Value"; - var timeSeriesLabel = "Time"; + const numSeriesLabel = "Value"; + const timeSeriesLabel = "Time"; - var xSeriesOpts = { + const xSeriesOpts = { show: true, scale: "x", auto: false, @@ -1235,41 +1228,41 @@ var uPlot = (function () { } function numAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace, forceMin) { - var splits = []; + let splits = []; - var numDec = fixedDec.get(foundIncr) || 0; + let 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 + for (let val = scaleMin; val <= scaleMax; val = roundDec(val + foundIncr, numDec)) + splits.push(Object.is(val, -0) ? 0 : val); // coalesces -0 return splits; } // this doesnt work for sin, which needs to come off from 0 independently in pos and neg dirs function logAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace, forceMin) { - var splits = []; + const splits = []; - var logBase = self.scales[self.axes[axisIdx].scale].log; + const logBase = self.scales[self.axes[axisIdx].scale].log; - var logFn = logBase == 10 ? log10 : log2; + const logFn = logBase == 10 ? log10 : log2; - var exp = floor(logFn(scaleMin)); + const exp = floor(logFn(scaleMin)); foundIncr = pow(logBase, exp); if (exp < 0) - { foundIncr = roundDec(foundIncr, -exp); } + foundIncr = roundDec(foundIncr, -exp); - var split = scaleMin; + let split = scaleMin; do { splits.push(split); split = roundDec(split + foundIncr, fixedDec.get(foundIncr)); if (split >= foundIncr * logBase) - { foundIncr = split; } + foundIncr = split; } while (split <= scaleMax); @@ -1277,37 +1270,37 @@ var uPlot = (function () { } function asinhAxisSplits(self, axisIdx, scaleMin, scaleMax, foundIncr, foundSpace, forceMin) { - var sc = self.scales[self.axes[axisIdx].scale]; + let sc = self.scales[self.axes[axisIdx].scale]; - var linthresh = sc.asinh; + let 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]; + let posSplits = scaleMax > linthresh ? logAxisSplits(self, axisIdx, max(linthresh, scaleMin), scaleMax, foundIncr) : [linthresh]; + let zero = scaleMax >= 0 && scaleMin <= 0 ? [0] : []; + let negSplits = scaleMin < -linthresh ? logAxisSplits(self, axisIdx, max(linthresh, -scaleMax), -scaleMin, foundIncr): [linthresh]; return negSplits.reverse().map(v => -v).concat(zero, posSplits); } - var RE_ALL = /./; - var RE_12357 = /[12357]/; - var RE_125 = /[125]/; - var RE_1 = /1/; + const RE_ALL = /./; + const RE_12357 = /[12357]/; + const RE_125 = /[125]/; + const RE_1 = /1/; function logAxisValsFilt(self, splits, axisIdx, foundSpace, foundIncr) { - var axis = self.axes[axisIdx]; - var scaleKey = axis.scale; - var sc = self.scales[scaleKey]; + let axis = self.axes[axisIdx]; + let scaleKey = axis.scale; + let sc = self.scales[scaleKey]; if (sc.distr == 3 && sc.log == 2) - { return splits; } + return splits; - var valToPos = self.valToPos; + let valToPos = self.valToPos; - var minSpace = axis._space; + let minSpace = axis._space; - var _10 = valToPos(10, scaleKey); + let _10 = valToPos(10, scaleKey); - var re = ( + let re = ( valToPos(9, scaleKey) - _10 >= minSpace ? RE_ALL : valToPos(7, scaleKey) - _10 >= minSpace ? RE_12357 : valToPos(5, scaleKey) - _10 >= minSpace ? RE_125 : @@ -1321,7 +1314,7 @@ var uPlot = (function () { return val == null ? "" : fmtNum(val); } - var yAxisOpts = { + const yAxisOpts = { show: true, scale: "y", stroke: hexBlack, @@ -1330,46 +1323,44 @@ var uPlot = (function () { size: 50, labelGap: 0, labelSize: 30, - labelFont: labelFont, + labelFont, side: 3, // class: "y-vals", // incrs: numIncrs, // values: (vals, space) => vals, // filter: retArg1, - grid: grid, - ticks: ticks, - font: font, + grid, + ticks, + font, rotate: 0, }; // takes stroke width function ptDia(width, mult) { - var dia = 3 + (width || 1) * 2; + let dia = 3 + (width || 1) * 2; return roundDec(dia * mult, 3); } 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); - - var s = self.series[si]; + let { scale, idxs } = self.series[0]; + let xData = self._data[0]; + let p0 = self.valToPos(xData[idxs[0]], scale, true); + let p1 = self.valToPos(xData[idxs[1]], scale, true); + let dim = abs(p1 - p0); + + let s = self.series[si]; // const dia = ptDia(s.width, pxRatio); - var maxPts = dim / (s.points.space * pxRatio); + let maxPts = dim / (s.points.space * pxRatio); return idxs[1] - idxs[0] <= maxPts; } function seriesFillTo(self, seriesIdx, dataMin, dataMax) { - var scale = self.scales[self.series[seriesIdx].scale]; - var isUpperBandEdge = self.bands && self.bands.some(b => b.series[0] == seriesIdx); + let scale = self.scales[self.series[seriesIdx].scale]; + let isUpperBandEdge = self.bands && self.bands.some(b => b.series[0] == seriesIdx); return scale.distr == 3 || isUpperBandEdge ? scale.min : 0; } - var ySeriesOpts = { + const ySeriesOpts = { scale: "y", auto: true, sorted: 0, @@ -1411,7 +1402,7 @@ var uPlot = (function () { return scaleMin / 10; } - var xScaleOpts = { + const xScaleOpts = { time: FEAT_TIME, auto: true, distr: 1, @@ -1423,49 +1414,49 @@ var uPlot = (function () { ori: 0, }; - var yScaleOpts = assign({}, xScaleOpts, { + const yScaleOpts = assign({}, xScaleOpts, { time: false, ori: 1, }); - var syncs = {}; + const syncs = {}; function _sync(key, opts) { - var s = syncs[key]; + let s = syncs[key]; if (!s) { s = { - key: key, + key, plots: [], - sub: function sub(plot) { + sub(plot) { s.plots.push(plot); }, - unsub: function unsub(plot) { + unsub(plot) { s.plots = s.plots.filter(c => c != plot); }, - pub: function pub(type, self, x, y, w, h, i) { - for (var j = 0; j < s.plots.length; j++) - { s.plots[j] != self && s.plots[j].pub(type, self, x, y, w, h, i); } + pub(type, self, x, y, w, h, i) { + for (let j = 0; j < s.plots.length; j++) + s.plots[j] != self && s.plots[j].pub(type, self, x, y, w, h, i); }, }; if (key != null) - { syncs[key] = s; } + syncs[key] = s; } return s; } - var BAND_CLIP_FILL = 1 << 0; - var BAND_CLIP_STROKE = 1 << 1; + const BAND_CLIP_FILL = 1 << 0; + const BAND_CLIP_STROKE = 1 << 1; function orient(u, seriesIdx, cb) { - var series = u.series[seriesIdx]; - var scales = u.scales; - var bbox = u.bbox; - var scaleX = scales[u.series[0].scale]; + const series = u.series[seriesIdx]; + const scales = u.scales; + const bbox = u.bbox; + const scaleX = scales[u.series[0].scale]; - var dx = u._data[0], + let dx = u._data[0], dy = u._data[seriesIdx], sx = scaleX, sy = scales[series.scale], @@ -1493,7 +1484,7 @@ var uPlot = (function () { lineToH, rectH, arcH, - bezierCurveToH + bezierCurveToH, ) : cb( series, @@ -1511,7 +1502,7 @@ var uPlot = (function () { lineToV, rectV, arcV, - bezierCurveToV + bezierCurveToV, ) ); } @@ -1519,10 +1510,10 @@ var uPlot = (function () { // 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; + const dir = scaleX.dir * (scaleX.ori == 0 ? 1 : -1); + const lineTo = scaleX.ori == 0 ? lineToH : lineToV; - var frIdx, toIdx; + let frIdx, toIdx; if (dir == 1) { frIdx = idx0; @@ -1534,14 +1525,14 @@ var uPlot = (function () { } // path start - var x0 = incrRound(valToPosX(dataX[frIdx], scaleX, xDim, xOff), 0.5); - var y0 = incrRound(valToPosY(dataY[frIdx], scaleY, yDim, yOff), 0.5); + let x0 = incrRound(valToPosX(dataX[frIdx], scaleX, xDim, xOff), 0.5); + let y0 = incrRound(valToPosY(dataY[frIdx], scaleY, yDim, yOff), 0.5); // path end x - var x1 = incrRound(valToPosX(dataX[toIdx], scaleX, xDim, xOff), 0.5); + let x1 = incrRound(valToPosX(dataX[toIdx], scaleX, xDim, xOff), 0.5); // upper y limit - var yLimit = incrRound(valToPosY(scaleY.max, scaleY, yDim, yOff), 0.5); + let yLimit = incrRound(valToPosY(scaleY.max, scaleY, yDim, yOff), 0.5); - var clip = new Path2D(strokePath); + let clip = new Path2D(strokePath); lineTo(clip, x1, yLimit); lineTo(clip, x0, yLimit); @@ -1552,18 +1543,18 @@ var uPlot = (function () { } function clipGaps(gaps, ori, plotLft, plotTop, plotWid, plotHgt) { - var clip = null; + let clip = null; // create clip path (invert gaps and non-gaps) if (gaps.length > 0) { clip = new Path2D(); - var rect = ori == 0 ? rectH : rectV; + const rect = ori == 0 ? rectH : rectV; - var prevGapEnd = plotLft; + let prevGapEnd = plotLft; - for (var i = 0; i < gaps.length; i++) { - var g = gaps[i]; + for (let i = 0; i < gaps.length; i++) { + let g = gaps[i]; if (g[1] > g[0]) { rect(clip, prevGapEnd, plotTop, g[0] - prevGapEnd, plotTop + plotHgt); @@ -1579,12 +1570,12 @@ var uPlot = (function () { } function addGap(gaps, fromX, toX) { - var prevGap = gaps[gaps.length - 1]; + let prevGap = gaps[gaps.length - 1]; if (prevGap && prevGap[0] == fromX) // TODO: gaps must be encoded at stroke widths? - { prevGap[1] = toX; } + prevGap[1] = toX; else - { gaps.push([fromX, toX]); } + gaps.push([fromX, toX]); } function pxRoundGen(pxAlign) { @@ -1608,10 +1599,9 @@ var uPlot = (function () { // 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; + let { pxRound, points } = series; - var moveTo, arc; + let moveTo, arc; if (scaleX.ori == 0) { moveTo = moveToH; @@ -1622,31 +1612,27 @@ var uPlot = (function () { arc = arcV; } - var width = roundDec(points.width * pxRatio, 3); + const width = roundDec(points.width * pxRatio, 3); - var rad = (points.size - points.width) / 2 * pxRatio; - var dia = roundDec(rad * 2, 3); + let rad = (points.size - points.width) / 2 * pxRatio; + let dia = roundDec(rad * 2, 3); - var fill = new Path2D(); - var clip = new Path2D(); + let fill = new Path2D(); + let clip = new Path2D(); - var ref = u.bbox; - var lft = ref.left; - var top = ref.top; - var wid = ref.width; - var hgt = ref.height; + let { left: lft, top: top, width: wid, height: hgt } = u.bbox; rectH(clip, lft - dia, top - dia, wid + dia * 2, - hgt + dia * 2 + hgt + dia * 2, ); - var drawPoint = pi => { + const drawPoint = pi => { if (dataY[pi] != null) { - var x = pxRound(valToPosX(dataX[pi], scaleX, xDim, xOff)); - var y = pxRound(valToPosY(dataY[pi], scaleY, yDim, yOff)); + let x = pxRound(valToPosX(dataX[pi], scaleX, xDim, xOff)); + let y = pxRound(valToPosY(dataY[pi], scaleY, yDim, yOff)); moveTo(fill, x + rad, y); arc(fill, x, y, rad, 0, PI * 2); @@ -1654,16 +1640,16 @@ var uPlot = (function () { }; if (filtIdxs) - { filtIdxs.forEach(drawPoint); } + filtIdxs.forEach(drawPoint); else { - for (var pi = idx0; pi <= idx1; pi++) - { drawPoint(pi); } + for (let pi = idx0; pi <= idx1; pi++) + drawPoint(pi); } return { stroke: width > 0 ? fill : null, - fill: fill, - clip: clip, + fill, + clip, flags: BAND_CLIP_FILL | BAND_CLIP_STROKE, }; }); @@ -1674,24 +1660,24 @@ var uPlot = (function () { return (stroke, accX, minY, maxY, inY, outY) => { if (minY != maxY) { if (inY != minY && outY != minY) - { lineTo(stroke, accX, minY); } + lineTo(stroke, accX, minY); if (inY != maxY && outY != maxY) - { lineTo(stroke, accX, maxY); } + lineTo(stroke, accX, maxY); lineTo(stroke, accX, outY); } }; } - var drawAccH = _drawAcc(lineToH); - var drawAccV = _drawAcc(lineToV); + const drawAccH = _drawAcc(lineToH); + const drawAccV = _drawAcc(lineToV); function linear() { return (u, seriesIdx, idx0, idx1) => { return orient(u, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => { - var pxRound = series.pxRound; + let pxRound = series.pxRound; - var lineTo, drawAcc; + let lineTo, drawAcc; if (scaleX.ori == 0) { lineTo = lineToH; @@ -1702,32 +1688,32 @@ var uPlot = (function () { drawAcc = drawAccV; } - var dir = scaleX.dir * (scaleX.ori == 0 ? 1 : -1); + const dir = scaleX.dir * (scaleX.ori == 0 ? 1 : -1); - var _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL}; - var stroke = _paths.stroke; + const _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL}; + const stroke = _paths.stroke; - var minY = inf, + let minY = inf, maxY = -inf, inY, outY, outX, drawnAtX; - var gaps = []; + let gaps = []; - var accX = pxRound(valToPosX(dataX[dir == 1 ? idx0 : idx1], scaleX, xDim, xOff)); - var accGaps = false; - var prevYNull = false; + let accX = pxRound(valToPosX(dataX[dir == 1 ? idx0 : idx1], scaleX, xDim, xOff)); + let accGaps = false; + let prevYNull = false; // 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); + let lftIdx = nonNullIdx(dataY, idx0, idx1, 1 * dir); + let rgtIdx = nonNullIdx(dataY, idx0, idx1, -1 * dir); + let lftX = incrRound(valToPosX(dataX[lftIdx], scaleX, xDim, xOff), 0.5); + let rgtX = incrRound(valToPosX(dataX[rgtIdx], scaleX, xDim, xOff), 0.5); if (lftX > xOff) - { addGap(gaps, xOff, lftX); } + addGap(gaps, xOff, lftX); - for (var i = dir == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += dir) { - var x = pxRound(valToPosX(dataX[i], scaleX, xDim, xOff)); + for (let i = dir == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += dir) { + let x = pxRound(valToPosX(dataX[i], scaleX, xDim, xOff)); if (x == accX) { if (dataY[i] != null) { @@ -1742,10 +1728,10 @@ var uPlot = (function () { maxY = max(outY, maxY); } else if (dataY[i] === null) - { accGaps = prevYNull = true; } + accGaps = prevYNull = true; } else { - var _addGap = false; + let _addGap = false; if (minY != inf) { drawAcc(stroke, accX, minY, maxY, inY, outY); @@ -1763,7 +1749,7 @@ var uPlot = (function () { // prior pixel can have data but still start a gap if ends with null if (prevYNull && x - accX > 1) - { _addGap = true; } + _addGap = true; prevYNull = false; } @@ -1775,7 +1761,7 @@ var uPlot = (function () { accGaps = true; if (x - accX > 1) - { _addGap = true; } + _addGap = true; } } @@ -1786,15 +1772,15 @@ var uPlot = (function () { } if (minY != inf && minY != maxY && drawnAtX != accX) - { drawAcc(stroke, accX, minY, maxY, inY, outY); } + drawAcc(stroke, accX, minY, maxY, inY, outY); if (rgtX < xOff + xDim) - { addGap(gaps, rgtX, xOff + xDim); } + addGap(gaps, rgtX, xOff + xDim); if (series.fill != null) { - var fill = _paths.fill = new Path2D(stroke); + let fill = _paths.fill = new Path2D(stroke); - var fillTo = pxRound(valToPosY(series.fillTo(u, seriesIdx, series.min, series.max), scaleY, yDim, yOff)); + let fillTo = pxRound(valToPosY(series.fillTo(u, seriesIdx, series.min, series.max), scaleY, yDim, yOff)); lineTo(fill, rgtX, fillTo); lineTo(fill, lftX, fillTo); @@ -1803,7 +1789,7 @@ var uPlot = (function () { _paths.gaps = gaps = series.gaps(u, seriesIdx, idx0, idx1, gaps); if (!series.spanGaps) - { _paths.clip = clipGaps(gaps, scaleX.ori, xOff, yOff, xDim, yDim); } + _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 @@ -1817,36 +1803,36 @@ var uPlot = (function () { } function stepped(opts) { - var align = ifNull(opts.align, 1); + const align = ifNull(opts.align, 1); // whether to draw ascenders/descenders at null/gap bondaries - var ascDesc = ifNull(opts.ascDesc, false); + const ascDesc = ifNull(opts.ascDesc, false); return (u, seriesIdx, idx0, idx1) => { return orient(u, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => { - var pxRound = series.pxRound; + let pxRound = series.pxRound; - var lineTo = scaleX.ori == 0 ? lineToH : lineToV; + let lineTo = scaleX.ori == 0 ? lineToH : lineToV; - var _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL}; - var stroke = _paths.stroke; + const _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL}; + const stroke = _paths.stroke; - var _dir = 1 * scaleX.dir * (scaleX.ori == 0 ? 1 : -1); + const _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 prevYPos = pxRound(valToPosY(dataY[_dir == 1 ? idx0 : idx1], scaleY, yDim, yOff)); - var firstXPos = pxRound(valToPosX(dataX[_dir == 1 ? idx0 : idx1], scaleX, xDim, xOff)); - var prevXPos = firstXPos; + let gaps = []; + let inGap = false; + let prevYPos = pxRound(valToPosY(dataY[_dir == 1 ? idx0 : idx1], scaleY, yDim, yOff)); + let firstXPos = pxRound(valToPosX(dataX[_dir == 1 ? idx0 : idx1], scaleX, xDim, xOff)); + let prevXPos = firstXPos; lineTo(stroke, firstXPos, prevYPos); - for (var i = _dir == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += _dir) { - var yVal1 = dataY[i]; + for (let i = _dir == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += _dir) { + let yVal1 = dataY[i]; - var x1 = pxRound(valToPosX(dataX[i], scaleX, xDim, xOff)); + let x1 = pxRound(valToPosX(dataX[i], scaleX, xDim, xOff)); if (yVal1 == null) { if (yVal1 === null) { @@ -1856,16 +1842,16 @@ var uPlot = (function () { continue; } - var y1 = pxRound(valToPosY(yVal1, scaleY, yDim, yOff)); + let y1 = pxRound(valToPosY(yVal1, scaleY, yDim, yOff)); if (inGap) { addGap(gaps, prevXPos, x1); // don't clip vertical extenders if (prevYPos != y1) { - var halfStroke = (series.width * pxRatio) / 2; + let halfStroke = (series.width * pxRatio) / 2; - var lastGap = gaps[gaps.length - 1]; + let lastGap = gaps[gaps.length - 1]; lastGap[0] += (ascDesc || align == 1) ? halfStroke : -halfStroke; lastGap[1] -= (ascDesc || align == -1) ? halfStroke : -halfStroke; @@ -1875,9 +1861,9 @@ var uPlot = (function () { } if (align == 1) - { lineTo(stroke, x1, prevYPos); } + lineTo(stroke, x1, prevYPos); else - { lineTo(stroke, prevXPos, y1); } + lineTo(stroke, prevXPos, y1); lineTo(stroke, x1, y1); @@ -1886,10 +1872,10 @@ var uPlot = (function () { } if (series.fill != null) { - var fill = _paths.fill = new Path2D(stroke); + let fill = _paths.fill = new Path2D(stroke); - var fillTo = series.fillTo(u, seriesIdx, series.min, series.max); - var minY = pxRound(valToPosY(fillTo, scaleY, yDim, yOff)); + let fillTo = series.fillTo(u, seriesIdx, series.min, series.max); + let minY = pxRound(valToPosY(fillTo, scaleY, yDim, yOff)); lineTo(fill, prevXPos, minY); lineTo(fill, firstXPos, minY); @@ -1898,7 +1884,7 @@ var uPlot = (function () { _paths.gaps = gaps = series.gaps(u, seriesIdx, idx0, idx1, gaps); if (!series.spanGaps) - { _paths.clip = clipGaps(gaps, scaleX.ori, xOff, yOff, xDim, yDim); } + _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 @@ -1913,64 +1899,64 @@ var uPlot = (function () { function bars(opts) { opts = opts || EMPTY_OBJ; - var size = ifNull(opts.size, [0.6, inf, 1]); - var align = opts.align || 0; - var extraGap = (opts.gap || 0) * pxRatio; + const size = ifNull(opts.size, [0.6, inf, 1]); + const align = opts.align || 0; + const extraGap = (opts.gap || 0) * pxRatio; - var gapFactor = 1 - size[0]; - var maxWidth = ifNull(size[1], inf) * pxRatio; - var minWidth = ifNull(size[2], 1) * pxRatio; + const gapFactor = 1 - size[0]; + const maxWidth = ifNull(size[1], inf) * pxRatio; + const minWidth = ifNull(size[2], 1) * pxRatio; - var disp = opts.disp; - var _each = ifNull(opts.each, _ => {}); + const disp = opts.disp; + const _each = ifNull(opts.each, _ => {}); return (u, seriesIdx, idx0, idx1) => { return orient(u, seriesIdx, (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => { - var pxRound = series.pxRound; + let pxRound = series.pxRound; - var _dirX = scaleX.dir * (scaleX.ori == 0 ? 1 : -1); - var _dirY = scaleY.dir * (scaleY.ori == 1 ? 1 : -1); + const _dirX = scaleX.dir * (scaleX.ori == 0 ? 1 : -1); + const _dirY = scaleY.dir * (scaleY.ori == 1 ? 1 : -1); - var rect = scaleX.ori == 0 ? rectH : rectV; + let rect = scaleX.ori == 0 ? rectH : rectV; - var each = scaleX.ori == 0 ? _each : (u, seriesIdx, i, top, lft, hgt, wid) => { + let each = scaleX.ori == 0 ? _each : (u, seriesIdx, i, top, lft, hgt, wid) => { _each(u, seriesIdx, i, lft, top, wid, hgt); }; - var fillToY = series.fillTo(u, seriesIdx, series.min, series.max); + let fillToY = series.fillTo(u, seriesIdx, series.min, series.max); - var y0Pos = valToPosY(fillToY, scaleY, yDim, yOff); + let y0Pos = valToPosY(fillToY, scaleY, yDim, yOff); - var xShift, barWid; + let xShift, barWid; - var strokeWidth = pxRound(series.width * pxRatio); + let 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)); } + 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); + let sizes = disp.size.values(u, seriesIdx, idx0, idx1); if (disp.size.unit == 2) - { barWid = sizes[0] * xDim; } + barWid = sizes[0] * xDim; else - { barWid = valToPosX(sizes[0], scaleX, xDim, xOff) - valToPosX(0, scaleX, xDim, xOff); } // assumes linear scale (delta from 0) + barWid = valToPosX(sizes[0], scaleX, xDim, xOff) - valToPosX(0, scaleX, xDim, xOff); // assumes linear scale (delta from 0) barWid = pxRound(barWid - strokeWidth); xShift = (_dirX == 1 ? -strokeWidth / 2 : barWid + strokeWidth / 2); } else { - var colWid = xDim; + let 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]); + for (let i = 1, minDelta = Infinity; i < dataX.length; i++) { + let delta = abs(dataX[i] - dataX[i-1]); if (delta < minDelta) { minDelta = delta; @@ -1979,17 +1965,17 @@ var uPlot = (function () { } } - var gapWid = colWid * gapFactor; + let gapWid = colWid * gapFactor; barWid = pxRound(min(maxWidth, max(minWidth, colWid - gapWid)) - strokeWidth - extraGap); xShift = (align == 0 ? barWid / 2 : align == _dirX ? 0 : barWid) - align * _dirX * extraGap / 2; } - var _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL | BAND_CLIP_STROKE}; // disp, geom + const _paths = {stroke: new Path2D(), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL | BAND_CLIP_STROKE}; // disp, geom - var hasBands = u.bands.length > 0; - var yLimit; + const hasBands = u.bands.length > 0; + let yLimit; if (hasBands) { // ADDL OPT: only create band clips for series that are band lower edges @@ -1998,47 +1984,47 @@ var uPlot = (function () { yLimit = incrRound(valToPosY(scaleY.max, scaleY, yDim, yOff), 0.5); } - var stroke = _paths.stroke; - var band = _paths.band; + const stroke = _paths.stroke; + const band = _paths.band; - for (var i$1 = _dirX == 1 ? idx0 : idx1; i$1 >= idx0 && i$1 <= idx1; i$1 += _dirX) { - var yVal = dataY[i$1]; + for (let i = _dirX == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += _dirX) { + let yVal = dataY[i]; // interpolate upwards band clips if (yVal == null) { if (hasBands) { // simple, but inefficient bi-directinal linear scans on each iteration - var prevNonNull = nonNullIdx(dataY, _dirX == 1 ? idx0 : idx1, i$1, -_dirX); - var nextNonNull = nonNullIdx(dataY, i$1, _dirX == 1 ? idx1 : idx0, _dirX); + let prevNonNull = nonNullIdx(dataY, _dirX == 1 ? idx0 : idx1, i, -_dirX); + let nextNonNull = nonNullIdx(dataY, i, _dirX == 1 ? idx1 : idx0, _dirX); - var prevVal = dataY[prevNonNull]; - var nextVal = dataY[nextNonNull]; + let prevVal = dataY[prevNonNull]; + let nextVal = dataY[nextNonNull]; - yVal = prevVal + (i$1 - prevNonNull) / (nextNonNull - prevNonNull) * (nextVal - prevVal); + yVal = prevVal + (i - prevNonNull) / (nextNonNull - prevNonNull) * (nextVal - prevVal); } else - { continue; } + continue; } - var xVal = scaleX.distr != 2 || disp != null ? dataX[i$1] : i$1; + let xVal = scaleX.distr != 2 || disp != null ? dataX[i] : i; // 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); + let xPos = valToPosX(xVal, scaleX, xDim, xOff); + let yPos = valToPosY(yVal, scaleY, yDim, yOff); - var lft = pxRound(xPos - xShift); - var btm = pxRound(max(yPos, y0Pos)); - var top = pxRound(min(yPos, y0Pos)); - var barHgt = btm - top; + let lft = pxRound(xPos - xShift); + let btm = pxRound(max(yPos, y0Pos)); + let top = pxRound(min(yPos, y0Pos)); + let barHgt = btm - top; - if (dataY[i$1] != null) { + if (dataY[i] != null) { rect(stroke, lft, top, barWid, barHgt); - each(u, seriesIdx, i$1, + each(u, seriesIdx, i, lft - strokeWidth / 2, top - strokeWidth / 2, barWid + strokeWidth, - barHgt + strokeWidth + barHgt + strokeWidth, ); } @@ -2059,7 +2045,7 @@ var uPlot = (function () { } if (series.fill != null) - { _paths.fill = new Path2D(stroke); } + _paths.fill = new Path2D(stroke); return _paths; }); @@ -2069,9 +2055,9 @@ var uPlot = (function () { 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; + let pxRound = series.pxRound; - var moveTo, bezierCurveTo, lineTo; + let moveTo, bezierCurveTo, lineTo; if (scaleX.ori == 0) { moveTo = moveToH; @@ -2084,23 +2070,23 @@ var uPlot = (function () { bezierCurveTo = bezierCurveToV; } - var _dir = 1 * scaleX.dir * (scaleX.ori == 0 ? 1 : -1); + const _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; + let gaps = []; + let inGap = false; + let firstXPos = pxRound(valToPosX(dataX[_dir == 1 ? idx0 : idx1], scaleX, xDim, xOff)); + let prevXPos = firstXPos; - var xCoords = []; - var yCoords = []; + let xCoords = []; + let 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); + for (let i = _dir == 1 ? idx0 : idx1; i >= idx0 && i <= idx1; i += _dir) { + let yVal = dataY[i]; + let xVal = dataX[i]; + let xPos = valToPosX(xVal, scaleX, xDim, xOff); if (yVal == null) { if (yVal === null) { @@ -2120,14 +2106,14 @@ var uPlot = (function () { } } - 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; + const _paths = {stroke: interp(xCoords, yCoords, moveTo, lineTo, bezierCurveTo, pxRound), fill: null, clip: null, band: null, gaps: null, flags: BAND_CLIP_FILL}; + const stroke = _paths.stroke; if (series.fill != null && stroke != null) { - var fill = _paths.fill = new Path2D(stroke); + let fill = _paths.fill = new Path2D(stroke); - var fillTo = series.fillTo(u, seriesIdx, series.min, series.max); - var minY = pxRound(valToPosY(fillTo, scaleY, yDim, yOff)); + let fillTo = series.fillTo(u, seriesIdx, series.min, series.max); + let minY = pxRound(valToPosY(fillTo, scaleY, yDim, yOff)); lineTo(fill, prevXPos, minY); lineTo(fill, firstXPos, minY); @@ -2136,7 +2122,7 @@ var uPlot = (function () { _paths.gaps = gaps = series.gaps(u, seriesIdx, idx0, idx1, gaps); if (!series.spanGaps) - { _paths.clip = clipGaps(gaps, scaleX.ori, xOff, yOff, xDim, yDim); } + _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 @@ -2168,25 +2154,25 @@ var uPlot = (function () { // 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; + const n = xs.length; if (n < 2) - { return null; } + return null; - var path = new Path2D(); + const path = new Path2D(); moveTo(path, xs[0], ys[0]); if (n == 2) - { lineTo(path, xs[1], ys[1]); } + lineTo(path, xs[1], ys[1]); else { - var ms = Array(n), + let 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++) { + for (let 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]; @@ -2196,31 +2182,31 @@ var uPlot = (function () { // 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; } + for (let i = 1; i < n - 1; i++) { + if (ds[i] === 0 || ds[i - 1] === 0 || (ds[i - 1] > 0) !== (ds[i] > 0)) + ms[i] = 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] + ms[i] = 3 * (dxs[i - 1] + dxs[i]) / ( + (2 * dxs[i] + dxs[i - 1]) / ds[i - 1] + + (dxs[i] + 2 * dxs[i - 1]) / ds[i] ); - if (!isFinite(ms[i$1])) - { ms[i$1] = 0; } + if (!isFinite(ms[i])) + ms[i] = 0; } } ms[n - 1] = ds[n - 2]; - for (var i$2 = 0; i$2 < n - 1; i$2++) { + for (let i = 0; i < n - 1; i++) { 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] + xs[i] + dxs[i] / 3, + ys[i] + ms[i] * dxs[i] / 3, + xs[i + 1] - dxs[i] / 3, + ys[i + 1] - ms[i + 1] * dxs[i] / 3, + xs[i + 1], + ys[i + 1], ); } } @@ -2228,7 +2214,7 @@ var uPlot = (function () { return path; } - var cursorPlots = new Set(); + const cursorPlots = new Set(); function invalidateRects() { cursorPlots.forEach(u => { @@ -2239,11 +2225,11 @@ var uPlot = (function () { on(resize, win, invalidateRects); on(scroll, win, invalidateRects, true); - var linearPath = linear() ; - var pointsPath = points() ; + const linearPath = linear() ; + const pointsPath = points() ; function setDefaults(d, xo, yo, initY) { - var d2 = initY ? [d[0], d[1]].concat(d.slice(2)) : [d[0]].concat(d.slice(1)); + let d2 = initY ? [d[0], d[1]].concat(d.slice(2)) : [d[0]].concat(d.slice(1)); return d2.map((o, i) => setDefault(o, i, xo, yo)); } @@ -2255,7 +2241,7 @@ var uPlot = (function () { return dataMin == null ? nullNullTuple : [dataMin, dataMax]; } - var snapTimeX = snapNumX; + const 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 @@ -2267,34 +2253,34 @@ var uPlot = (function () { return dataMin == null ? nullNullTuple : rangeLog(dataMin, dataMax, self.scales[scale].log, false); } - var snapLogX = snapLogY; + const snapLogX = snapLogY; function snapAsinhY(self, dataMin, dataMax, scale) { return dataMin == null ? nullNullTuple : rangeAsinh(dataMin, dataMax, self.scales[scale].log, false); } - var snapAsinhX = snapAsinhY; + const snapAsinhX = snapAsinhY; // dim is logical (getClientBoundingRect) pixels, not canvas pixels function findIncr(min, max, incrs, dim, minSpace) { - var pxPerUnit = dim / (max - min); + let pxPerUnit = dim / (max - min); - var minDec = (""+floor(min)).length; + let minDec = (""+floor(min)).length; for (var i = 0; i < incrs.length; i++) { - var space = incrs[i] * pxPerUnit; + let space = incrs[i] * pxPerUnit; - var incrDec = incrs[i] < 10 ? fixedDec.get(incrs[i]) : 0; + let incrDec = incrs[i] < 10 ? fixedDec.get(incrs[i]) : 0; if (space >= minSpace && minDec + incrDec < 17) - { return [incrs[i], space]; } + return [incrs[i], space]; } return [0, 0]; } function pxRatioFont(font) { - var fontSize, fontSizeCss; + let fontSize, fontSizeCss; font = font.replace(/(\d+)px/, (m, p1) => (fontSize = round((fontSizeCss = +p1) * pxRatio)) + 'px'); return [font, fontSize, fontSizeCss]; } @@ -2302,7 +2288,7 @@ var uPlot = (function () { function syncFontSize(axis) { if (axis.show) { [axis.font, axis.labelFont].forEach(f => { - var size = roundDec(f[2] * pxRatio, 1); + let size = roundDec(f[2] * pxRatio, 1); f[0] = f[0].replace(/[0-9.]+px/, size + 'px'); f[1] = size; }); @@ -2310,11 +2296,11 @@ var uPlot = (function () { } function uPlot(opts, data, then) { - var self = {}; + const self = {}; // TODO: cache denoms & mins scale.cache = {r, min, } function getValPct(val, scale) { - var _val = ( + let _val = ( scale.distr == 3 ? log10(val > 0 ? val : scale.clamp(self, val, scale.min, scale.max, scale.key)) : scale.distr == 4 ? asinh(val, scale.asinh) : val @@ -2324,12 +2310,12 @@ var uPlot = (function () { } function getHPos(val, scale, dim, off) { - var pct = getValPct(val, scale); + let pct = getValPct(val, scale); return off + dim * (scale.dir == -1 ? (1 - pct) : pct); } function getVPos(val, scale, dim, off) { - var pct = getValPct(val, scale); + let pct = getValPct(val, scale); return off + dim * (scale.dir == -1 ? pct : (1 - pct)); } @@ -2340,65 +2326,65 @@ var uPlot = (function () { self.valToPosH = getHPos; self.valToPosV = getVPos; - var ready = false; + let ready = false; self.status = 0; - var root = self.root = placeDiv(UPLOT); + const root = self.root = placeDiv(UPLOT); if (opts.id != null) - { root.id = opts.id; } + root.id = opts.id; addClass(root, opts.class); if (opts.title) { - var title = placeDiv(TITLE, root); + let title = placeDiv(TITLE, root); title.textContent = opts.title; } - var can = placeTag("canvas"); - var ctx = self.ctx = can.getContext("2d"); + const can = placeTag("canvas"); + const ctx = self.ctx = can.getContext("2d"); - var wrap = placeDiv(WRAP, root); - var under = self.under = placeDiv(UNDER, wrap); + const wrap = placeDiv(WRAP, root); + const under = self.under = placeDiv(UNDER, wrap); wrap.appendChild(can); - var over = self.over = placeDiv(OVER, wrap); + const over = self.over = placeDiv(OVER, wrap); opts = copy(opts); - var pxAlign = +ifNull(opts.pxAlign, 1); + const pxAlign = +ifNull(opts.pxAlign, 1); - var pxRound = pxRoundGen(pxAlign); + const pxRound = pxRoundGen(pxAlign); (opts.plugins || []).forEach(p => { if (p.opts) - { opts = p.opts(self, opts) || opts; } + opts = p.opts(self, opts) || opts; }); - var ms = opts.ms || 1e-3; + const ms = opts.ms || 1e-3; - var series = self.series = setDefaults(opts.series || [], xSeriesOpts, ySeriesOpts, false); - var axes = self.axes = setDefaults(opts.axes || [], xAxisOpts, yAxisOpts, true); - var scales = self.scales = {}; - var bands = self.bands = opts.bands || []; + const series = self.series = setDefaults(opts.series || [], xSeriesOpts, ySeriesOpts, false); + const axes = self.axes = setDefaults(opts.axes || [], xAxisOpts, yAxisOpts, true); + const scales = self.scales = {}; + const bands = self.bands = opts.bands || []; bands.forEach(b => { b.fill = fnOrSelf(b.fill || null); }); - var xScaleKey = series[0].scale; + const xScaleKey = series[0].scale; - var drawOrderMap = { + const drawOrderMap = { axes: drawAxesGrid, series: drawSeries, }; - var drawOrder = (opts.drawOrder || ["axes", "series"]).map(key => drawOrderMap[key]); + const drawOrder = (opts.drawOrder || ["axes", "series"]).map(key => drawOrderMap[key]); function initScale(scaleKey) { - var sc = scales[scaleKey]; + let sc = scales[scaleKey]; if (sc == null) { - var scaleOpts = (opts.scales || EMPTY_OBJ)[scaleKey] || EMPTY_OBJ; + let scaleOpts = (opts.scales || EMPTY_OBJ)[scaleKey] || EMPTY_OBJ; if (scaleOpts.from != null) { // ensure parent is initialized @@ -2411,11 +2397,11 @@ var uPlot = (function () { sc.key = scaleKey; - var isTime = sc.time; + let isTime = sc.time; - var rn = sc.range; + let rn = sc.range; - var rangeIsArr = isArr(rn); + let rangeIsArr = isArr(rn); if (scaleKey != xScaleKey) { // if range array has null limits, it should be auto @@ -2436,7 +2422,7 @@ var uPlot = (function () { } if (!rangeIsArr && isObj(rn)) { - var cfg = rn; + let cfg = rn; // this is similar to snapNumY rn = (self, dataMin, dataMax) => dataMin == null ? nullNullTuple : rangeNum(dataMin, dataMax, cfg); } @@ -2468,14 +2454,14 @@ var uPlot = (function () { initScale(a.scale); }); - for (var k in opts.scales) - { initScale(k); } + for (let k in opts.scales) + initScale(k); - var scaleX = scales[xScaleKey]; + const scaleX = scales[xScaleKey]; - var xScaleDistr = scaleX.distr; + const xScaleDistr = scaleX.distr; - var valToPosX, valToPosY; + let valToPosX, valToPosY; if (scaleX.ori == 0) { addClass(root, ORI_HZ); @@ -2514,31 +2500,31 @@ var uPlot = (function () { */ } - var pendScales = {}; + const pendScales = {}; // explicitly-set initial scales - for (var k$1 in scales) { - var sc = scales[k$1]; + for (let k in scales) { + let sc = scales[k]; if (sc.min != null || sc.max != null) { - pendScales[k$1] = {min: sc.min, max: sc.max}; + pendScales[k] = {min: sc.min, max: sc.max}; sc.min = sc.max = null; } } // self.tz = opts.tz || Intl.DateTimeFormat().resolvedOptions().timeZone; - var _tzDate = (opts.tzDate || (ts => new Date(round(ts / ms)))); - var _fmtDate = (opts.fmtDate || fmtDate); + const _tzDate = (opts.tzDate || (ts => new Date(round(ts / ms)))); + const _fmtDate = (opts.fmtDate || fmtDate); - 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)); + const _timeAxisSplits = (ms == 1 ? timeAxisSplitsMs(_tzDate) : timeAxisSplitsS(_tzDate)); + const _timeAxisVals = timeAxisVals(_tzDate, timeAxisStamps((ms == 1 ? _timeAxisStampsMs : _timeAxisStampsS), _fmtDate)); + const _timeSeriesVal = timeSeriesVal(_tzDate, timeSeriesStamp(_timeSeriesStamp, _fmtDate)); - var activeIdxs = []; + const activeIdxs = []; - var legend = (self.legend = assign({}, legendOpts, opts.legend)); - var showLegend = legend.show; - var markers = legend.markers; + const legend = (self.legend = assign({}, legendOpts, opts.legend)); + const showLegend = legend.show; + const markers = legend.markers; { legend.idxs = activeIdxs; @@ -2549,31 +2535,31 @@ var uPlot = (function () { markers.fill = fnOrSelf(markers.fill); } - var legendEl; - var legendRows = []; - var legendCells = []; - var legendCols; - var multiValLegend = false; - var NULL_LEGEND_VALUES = {}; + let legendEl; + let legendRows = []; + let legendCells = []; + let legendCols; + let multiValLegend = false; + let NULL_LEGEND_VALUES = {}; if (legend.live) { - var getMultiVals = series[1] ? series[1].values : null; + const getMultiVals = series[1] ? series[1].values : null; multiValLegend = getMultiVals != null; legendCols = multiValLegend ? getMultiVals(self, 1, 0) : {_: 0}; - for (var k$2 in legendCols) - { NULL_LEGEND_VALUES[k$2] = "--"; } + for (let k in legendCols) + NULL_LEGEND_VALUES[k] = "--"; } if (showLegend) { legendEl = placeTag("table", LEGEND, root); if (multiValLegend) { - var head = placeTag("tr", LEGEND_THEAD, legendEl); + let head = placeTag("tr", LEGEND_THEAD, legendEl); placeTag("th", null, head); for (var key in legendCols) - { placeTag("th", LEGEND_LABEL, head).textContent = key; } + placeTag("th", LEGEND_LABEL, head).textContent = key; } else { addClass(legendEl, LEGEND_INLINE); @@ -2581,66 +2567,66 @@ var uPlot = (function () { } } - var son = {show: true}; - var soff = {show: false}; + const son = {show: true}; + const soff = {show: false}; function initLegendRow(s, i) { if (i == 0 && (multiValLegend || !legend.live)) - { return nullNullTuple; } + return nullNullTuple; - var cells = []; + let cells = []; - var row = placeTag("tr", LEGEND_SERIES, legendEl, legendEl.childNodes[i]); + let row = placeTag("tr", LEGEND_SERIES, legendEl, legendEl.childNodes[i]); addClass(row, s.class); if (!s.show) - { addClass(row, OFF); } + addClass(row, OFF); - var label = placeTag("th", null, row); + let label = placeTag("th", null, row); if (markers.show) { - var indic = placeDiv(LEGEND_MARKER, label); + let indic = placeDiv(LEGEND_MARKER, label); if (i > 0) { - var width = markers.width(self, i); + let width = markers.width(self, i); if (width) - { indic.style.border = width + "px " + markers.dash(self, i) + " " + markers.stroke(self, i); } + indic.style.border = width + "px " + markers.dash(self, i) + " " + markers.stroke(self, i); indic.style.background = markers.fill(self, i); } } - var text = placeDiv(LEGEND_LABEL, label); + let text = placeDiv(LEGEND_LABEL, label); text.textContent = s.label; if (i > 0) { if (!markers.show) - { text.style.color = s.width > 0 ? markers.stroke(self, i) : markers.fill(self, i); } + text.style.color = s.width > 0 ? markers.stroke(self, i) : markers.fill(self, i); onMouse("click", label, e => { if (cursor._lock) - { return; } + return; - var seriesIdx = series.indexOf(s); + let 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); + let 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); } + setSeries(seriesIdx, {show: !s.show}, syncOpts.setSeries); }); if (cursorFocus) { onMouse(mouseenter, label, e => { if (cursor._lock) - { return; } + return; setSeries(series.indexOf(s), FOCUS_TRUE, syncOpts.setSeries); }); @@ -2648,7 +2634,7 @@ var uPlot = (function () { } for (var key in legendCols) { - var v = placeTag("td", LEGEND_VALUE, row); + let v = placeTag("td", LEGEND_VALUE, row); v.textContent = "--"; cells.push(v); } @@ -2656,11 +2642,11 @@ var uPlot = (function () { return [row, cells]; } - var mouseListeners = new Map(); + const mouseListeners = new Map(); function onMouse(ev, targ, fn) { - var targListeners = mouseListeners.get(targ) || {}; - var listener = cursor.bind[ev](self, targ, fn); + const targListeners = mouseListeners.get(targ) || {}; + const listener = cursor.bind[ev](self, targ, fn); if (listener) { on(ev, targ, targListeners[ev] = listener); @@ -2669,9 +2655,9 @@ var uPlot = (function () { } function offMouse(ev, targ, fn) { - var targListeners = mouseListeners.get(targ) || {}; + const targListeners = mouseListeners.get(targ) || {}; - for (var k in targListeners) { + for (let k in targListeners) { if (ev == null || k == ev) { off(k, targ, targListeners[k]); delete targListeners[k]; @@ -2679,35 +2665,35 @@ var uPlot = (function () { } if (ev == null) - { mouseListeners.delete(targ); } + mouseListeners.delete(targ); } - var fullWidCss = 0; - var fullHgtCss = 0; + let fullWidCss = 0; + let fullHgtCss = 0; - var plotWidCss = 0; - var plotHgtCss = 0; + let plotWidCss = 0; + let plotHgtCss = 0; // plot margins to account for axes - var plotLftCss = 0; - var plotTopCss = 0; + let plotLftCss = 0; + let plotTopCss = 0; - var plotLft = 0; - var plotTop = 0; - var plotWid = 0; - var plotHgt = 0; + let plotLft = 0; + let plotTop = 0; + let plotWid = 0; + let plotHgt = 0; self.bbox = {}; - var shouldSetScales = false; - var shouldSetSize = false; - var shouldConvergeSize = false; - var shouldSetCursor = false; - var shouldSetLegend = false; + let shouldSetScales = false; + let shouldSetSize = false; + let shouldConvergeSize = false; + let shouldSetCursor = false; + let shouldSetLegend = false; function _setSize(width, height, force) { if (force || (width != self.width || height != self.height)) - { calcSize(width, height); } + calcSize(width, height); resetYSeries(false); @@ -2727,7 +2713,7 @@ var uPlot = (function () { calcPlotRect(); calcAxesRects(); - var bb = self.bbox; + let bb = self.bbox; plotLft = bb.left = incrRound(plotLftCss * pxRatio, 0.5); plotTop = bb.top = incrRound(plotTopCss * pxRatio, 0.5); @@ -2738,18 +2724,18 @@ var uPlot = (function () { } // ensures size calc convergence - var CYCLE_LIMIT = 3; + const CYCLE_LIMIT = 3; function convergeSize() { - var converged = false; + let converged = false; - var cycleNum = 0; + let cycleNum = 0; while (!converged) { cycleNum++; - var axesConverged = axesCalc(cycleNum); - var paddingConverged = paddingCalc(cycleNum); + let axesConverged = axesCalc(cycleNum); + let paddingConverged = paddingCalc(cycleNum); converged = cycleNum == CYCLE_LIMIT || (axesConverged && paddingConverged); @@ -2760,10 +2746,7 @@ var uPlot = (function () { } } - function setSize(ref) { - var width = ref.width; - var height = ref.height; - + function setSize({width, height}) { _setSize(width, height); } @@ -2772,19 +2755,18 @@ var uPlot = (function () { // accumulate axis offsets, reduce canvas width function calcPlotRect() { // easements for edge labels - var hasTopAxis = false; - var hasBtmAxis = false; - var hasRgtAxis = false; - var hasLftAxis = false; + let hasTopAxis = false; + let hasBtmAxis = false; + let hasRgtAxis = false; + let hasLftAxis = false; axes.forEach((axis, i) => { 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); + let {side, _size} = axis; + let isVt = side % 2; + let labelSize = axis.labelSize = (axis.label != null ? (axis.labelSize || 30) : 0); - var fullSize = _size + labelSize; + let fullSize = _size + labelSize; if (fullSize > 0) { if (isVt) { @@ -2795,7 +2777,7 @@ var uPlot = (function () { hasLftAxis = true; } else - { hasRgtAxis = true; } + hasRgtAxis = true; } else { plotHgtCss -= fullSize; @@ -2805,7 +2787,7 @@ var uPlot = (function () { hasTopAxis = true; } else - { hasBtmAxis = true; } + hasBtmAxis = true; } } } @@ -2827,11 +2809,11 @@ var uPlot = (function () { function calcAxesRects() { // will accum + - var off1 = plotLftCss + plotWidCss; - var off2 = plotTopCss + plotHgtCss; + let off1 = plotLftCss + plotWidCss; + let off2 = plotTopCss + plotHgtCss; // will accum - - var off3 = plotLftCss; - var off0 = plotTopCss; + let off3 = plotLftCss; + let off0 = plotTopCss; function incrOffset(side, size) { switch (side) { @@ -2844,24 +2826,24 @@ var uPlot = (function () { axes.forEach((axis, i) => { if (axis.show && axis._show) { - var side = axis.side; + let side = axis.side; axis._pos = incrOffset(side, axis._size); if (axis.label != null) - { axis._lpos = incrOffset(side, axis.labelSize); } + axis._lpos = incrOffset(side, axis.labelSize); } }); } - var cursor = (self.cursor = assign({}, cursorOpts, opts.cursor)); + const cursor = (self.cursor = assign({}, cursorOpts, opts.cursor)); { cursor.idxs = activeIdxs; cursor._lock = false; - var points = cursor.points; + let points = cursor.points; points.show = fnOrSelf(points.show); points.size = fnOrSelf(points.size); @@ -2870,15 +2852,15 @@ var uPlot = (function () { points.fill = fnOrSelf(points.fill); } - var focus = self.focus = assign({}, opts.focus || {alpha: 0.3}, cursor.focus); - var cursorFocus = focus.prox >= 0; + const focus = self.focus = assign({}, opts.focus || {alpha: 0.3}, cursor.focus); + const cursorFocus = focus.prox >= 0; // series-intersection markers - var cursorPts = [null]; + let cursorPts = [null]; function initCursorPt(s, si) { if (si > 0) { - var pt = cursor.points.show(self, si); + let pt = cursor.points.show(self, si); if (pt) { addClass(pt, CURSOR_PT); @@ -2892,9 +2874,9 @@ var uPlot = (function () { } function initSeries(s, i) { - var isTime = scales[s.scale].time; + let isTime = scales[s.scale].time; - var sv = s.value; + let sv = s.value; s.value = isTime ? (isStr(sv) ? timeSeriesVal(_tzDate, timeSeriesStamp(sv, _fmtDate)) : sv || _timeSeriesVal) : sv || numSeriesVal; s.label = s.label || (isTime ? timeSeriesLabel : numSeriesLabel); @@ -2909,8 +2891,8 @@ var uPlot = (function () { s.fill = fnOrSelf(s.fill || null); s._stroke = s._fill = s._paths = s._focus = null; - var _ptDia = ptDia(s.width, 1); - var points = s.points = assign({}, { + let _ptDia = ptDia(s.width, 1); + let points = s.points = assign({}, { size: _ptDia, width: max(1, _ptDia * .2), stroke: s.stroke, @@ -2928,7 +2910,7 @@ var uPlot = (function () { } if (showLegend) { - var rowCells = initLegendRow(s, i); + let 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 :( @@ -2937,7 +2919,7 @@ var uPlot = (function () { if (cursor.show) { activeIdxs.splice(i, 0, null); - var pt = initCursorPt(s, i); + let pt = initCursorPt(s, i); pt && cursorPts.splice(i, 0, pt); } } @@ -2959,7 +2941,7 @@ var uPlot = (function () { legend.values.splice(i, 1); legendCells.splice(i, 1); - var tr = legendRows.splice(i, 1)[0]; + let tr = legendRows.splice(i, 1)[0]; offMouse(null, tr.firstChild); tr.remove(); } @@ -2975,15 +2957,15 @@ var uPlot = (function () { self.delSeries = delSeries; - var sidesWithAxes = [false, false, false, false]; + const sidesWithAxes = [false, false, false, false]; function initAxis(axis, i) { axis._show = axis.show; if (axis.show) { - var isVt = axis.side % 2; + let isVt = axis.side % 2; - var sc = scales[axis.scale]; + let sc = scales[axis.scale]; // this can occur if all series specify non-default scales if (sc == null) { @@ -2992,7 +2974,7 @@ var uPlot = (function () { } // also set defaults for incrs & values based on axis distr - var isTime = sc.time; + let isTime = sc.time; axis.size = fnOrSelf(axis.size); axis.space = fnOrSelf(axis.space); @@ -3004,7 +2986,7 @@ var uPlot = (function () { axis.grid.stroke = fnOrSelf(axis.grid.stroke); axis.ticks.stroke = fnOrSelf(axis.ticks.stroke); - var av = axis.values; + let av = axis.values; axis.values = ( // static array of tick values @@ -3036,40 +3018,37 @@ var uPlot = (function () { axis._values = null; if (axis._size > 0) - { sidesWithAxes[i] = true; } + sidesWithAxes[i] = true; } } function autoPadSide(self, side, sidesWithAxes, cycleNum) { - var hasTopAxis = sidesWithAxes[0]; - var hasRgtAxis = sidesWithAxes[1]; - var hasBtmAxis = sidesWithAxes[2]; - var hasLftAxis = sidesWithAxes[3]; + let [hasTopAxis, hasRgtAxis, hasBtmAxis, hasLftAxis] = sidesWithAxes; - var ori = side % 2; - var size = 0; + let ori = side % 2; + let size = 0; if (ori == 0 && (hasLftAxis || hasRgtAxis)) - { size = (side == 0 && !hasTopAxis || side == 2 && !hasBtmAxis ? round(xAxisOpts.size / 3) : 0); } + 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); } + size = (side == 1 && !hasRgtAxis || side == 3 && !hasLftAxis ? round(yAxisOpts.size / 2) : 0); return size; } - 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)); + const padding = self.padding = (opts.padding || [autoPadSide,autoPadSide,autoPadSide,autoPadSide]).map(p => fnOrSelf(ifNull(p, autoPadSide))); + const _padding = self._padding = padding.map((p, i) => p(self, i, sidesWithAxes, 0)); - var dataLen; + let dataLen; // rendered data window - var i0 = null; - var i1 = null; - var idxs = series[0].idxs; + let i0 = null; + let i1 = null; + const idxs = series[0].idxs; - var data0 = null; + let data0 = null; - var viaAutoScaleX = false; + let viaAutoScaleX = false; function setData(_data, _resetScales) { data = (_data || []).slice(); @@ -3080,7 +3059,7 @@ var uPlot = (function () { dataLen = data0.length; if (xScaleDistr == 2) - { data[0] = data0.map((v, i) => i); } + data[0] = data0.map((v, i) => i); self._data = data; @@ -3089,12 +3068,12 @@ var uPlot = (function () { fire("setData"); if (_resetScales !== false) { - var xsc = scaleX; + let xsc = scaleX; if (xsc.auto(self, viaAutoScaleX)) - { autoScaleX(); } + autoScaleX(); else - { _setScale(xScaleKey, xsc.min, xsc.max); } + _setScale(xScaleKey, xsc.min, xsc.max); shouldSetCursor = cursor.left >= 0; shouldSetLegend = true; @@ -3105,11 +3084,9 @@ var uPlot = (function () { self.setData = setData; function autoScaleX() { - var assign, assign$1, assign$2; - viaAutoScaleX = true; - var _min, _max; + let _min, _max; if (dataLen > 0) { i0 = idxs[0] = 0; @@ -3124,13 +3101,13 @@ var uPlot = (function () { } else if (dataLen == 1) { if (xScaleDistr == 3) - { (assign = rangeLog(_min, _min, scaleX.log, false), _min = assign[0], _max = assign[1]); } + [_min, _max] = rangeLog(_min, _min, scaleX.log, false); else if (xScaleDistr == 4) - { (assign$1 = rangeAsinh(_min, _min, scaleX.log, false), _min = assign$1[0], _max = assign$1[1]); } + [_min, _max] = rangeAsinh(_min, _min, scaleX.log, false); else if (scaleX.time) - { _max = _min + round(86400 / ms); } + _max = _min + round(86400 / ms); else - { (assign$2 = rangeNum(_min, _max, rangePad, true), _min = assign$2[0], _max = assign$2[1]); } + [_min, _max] = rangeNum(_min, _max, rangePad, true); } } else { @@ -3141,35 +3118,55 @@ var uPlot = (function () { _setScale(xScaleKey, _min, _max); } - function setCtxStyle(stroke, width, dash, cap, fill) { - ctx.strokeStyle = stroke || transparent; - ctx.lineWidth = width; - ctx.lineJoin = "round"; - ctx.lineCap = cap || "butt"; // (‿|‿) - ctx.setLineDash(dash || []); - ctx.fillStyle = fill || transparent; + let ctxStroke, ctxFill, ctxWidth, ctxDash, ctxJoin, ctxCap, ctxFont, ctxAlign, ctxBaseline; + let ctxAlpha; + + function setCtxStyle(stroke = transparent, width, dash = EMPTY_ARR, cap = "butt", fill = transparent, join = "round") { + if (stroke != ctxStroke) + ctx.strokeStyle = ctxStroke = stroke; + if (fill != ctxFill) + ctx.fillStyle = ctxFill = fill; + if (width != ctxWidth) + ctx.lineWidth = ctxWidth = width; + if (join != ctxJoin) + ctx.lineJoin = ctxJoin = join; + if (cap != ctxCap) + ctx.lineCap = ctxCap = cap; // (‿|‿) + if (dash != ctxDash) + ctx.setLineDash(ctxDash = dash); + } + + function setFontStyle(font, fill, align, baseline) { + if (fill != ctxFill) + ctx.fillStyle = ctxFill = fill; + if (font != ctxFont) + ctx.font = ctxFont = font; + if (align != ctxAlign) + ctx.textAlign = ctxAlign = align; + if (baseline != ctxBaseline) + ctx.textBaseline = ctxBaseline = baseline; } function setScales() { // log("setScales()", arguments); // wip scales - var wipScales = copy(scales, fastIsObj); + let wipScales = copy(scales, fastIsObj); - for (var k in wipScales) { - var wsc = wipScales[k]; - var psc = pendScales[k]; + for (let k in wipScales) { + let wsc = wipScales[k]; + let 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); } + resetYSeries(true); } else if (k != xScaleKey) { if (dataLen == 0 && wsc.from == null) { - var minMax = wsc.range(self, null, null, k); + let minMax = wsc.range(self, null, null, k); wsc.min = minMax[0]; wsc.max = minMax[1]; } @@ -3183,12 +3180,12 @@ var uPlot = (function () { if (dataLen > 0) { // pre-range y-scales from y series' data values series.forEach((s, i) => { - var k = s.scale; - var wsc = wipScales[k]; - var psc = pendScales[k]; + let k = s.scale; + let wsc = wipScales[k]; + let psc = pendScales[k]; if (i == 0) { - var minMax = wsc.range(self, wsc.min, wsc.max, k); + let minMax = wsc.range(self, wsc.min, wsc.max, k); wsc.min = minMax[0]; wsc.max = minMax[1]; @@ -3198,20 +3195,20 @@ var uPlot = (function () { // closest indices can be outside of view if (data[0][i0] < wsc.min) - { i0++; } + i0++; if (data[0][i1] > wsc.max) - { i1--; } + 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 - 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]; + let minMax = s.min == null ? (wsc.distr == 3 ? getMinMaxLog(data[i], i0, i1) : getMinMax(data[i], i0, i1, s.sorted)) : [s.min, s.max]; // initial min/max - wsc.min = min(wsc.min, s.min = minMax$1[0]); - wsc.max = max(wsc.max, s.max = minMax$1[1]); + wsc.min = min(wsc.min, s.min = minMax[0]); + wsc.max = max(wsc.max, s.max = minMax[1]); } s.idxs[0] = i0; @@ -3219,52 +3216,52 @@ var uPlot = (function () { }); // range independent scales - for (var k$1 in wipScales) { - var wsc$1 = wipScales[k$1]; - var psc$1 = pendScales[k$1]; + for (let k in wipScales) { + let wsc = wipScales[k]; + let psc = pendScales[k]; - if (wsc$1.from == null && (psc$1 == null || psc$1.min == null)) { - var minMax$1 = wsc$1.range( + if (wsc.from == null && (psc == null || psc.min == null)) { + let minMax = wsc.range( self, - wsc$1.min == inf ? null : wsc$1.min, - wsc$1.max == -inf ? null : wsc$1.max, - k$1 + wsc.min == inf ? null : wsc.min, + wsc.max == -inf ? null : wsc.max, + k ); - wsc$1.min = minMax$1[0]; - wsc$1.max = minMax$1[1]; + wsc.min = minMax[0]; + wsc.max = minMax[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]; + for (let k in wipScales) { + let wsc = wipScales[k]; + + if (wsc.from != null) { + let base = wipScales[wsc.from]; + let minMax = wsc.range(self, base.min, base.max, k); + wsc.min = minMax[0]; + wsc.max = minMax[1]; } } - var changed = {}; - var anyChanged = false; + let changed = {}; + let anyChanged = false; - for (var k$3 in wipScales) { - var wsc$3 = wipScales[k$3]; - var sc = scales[k$3]; + for (let k in wipScales) { + let wsc = wipScales[k]; + let sc = scales[k]; - if (sc.min != wsc$3.min || sc.max != wsc$3.max) { - sc.min = wsc$3.min; - sc.max = wsc$3.max; + if (sc.min != wsc.min || sc.max != wsc.max) { + sc.min = wsc.min; + sc.max = wsc.max; - var distr = sc.distr; + let distr = sc.distr; sc._min = distr == 3 ? log10(sc.min) : distr == 4 ? asinh(sc.min, sc.asinh) : sc.min; sc._max = distr == 3 ? log10(sc.max) : distr == 4 ? asinh(sc.max, sc.asinh) : sc.max; - changed[k$3] = anyChanged = true; + changed[k] = anyChanged = true; } } @@ -3272,32 +3269,32 @@ var uPlot = (function () { // invalidate paths of all series on changed scales series.forEach(s => { if (changed[s.scale]) - { s._paths = null; } + s._paths = null; }); - for (var k$4 in changed) { + for (let k in changed) { shouldConvergeSize = true; - fire("setScale", k$4); + fire("setScale", k); } if (cursor.show) - { shouldSetCursor = shouldSetLegend = cursor.left >= 0; } + shouldSetCursor = shouldSetLegend = cursor.left >= 0; } - for (var k$5 in pendScales) - { pendScales[k$5] = null; } + for (let k in pendScales) + pendScales[k] = 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); + let _i0 = clamp(i0 - 1, 0, dataLen - 1); + let _i1 = clamp(i1 + 1, 0, dataLen - 1); while (ydata[_i0] == null && _i0 > 0) - { _i0--; } + _i0--; while (ydata[_i1] == null && _i1 < dataLen - 1) - { _i1++; } + _i1++; return [_i0, _i1]; } @@ -3306,7 +3303,7 @@ var uPlot = (function () { if (dataLen > 0) { series.forEach((s, i) => { if (i > 0 && s.show && s._paths == null) { - var _idxs = getOuterIdxs(data[i]); + let _idxs = getOuterIdxs(data[i]); s._paths = s.paths(self, i, _idxs[0], _idxs[1]); } }); @@ -3321,8 +3318,8 @@ var uPlot = (function () { { cacheStrokeFill(i, true); - var show = s.points.show(self, i, i0, i1); - var idxs = s.points.filter(self, i, show, s._paths ? s._paths.gaps : null); + let show = s.points.show(self, i, i0, i1); + let 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); @@ -3337,125 +3334,120 @@ var uPlot = (function () { } function cacheStrokeFill(si, _points) { - var s = _points ? series[si].points : series[si]; + let 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]; + let s = _points ? series[si].points : series[si]; - var strokeStyle = s._stroke; - var fillStyle = s._fill; + let strokeStyle = s._stroke; + let fillStyle = s._fill; - var ref = s._paths; - var stroke = ref.stroke; - var fill = ref.fill; - var clip = ref.clip; - var flags = ref.flags; - var width = roundDec(s.width * pxRatio, 3); - var offset = (width % 2) / 2; + let { stroke, fill, clip: gapsClip, flags } = s._paths; + let boundsClip = null; + let width = roundDec(s.width * pxRatio, 3); + let offset = (width % 2) / 2; if (_points && fillStyle == null) - { fillStyle = width > 0 ? "#fff" : strokeStyle; } + fillStyle = width > 0 ? "#fff" : strokeStyle; - ctx.globalAlpha = s.alpha; + if (ctxAlpha != s.alpha) + ctx.globalAlpha = ctxAlpha = s.alpha; - var _pxAlign = s.pxAlign == 1; + let _pxAlign = s.pxAlign == 1; _pxAlign && ctx.translate(offset, offset); - ctx.save(); - if (!_points) { - var lft = plotLft, + let lft = plotLft, top = plotTop, wid = plotWid, hgt = plotHgt; - var halfWid = width * pxRatio / 2; + let halfWid = width * pxRatio / 2; if (s.min == 0) - { hgt += halfWid; } + hgt += halfWid; if (s.max == 0) { top -= halfWid; hgt += halfWid; } - ctx.beginPath(); - ctx.rect(lft, top, wid, hgt); - ctx.clip(); + boundsClip = new Path2D(); + boundsClip.rect(lft, top, wid, hgt); } - clip && ctx.clip(clip); - + // the points pathbuilder's gapsClip is its boundsClip, since points dont need gaps clipping, and bounds depend on point size if (_points) - { strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, null, flags); } + strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags, gapsClip, null, null); else - { fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags); } - - ctx.restore(); + fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags, boundsClip, gapsClip); _pxAlign && ctx.translate(-offset, -offset); - ctx.globalAlpha = 1; + if (ctxAlpha != 1) + ctx.globalAlpha = ctxAlpha = 1; } - function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags) { - var didStrokeFill = false; + function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip) { + let didStrokeFill = false; // 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) => { // isUpperEdge? if (b.series[0] == si) { - var lowerEdge = series[b.series[1]]; + let lowerEdge = series[b.series[1]]; - var clip = (lowerEdge._paths || EMPTY_OBJ).band; - - ctx.save(); + let bandClip = (lowerEdge._paths || EMPTY_OBJ).band; - var _fillStyle = null; + let _fillStyle = null; // hasLowerEdge? - if (lowerEdge.show && clip) - { _fillStyle = b.fill(self, bi) || fillStyle; } + if (lowerEdge.show && bandClip) + _fillStyle = b.fill(self, bi) || fillStyle; else - { clip = null; } + bandClip = null; - strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, clip, flags); - - ctx.restore(); + strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, bandClip); didStrokeFill = true; } }); if (!didStrokeFill) - { strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, null, flags); } + strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, null); } - var CLIP_FILL_STROKE = BAND_CLIP_FILL | BAND_CLIP_STROKE; + const CLIP_FILL_STROKE = BAND_CLIP_FILL | BAND_CLIP_STROKE; - function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, clip, flags) { + function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, bandClip) { setCtxStyle(strokeStyle, lineWidth, lineDash, lineCap, fillStyle); - if (clip) { + if (boundsClip || gapsClip || bandClip) { + ctx.save(); + boundsClip && ctx.clip(boundsClip); + gapsClip && ctx.clip(gapsClip); + } + + if (bandClip) { if ((flags & CLIP_FILL_STROKE) == CLIP_FILL_STROKE) { - ctx.clip(clip); + ctx.clip(bandClip); doFill(fillStyle, fillPath); doStroke(strokeStyle, strokePath, lineWidth); } else if (flags & BAND_CLIP_STROKE) { doFill(fillStyle, fillPath); - ctx.clip(clip); + ctx.clip(bandClip); doStroke(strokeStyle, strokePath, lineWidth); } else if (flags & BAND_CLIP_FILL) { ctx.save(); - ctx.clip(clip); + ctx.clip(bandClip); doFill(fillStyle, fillPath); ctx.restore(); doStroke(strokeStyle, strokePath, lineWidth); @@ -3465,6 +3457,9 @@ var uPlot = (function () { doFill(fillStyle, fillPath); doStroke(strokeStyle, strokePath, lineWidth); } + + if (boundsClip || gapsClip || bandClip) + ctx.restore(); } function doStroke(strokeStyle, strokePath, lineWidth) { @@ -3472,19 +3467,19 @@ var uPlot = (function () { } function doFill(fillStyle, fillPath) { - fillStyle && fillPath && ctx.fill(fillPath); + fillStyle && fillPath && ctx.fill(fillPath); } function getIncrSpace(axisIdx, min, max, fullDim) { - var axis = axes[axisIdx]; + let axis = axes[axisIdx]; - var incrSpace; + let incrSpace; if (fullDim <= 0) - { incrSpace = [0, 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); + let minSpace = axis._space = axis.space(self, axisIdx, min, max, fullDim); + let incrs = axis._incrs = axis.incrs(self, axisIdx, min, max, fullDim, minSpace); incrSpace = axis._found = findIncr(min, max, incrs, fullDim, minSpace); } @@ -3492,15 +3487,15 @@ var uPlot = (function () { } function drawOrthoLines(offs, filts, ori, side, pos0, len, width, stroke, dash, cap) { - var offset = (width % 2) / 2; + let offset = (width % 2) / 2; pxAlign == 1 && ctx.translate(offset, offset); - setCtxStyle(stroke, width, dash, cap); + setCtxStyle(stroke, width, dash, cap, stroke); ctx.beginPath(); - var x0, y0, x1, y1, pos1 = pos0 + (side == 0 || side == 3 ? -len : len); + let x0, y0, x1, y1, pos1 = pos0 + (side == 0 || side == 3 ? -len : len); if (ori == 0) { y0 = pos0; @@ -3511,18 +3506,17 @@ var uPlot = (function () { x1 = pos1; } - offs.forEach((off, i) => { - if (filts[i] == null) - { return; } - - if (ori == 0) - { x0 = x1 = off; } - else - { y0 = y1 = off; } + for (let i = 0; i < offs.length; i++) { + if (filts[i] != null) { + if (ori == 0) + x0 = x1 = offs[i]; + else + y0 = y1 = offs[i]; - ctx.moveTo(x0, y0); - ctx.lineTo(x1, y1); - }); + ctx.moveTo(x0, y0); + ctx.lineTo(x1, y1); + } + } ctx.stroke(); @@ -3532,13 +3526,13 @@ var uPlot = (function () { function axesCalc(cycleNum) { // log("axesCalc()", arguments); - var converged = true; + let converged = true; axes.forEach((axis, i) => { if (!axis.show) - { return; } + return; - var scale = scales[axis.scale]; + let scale = scales[axis.scale]; if (scale.min == null) { if (axis._show) { @@ -3556,53 +3550,50 @@ var uPlot = (function () { } } - var side = axis.side; - var ori = side % 2; + let side = axis.side; + let ori = side % 2; - var min = scale.min; - var max = scale.max; // // should this toggle them ._show = false + let {min, max} = scale; // // should this toggle them ._show = false - var ref = getIncrSpace(i, min, max, ori == 0 ? plotWidCss : plotHgtCss); - var _incr = ref[0]; - var _space = ref[1]; + let [_incr, _space] = getIncrSpace(i, min, max, ori == 0 ? plotWidCss : plotHgtCss); if (_space == 0) - { return; } + return; // if we're using index positions, force first tick to match passed index - var forceMin = scale.distr == 2; + let forceMin = scale.distr == 2; - var _splits = axis._splits = axis.splits(self, i, min, max, _incr, _space, forceMin); + let _splits = axis._splits = axis.splits(self, i, min, max, _incr, _space, forceMin); // tick labels // BOO this assumes a specific data/series - var splits = scale.distr == 2 ? _splits.map(i => data0[i]) : _splits; - var incr = scale.distr == 2 ? data0[_splits[1]] - data0[_splits[0]] : _incr; + let splits = scale.distr == 2 ? _splits.map(i => data0[i]) : _splits; + let incr = scale.distr == 2 ? data0[_splits[1]] - data0[_splits[0]] : _incr; - var values = axis._values = axis.values(self, axis.filter(self, splits, i, _space, incr), i, _space, incr); + let values = axis._values = axis.values(self, axis.filter(self, splits, i, _space, incr), i, _space, incr); // rotating of labels only supported on bottom x axis axis._rotate = side == 2 ? axis.rotate(self, values, i, _space) : 0; - var oldSize = axis._size; + let oldSize = axis._size; axis._size = ceil(axis.size(self, values, i, cycleNum)); if (oldSize != null && axis._size != oldSize) // ready && ? - { converged = false; } + converged = false; }); return converged; } function paddingCalc(cycleNum) { - var converged = true; + let converged = true; padding.forEach((p, i) => { - var _p = p(self, i, sidesWithAxes, cycleNum); + let _p = p(self, i, sidesWithAxes, cycleNum); if (_p != _padding[i]) - { converged = false; } + converged = false; _padding[i] = _p; }); @@ -3611,23 +3602,27 @@ var uPlot = (function () { } function drawAxesGrid() { - axes.forEach((axis, i) => { + for (let i = 0; i < axes.length; i++) { + let axis = axes[i]; + if (!axis.show || !axis._show) - { return; } + return; - var side = axis.side; - var ori = side % 2; + let side = axis.side; + let ori = side % 2; - var x, y; + let x, y; - var fillStyle = axis.stroke(self, i); + let fillStyle = axis.stroke(self, i); - var shiftDir = side == 0 || side == 3 ? -1 : 1; + let 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); + let shiftAmt = axis.labelGap * shiftDir; + let baseLpos = round((axis._lpos + shiftAmt) * pxRatio); + + setFontStyle(axis.labelFont[0], fillStyle, "center", side == 2 ? TOP : BOTTOM); ctx.save(); @@ -3636,7 +3631,7 @@ var uPlot = (function () { ctx.translate( baseLpos, - round(plotTop + plotHgt / 2) + round(plotTop + plotHgt / 2), ); ctx.rotate((side == 3 ? -PI : PI) / 2); @@ -3646,84 +3641,87 @@ var uPlot = (function () { 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(); } - var ref = axis._found; - var _incr = ref[0]; - var _space = ref[1]; + let [_incr, _space] = axis._found; if (_space == 0) - { return; } + return; - var scale = scales[axis.scale]; + let scale = scales[axis.scale]; - var plotDim = ori == 0 ? plotWid : plotHgt; - var plotOff = ori == 0 ? plotLft : plotTop; + let plotDim = ori == 0 ? plotWid : plotHgt; + let plotOff = ori == 0 ? plotLft : plotTop; - var axisGap = round(axis.gap * pxRatio); + let axisGap = round(axis.gap * pxRatio); - var _splits = axis._splits; + let _splits = axis._splits; // tick labels // BOO this assumes a specific data/series - var splits = scale.distr == 2 ? _splits.map(i => data0[i]) : _splits; - var incr = scale.distr == 2 ? data0[_splits[1]] - data0[_splits[0]] : _incr; + let splits = scale.distr == 2 ? _splits.map(i => data0[i]) : _splits; + let incr = scale.distr == 2 ? data0[_splits[1]] - data0[_splits[0]] : _incr; - var ticks = axis.ticks; - var tickSize = ticks.show ? round(ticks.size * pxRatio) : 0; + let ticks = axis.ticks; + let tickSize = ticks.show ? round(ticks.size * pxRatio) : 0; // rotating of labels only supported on bottom x axis - var angle = axis._rotate * -PI/180; + let angle = axis._rotate * -PI/180; - var basePos = pxRound(axis._pos * pxRatio); - var shiftAmt = (tickSize + axisGap) * shiftDir; - var finalPos = basePos + shiftAmt; + let basePos = pxRound(axis._pos * pxRatio); + let shiftAmt = (tickSize + axisGap) * shiftDir; + let finalPos = basePos + shiftAmt; y = ori == 0 ? finalPos : 0; x = ori == 1 ? finalPos : 0; - ctx.font = axis.font[0]; - ctx.fillStyle = fillStyle; - ctx.textAlign = axis.align == 1 ? LEFT : + let font = axis.font[0]; + let 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 || + let textBaseline = angle || ori == 1 ? "middle" : side == 2 ? TOP : BOTTOM; - var lineHeight = axis.font[1] * lineMult; + setFontStyle(font, fillStyle, textAlign, textBaseline); - var canOffs = _splits.map(val => pxRound(getPos(val, scale, plotDim, plotOff))); + let lineHeight = axis.font[1] * lineMult; - axis._values.forEach((val, i) => { - if (val == null) - { return; } + let canOffs = _splits.map(val => pxRound(getPos(val, scale, plotDim, plotOff))); - if (ori == 0) - { x = canOffs[i]; } - else - { y = canOffs[i]; } - - (""+val).split(/\n/gm).forEach((text, j) => { - if (angle) { - ctx.save(); - ctx.translate(x, y + j * lineHeight); - ctx.rotate(angle); - ctx.fillText(text, 0, 0); - ctx.restore(); - } + let _values = axis._values; + + for (let i = 0; i < _values.length; i++) { + let val = _values[i]; + + if (val != null) { + if (ori == 0) + x = canOffs[i]; else - { ctx.fillText(text, x, y + j * lineHeight); } - }); - }); + y = canOffs[i]; + + val = "" + val; + + let _parts = val.indexOf("\n") == -1 ? [val] : val.split(/\n/gm); + + for (let j = 0; j < _parts.length; j++) { + let text = _parts[j]; + + if (angle) { + ctx.save(); + ctx.translate(x, y + j * lineHeight); // can this be replaced with position math? + ctx.rotate(angle); // can this be done once? + ctx.fillText(text, 0, 0); + ctx.restore(); + } + else + ctx.fillText(text, x, y + j * lineHeight); + } + } + } // ticks if (ticks.show) { @@ -3737,12 +3735,12 @@ var uPlot = (function () { roundDec(ticks.width * pxRatio, 3), ticks.stroke(self, i), ticks.dash, - ticks.cap + ticks.cap, ); } // grid - var grid = axis.grid; + let grid = axis.grid; if (grid.show) { drawOrthoLines( @@ -3755,10 +3753,10 @@ var uPlot = (function () { roundDec(grid.width * pxRatio, 3), grid.stroke(self, i), grid.dash, - grid.cap + grid.cap, ); } - }); + } fire("drawAxes"); } @@ -3778,7 +3776,7 @@ var uPlot = (function () { }); } - var queuedCommit = false; + let queuedCommit = false; function commit() { if (!queuedCommit) { @@ -3863,32 +3861,32 @@ var uPlot = (function () { shouldConvergeSize = recalcAxes || false; if (rebuildPaths !== false) - { _setScale(xScaleKey, scaleX.min, scaleX.max); } + _setScale(xScaleKey, scaleX.min, scaleX.max); else - { commit(); } + 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]; + let sc = scales[key]; if (sc.from == null) { if (dataLen == 0) { - var minMax = sc.range(self, opts.min, opts.max, key); + let minMax = sc.range(self, opts.min, opts.max, key); opts.min = minMax[0]; opts.max = minMax[1]; } if (opts.min > opts.max) { - var _min = opts.min; + let _min = opts.min; opts.min = opts.max; opts.max = _min; } if (dataLen > 1 && opts.min != null && opts.max != null && opts.max - opts.min < 1e-16) - { return; } + return; if (key == xScaleKey) { if (sc.distr == 2 && dataLen > 0) { @@ -3910,39 +3908,39 @@ var uPlot = (function () { // INTERACTION - var xCursor; - var yCursor; - var vCursor; - var hCursor; + let xCursor; + let yCursor; + let vCursor; + let hCursor; // starting position before cursor.move - var rawMouseLeft0; - var rawMouseTop0; + let rawMouseLeft0; + let rawMouseTop0; // starting position - var mouseLeft0; - var mouseTop0; + let mouseLeft0; + let mouseTop0; // current position before cursor.move - var rawMouseLeft1; - var rawMouseTop1; + let rawMouseLeft1; + let rawMouseTop1; // current position - var mouseLeft1; - var mouseTop1; + let mouseLeft1; + let mouseTop1; - var dragging = false; + let dragging = false; - var drag = cursor.drag; + const drag = cursor.drag; - var dragX = drag.x; - var dragY = drag.y; + let dragX = drag.x; + let dragY = drag.y; if (cursor.show) { if (cursor.x) - { xCursor = placeDiv(CURSOR_X, over); } + xCursor = placeDiv(CURSOR_X, over); if (cursor.y) - { yCursor = placeDiv(CURSOR_Y, over); } + yCursor = placeDiv(CURSOR_Y, over); if (scaleX.ori == 0) { vCursor = xCursor; @@ -3957,7 +3955,7 @@ var uPlot = (function () { mouseTop1 = cursor.top; } - var select = self.select = assign({ + const select = self.select = assign({ show: true, over: true, left: 0, @@ -3966,12 +3964,12 @@ var uPlot = (function () { height: 0, }, opts.select); - var selectDiv = select.show ? placeDiv(SELECT, select.over ? over : under) : null; + const 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]); } + for (let prop in opts) + setStylePx(selectDiv, prop, select[prop] = opts[prop]); _fire !== false && fire("setSelect"); } @@ -3980,11 +3978,11 @@ var uPlot = (function () { self.setSelect = setSelect; function toggleDOM(i, onOff) { - var s = series[i]; - var label = showLegend ? legendRows[i] : null; + let s = series[i]; + let label = showLegend ? legendRows[i] : null; if (s.show) - { label && remClass(label, OFF); } + label && remClass(label, OFF); else { label && addClass(label, OFF); cursorPts.length > 1 && trans(cursorPts[i], -10, -10, plotWidCss, plotHgtCss); @@ -3992,16 +3990,16 @@ var uPlot = (function () { } function _setScale(key, min, max) { - setScale(key, {min: min, max: max}); + setScale(key, {min, max}); } function setSeries(i, opts, pub) { // log("setSeries()", arguments); - var s = series[i]; + let s = series[i]; if (opts.focus != null) - { setFocus(i); } + setFocus(i); if (opts.show != null) { s.show = opts.show; @@ -4030,9 +4028,9 @@ var uPlot = (function () { function delBand(bi) { if (bi == null) - { bands.length = 0; } + bands.length = 0; else - { bands.splice(bi, 1); } + bands.splice(bi, 1); } self.addBand = addBand; @@ -4043,29 +4041,29 @@ var uPlot = (function () { series[i].alpha = value; if (cursor.show && cursorPts[i]) - { cursorPts[i].style.opacity = value; } + cursorPts[i].style.opacity = value; if (showLegend && legendRows[i]) - { legendRows[i].style.opacity = value; } + legendRows[i].style.opacity = value; } // y-distance - var closestDist; - var closestSeries; - var focusedSeries; - var FOCUS_TRUE = {focus: true}; - var FOCUS_FALSE = {focus: false}; + let closestDist; + let closestSeries; + let focusedSeries; + const FOCUS_TRUE = {focus: true}; + const FOCUS_FALSE = {focus: false}; function setFocus(i) { if (i != focusedSeries) { // log("setFocus()", arguments); - var allFocused = i == null; + let allFocused = i == null; - var _setAlpha = focus.alpha != 1; + let _setAlpha = focus.alpha != 1; series.forEach((s, i2) => { - var isFocused = allFocused || i2 == 0 || i2 == i; + let isFocused = allFocused || i2 == 0 || i2 == i; s._focus = allFocused ? null : isFocused; _setAlpha && setAlpha(i2, isFocused ? 1 : focus.alpha); }); @@ -4078,19 +4076,19 @@ var uPlot = (function () { if (showLegend && cursorFocus) { on(mouseleave, legendEl, e => { if (cursor._lock) - { return; } + return; setSeries(null, FOCUS_FALSE, syncOpts.setSeries); updateCursor(); }); } function posToVal(pos, scale, can) { - var sc = scales[scale]; + let sc = scales[scale]; if (can) - { pos = pos / pxRatio - (sc.ori == 1 ? plotTopCss : plotLftCss); } + pos = pos / pxRatio - (sc.ori == 1 ? plotTopCss : plotLftCss); - var dim = plotWidCss; + let dim = plotWidCss; if (sc.ori == 1) { dim = plotHgtCss; @@ -4098,15 +4096,15 @@ var uPlot = (function () { } if (sc.dir == -1) - { pos = dim - pos; } + pos = dim - pos; - var _min = sc._min, + let _min = sc._min, _max = sc._max, pct = pos / dim; - var sv = _min + (_max - _min) * pct; + let sv = _min + (_max - _min) * pct; - var distr = sc.distr; + let distr = sc.distr; return ( distr == 3 ? pow(10, sv) : @@ -4116,7 +4114,7 @@ var uPlot = (function () { } function closestIdxFromXpos(pos, can) { - var v = posToVal(pos, xScaleKey, can); + let v = posToVal(pos, xScaleKey, can); return closestIdx(v, data[0], i0, i1); } @@ -4127,11 +4125,11 @@ var uPlot = (function () { scales[scale].ori == 0 ? getHPos(val, scales[scale], can ? plotWid : plotWidCss, - can ? plotLft : 0 + can ? plotLft : 0, ) : getVPos(val, scales[scale], can ? plotHgt : plotHgtCss, - can ? plotTop : 0 + can ? plotTop : 0, ) ); @@ -4160,28 +4158,28 @@ var uPlot = (function () { setStylePx(selectDiv, HEIGHT, select.height = dim); } - var setSelX = scaleX.ori == 0 ? setSelH : setSelV; - var setSelY = scaleX.ori == 1 ? setSelH : setSelV; + let setSelX = scaleX.ori == 0 ? setSelH : setSelV; + let setSelY = scaleX.ori == 1 ? setSelH : setSelV; function syncLegend() { if (showLegend && legend.live) { - for (var i = 0; i < series.length; i++) { + for (let i = 0; i < series.length; i++) { if (i == 0 && multiValLegend) - { continue; } + continue; - var vals = legend.values[i]; + let vals = legend.values[i]; - var j = 0; + let j = 0; - for (var k in vals) - { legendCells[i][j++].firstChild.nodeValue = vals[k]; } + for (let k in vals) + legendCells[i][j++].firstChild.nodeValue = vals[k]; } } } function setLegend(opts, _fire) { if (opts != null) { - var idx = opts.idx; + let idx = opts.idx; legend.idx = idx; series.forEach((s, sidx) => { @@ -4190,7 +4188,7 @@ var uPlot = (function () { } if (showLegend && legend.live) - { syncLegend(); } + syncLegend(); shouldSetLegend = false; @@ -4200,13 +4198,13 @@ var uPlot = (function () { self.setLegend = setLegend; function setLegendValues(sidx, idx) { - var val; + let val; if (idx == null) - { val = NULL_LEGEND_VALUES; } + val = NULL_LEGEND_VALUES; else { - var s = series[sidx]; - var src = sidx == 0 && xScaleDistr == 2 ? data0 : data[sidx]; + let s = series[sidx]; + let src = sidx == 0 && xScaleDistr == 2 ? data0 : data[sidx]; val = multiValLegend ? s.values(self, sidx, idx) : {_: s.value(self, src[idx], sidx, idx)}; } @@ -4214,90 +4212,88 @@ var uPlot = (function () { } function updateCursor(ts, src, _fire) { - var assign; - // ts == null && log("updateCursor()", arguments); rawMouseLeft1 = mouseLeft1; rawMouseTop1 = mouseTop1; - (assign = cursor.move(self, mouseLeft1, mouseTop1), mouseLeft1 = assign[0], mouseTop1 = assign[1]); + [mouseLeft1, mouseTop1] = cursor.move(self, mouseLeft1, mouseTop1); if (cursor.show) { vCursor && trans(vCursor, round(mouseLeft1), 0, plotWidCss, plotHgtCss); hCursor && trans(hCursor, 0, round(mouseTop1), plotWidCss, plotHgtCss); } - var idx; + let 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; + let noDataInRange = i0 > i1; closestDist = inf; // TODO: extract - var xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss; - var yDim = scaleX.ori == 1 ? plotWidCss : plotHgtCss; + let xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss; + let yDim = scaleX.ori == 1 ? plotWidCss : plotHgtCss; // if cursor hidden, hide points & clear legend vals if (mouseLeft1 < 0 || dataLen == 0 || noDataInRange) { idx = null; - for (var i = 0; i < series.length; i++) { + for (let i = 0; i < series.length; i++) { if (i > 0) { cursorPts.length > 1 && trans(cursorPts[i], -10, -10, plotWidCss, plotHgtCss); } } if (cursorFocus) - { setSeries(null, FOCUS_TRUE, syncOpts.setSeries); } + setSeries(null, FOCUS_TRUE, syncOpts.setSeries); 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; } + for (let i = 0; i < series.length; i++) + legend.values[i] = NULL_LEGEND_VALUES; } } else { // let pctY = 1 - (y / rect.height); - var mouseXPos = scaleX.ori == 0 ? mouseLeft1 : mouseTop1; + let mouseXPos = scaleX.ori == 0 ? mouseLeft1 : mouseTop1; - var valAtPosX = posToVal(mouseXPos, xScaleKey); + let valAtPosX = posToVal(mouseXPos, xScaleKey); idx = closestIdx(valAtPosX, data[0], i0, i1); - var xPos = incrRoundUp(valToPosX(data[0][idx], scaleX, xDim, 0), 0.5); + let xPos = incrRoundUp(valToPosX(data[0][idx], scaleX, xDim, 0), 0.5); - for (var i$2 = 0; i$2 < series.length; i$2++) { - var s = series[i$2]; + for (let i = 0; i < series.length; i++) { + let s = series[i]; - var idx2 = cursor.dataIdx(self, i$2, idx, valAtPosX); + let idx2 = cursor.dataIdx(self, i, idx, valAtPosX); - var yVal2 = data[i$2][idx2]; + let yVal2 = data[i][idx2]; - shouldSetLegend = shouldSetLegend || yVal2 != data[i$2][activeIdxs[i$2]]; + shouldSetLegend = shouldSetLegend || yVal2 != data[i][activeIdxs[i]]; - activeIdxs[i$2] = idx2; + activeIdxs[i] = idx2; - var xPos2 = idx2 == idx ? xPos : incrRoundUp(valToPosX(data[0][idx2], scaleX, xDim, 0), 0.5); + let xPos2 = idx2 == idx ? xPos : incrRoundUp(valToPosX(data[0][idx2], scaleX, xDim, 0), 0.5); - if (i$2 > 0 && s.show) { - var yPos = yVal2 == null ? -10 : incrRoundUp(valToPosY(yVal2, scales[s.scale], yDim, 0), 0.5); + if (i > 0 && s.show) { + let yPos = yVal2 == null ? -10 : incrRoundUp(valToPosY(yVal2, scales[s.scale], yDim, 0), 0.5); if (yPos > 0) { - var dist = abs(yPos - mouseTop1); + let dist = abs(yPos - mouseTop1); if (dist <= closestDist) { closestDist = dist; - closestSeries = i$2; + closestSeries = i; } } - var hPos = (void 0), vPos = (void 0); + let hPos, vPos; if (scaleX.ori == 0) { hPos = xPos2; @@ -4309,16 +4305,16 @@ var uPlot = (function () { } 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)); + trans(cursorPts[i], hPos, vPos, plotWidCss, plotHgtCss); + color(cursorPts[i], cursor.points.fill(self, i), cursor.points.stroke(self, i)); } } if (legend.live) { - if (!shouldSetLegend || i$2 == 0 && multiValLegend) - { continue; } + if (!shouldSetLegend || i == 0 && multiValLegend) + continue; - setLegendValues(i$2, idx2); + setLegendValues(i, idx2); } } } @@ -4331,34 +4327,24 @@ var uPlot = (function () { // 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]; - 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]; + let [xKey, yKey] = syncOpts.scales; + let [matchXKeys, matchYKeys] = syncOpts.match; + let [xKeySrc, yKeySrc] = src.cursor.sync.scales; // match the dragX/dragY implicitness/explicitness of src - var sdrag = src.cursor.drag; + let sdrag = src.cursor.drag; dragX = sdrag._x; dragY = sdrag._y; - 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; + let { left, top, width, height } = src.select; - var sori = src.scales[xKey].ori; - var sPosToVal = src.posToVal; + let sori = src.scales[xKey].ori; + let sPosToVal = src.posToVal; - var sOff, sDim, sc, a, b; + let sOff, sDim, sc, a, b; - var matchingX = xKey != null && matchXKeys(xKey, xKeySrc); - var matchingY = yKey != null && matchYKeys(yKey, yKeySrc); + let matchingX = xKey != null && matchXKeys(xKey, xKeySrc); + let matchingY = yKey != null && matchYKeys(yKey, yKeySrc); if (matchingX) { if (sori == 0) { @@ -4379,10 +4365,10 @@ var uPlot = (function () { setSelX(min(a,b), abs(b-a)); } else - { setSelX(0, xDim); } + setSelX(0, xDim); if (!matchingY) - { setSelY(0, yDim); } + setSelY(0, yDim); } if (matchingY) { @@ -4404,18 +4390,18 @@ var uPlot = (function () { setSelY(min(a,b), abs(b-a)); } else - { setSelY(0, yDim); } + setSelY(0, yDim); if (!matchingX) - { setSelX(0, xDim); } + setSelX(0, xDim); } } else { - var rawDX = abs(rawMouseLeft1 - rawMouseLeft0); - var rawDY = abs(rawMouseTop1 - rawMouseTop0); + let rawDX = abs(rawMouseLeft1 - rawMouseLeft0); + let rawDY = abs(rawMouseTop1 - rawMouseTop0); if (scaleX.ori == 1) { - var _rawDX = rawDX; + let _rawDX = rawDX; rawDX = rawDY; rawDY = _rawDX; } @@ -4423,7 +4409,7 @@ var uPlot = (function () { dragX = drag.x && rawDX >= drag.dist; dragY = drag.y && rawDY >= drag.dist; - var uni = drag.uni; + let uni = drag.uni; if (uni != null) { // only calc drag status if they pass the dist thresh @@ -4434,17 +4420,17 @@ var uPlot = (function () { // force unidirectionality when both are under uni limit if (!dragX && !dragY) { if (rawDY > rawDX) - { dragY = true; } + dragY = true; else - { dragX = true; } + 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; } + dragX = dragY = true; - var p0, p1; + let p0, p1; if (dragX) { if (scaleX.ori == 0) { @@ -4459,7 +4445,7 @@ var uPlot = (function () { setSelX(min(p0, p1), abs(p1 - p0)); if (!dragY) - { setSelY(0, yDim); } + setSelY(0, yDim); } if (dragY) { @@ -4475,7 +4461,7 @@ var uPlot = (function () { setSelY(min(p0, p1), abs(p1 - p0)); if (!dragX) - { setSelX(0, xDim); } + setSelX(0, xDim); } // the drag didn't pass the dist requirement @@ -4495,9 +4481,7 @@ var uPlot = (function () { // if ts is present, means we're implicitly syncing own cursor if (ts != null) { if (syncKey != null) { - var ref$4 = syncOpts.scales; - var xSyncKey = ref$4[0]; - var ySyncKey = ref$4[1]; + let [xSyncKey, ySyncKey] = syncOpts.scales; 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; @@ -4508,18 +4492,18 @@ var uPlot = (function () { pubSync(mousemove, self, mouseLeft1, mouseTop1, plotWidCss, plotHgtCss, idx); if (cursorFocus) { - var o = syncOpts.setSeries; - var p = focus.prox; + let o = syncOpts.setSeries; + let p = focus.prox; if (focusedSeries == null) { if (closestDist <= p) - { setSeries(closestSeries, FOCUS_TRUE, o); } + setSeries(closestSeries, FOCUS_TRUE, o); } else { if (closestDist > p) - { setSeries(null, FOCUS_TRUE, o); } + setSeries(null, FOCUS_TRUE, o); else if (closestSeries != focusedSeries) - { setSeries(closestSeries, FOCUS_TRUE, o); } + setSeries(closestSeries, FOCUS_TRUE, o); } } } @@ -4527,11 +4511,11 @@ var uPlot = (function () { ready && _fire !== false && fire("setCursor"); } - var rect = null; + let rect = null; function syncRect(defer) { if (defer === true) - { rect = null; } + rect = null; else { rect = over.getBoundingClientRect(); fire("syncRect", rect); @@ -4540,21 +4524,19 @@ var uPlot = (function () { function mouseMove(e, src, _l, _t, _w, _h, _i) { if (cursor._lock) - { return; } + return; cacheMouse(e, src, _l, _t, _w, _h, _i, false, e != null); if (e != null) - { updateCursor(1); } + updateCursor(1); else - { updateCursor(null, src); } + updateCursor(null, src); } function cacheMouse(e, src, _l, _t, _w, _h, _i, initial, snap) { - var assign; - if (rect == null) - { syncRect(false); } + syncRect(false); if (e != null) { _l = e.clientX - rect.left; @@ -4567,24 +4549,16 @@ var uPlot = (function () { return; } - var ref = syncOpts.scales; - var xKey = ref[0]; - var yKey = ref[1]; + let [xKey, yKey] = syncOpts.scales; - 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]; + let syncOptsSrc = src.cursor.sync; + let [xValSrc, yValSrc] = syncOptsSrc.values; + let [xKeySrc, yKeySrc] = syncOptsSrc.scales; + let [matchXKeys, matchYKeys] = syncOpts.match; - var rotSrc = src.scales[xKeySrc].ori == 1; + let rotSrc = src.scales[xKeySrc].ori == 1; - var xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss, + let xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss, yDim = scaleX.ori == 1 ? plotWidCss : plotHgtCss, _xDim = rotSrc ? _h : _w, _yDim = rotSrc ? _w : _h, @@ -4592,35 +4566,35 @@ var uPlot = (function () { _yPos = rotSrc ? _l : _t; if (xKeySrc != null) - { _l = matchXKeys(xKey, xKeySrc) ? getPos(xValSrc, scales[xKey], xDim, 0) : -10; } + _l = matchXKeys(xKey, xKeySrc) ? getPos(xValSrc, scales[xKey], xDim, 0) : -10; else - { _l = xDim * (_xPos/_xDim); } + _l = xDim * (_xPos/_xDim); if (yKeySrc != null) - { _t = matchYKeys(yKey, yKeySrc) ? getPos(yValSrc, scales[yKey], yDim, 0) : -10; } + _t = matchYKeys(yKey, yKeySrc) ? getPos(yValSrc, scales[yKey], yDim, 0) : -10; else - { _t = yDim * (_yPos/_yDim); } + _t = yDim * (_yPos/_yDim); if (scaleX.ori == 1) { - var _l$1 = _l; + let __l = _l; _l = _t; - _t = _l$1; + _t = __l; } } if (snap) { if (_l <= 1 || _l >= plotWidCss - 1) - { _l = incrRound(_l, plotWidCss); } + _l = incrRound(_l, plotWidCss); if (_t <= 1 || _t >= plotHgtCss - 1) - { _t = incrRound(_t, plotHgtCss); } + _t = incrRound(_t, plotHgtCss); } if (initial) { rawMouseLeft0 = _l; rawMouseTop0 = _t; - (assign = cursor.move(self, _l, _t), mouseLeft0 = assign[0], mouseTop0 = assign[1]); + [mouseLeft0, mouseTop0] = cursor.move(self, _l, _t); } else { mouseLeft1 = _l; @@ -4652,12 +4626,9 @@ var uPlot = (function () { cacheMouse(e, src, _l, _t, _w, _h, _i, false, true); - var left = select.left; - var top = select.top; - var width = select.width; - var height = select.height; + let { left, top, width, height } = select; - var hasSelect = width > 0 || height > 0; + let hasSelect = width > 0 || height > 0; hasSelect && setSelect(select); @@ -4667,7 +4638,7 @@ var uPlot = (function () { // dragY = drag.y; // } - var xOff = left, + let xOff = left, xDim = width, yOff = top, yDim = height; @@ -4687,8 +4658,8 @@ var uPlot = (function () { } if (dragY) { - for (var k in scales) { - var sc = scales[k]; + for (let k in scales) { + let sc = scales[k]; if (k != xScaleKey && sc.from == null && sc.min != inf) { _setScale(k, @@ -4705,7 +4676,7 @@ var uPlot = (function () { cursor._lock = !cursor._lock; if (!cursor._lock) - { updateCursor(); } + updateCursor(); } if (e != null) { @@ -4716,15 +4687,15 @@ var uPlot = (function () { function mouseLeave(e, src, _l, _t, _w, _h, _i) { if (!cursor._lock) { - var _dragging = dragging; + let _dragging = dragging; if (dragging) { // handle case when mousemove aren't fired all the way to edges by browser - var snapH = true; - var snapV = true; - var snapProx = 10; + let snapH = true; + let snapV = true; + let snapProx = 10; - var dragH, dragV; + let dragH, dragV; if (scaleX.ori == 0) { dragH = dragX; @@ -4742,10 +4713,10 @@ var uPlot = (function () { } if (dragH && snapH) - { mouseLeft1 = mouseLeft1 < mouseLeft0 ? 0 : plotWidCss; } + mouseLeft1 = mouseLeft1 < mouseLeft0 ? 0 : plotWidCss; if (dragV && snapV) - { mouseTop1 = mouseTop1 < mouseTop0 ? 0 : plotHgtCss; } + mouseTop1 = mouseTop1 < mouseTop0 ? 0 : plotHgtCss; updateCursor(1); @@ -4759,7 +4730,7 @@ var uPlot = (function () { updateCursor(1); if (_dragging) - { dragging = _dragging; } + dragging = _dragging; } } @@ -4769,7 +4740,7 @@ var uPlot = (function () { hideSelect(); if (e != null) - { pubSync(dblclick, self, mouseLeft1, mouseTop1, plotWidCss, plotHgtCss, null); } + pubSync(dblclick, self, mouseLeft1, mouseTop1, plotWidCss, plotHgtCss, null); } function syncPxRatio() { @@ -4780,7 +4751,7 @@ var uPlot = (function () { on(ddpxchange, win, syncPxRatio); // internal pub/sub - var events = {}; + const events = {}; events.mousedown = mouseDown; events.mousemove = mouseMove; @@ -4804,7 +4775,7 @@ var uPlot = (function () { } // external on/off - var hooks = self.hooks = opts.hooks || {}; + const hooks = self.hooks = opts.hooks || {}; function fire(evName, a1, a2) { if (evName in hooks) { @@ -4815,11 +4786,11 @@ var uPlot = (function () { } (opts.plugins || []).forEach(p => { - for (var evName in p.hooks) - { hooks[evName] = (hooks[evName] || []).concat(p.hooks[evName]); } + for (let evName in p.hooks) + hooks[evName] = (hooks[evName] || []).concat(p.hooks[evName]); }); - var syncOpts = assign({ + const syncOpts = assign({ key: null, setSeries: false, filters: { @@ -4833,20 +4804,20 @@ var uPlot = (function () { (cursor.sync = syncOpts); - var syncKey = syncOpts.key; + const syncKey = syncOpts.key; - var sync = _sync(syncKey); + const sync = _sync(syncKey); 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); } + sync.pub(type, src, x, y, w, h, i); } sync.sub(self); function pub(type, src, x, y, w, h, i) { if (syncOpts.filters.sub(type, src, x, y, w, h, i)) - { events[type](null, src, x, y, w, h, i); } + events[type](null, src, x, y, w, h, i); } (self.pub = pub); @@ -4868,9 +4839,9 @@ var uPlot = (function () { setData(data || opts.data, false); if (pendScales[xScaleKey]) - { setScale(xScaleKey, pendScales[xScaleKey]); } + setScale(xScaleKey, pendScales[xScaleKey]); else - { autoScaleX(); } + autoScaleX(); _setSize(opts.width, opts.height); @@ -4889,10 +4860,10 @@ var uPlot = (function () { _init(); } else - { then(self, _init); } + then(self, _init); } else - { _init(); } + _init(); return self; } @@ -4921,8 +4892,8 @@ var uPlot = (function () { uPlot.addGap = addGap; uPlot.clipGaps = clipGaps; - var paths = uPlot.paths = { - points: points, + let paths = uPlot.paths = { + points, }; (paths.linear = linear); diff --git a/dist/uPlot.iife.min.js b/dist/uPlot.iife.min.js index e974c1b7..99604cda 100644 --- a/dist/uPlot.iife.min.js +++ b/dist/uPlot.iife.min.js @@ -1,2 +1,2 @@ /*! https://github.com/leeoniya/uPlot (v1.6.15) */ -var uPlot=function(){"use strict";function n(n,e,r,t){var l;r=r||0;for(var a=2147483647>=(t=t||e.length-1);t-r>1;)n>e[l=a?r+t>>1:m((r+t)/2)]?r=l:t=l;return n-e[r]>e[t]-n?t:r}function e(n,e,r,t){for(var l=1==t?e:r;l>=e&&r>=l;l+=t)if(null!=n[l])return l;return-1}var r=[0,0];function t(n,e,t,l){return r[0]=0>t?R(n,-t):n,r[1]=0>l?R(e,-l):e,r}function l(n,e,r,l){var a,i,o,s=k(n),u=10==r?y:M;return n==e&&(-1==s?(n*=r,e/=r):(n/=r,e*=r)),l?(a=m(u(n)),i=x(u(e)),n=(o=t(b(r,a),b(r,i),a,i))[0],e=o[1]):(a=m(u(p(n))),i=m(u(p(e))),n=H(n,(o=t(b(r,a),b(r,i),a,i))[0]),e=F(e,o[1])),[n,e]}function a(n,e,r,t){var a=l(n,e,r,t);return 0==n&&(a[0]=0),0==e&&(a[1]=0),a}var i={mode:3,pad:.1},o={pad:0,soft:null,mode:0},s={min:o,max:o};function u(n,e,r,t){return V(r)?c(n,e,r):(o.pad=r,o.soft=t?0:null,o.mode=t?3:0,c(n,e,s))}function f(n,e){return null==n?e:n}function c(n,e,r){var t=r.min,l=r.max,a=f(t.pad,0),i=f(l.pad,0),o=f(t.hard,-z),s=f(l.hard,z),u=f(t.soft,z),c=f(l.soft,-z),v=f(t.mode,0),h=f(l.mode,0),d=e-n;1e-9>d&&(d=0,0!=n&&0!=e||(d=1e-9,2==v&&u!=z&&(a=0),2==h&&c!=-z&&(i=0)));var g=d||p(e)||1e3,x=y(g),k=b(10,m(x)),M=R(H(n-g*(0==d?0==n?.1:1:a),k/10),9),S=u>n||1!=v&&(3!=v||M>u)&&(2!=v||u>M)?z:u,D=_(o,S>M&&n>=S?S:w(S,M)),E=R(F(e+g*(0==d?0==e?.1:1:i),k/10),9),T=e>c||1!=h&&(3!=h||c>E)&&(2!=h||E>c)?-z:c,A=w(s,E>T&&T>=e?T:_(T,E));return D==A&&0==D&&(A=100),[D,A]}var v=new Intl.NumberFormat(navigator.language).format,h=Math,d=h.PI,p=h.abs,m=h.floor,g=h.round,x=h.ceil,w=h.min,_=h.max,b=h.pow,k=h.sign,y=h.log10,M=h.log2,S=(n,e)=>(void 0===e&&(e=1),h.asinh(n/e)),z=1/0;function D(n,e){return g(n/e)*e}function E(n,e,r){return w(_(n,e),r)}function T(n){return"function"==typeof n?n:()=>n}var A=n=>n,P=(n,e)=>e,W=()=>null,Y=()=>!0,C=(n,e)=>n==e;function F(n,e){return x(n/e)*e}function H(n,e){return m(n/e)*e}function R(n,e){return g(n*(e=Math.pow(10,e)))/e}var L=new Map;function I(n){return((""+n).split(".")[1]||"").length}function G(n,e,r,t){for(var l=[],a=t.map(I),i=e;r>i;i++)for(var o=p(i),s=R(b(n,i),o),u=0;t.length>u;u++){var f=t[u]*s,c=(0>f||0>i?o:0)+(a[u]>i?a[u]:0),v=R(f,c);l.push(v),L.set(v,c)}return l}var B={},N=[null,null],O=Array.isArray;function j(n){return"string"==typeof n}function V(n){var e=!1;if(null!=n){var r=n.constructor;e=null==r||r==Object}return e}function U(n){return null!=n&&"object"==typeof n}function J(n,e){var r;if(e=e||V,O(n))r=n.map((n=>J(n,e)));else if(e(n))for(var t in r={},n)r[t]=J(n[t],e);else r=n;return r}function q(n){for(var e=arguments,r=1;e.length>r;r++){var t=e[r];for(var l in t)V(n[l])?q(n[l],J(t[l])):n[l]=J(t[l])}return n}function Z(n,e,r){for(var t=0,l=void 0,a=-1;e.length>t;t++){var i=e[t];if(i>a){for(l=i-1;l>=0&&null==n[l];)n[l--]=null;for(l=i+1;r>l&&null==n[l];)n[a=l++]=null}}}var K,X,Q="undefined"==typeof queueMicrotask?n=>Promise.resolve().then(n):queueMicrotask,$="width",nn="height",en="top",rn="bottom",tn="left",ln="right",an="#000",on="#0000",sn="mousemove",un="mousedown",fn="mouseup",cn="mouseenter",vn="mouseleave",hn="dblclick",dn="change",pn="dppxchange",mn="u-off",gn="u-label",xn=document,wn=window;function _n(n,e){if(null!=e){var r=n.classList;!r.contains(e)&&r.add(e)}}function bn(n,e){var r=n.classList;r.contains(e)&&r.remove(e)}function kn(n,e,r){n.style[e]=r+"px"}function yn(n,e,r,t){var l=xn.createElement(n);return null!=e&&_n(l,e),null!=r&&r.insertBefore(l,t),l}function Mn(n,e){return yn("div",n,e)}var Sn=new WeakMap;function zn(n,e,r,t,l){var a="translate("+e+"px,"+r+"px)";a!=Sn.get(n)&&(n.style.transform=a,Sn.set(n,a),0>e||0>r||e>t||r>l?_n(n,mn):bn(n,mn))}var Dn=new WeakMap;function En(n,e,r){var t=e+r;t!=Dn.get(n)&&(Dn.set(n,t),n.style.background=e,n.style.borderColor=r)}var Tn={passive:!0},An=q({capture:!0},Tn);function Pn(n,e,r,t){e.addEventListener(n,r,t?An:Tn)}function Wn(n,e,r,t){e.removeEventListener(n,r,t?An:Tn)}!function n(){K=devicePixelRatio,X&&Wn(dn,X,n),X=matchMedia("screen and (min-resolution: "+(K-.001)+"dppx) and (max-resolution: "+(K+.001)+"dppx)"),Pn(dn,X,n),wn.dispatchEvent(new CustomEvent(pn))}();var Yn=["January","February","March","April","May","June","July","August","September","October","November","December"],Cn=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function Fn(n){return n.slice(0,3)}var Hn=Cn.map(Fn),Rn=Yn.map(Fn),Ln={MMMM:Yn,MMM:Rn,WWWW:Cn,WWW:Hn};function In(n){return(10>n?"0":"")+n}var Gn={YYYY:n=>n.getFullYear(),YY:n=>(n.getFullYear()+"").slice(2),MMMM:(n,e)=>e.MMMM[n.getMonth()],MMM:(n,e)=>e.MMM[n.getMonth()],MM:n=>In(n.getMonth()+1),M:n=>n.getMonth()+1,DD:n=>In(n.getDate()),D:n=>n.getDate(),WWWW:(n,e)=>e.WWWW[n.getDay()],WWW:(n,e)=>e.WWW[n.getDay()],HH:n=>In(n.getHours()),H:n=>n.getHours(),h:n=>{var e=n.getHours();return 0==e?12:e>12?e-12:e},AA:n=>12>n.getHours()?"AM":"PM",aa:n=>12>n.getHours()?"am":"pm",a:n=>12>n.getHours()?"a":"p",mm:n=>In(n.getMinutes()),m:n=>n.getMinutes(),ss:n=>In(n.getSeconds()),s:n=>n.getSeconds(),fff:n=>function(n){return(10>n?"00":100>n?"0":"")+n}(n.getMilliseconds())};function Bn(n,e){e=e||Ln;for(var r,t=[],l=/\{([a-z]+)\}|[^{]+/gi;r=l.exec(n);)t.push("{"==r[0][0]?Gn[r[1]]:r[0]);return n=>{for(var r="",l=0;t.length>l;l++)r+="string"==typeof t[l]?t[l]:t[l](n,e);return r}}var Nn=(new Intl.DateTimeFormat).resolvedOptions().timeZone,On=n=>n%1==0,jn=[1,2,2.5,5],Vn=G(10,-16,0,jn),Un=G(10,0,16,jn),Jn=Un.filter(On),qn=Vn.concat(Un),Zn="{YYYY}",Kn="\n"+Zn,Xn="{M}/{D}",Qn="\n"+Xn,$n=Qn+"/{YY}",ne="{aa}",ee="{h}:{mm}"+ne,re="\n"+ee,te=":{ss}",le=null;function ae(n){var e=1e3*n,r=60*e,t=60*r,l=24*t,a=30*l,i=365*l;return[(1==n?G(10,0,3,jn).filter(On):G(10,-3,0,jn)).concat([e,5*e,10*e,15*e,30*e,r,5*r,10*r,15*r,30*r,t,2*t,3*t,4*t,6*t,8*t,12*t,l,2*l,3*l,4*l,5*l,6*l,7*l,8*l,9*l,10*l,15*l,a,2*a,3*a,4*a,6*a,i,2*i,5*i,10*i,25*i,50*i,100*i]),[[i,Zn,le,le,le,le,le,le,1],[28*l,"{MMM}",Kn,le,le,le,le,le,1],[l,Xn,Kn,le,le,le,le,le,1],[t,"{h}"+ne,$n,le,Qn,le,le,le,1],[r,ee,$n,le,Qn,le,le,le,1],[e,te,$n+" "+ee,le,Qn+" "+ee,le,re,le,1],[n,te+".{fff}",$n+" "+ee,le,Qn+" "+ee,le,re,le,1]],function(e){return(o,s,u,f,c,v)=>{var h=[],d=c>=i,p=c>=a&&i>c,x=e(u),w=R(x*n,3),_=me(x.getFullYear(),d?0:x.getMonth(),p||d?1:x.getDate()),b=R(_*n,3);if(p||d)for(var k=p?c/a:0,y=d?c/i:0,M=w==b?w:R(me(_.getFullYear()+y,_.getMonth()+k,1)*n,3),S=new Date(g(M/n)),z=S.getFullYear(),D=S.getMonth(),E=0;f>=M;E++){var T=me(z+y*E,D+k*E,1),A=T-e(R(T*n,3));(M=R((+T+A)*n,3))>f||h.push(M)}else{var P=l>c?c:l,W=b+(m(u)-m(w))+F(w-b,P);h.push(W);for(var Y=e(W),C=Y.getHours()+Y.getMinutes()/r+Y.getSeconds()/t,H=c/t,L=v/o.axes[s]._space;(W=R(W+c,1==n?0:3))<=f;)if(H>1){var I=m(R(C+H,6))%24,G=e(W).getHours()-I;G>1&&(G=-1),C=(C+H)%24,.7>R(((W-=G*t)-h[h.length-1])/c,3)*L||h.push(W)}else h.push(W)}return h}}]}var ie=ae(1),oe=ie[0],se=ie[1],ue=ie[2],fe=ae(.001),ce=fe[0],ve=fe[1],he=fe[2];function de(n,e){return n.map((n=>n.map(((r,t)=>0==t||8==t||null==r?r:e(1==t||0==n[8]?r:n[1]+r)))))}function pe(n,e){return(r,t,l,a,i)=>{var o,s,u,f,c,v,h=e.find((n=>i>=n[0]))||e[e.length-1];return t.map((e=>{var r=n(e),t=r.getFullYear(),l=r.getMonth(),a=r.getDate(),i=r.getHours(),d=r.getMinutes(),p=r.getSeconds(),m=t!=o&&h[2]||l!=s&&h[3]||a!=u&&h[4]||i!=f&&h[5]||d!=c&&h[6]||p!=v&&h[7]||h[1];return o=t,s=l,u=a,f=i,c=d,v=p,m(r)}))}}function me(n,e,r){return new Date(n,e,r)}function ge(n,e){return e(n)}function xe(n,e){return(r,t)=>e(n(t))}G(2,-53,53,[1]);var we={show:!0,live:!0,isolate:!1,markers:{show:!0,width:2,stroke:function(n,e){var r=n.series[e];return r.width?r.stroke(n,e):r.points.width?r.points.stroke(n,e):null},fill:function(n,e){return n.series[e].fill(n,e)},dash:"solid"},idx:null,idxs:null,values:[]},_e=[0,0];function be(n,e,r){return n=>{0==n.button&&r(n)}}function ke(n,e,r){return r}var ye={show:!0,x:!0,y:!0,lock:!1,move:function(n,e,r){return _e[0]=e,_e[1]=r,_e},points:{show:function(n,e){var r=n.cursor.points,t=Mn(),l=r.size(n,e);kn(t,$,l),kn(t,nn,l);var a=l/-2;kn(t,"marginLeft",a),kn(t,"marginTop",a);var i=r.width(n,e,l);return i&&kn(t,"borderWidth",i),t},size:function(n,e){return Be(n.series[e].points.width,1)},width:0,stroke:function(n,e){var r=n.series[e].points;return r._stroke||r._fill},fill:function(n,e){var r=n.series[e].points;return r._fill||r._stroke}},bind:{mousedown:be,mouseup:be,click:be,dblclick:be,mousemove:ke,mouseleave:ke,mouseenter:ke},drag:{setScale:!0,x:!0,y:!1,dist:0,uni:null,_x:!1,_y:!1},focus:{prox:-1},left:-10,top:-10,idx:null,dataIdx:function(n,e,r){return r},idxs:null},Me={show:!0,stroke:"rgba(0,0,0,0.07)",width:2,filter:P},Se=q({},Me,{size:10}),ze='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"',De="bold "+ze,Ee={show:!0,scale:"x",stroke:an,space:50,gap:5,size:50,labelGap:0,labelSize:30,labelFont:De,side:2,grid:Me,ticks:Se,font:ze,rotate:0},Te={show:!0,scale:"x",auto:!1,sorted:1,min:z,max:-z,idxs:[]};function Ae(n,e){return e.map((n=>null==n?"":v(n)))}function Pe(n,e,r,t,l,a,i){for(var o=[],s=L.get(l)||0,u=r=i?r:R(F(r,l),s);t>=u;u=R(u+l,s))o.push(Object.is(u,-0)?0:u);return o}function We(n,e,r,t,l){var a=[],i=n.scales[n.axes[e].scale].log,o=m((10==i?y:M)(r));l=b(i,o),0>o&&(l=R(l,-o));var s=r;do{a.push(s),l*i>(s=R(s+l,L.get(l)))||(l=s)}while(t>=s);return a}function Ye(n,e,r,t,l){var a=n.scales[n.axes[e].scale].asinh,i=t>a?We(n,e,_(a,r),t,l):[a],o=0>t||r>0?[]:[0];return(-a>r?We(n,e,_(a,-t),-r,l):[a]).reverse().map((n=>-n)).concat(o,i)}var Ce=/./,Fe=/[12357]/,He=/[125]/,Re=/1/;function Le(n,e,r){var t=n.axes[r],l=t.scale,a=n.scales[l];if(3==a.distr&&2==a.log)return e;var i=n.valToPos,o=t._space,s=i(10,l),u=i(9,l)-s4==a.distr&&0==n||u.test(n)?n:null))}function Ie(n,e){return null==e?"":v(e)}var Ge={show:!0,scale:"y",stroke:an,space:30,gap:5,size:50,labelGap:0,labelSize:30,labelFont:De,side:3,grid:Me,ticks:Se,font:ze,rotate:0};function Be(n,e){return R((3+2*(n||1))*e,3)}function Ne(n,e){var r=n.scales[n.series[e].scale],t=n.bands&&n.bands.some((n=>n.series[0]==e));return 3==r.distr||t?r.min:0}var Oe={scale:"y",auto:!0,sorted:0,show:!0,spanGaps:!1,gaps:(n,e,r,t,l)=>l,alpha:1,points:{show:function(n,e){var r=n.series[0],t=r.scale,l=r.idxs,a=n._data[0],i=n.valToPos(a[l[0]],t,!0),o=n.valToPos(a[l[1]],t,!0);return p(o-i)/(n.series[e].points.space*K)>=l[1]-l[0]},filter:null},values:null,min:z,max:-z,idxs:[],path:null,clip:null};function je(n,e,r){return r/10}var Ve={time:!0,auto:!0,distr:1,log:10,asinh:1,min:null,max:null,dir:1,ori:0},Ue=q({},Ve,{time:!1,ori:1}),Je={};function qe(n){var e=Je[n];return e||(e={key:n,plots:[],sub:function(n){e.plots.push(n)},unsub:function(n){e.plots=e.plots.filter((e=>e!=n))},pub:function(n,r,t,l,a,i,o){for(var s=0;e.plots.length>s;s++)e.plots[s]!=r&&e.plots[s].pub(n,r,t,l,a,i,o)}},null!=n&&(Je[n]=e)),e}function Ze(n,e,r){var t=n.series[e],l=n.scales,a=n.bbox,i=n._data[0],o=n._data[e],s=l[n.series[0].scale],u=l[t.scale],f=a.left,c=a.top,v=a.width,h=a.height,d=n.valToPosH,p=n.valToPosV;return 0==s.ori?r(t,i,o,s,u,d,p,f,c,v,h,nr,rr,lr,ir,sr):r(t,i,o,s,u,p,d,c,f,h,v,er,tr,ar,or,ur)}function Ke(n,e,r,t,l){return Ze(n,e,((n,e,a,i,o,s,u,f,c,v,h)=>{var d,p,m=0==i.ori?rr:tr;1==i.dir*(0==i.ori?1:-1)?(d=r,p=t):(d=t,p=r);var g=D(s(e[d],i,v,f),.5),x=D(u(a[d],o,h,c),.5),w=D(s(e[p],i,v,f),.5),_=D(u(o.max,o,h,c),.5),b=new Path2D(l);return m(b,w,_),m(b,g,_),m(b,g,x),b}))}function Xe(n,e,r,t,l,a){var i=null;if(n.length>0){i=new Path2D;for(var o=0==e?lr:ar,s=r,u=0;n.length>u;u++){var f=n[u];f[1]>f[0]&&(o(i,s,t,f[0]-s,t+a),s=f[1])}o(i,s,t,r+l-s,t+a)}return i}function Qe(n,e,r){var t=n[n.length-1];t&&t[0]==e?t[1]=r:n.push([e,r])}function $e(n){return 0==n?A:1==n?g:e=>D(e,n)}function nr(n,e,r){n.moveTo(e,r)}function er(n,e,r){n.moveTo(r,e)}function rr(n,e,r){n.lineTo(e,r)}function tr(n,e,r){n.lineTo(r,e)}function lr(n,e,r,t,l){n.rect(e,r,t,l)}function ar(n,e,r,t,l){n.rect(r,e,l,t)}function ir(n,e,r,t,l,a){n.arc(e,r,t,l,a)}function or(n,e,r,t,l,a){n.arc(r,e,t,l,a)}function sr(n,e,r,t,l,a,i){n.bezierCurveTo(e,r,t,l,a,i)}function ur(n,e,r,t,l,a,i){n.bezierCurveTo(r,e,l,t,i,a)}function fr(){return(n,e,r,t,l)=>Ze(n,e,((e,a,i,o,s,u,f,c,v,h,p)=>{var m,g,x=e.pxRound,w=e.points;0==o.ori?(m=nr,g=ir):(m=er,g=or);var _=R(w.width*K,3),b=(w.size-w.width)/2*K,k=R(2*b,3),y=new Path2D,M=new Path2D,S=n.bbox;lr(M,S.left-k,S.top-k,S.width+2*k,S.height+2*k);var z=n=>{if(null!=i[n]){var e=x(u(a[n],o,h,c)),r=x(f(i[n],s,p,v));m(y,e+b,r),g(y,e,r,b,0,2*d)}};if(l)l.forEach(z);else for(var D=r;t>=D;D++)z(D);return{stroke:_>0?y:null,fill:y,clip:M,flags:3}}))}function cr(n){return(e,r,t,l,a,i)=>{t!=l&&(a!=t&&i!=t&&n(e,r,t),a!=l&&i!=l&&n(e,r,l),n(e,r,i))}}var vr=cr(rr),hr=cr(tr);function dr(){return(n,r,t,l)=>Ze(n,r,((a,i,o,s,u,f,c,v,h,d,p)=>{var m,g,x=a.pxRound;0==s.ori?(m=rr,g=vr):(m=tr,g=hr);var b,k,y,M,S=s.dir*(0==s.ori?1:-1),E={stroke:new Path2D,fill:null,clip:null,band:null,gaps:null,flags:1},T=E.stroke,A=z,P=-z,W=[],Y=x(f(i[1==S?t:l],s,d,v)),C=!1,F=!1,H=e(o,t,l,1*S),R=e(o,t,l,-1*S),L=D(f(i[H],s,d,v),.5),I=D(f(i[R],s,d,v),.5);L>v&&Qe(W,v,L);for(var G=1==S?t:l;G>=t&&l>=G;G+=S){var B=x(f(i[G],s,d,v));if(B==Y)null!=o[G]?(k=x(c(o[G],u,p,h)),A==z&&(m(T,B,k),b=k),A=w(k,A),P=_(k,P)):null===o[G]&&(C=F=!0);else{var N=!1;A!=z?(g(T,Y,A,P,b,k),y=M=Y):C&&(N=!0,C=!1),null!=o[G]?(m(T,B,k=x(c(o[G],u,p,h))),A=P=b=k,F&&B-Y>1&&(N=!0),F=!1):(A=z,P=-z,null===o[G]&&(C=!0,B-Y>1&&(N=!0))),N&&Qe(W,y,B),Y=B}}if(A!=z&&A!=P&&M!=Y&&g(T,Y,A,P,b,k),v+d>I&&Qe(W,I,v+d),null!=a.fill){var O=E.fill=new Path2D(T),j=x(c(a.fillTo(n,r,a.min,a.max),u,p,h));m(O,I,j),m(O,L,j)}return E.gaps=W=a.gaps(n,r,t,l,W),a.spanGaps||(E.clip=Xe(W,s.ori,v,h,d,p)),n.bands.length>0&&(E.band=Ke(n,r,t,l,T)),E}))}function pr(n,e,r,t,l){var a=n.length;if(2>a)return null;var i=new Path2D;if(r(i,n[0],e[0]),2==a)t(i,n[1],e[1]);else{for(var o=Array(a),s=Array(a-1),u=Array(a-1),f=Array(a-1),c=0;a-1>c;c++)u[c]=e[c+1]-e[c],f[c]=n[c+1]-n[c],s[c]=u[c]/f[c];o[0]=s[0];for(var v=1;a-1>v;v++)0===s[v]||0===s[v-1]||s[v-1]>0!=s[v]>0?o[v]=0:(o[v]=3*(f[v-1]+f[v])/((2*f[v]+f[v-1])/s[v-1]+(f[v]+2*f[v-1])/s[v]),isFinite(o[v])||(o[v]=0));o[a-1]=s[a-2];for(var h=0;a-1>h;h++)l(i,n[h]+f[h]/3,e[h]+o[h]*f[h]/3,n[h+1]-f[h]/3,e[h+1]-o[h+1]*f[h]/3,n[h+1],e[h+1])}return i}var mr=new Set;function gr(){mr.forEach((n=>{n.syncRect(!0)}))}Pn("resize",wn,gr),Pn("scroll",wn,gr,!0);var xr=dr(),wr=fr();function _r(n,e,r,t){return(t?[n[0],n[1]].concat(n.slice(2)):[n[0]].concat(n.slice(1))).map(((n,t)=>br(n,t,e,r)))}function br(n,e,r,t){return q({},0==e?r:t,n)}function kr(n,e,r){return null==e?N:[e,r]}var yr=kr;function Mr(n,e,r){return null==e?N:u(e,r,.1,!0)}function Sr(n,e,r,t){return null==e?N:l(e,r,n.scales[t].log,!1)}var zr=Sr;function Dr(n,e,r,t){return null==e?N:a(e,r,n.scales[t].log,!1)}var Er=Dr;function Tr(n){var e,r;return[n=n.replace(/(\d+)px/,((n,t)=>(e=g((r=+t)*K))+"px")),e,r]}function Ar(n){n.show&&[n.font,n.labelFont].forEach((n=>{var e=R(n[2]*K,1);n[0]=n[0].replace(/[0-9.]+px/,e+"px"),n[1]=e}))}function Pr(e,r,t){var o={};function s(n,e){return((3==e.distr?y(n>0?n:e.clamp(o,n,e.min,e.max,e.key)):4==e.distr?S(n,e.asinh):n)-e._min)/(e._max-e._min)}function c(n,e,r,t){var l=s(n,e);return t+r*(-1==e.dir?1-l:l)}function v(n,e,r,t){var l=s(n,e);return t+r*(-1==e.dir?l:1-l)}function k(n,e,r,t){return 0==e.ori?c(n,e,r,t):v(n,e,r,t)}o.valToPosH=c,o.valToPosV=v;var M=!1;o.status=0;var A=o.root=Mn("uplot");null!=e.id&&(A.id=e.id),_n(A,e.class),e.title&&(Mn("u-title",A).textContent=e.title);var H=yn("canvas"),I=o.ctx=H.getContext("2d"),G=Mn("u-wrap",A),Z=o.under=Mn("u-under",G);G.appendChild(H);var X=o.over=Mn("u-over",G),an=+f((e=J(e)).pxAlign,1),dn=$e(an);(e.plugins||[]).forEach((n=>{n.opts&&(e=n.opts(o,e)||e)}));var Sn=e.ms||.001,Dn=o.series=_r(e.series||[],Te,Oe,!1),Tn=o.axes=_r(e.axes||[],Ee,Ge,!0),An=o.scales={},Yn=o.bands=e.bands||[];Yn.forEach((n=>{n.fill=T(n.fill||null)}));var Cn=Dn[0].scale,Fn={axes:function(){Tn.forEach(((n,e)=>{if(n.show&&n._show){var r,t,l=n.side,a=l%2,i=n.stroke(o,e),s=0==l||3==l?-1:1;if(n.label){var u=g((n._lpos+n.labelGap*s)*K);I.save(),1==a?(r=t=0,I.translate(u,g(er+tr/2)),I.rotate((3==l?-d:d)/2)):(r=g(nr+rr/2),t=u),I.font=n.labelFont[0],I.fillStyle=i,I.textAlign="center",I.textBaseline=2==l?en:rn,I.fillText(n.label,r,t),I.restore()}var f=n._found,c=f[0],v=f[1];if(0!=v){var h=An[n.scale],p=0==a?rr:tr,m=0==a?nr:er,x=g(n.gap*K),w=n._splits,_=2==h.distr?w.map((n=>Ir[n])):w,b=2==h.distr?Ir[w[1]]-Ir[w[0]]:c,y=n.ticks,M=y.show?g(y.size*K):0,S=n._rotate*-d/180,z=dn(n._pos*K),D=z+(M+x)*s;t=0==a?D:0,r=1==a?D:0,I.font=n.font[0],I.fillStyle=i,I.textAlign=1==n.align?tn:2==n.align?ln:S>0?tn:0>S?ln:0==a?"center":3==l?ln:tn,I.textBaseline=S||1==a?"middle":2==l?en:rn;var E=1.5*n.font[1],T=w.map((n=>dn(k(n,h,p,m))));n._values.forEach(((n,e)=>{null!=n&&(0==a?r=T[e]:t=T[e],(""+n).split(/\n/gm).forEach(((n,e)=>{S?(I.save(),I.translate(r,t+e*E),I.rotate(S),I.fillText(n,0,0),I.restore()):I.fillText(n,r,t+e*E)})))})),y.show&&Zr(T,y.filter(o,_,e,v,b),a,l,z,M,R(y.width*K,3),y.stroke(o,e),y.dash,y.cap);var A=n.grid;A.show&&Zr(T,A.filter(o,_,e,v,b),a,0==a?2:1,0==a?er:nr,0==a?tr:rr,R(A.width*K,3),A.stroke(o,e),A.dash,A.cap)}}})),qt("drawAxes")},series:function(){Yr>0&&(Dn.forEach(((n,e)=>{if(e>0&&n.show&&null==n._paths){var t=function(n){for(var e=E(Hr-1,0,Yr-1),r=E(Rr+1,0,Yr-1);null==n[e]&&e>0;)e--;for(;null==n[r]&&Yr-1>r;)r++;return[e,r]}(r[e]);n._paths=n.paths(o,e,t[0],t[1])}})),Dn.forEach(((n,e)=>{if(e>0&&n.show){jr(e,!1),n._paths&&Vr(e,!1),jr(e,!0);var r=n.points.show(o,e,Hr,Rr),t=n.points.filter(o,e,r,n._paths?n._paths.gaps:null);(r||t)&&(n.points._paths=n.points.paths(o,e,Hr,Rr,t),Vr(e,!0)),qt("drawSeries",e)}})))}},Hn=(e.drawOrder||["axes","series"]).map((n=>Fn[n]));function Rn(n){var r=An[n];if(null==r){var t=(e.scales||B)[n]||B;if(null!=t.from)Rn(t.from),An[n]=q({},An[t.from],t);else{(r=An[n]=q({},n==Cn?Ve:Ue,t)).key=n;var l=r.time,a=r.range,o=O(a);if(n!=Cn&&(!o||null!=a[0]&&null!=a[1]||(a={min:null==a[0]?i:{mode:1,hard:a[0],soft:a[0]},max:null==a[1]?i:{mode:1,hard:a[1],soft:a[1]}},o=!1),!o&&V(a))){var s=a;a=(n,e,r)=>null==e?N:u(e,r,s)}r.range=T(a||(l?yr:n==Cn?3==r.distr?zr:4==r.distr?Er:kr:3==r.distr?Sr:4==r.distr?Dr:Mr)),r.auto=T(!o&&r.auto),r.clamp=T(r.clamp||je),r._min=r._max=null}}}for(var Ln in Rn("x"),Rn("y"),Dn.forEach((n=>{Rn(n.scale)})),Tn.forEach((n=>{Rn(n.scale)})),e.scales)Rn(Ln);var In,Gn,Nn=An[Cn],On=Nn.distr;0==Nn.ori?(_n(A,"u-hz"),In=c,Gn=v):(_n(A,"u-vt"),In=v,Gn=c);var jn={};for(var Vn in An){var Un=An[Vn];null==Un.min&&null==Un.max||(jn[Vn]={min:Un.min,max:Un.max},Un.min=Un.max=null)}var Zn,Kn=e.tzDate||(n=>new Date(g(n/Sn))),Xn=e.fmtDate||Bn,Qn=1==Sn?ue(Kn):he(Kn),$n=pe(Kn,de(1==Sn?se:ve,Xn)),ne=xe(Kn,ge("{YYYY}-{MM}-{DD} {h}:{mm}{aa}",Xn)),ee=[],re=o.legend=q({},we,e.legend),te=re.show,le=re.markers;re.idxs=ee,le.width=T(le.width),le.dash=T(le.dash),le.stroke=T(le.stroke),le.fill=T(le.fill);var ae,ie=[],fe=[],me=!1,_e={};if(re.live){var be=Dn[1]?Dn[1].values:null;for(var ke in ae=(me=null!=be)?be(o,1,0):{_:0})_e[ke]="--"}if(te)if(Zn=yn("table","u-legend",A),me){var Me=yn("tr","u-thead",Zn);for(var Se in yn("th",null,Me),ae)yn("th",gn,Me).textContent=Se}else _n(Zn,"u-inline"),re.live&&_n(Zn,"u-live");var ze={show:!0},De={show:!1},Ce=new Map;function Fe(n,e,r){var t=Ce.get(e)||{},l=cr.bind[n](o,e,r);l&&(Pn(n,e,t[n]=l),Ce.set(e,t))}function He(n,e){var r=Ce.get(e)||{};for(var t in r)null!=n&&t!=n||(Wn(t,e,r[t]),delete r[t]);null==n&&Ce.delete(e)}var Re=0,Je=0,Ze=0,Ke=0,Xe=0,Qe=0,nr=0,er=0,rr=0,tr=0;o.bbox={};var lr=!1,ar=!1,ir=!1,or=!1,sr=!1;function ur(n,e,r){(r||n!=o.width||e!=o.height)&&fr(n,e),Qr(!1),ir=!0,ar=!0,or=sr=cr.left>=0,vt()}function fr(n,e){o.width=Re=Ze=n,o.height=Je=Ke=e,Xe=Qe=0,function(){var n=!1,e=!1,r=!1,t=!1;Tn.forEach((l=>{if(l.show&&l._show){var a=l.side,i=a%2,o=l._size+(l.labelSize=null!=l.label?l.labelSize||30:0);o>0&&(i?(Ze-=o,3==a?(Xe+=o,t=!0):r=!0):(Ke-=o,0==a?(Qe+=o,n=!0):e=!0))}})),Pr[0]=n,Pr[1]=r,Pr[2]=e,Pr[3]=t,Ze-=Fr[1]+Fr[3],Xe+=Fr[3],Ke-=Fr[2]+Fr[0],Qe+=Fr[0]}(),function(){var n=Xe+Ze,e=Qe+Ke,r=Xe,t=Qe;function l(l,a){switch(l){case 1:return(n+=a)-a;case 2:return(e+=a)-a;case 3:return(r-=a)+a;case 0:return(t-=a)+a}}Tn.forEach((n=>{if(n.show&&n._show){var e=n.side;n._pos=l(e,n._size),null!=n.label&&(n._lpos=l(e,n.labelSize))}}))}();var r=o.bbox;nr=r.left=D(Xe*K,.5),er=r.top=D(Qe*K,.5),rr=r.width=D(Ze*K,.5),tr=r.height=D(Ke*K,.5)}o.setSize=function(n){ur(n.width,n.height)};var cr=o.cursor=q({},ye,e.cursor);cr.idxs=ee,cr._lock=!1;var vr=cr.points;vr.show=T(vr.show),vr.size=T(vr.size),vr.stroke=T(vr.stroke),vr.width=T(vr.width),vr.fill=T(vr.fill);var hr=o.focus=q({},e.focus||{alpha:.3},cr.focus),dr=hr.prox>=0,pr=[null];function gr(n,e){var r=An[n.scale].time,t=n.value;if(n.value=r?j(t)?xe(Kn,ge(t,Xn)):t||ne:t||Ie,n.label=n.label||(r?"Time":"Value"),e>0){n.width=null==n.width?1:n.width,n.paths=n.paths||xr||W,n.fillTo=T(n.fillTo||Ne),n.pxAlign=+f(n.pxAlign,an),n.pxRound=$e(n.pxAlign),n.stroke=T(n.stroke||null),n.fill=T(n.fill||null),n._stroke=n._fill=n._paths=n._focus=null;var l=Be(n.width,1),a=n.points=q({},{size:l,width:_(1,.2*l),stroke:n.stroke,space:2*l,paths:wr,_stroke:null,_fill:null},n.points);a.show=T(a.show),a.filter=T(a.filter),a.fill=T(a.fill),a.stroke=T(a.stroke),a.paths=T(a.paths),a.pxAlign=n.pxAlign}if(te){var i=function(n,e){if(0==e&&(me||!re.live))return N;var r=[],t=yn("tr","u-series",Zn,Zn.childNodes[e]);_n(t,n.class),n.show||_n(t,mn);var l=yn("th",null,t);if(le.show){var a=Mn("u-marker",l);if(e>0){var i=le.width(o,e);i&&(a.style.border=i+"px "+le.dash(o,e)+" "+le.stroke(o,e)),a.style.background=le.fill(o,e)}}var s=Mn(gn,l);for(var u in s.textContent=n.label,e>0&&(le.show||(s.style.color=n.width>0?le.stroke(o,e):le.fill(o,e)),Fe("click",l,(e=>{if(!cr._lock){var r=Dn.indexOf(n);if(e.ctrlKey!=re.isolate){var t=Dn.some(((n,e)=>e>0&&e!=r&&n.show));Dn.forEach(((n,e)=>{e>0&&zt(e,t?e==r?ze:De:ze,Zt.setSeries)}))}else zt(r,{show:!n.show},Zt.setSeries)}})),dr&&Fe(cn,l,(()=>{cr._lock||zt(Dn.indexOf(n),Dt,Zt.setSeries)}))),ae){var f=yn("td","u-value",t);f.textContent="--",r.push(f)}return[t,r]}(n,e);ie.splice(e,0,i[0]),fe.splice(e,0,i[1]),re.values.push(null)}if(cr.show){ee.splice(e,0,null);var s=function(n,e){if(e>0){var r=cr.points.show(o,e);if(r)return _n(r,"u-cursor-pt"),_n(r,n.class),zn(r,-10,-10,Ze,Ke),X.insertBefore(r,pr[e]),r}}(n,e);s&&pr.splice(e,0,s)}}o.addSeries=function(n,e){n=br(n,e=null==e?Dn.length:e,Te,Oe),Dn.splice(e,0,n),gr(Dn[e],e)},o.delSeries=function(n){if(Dn.splice(n,1),te){re.values.splice(n,1),fe.splice(n,1);var e=ie.splice(n,1)[0];He(null,e.firstChild),e.remove()}cr.show&&(ee.splice(n,1),pr.length>1&&pr.splice(n,1)[0].remove())};var Pr=[!1,!1,!1,!1];function Wr(n,e,r){var t=r[0],l=r[1],a=r[2],i=r[3],o=e%2,s=0;return 0==o&&(i||l)&&(s=0==e&&!t||2==e&&!a?g(Ee.size/3):0),1==o&&(t||a)&&(s=1==e&&!l||3==e&&!i?g(Ge.size/2):0),s}var Yr,Cr=o.padding=(e.padding||[Wr,Wr,Wr,Wr]).map((n=>T(f(n,Wr)))),Fr=o._padding=Cr.map(((n,e)=>n(o,e,Pr,0))),Hr=null,Rr=null,Lr=Dn[0].idxs,Ir=null,Gr=!1;function Br(n,e){if((r=(n||[]).slice())[0]=r[0]||[],o.data=r.slice(),Yr=(Ir=r[0]).length,2==On&&(r[0]=Ir.map(((n,e)=>e))),o._data=r,Qr(!0),qt("setData"),!1!==e){var t=Nn;t.auto(o,Gr)?Nr():St(Cn,t.min,t.max),or=cr.left>=0,sr=!0,vt()}}function Nr(){var n,e,t,i,o;Gr=!0,Yr>0?(Hr=Lr[0]=0,Rr=Lr[1]=Yr-1,i=r[0][Hr],o=r[0][Rr],2==On?(i=Hr,o=Rr):1==Yr&&(3==On?(i=(n=l(i,i,Nn.log,!1))[0],o=n[1]):4==On?(i=(e=a(i,i,Nn.log,!1))[0],o=e[1]):Nn.time?o=i+g(86400/Sn):(i=(t=u(i,o,.1,!0))[0],o=t[1]))):(Hr=Lr[0]=i=null,Rr=Lr[1]=o=null),St(Cn,i,o)}function Or(n,e,r,t,l){I.strokeStyle=n||on,I.lineWidth=e,I.lineJoin="round",I.lineCap=t||"butt",I.setLineDash(r||[]),I.fillStyle=l||on}function jr(n,e){var r=e?Dn[n].points:Dn[n];r._stroke=r.stroke(o,n),r._fill=r.fill(o,n)}function Vr(n,e){var r=e?Dn[n].points:Dn[n],t=r._stroke,l=r._fill,a=r._paths,i=a.stroke,s=a.fill,u=a.clip,f=a.flags,c=R(r.width*K,3),v=c%2/2;e&&null==l&&(l=c>0?"#fff":t),I.globalAlpha=r.alpha;var h=1==r.pxAlign;if(h&&I.translate(v,v),I.save(),!e){var d=nr,p=er,m=rr,g=tr,x=c*K/2;0==r.min&&(g+=x),0==r.max&&(p-=x,g+=x),I.beginPath(),I.rect(d,p,m,g),I.clip()}u&&I.clip(u),e?Ur(t,c,r.dash,r.cap,l,i,s,null,f):function(n,e,r,t,l,a,i,s,u){var f=!1;Yn.forEach(((c,v)=>{if(c.series[0]==n){var h=Dn[c.series[1]],d=(h._paths||B).band;I.save();var p=null;h.show&&d?p=c.fill(o,v)||a:d=null,Ur(e,r,t,l,p,i,s,d,u),I.restore(),f=!0}})),f||Ur(e,r,t,l,a,i,s,null,u)}(n,t,c,r.dash,r.cap,l,i,s,f),I.restore(),h&&I.translate(-v,-v),I.globalAlpha=1}function Ur(n,e,r,t,l,a,i,o,s){Or(n,e,r,t,l),o?3==(3&s)?(I.clip(o),qr(l,i),Jr(n,a,e)):2&s?(qr(l,i),I.clip(o),Jr(n,a,e)):1&s&&(I.save(),I.clip(o),qr(l,i),I.restore(),Jr(n,a,e)):(qr(l,i),Jr(n,a,e))}function Jr(n,e,r){n&&e&&r&&I.stroke(e)}function qr(n,e){n&&e&&I.fill(e)}function Zr(n,e,r,t,l,a,i,o,s,u){var f=i%2/2;1==an&&I.translate(f,f),Or(o,i,s,u),I.beginPath();var c,v,h,d,p=l+(0==t||3==t?-a:a);0==r?(v=l,d=p):(c=l,h=p),n.forEach(((n,t)=>{null!=e[t]&&(0==r?c=h=n:v=d=n,I.moveTo(c,v),I.lineTo(h,d))})),I.stroke(),1==an&&I.translate(-f,-f)}function Kr(n){var e=!0;return Tn.forEach(((r,t)=>{if(r.show){var l=An[r.scale];if(null!=l.min){r._show||(e=!1,r._show=!0,Qr(!1));var a=r.side,i=l.min,s=l.max,u=function(n,e,r,t){var l,a=Tn[n];if(t>0){var i=a._space=a.space(o,n,e,r,t),s=a._incrs=a.incrs(o,n,e,r,t,i);l=a._found=function(n,e,r,t,l){for(var a=t/(e-n),i=(""+m(n)).length,o=0;r.length>o;o++){var s=r[o]*a,u=10>r[o]?L.get(r[o]):0;if(s>=l&&17>i+u)return[r[o],s]}return[0,0]}(e,r,s,t,i)}else l=[0,0];return l}(t,i,s,0==a%2?Ze:Ke),f=u[0],c=u[1];if(0!=c){var v=r._splits=r.splits(o,t,i,s,f,c,2==l.distr),h=2==l.distr?v.map((n=>Ir[n])):v,d=2==l.distr?Ir[v[1]]-Ir[v[0]]:f,p=r._values=r.values(o,r.filter(o,h,t,c,d),t,c,d);r._rotate=2==a?r.rotate(o,p,t,c):0;var g=r._size;r._size=x(r.size(o,p,t,n)),null!=g&&r._size!=g&&(e=!1)}}else r._show&&(e=!1,r._show=!1,Qr(!1))}})),e}function Xr(n){var e=!0;return Cr.forEach(((r,t)=>{var l=r(o,t,Pr,n);l!=Fr[t]&&(e=!1),Fr[t]=l})),e}function Qr(n){Dn.forEach(((e,r)=>{r>0&&(e._paths=null,n&&(e.min=null,e.max=null))}))}o.setData=Br;var $r,nt,et,rt,tt,lt,at,it,ot,st,ut,ft,ct=!1;function vt(){ct||(Q(ht),ct=!0)}function ht(){lr&&(function(){var e=J(An,U);for(var t in e){var l=e[t],a=jn[t];if(null!=a&&null!=a.min)q(l,a),t==Cn&&Qr(!0);else if(t!=Cn)if(0==Yr&&null==l.from){var i=l.range(o,null,null,t);l.min=i[0],l.max=i[1]}else l.min=z,l.max=-z}if(Yr>0)for(var s in Dn.forEach(((t,l)=>{var a=t.scale,i=e[a],s=jn[a];if(0==l){var u=i.range(o,i.min,i.max,a);i.min=u[0],i.max=u[1],Hr=n(i.min,r[0]),Rr=n(i.max,r[0]),i.min>r[0][Hr]&&Hr++,r[0][Rr]>i.max&&Rr--,t.min=Ir[Hr],t.max=Ir[Rr]}else if(t.show&&t.auto&&i.auto(o,Gr)&&(null==s||null==s.min)){var f=null==t.min?3==i.distr?function(n,e,r){for(var t=z,l=-z,a=e;r>=a;a++)n[a]>0&&(t=w(t,n[a]),l=_(l,n[a]));return[t==z?1:t,l==-z?10:l]}(r[l],Hr,Rr):function(n,e,r,t){var l=z,a=-z;if(1==t)l=n[e],a=n[r];else if(-1==t)l=n[r],a=n[e];else for(var i=e;r>=i;i++)null!=n[i]&&(l=w(l,n[i]),a=_(a,n[i]));return[l,a]}(r[l],Hr,Rr,t.sorted):[t.min,t.max];i.min=w(i.min,t.min=f[0]),i.max=_(i.max,t.max=f[1])}t.idxs[0]=Hr,t.idxs[1]=Rr})),e){var u=e[s],f=jn[s];if(null==u.from&&(null==f||null==f.min)){var c=u.range(o,u.min==z?null:u.min,u.max==-z?null:u.max,s);u.min=c[0],u.max=c[1]}}for(var v in e){var h=e[v];if(null!=h.from){var d=e[h.from],p=h.range(o,d.min,d.max,v);h.min=p[0],h.max=p[1]}}var m={},g=!1;for(var x in e){var b=e[x],k=An[x];if(k.min!=b.min||k.max!=b.max){k.min=b.min,k.max=b.max;var M=k.distr;k._min=3==M?y(k.min):4==M?S(k.min,k.asinh):k.min,k._max=3==M?y(k.max):4==M?S(k.max,k.asinh):k.max,m[x]=g=!0}}if(g){for(var D in Dn.forEach((n=>{m[n.scale]&&(n._paths=null)})),m)ir=!0,qt("setScale",D);cr.show&&(or=sr=cr.left>=0)}for(var E in jn)jn[E]=null}(),lr=!1),ir&&(function(){for(var n=!1,e=0;!n;){var r=Kr(++e),t=Xr(e);(n=3==e||r&&t)||(fr(o.width,o.height),ar=!0)}}(),ir=!1),ar&&(kn(Z,tn,Xe),kn(Z,en,Qe),kn(Z,$,Ze),kn(Z,nn,Ke),kn(X,tn,Xe),kn(X,en,Qe),kn(X,$,Ze),kn(X,nn,Ke),kn(G,$,Re),kn(G,nn,Je),H.width=g(Re*K),H.height=g(Je*K),Lt(!1),qt("setSize"),ar=!1),Re>0&&Je>0&&(I.clearRect(0,0,H.width,H.height),qt("drawClear"),Hn.forEach((n=>n())),qt("draw")),cr.show&&or&&(Ht(),or=!1),M||(M=!0,o.status=1,qt("ready")),Gr=!1,ct=!1}function dt(e,t){var l=An[e];if(null==l.from){if(0==Yr){var a=l.range(o,t.min,t.max,e);t.min=a[0],t.max=a[1]}if(t.min>t.max){var i=t.min;t.min=t.max,t.max=i}if(Yr>1&&null!=t.min&&null!=t.max&&1e-16>t.max-t.min)return;e==Cn&&2==l.distr&&Yr>0&&(t.min=n(t.min,r[0]),t.max=n(t.max,r[0])),jn[e]=t,lr=!0,vt()}}o.redraw=(n,e)=>{ir=e||!1,!1!==n?St(Cn,Nn.min,Nn.max):vt()},o.setScale=dt;var pt=!1,mt=cr.drag,gt=mt.x,xt=mt.y;cr.show&&(cr.x&&($r=Mn("u-cursor-x",X)),cr.y&&(nt=Mn("u-cursor-y",X)),0==Nn.ori?(et=$r,rt=nt):(et=nt,rt=$r),ut=cr.left,ft=cr.top);var wt,_t,bt,kt=o.select=q({show:!0,over:!0,left:0,width:0,top:0,height:0},e.select),yt=kt.show?Mn("u-select",kt.over?X:Z):null;function Mt(n,e){if(kt.show){for(var r in n)kn(yt,r,kt[r]=n[r]);!1!==e&&qt("setSelect")}}function St(n,e,r){dt(n,{min:e,max:r})}function zt(n,e,r){var t=Dn[n];null!=e.focus&&function(n){if(n!=bt){var e=null==n,r=1!=hr.alpha;Dn.forEach(((t,l)=>{var a=e||0==l||l==n;t._focus=e?null:a,r&&function(n,e){Dn[n].alpha=e,cr.show&&pr[n]&&(pr[n].style.opacity=e),te&&ie[n]&&(ie[n].style.opacity=e)}(l,a?1:hr.alpha)})),bt=n,r&&vt()}}(n),null!=e.show&&(t.show=e.show,function(n){var e=te?ie[n]:null;Dn[n].show?e&&bn(e,mn):(e&&_n(e,mn),pr.length>1&&zn(pr[n],-10,-10,Ze,Ke))}(n),St(t.scale,null,null),vt()),qt("setSeries",n,e),r&&Qt("setSeries",o,n,e)}o.setSelect=Mt,o.setSeries=zt,o.addBand=function(n,e){n.fill=T(n.fill||null),Yn.splice(e=null==e?Yn.length:e,0,n)},o.setBand=function(n,e){q(Yn[n],e)},o.delBand=function(n){null==n?Yn.length=0:Yn.splice(n,1)};var Dt={focus:!0},Et={focus:!1};function Tt(n,e,r){var t=An[e];r&&(n=n/K-(1==t.ori?Qe:Xe));var l=Ze;1==t.ori&&(n=(l=Ke)-n),-1==t.dir&&(n=l-n);var a=t._min,i=a+n/l*(t._max-a),o=t.distr;return 3==o?b(10,i):4==o?((n,e)=>(void 0===e&&(e=1),h.sinh(n/e)))(i,t.asinh):i}function At(n,e){kn(yt,tn,kt.left=n),kn(yt,$,kt.width=e)}function Pt(n,e){kn(yt,en,kt.top=n),kn(yt,nn,kt.height=e)}te&&dr&&Pn(vn,Zn,(()=>{cr._lock||(zt(null,Et,Zt.setSeries),Ht())})),o.valToIdx=e=>n(e,r[0]),o.posToIdx=function(e,t){return n(Tt(e,Cn,t),r[0],Hr,Rr)},o.posToVal=Tt,o.valToPos=(n,e,r)=>0==An[e].ori?c(n,An[e],r?rr:Ze,r?nr:0):v(n,An[e],r?tr:Ke,r?er:0),o.batch=function(n){n(o),vt()},o.setCursor=(n,e)=>{ut=n.left,ft=n.top,Ht(null,null,e)};var Wt=0==Nn.ori?At:Pt,Yt=1==Nn.ori?At:Pt;function Ct(n,e){if(null!=n){var r=n.idx;re.idx=r,Dn.forEach(((n,e)=>{(e>0||!me)&&Ft(e,r)}))}te&&re.live&&function(){if(te&&re.live)for(var n=0;Dn.length>n;n++)if(0!=n||!me){var e=re.values[n],r=0;for(var t in e)fe[n][r++].firstChild.nodeValue=e[t]}}(),sr=!1,!1!==e&&qt("setLegend")}function Ft(n,e){var t;if(null==e)t=_e;else{var l=Dn[n],a=0==n&&2==On?Ir:r[n];t=me?l.values(o,n,e):{_:l.value(o,a[e],n,e)}}re.values[n]=t}function Ht(e,t,l){var a,i;ot=ut,st=ft,a=cr.move(o,ut,ft),ut=a[0],ft=a[1],cr.show&&(et&&zn(et,g(ut),0,Ze,Ke),rt&&zn(rt,0,g(ft),Ze,Ke)),wt=z;var s=0==Nn.ori?Ze:Ke,u=1==Nn.ori?Ze:Ke;if(0>ut||0==Yr||Hr>Rr){i=null;for(var f=0;Dn.length>f;f++)f>0&&pr.length>1&&zn(pr[f],-10,-10,Ze,Ke);if(dr&&zt(null,Dt,Zt.setSeries),re.live){ee.fill(null),sr=!0;for(var c=0;Dn.length>c;c++)re.values[c]=_e}}else{var v=Tt(0==Nn.ori?ut:ft,Cn);i=n(v,r[0],Hr,Rr);for(var h=F(In(r[0][i],Nn,s,0),.5),d=0;Dn.length>d;d++){var m=Dn[d],x=cr.dataIdx(o,d,i,v),_=r[d][x];sr=sr||_!=r[d][ee[d]],ee[d]=x;var b=x==i?h:F(In(r[0][x],Nn,s,0),.5);if(d>0&&m.show){var k=null==_?-10:F(Gn(_,An[m.scale],u,0),.5);if(k>0){var y=p(k-ft);y>wt||(wt=y,_t=d)}var S=void 0,D=void 0;0==Nn.ori?(S=b,D=k):(S=k,D=b),sr&&pr.length>1&&(zn(pr[d],S,D,Ze,Ke),En(pr[d],cr.points.fill(o,d),cr.points.stroke(o,d)))}if(re.live){if(!sr||0==d&&me)continue;Ft(d,x)}}}if(sr&&(re.idx=i,Ct()),kt.show&&pt)if(null!=t){var E=Zt.scales,T=E[0],A=E[1],P=Zt.match,W=P[1],Y=t.cursor.sync.scales,C=Y[0],H=Y[1],R=t.cursor.drag;gt=R._x,xt=R._y;var L,I,G,B,N,O=t.select,j=O.left,V=O.top,U=O.width,J=O.height,q=t.scales[T].ori,Z=t.posToVal,K=null!=T&&(0,P[0])(T,C),X=null!=A&&W(A,H);K&&(0==q?(L=j,I=U):(L=V,I=J),gt?(G=An[T],B=In(Z(L,C),G,s,0),N=In(Z(L+I,C),G,s,0),Wt(w(B,N),p(N-B))):Wt(0,s),X||Yt(0,u)),X&&(1==q?(L=j,I=U):(L=V,I=J),xt?(G=An[A],B=Gn(Z(L,H),G,u,0),N=Gn(Z(L+I,H),G,u,0),Yt(w(B,N),p(N-B))):Yt(0,u),K||Wt(0,s))}else{var Q=p(ot-tt),$=p(st-lt);if(1==Nn.ori){var nn=Q;Q=$,$=nn}gt=mt.x&&Q>=mt.dist,xt=mt.y&&$>=mt.dist;var en,rn,tn=mt.uni;null!=tn?gt&&xt&&(xt=$>=tn,(gt=Q>=tn)||xt||($>Q?xt=!0:gt=!0)):mt.x&&mt.y&&(gt||xt)&&(gt=xt=!0),gt&&(0==Nn.ori?(en=at,rn=ut):(en=it,rn=ft),Wt(w(en,rn),p(rn-en)),xt||Yt(0,u)),xt&&(1==Nn.ori?(en=at,rn=ut):(en=it,rn=ft),Yt(w(en,rn),p(rn-en)),gt||Wt(0,s)),gt||xt||(Wt(0,0),Yt(0,0))}if(cr.idx=i,cr.left=ut,cr.top=ft,mt._x=gt,mt._y=xt,null!=e){if(null!=Kt){var ln=Zt.scales,an=ln[0],on=ln[1];Zt.values[0]=null!=an?Tt(0==Nn.ori?ut:ft,an):null,Zt.values[1]=null!=on?Tt(1==Nn.ori?ut:ft,on):null}if(Qt(sn,o,ut,ft,Ze,Ke,i),dr){var un=Zt.setSeries,fn=hr.prox;null==bt?wt>fn||zt(_t,Dt,un):wt>fn?zt(null,Dt,un):_t!=bt&&zt(_t,Dt,un)}}M&&!1!==l&&qt("setCursor")}o.setLegend=Ct;var Rt=null;function Lt(n){!0===n?Rt=null:qt("syncRect",Rt=X.getBoundingClientRect())}function It(n,e,r,t,l,a){cr._lock||(Gt(n,e,r,t,l,a,0,!1,null!=n),null!=n?Ht(1):Ht(null,e))}function Gt(n,e,r,t,l,a,i,s,u){var f;if(null==Rt&&Lt(!1),null!=n)r=n.clientX-Rt.left,t=n.clientY-Rt.top;else{if(0>r||0>t)return ut=-10,void(ft=-10);var c=Zt.scales,v=c[0],h=c[1],d=e.cursor.sync,p=d.values,m=p[0],g=p[1],x=d.scales,w=x[0],_=x[1],b=Zt.match,y=b[1],M=1==e.scales[w].ori,S=0==Nn.ori?Ze:Ke,z=1==Nn.ori?Ze:Ke,E=M?a:l,T=M?l:a,A=M?t:r,P=M?r:t;if(r=null!=w?(0,b[0])(v,w)?k(m,An[v],S,0):-10:S*(A/E),t=null!=_?y(h,_)?k(g,An[h],z,0):-10:z*(P/T),1==Nn.ori){var W=r;r=t,t=W}}u&&(r>1&&Ze-1>r||(r=D(r,Ze)),t>1&&Ke-1>t||(t=D(t,Ke))),s?(tt=r,lt=t,f=cr.move(o,r,t),at=f[0],it=f[1]):(ut=r,ft=t)}function Bt(){Mt({width:0,height:0},!1)}function Nt(n,e,r,t,l,a){pt=!0,gt=xt=mt._x=mt._y=!1,Gt(n,e,r,t,l,a,0,!0,!1),null!=n&&(Fe(fn,xn,Ot),Qt(un,o,at,it,Ze,Ke,null))}function Ot(n,e,r,t,l,a){pt=mt._x=mt._y=!1,Gt(n,e,r,t,l,a,0,!1,!0);var i=kt.left,s=kt.top,u=kt.width,f=kt.height,c=u>0||f>0;if(c&&Mt(kt),mt.setScale&&c){var v=i,h=u,d=s,p=f;if(1==Nn.ori&&(v=s,h=f,d=i,p=u),gt&&St(Cn,Tt(v,Cn),Tt(v+h,Cn)),xt)for(var m in An){var g=An[m];m!=Cn&&null==g.from&&g.min!=z&&St(m,Tt(d+p,m),Tt(d,m))}Bt()}else cr.lock&&(cr._lock=!cr._lock,cr._lock||Ht());null!=n&&(He(fn,xn),Qt(fn,o,ut,ft,Ze,Ke,null))}function jt(n){Nr(),Bt(),null!=n&&Qt(hn,o,ut,ft,Ze,Ke,null)}function Vt(){Tn.forEach(Ar),ur(o.width,o.height,!0)}Pn(pn,wn,Vt);var Ut={};Ut.mousedown=Nt,Ut.mousemove=It,Ut.mouseup=Ot,Ut.dblclick=jt,Ut.setSeries=(n,e,r,t)=>{zt(r,t)},cr.show&&(Fe(un,X,Nt),Fe(sn,X,It),Fe(cn,X,Lt),Fe(vn,X,(function(){if(!cr._lock){var n=pt;if(pt){var e,r,t=!0,l=!0;0==Nn.ori?(e=gt,r=xt):(e=xt,r=gt),e&&r&&(t=10>=ut||ut>=Ze-10,l=10>=ft||ft>=Ke-10),e&&t&&(ut=at>ut?0:Ze),r&&l&&(ft=it>ft?0:Ke),Ht(1),pt=!1}ut=-10,ft=-10,Ht(1),n&&(pt=n)}})),Fe(hn,X,jt),mr.add(o),o.syncRect=Lt);var Jt=o.hooks=e.hooks||{};function qt(n,e,r){n in Jt&&Jt[n].forEach((n=>{n.call(null,o,e,r)}))}(e.plugins||[]).forEach((n=>{for(var e in n.hooks)Jt[e]=(Jt[e]||[]).concat(n.hooks[e])}));var Zt=q({key:null,setSeries:!1,filters:{pub:Y,sub:Y},scales:[Cn,Dn[1]?Dn[1].scale:null],match:[C,C],values:[null,null]},cr.sync);cr.sync=Zt;var Kt=Zt.key,Xt=qe(Kt);function Qt(n,e,r,t,l,a,i){Zt.filters.pub(n,e,r,t,l,a,i)&&Xt.pub(n,e,r,t,l,a,i)}function $t(){qt("init",e,r),Br(r||e.data,!1),jn[Cn]?dt(Cn,jn[Cn]):Nr(),ur(e.width,e.height),Ht(),Mt(kt,!1)}return Xt.sub(o),o.pub=function(n,e,r,t,l,a,i){Zt.filters.sub(n,e,r,t,l,a,i)&&Ut[n](null,e,r,t,l,a,i)},o.destroy=function(){Xt.unsub(o),mr.delete(o),Ce.clear(),Wn(pn,wn,Vt),A.remove(),qt("destroy")},Dn.forEach(gr),Tn.forEach((function(n,e){if(n._show=n.show,n.show){var r=An[n.scale];null==r&&(n.scale=n.side%2?Dn[1].scale:Cn,r=An[n.scale]);var t=r.time;n.size=T(n.size),n.space=T(n.space),n.rotate=T(n.rotate),n.incrs=T(n.incrs||(2==r.distr?Jn:t?1==Sn?oe:ce:qn)),n.splits=T(n.splits||(t&&1==r.distr?Qn:3==r.distr?We:4==r.distr?Ye:Pe)),n.stroke=T(n.stroke),n.grid.stroke=T(n.grid.stroke),n.ticks.stroke=T(n.ticks.stroke);var l=n.values;n.values=O(l)&&!O(l[0])?T(l):t?O(l)?pe(Kn,de(l,Xn)):j(l)?function(n,e){var r=Bn(e);return(e,t)=>t.map((e=>r(n(e))))}(Kn,l):l||$n:l||Ae,n.filter=T(n.filter||(3>r.distr?P:Le)),n.font=Tr(n.font),n.labelFont=Tr(n.labelFont),n._size=n.size(o,null,e,0),n._space=n._rotate=n._incrs=n._found=n._splits=n._values=null,n._size>0&&(Pr[e]=!0)}})),t?t instanceof HTMLElement?(t.appendChild(A),$t()):t(o,$t):$t(),o}Pr.assign=q,Pr.fmtNum=v,Pr.rangeNum=u,Pr.rangeLog=l,Pr.rangeAsinh=a,Pr.orient=Ze,Pr.join=function(n,e){for(var r=new Set,t=0;n.length>t;t++)for(var l=n[t][0],a=l.length,i=0;a>i;i++)r.add(l[i]);for(var o=[Array.from(r).sort(((n,e)=>n-e))],s=o[0].length,u=new Map,f=0;s>f;f++)u.set(o[0][f],f);for(var c=0;n.length>c;c++)for(var v=n[c],h=v[0],d=1;v.length>d;d++){for(var p=v[d],m=Array(s).fill(void 0),g=e?e[c][d]:1,x=[],w=0;p.length>w;w++){var _=p[w],b=u.get(h[w]);null===_?0!=g&&(m[b]=_,2==g&&x.push(b)):m[b]=_}Z(m,x,s),o.push(m)}return o},Pr.fmtDate=Bn,Pr.tzDate=function(n,e){var r;return"UTC"==e||"Etc/UTC"==e?r=new Date(+n+6e4*n.getTimezoneOffset()):e==Nn?r=n:(r=new Date(n.toLocaleString("en-US",{timeZone:e}))).setMilliseconds(n.getMilliseconds()),r},Pr.sync=qe,Pr.addGap=Qe,Pr.clipGaps=Xe;var Wr=Pr.paths={points:fr};return Wr.linear=dr,Wr.stepped=function(n){var r=f(n.align,1),t=f(n.ascDesc,!1);return(n,l,a,i)=>Ze(n,l,((o,s,u,f,c,v,h,d,p,m,g)=>{var x=o.pxRound,w=0==f.ori?rr:tr,_={stroke:new Path2D,fill:null,clip:null,band:null,gaps:null,flags:1},b=_.stroke,k=1*f.dir*(0==f.ori?1:-1);a=e(u,a,i,1),i=e(u,a,i,-1);var y=[],M=!1,S=x(h(u[1==k?a:i],c,g,p)),z=x(v(s[1==k?a:i],f,m,d)),D=z;w(b,z,S);for(var E=1==k?a:i;E>=a&&i>=E;E+=k){var T=u[E],A=x(v(s[E],f,m,d));if(null!=T){var P=x(h(T,c,g,p));if(M){if(Qe(y,D,A),S!=P){var W=o.width*K/2,Y=y[y.length-1];Y[0]+=t||1==r?W:-W,Y[1]-=t||-1==r?W:-W}M=!1}1==r?w(b,A,S):w(b,D,P),w(b,A,P),S=P,D=A}else null===T&&(Qe(y,D,A),M=!0)}if(null!=o.fill){var C=_.fill=new Path2D(b),F=x(h(o.fillTo(n,l,o.min,o.max),c,g,p));w(C,D,F),w(C,z,F)}return _.gaps=y=o.gaps(n,l,a,i,y),o.spanGaps||(_.clip=Xe(y,f.ori,d,p,m,g)),n.bands.length>0&&(_.band=Ke(n,l,a,i,b)),_}))},Wr.bars=function(n){var r=f((n=n||B).size,[.6,z,1]),t=n.align||0,l=(n.gap||0)*K,a=1-r[0],i=f(r[1],z)*K,o=f(r[2],1)*K,s=n.disp,u=f(n.each,(()=>{}));return(n,r,f,c)=>Ze(n,r,((v,h,d,m,g,x,b,k,y,M,S)=>{var z,E,T=v.pxRound,A=m.dir*(0==m.ori?1:-1),P=g.dir*(1==g.ori?1:-1),W=0==m.ori?lr:ar,Y=0==m.ori?u:(n,e,r,t,l,a,i)=>{u(n,e,r,l,t,i,a)},C=b(v.fillTo(n,r,v.min,v.max),g,S,y),F=T(v.width*K);if(null!=s){h=s.x0.values(n,r,f,c),2==s.x0.unit&&(h=h.map((e=>n.posToVal(k+e*M,m.key,!0))));var H=s.size.values(n,r,f,c);E=T((E=2==s.size.unit?H[0]*M:x(H[0],m,M,k)-x(0,m,M,k))-F),z=1==A?-F/2:E+F/2}else{var R=M;if(h.length>1)for(var L=1,I=1/0;h.length>L;L++){var G=p(h[L]-h[L-1]);I>G&&(I=G,R=p(x(h[L],m,M,k)-x(h[L-1],m,M,k)))}E=T(w(i,_(o,R-R*a))-F-l),z=(0==t?E/2:t==A?0:E)-t*A*l/2}var B,N={stroke:new Path2D,fill:null,clip:null,band:null,gaps:null,flags:3},O=n.bands.length>0;O&&(N.band=new Path2D,B=D(b(g.max,g,S,y),.5));for(var j=N.stroke,V=N.band,U=1==A?f:c;U>=f&&c>=U;U+=A){var J=d[U];if(null==J){if(!O)continue;var q=e(d,1==A?f:c,U,-A),Z=e(d,U,1==A?c:f,A),X=d[q];J=X+(U-q)/(Z-q)*(d[Z]-X)}var Q=x(2!=m.distr||null!=s?h[U]:U,m,M,k),$=b(J,g,S,y),nn=T(Q-z),en=T(_($,C)),rn=T(w($,C)),tn=en-rn;null!=d[U]&&(W(j,nn,rn,E,tn),Y(n,r,U,nn-F/2,rn-F/2,E+F,tn+F)),O&&(1==P?(en=rn,rn=B):(rn=en,en=B),W(V,nn-F/2,rn+F/2,E+F,(tn=en-rn)-F))}return null!=v.fill&&(N.fill=new Path2D(j)),N}))},Wr.spline=function(){return function(n){return(r,t,l,a)=>Ze(r,t,((i,o,s,u,f,c,v,h,d,p,m)=>{var g,x,w,_=i.pxRound;0==u.ori?(g=nr,w=rr,x=sr):(g=er,w=tr,x=ur);var b=1*u.dir*(0==u.ori?1:-1);l=e(s,l,a,1),a=e(s,l,a,-1);for(var k=[],y=!1,M=_(c(o[1==b?l:a],u,p,h)),S=M,z=[],D=[],E=1==b?l:a;E>=l&&a>=E;E+=b){var T=s[E],A=c(o[E],u,p,h);null!=T?(y&&(Qe(k,S,A),y=!1),z.push(S=A),D.push(v(s[E],f,m,d))):null===T&&(Qe(k,S,A),y=!0)}var P={stroke:n(z,D,g,w,x,_),fill:null,clip:null,band:null,gaps:null,flags:1},W=P.stroke;if(null!=i.fill&&null!=W){var Y=P.fill=new Path2D(W),C=_(v(i.fillTo(r,t,i.min,i.max),f,m,d));w(Y,S,C),w(Y,M,C)}return P.gaps=k=i.gaps(r,t,l,a,k),i.spanGaps||(P.clip=Xe(k,u.ori,h,d,p,m)),r.bands.length>0&&(P.band=Ke(r,t,l,a,W)),P}))}(pr)},Pr}(); +var uPlot=function(){"use strict";function t(t,e,l,n){let i;l=l||0;let o=2147483647>=(n=n||e.length-1);for(;n-l>1;)i=o?l+n>>1:g((l+n)/2),t>e[i]?l=i:n=i;return t-e[l]>e[n]-t?n:l}function e(t,e,l,n){for(let i=1==n?e:l;i>=e&&l>=i;i+=n)if(null!=t[i])return i;return-1}const l=[0,0];function n(t,e,n,i){return l[0]=0>n?R(t,-n):t,l[1]=0>i?R(e,-i):e,l}function i(t,e,l,i){let o,s,r,u=k(t),a=10==l?y:M;return t==e&&(-1==u?(t*=l,e/=l):(t/=l,e*=l)),i?(o=g(a(t)),s=w(a(e)),r=n(v(l,o),v(l,s),o,s),t=r[0],e=r[1]):(o=g(a(m(t))),s=g(a(m(e))),r=n(v(l,o),v(l,s),o,s),t=H(t,r[0]),e=F(e,r[1])),[t,e]}function o(t,e,l,n){let o=i(t,e,l,n);return 0==t&&(o[0]=0),0==e&&(o[1]=0),o}const s={mode:3,pad:.1},r={pad:0,soft:null,mode:0},u={min:r,max:r};function a(t,e,l,n){return U(l)?f(t,e,l):(r.pad=l,r.soft=n?0:null,r.mode=n?3:0,f(t,e,u))}function c(t,e){return null==t?e:t}function f(t,e,l){let n=l.min,i=l.max,o=c(n.pad,0),s=c(i.pad,0),r=c(n.hard,-z),u=c(i.hard,z),a=c(n.soft,z),f=c(i.soft,-z),h=c(n.mode,0),d=c(i.mode,0),p=e-t;1e-9>p&&(p=0,0!=t&&0!=e||(p=1e-9,2==h&&a!=z&&(o=0),2==d&&f!=-z&&(s=0)));let x=p||m(e)||1e3,w=y(x),k=v(10,g(w)),M=R(H(t-x*(0==p?0==t?.1:1:o),k/10),9),S=a>t||1!=h&&(3!=h||M>a)&&(2!=h||a>M)?z:a,D=b(r,S>M&&t>=S?S:_(S,M)),T=R(F(e+x*(0==p?0==e?.1:1:s),k/10),9),E=e>f||1!=d&&(3!=d||f>T)&&(2!=d||T>f)?-z:f,P=_(u,T>E&&E>=e?E:b(E,T));return D==P&&0==D&&(P=100),[D,P]}const h=new Intl.NumberFormat(navigator.language).format,d=Math,p=d.PI,m=d.abs,g=d.floor,x=d.round,w=d.ceil,_=d.min,b=d.max,v=d.pow,k=d.sign,y=d.log10,M=d.log2,S=(t,e=1)=>d.asinh(t/e),z=1/0;function D(t,e){return x(t/e)*e}function T(t,e,l){return _(b(t,e),l)}function E(t){return"function"==typeof t?t:()=>t}const P=t=>t,A=(t,e)=>e,W=()=>null,Y=()=>!0,C=(t,e)=>t==e;function F(t,e){return w(t/e)*e}function H(t,e){return g(t/e)*e}function R(t,e){return x(t*(e=10**e))/e}const L=new Map;function I(t){return((""+t).split(".")[1]||"").length}function G(t,e,l,n){let i=[],o=n.map(I);for(let s=e;l>s;s++){let e=m(s),l=R(v(t,s),e);for(let t=0;n.length>t;t++){let r=n[t]*l,u=(0>r||0>s?e:0)+(o[t]>s?o[t]:0),a=R(r,u);i.push(a),L.set(a,u)}}return i}const O={},N=[],j=[null,null],B=Array.isArray;function V(t){return"string"==typeof t}function U(t){let e=!1;if(null!=t){let l=t.constructor;e=null==l||l==Object}return e}function J(t){return null!=t&&"object"==typeof t}function q(t,e){let l;if(e=e||U,B(t))l=t.map((t=>q(t,e)));else if(e(t))for(var n in l={},t)l[n]=q(t[n],e);else l=t;return l}function Z(t){let e=arguments;for(let l=1;e.length>l;l++){let n=e[l];for(let e in n)U(t[e])?Z(t[e],q(n[e])):t[e]=q(n[e])}return t}function $(t,e,l){for(let n,i=0,o=-1;e.length>i;i++){let s=e[i];if(s>o){for(n=s-1;n>=0&&null==t[n];)t[n--]=null;for(n=s+1;l>n&&null==t[n];)t[o=n++]=null}}}const K="undefined"==typeof queueMicrotask?t=>Promise.resolve().then(t):queueMicrotask,X="width",Q="height",tt="top",et="bottom",lt="left",nt="right",it="#000",ot="mousemove",st="mousedown",rt="mouseup",ut="mouseenter",at="mouseleave",ct="dblclick",ft="change",ht="dppxchange",dt="u-off",pt="u-label",mt=document,gt=window;let xt,wt;function _t(t,e){if(null!=e){let l=t.classList;!l.contains(e)&&l.add(e)}}function bt(t,e){let l=t.classList;l.contains(e)&&l.remove(e)}function vt(t,e,l){t.style[e]=l+"px"}function kt(t,e,l,n){let i=mt.createElement(t);return null!=e&&_t(i,e),null!=l&&l.insertBefore(i,n),i}function yt(t,e){return kt("div",t,e)}const Mt=new WeakMap;function St(t,e,l,n,i){let o="translate("+e+"px,"+l+"px)";o!=Mt.get(t)&&(t.style.transform=o,Mt.set(t,o),0>e||0>l||e>n||l>i?_t(t,dt):bt(t,dt))}const zt=new WeakMap;function Dt(t,e,l){let n=e+l;n!=zt.get(t)&&(zt.set(t,n),t.style.background=e,t.style.borderColor=l)}const Tt={passive:!0},Et=Z({capture:!0},Tt);function Pt(t,e,l,n){e.addEventListener(t,l,n?Et:Tt)}function At(t,e,l,n){e.removeEventListener(t,l,n?Et:Tt)}!function t(){xt=devicePixelRatio,wt&&At(ft,wt,t),wt=matchMedia(`screen and (min-resolution: ${xt-.001}dppx) and (max-resolution: ${xt+.001}dppx)`),Pt(ft,wt,t),gt.dispatchEvent(new CustomEvent(ht))}();const Wt=["January","February","March","April","May","June","July","August","September","October","November","December"],Yt=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function Ct(t){return t.slice(0,3)}const Ft=Yt.map(Ct),Ht=Wt.map(Ct),Rt={MMMM:Wt,MMM:Ht,WWWW:Yt,WWW:Ft};function Lt(t){return(10>t?"0":"")+t}const It={YYYY:t=>t.getFullYear(),YY:t=>(t.getFullYear()+"").slice(2),MMMM:(t,e)=>e.MMMM[t.getMonth()],MMM:(t,e)=>e.MMM[t.getMonth()],MM:t=>Lt(t.getMonth()+1),M:t=>t.getMonth()+1,DD:t=>Lt(t.getDate()),D:t=>t.getDate(),WWWW:(t,e)=>e.WWWW[t.getDay()],WWW:(t,e)=>e.WWW[t.getDay()],HH:t=>Lt(t.getHours()),H:t=>t.getHours(),h:t=>{let e=t.getHours();return 0==e?12:e>12?e-12:e},AA:t=>12>t.getHours()?"AM":"PM",aa:t=>12>t.getHours()?"am":"pm",a:t=>12>t.getHours()?"a":"p",mm:t=>Lt(t.getMinutes()),m:t=>t.getMinutes(),ss:t=>Lt(t.getSeconds()),s:t=>t.getSeconds(),fff:t=>function(t){return(10>t?"00":100>t?"0":"")+t}(t.getMilliseconds())};function Gt(t,e){e=e||Rt;let l,n=[],i=/\{([a-z]+)\}|[^{]+/gi;for(;l=i.exec(t);)n.push("{"==l[0][0]?It[l[1]]:l[0]);return t=>{let l="";for(let i=0;n.length>i;i++)l+="string"==typeof n[i]?n[i]:n[i](t,e);return l}}const Ot=(new Intl.DateTimeFormat).resolvedOptions().timeZone,Nt=t=>t%1==0,jt=[1,2,2.5,5],Bt=G(10,-16,0,jt),Vt=G(10,0,16,jt),Ut=Vt.filter(Nt),Jt=Bt.concat(Vt),qt="{YYYY}",Zt="\n"+qt,$t="{M}/{D}",Kt="\n"+$t,Xt=Kt+"/{YY}",Qt="{aa}",te="{h}:{mm}"+Qt,ee="\n"+te,le=":{ss}",ne=null;function ie(t){let e=1e3*t,l=60*e,n=60*l,i=24*n,o=30*i,s=365*i;return[(1==t?G(10,0,3,jt).filter(Nt):G(10,-3,0,jt)).concat([e,5*e,10*e,15*e,30*e,l,5*l,10*l,15*l,30*l,n,2*n,3*n,4*n,6*n,8*n,12*n,i,2*i,3*i,4*i,5*i,6*i,7*i,8*i,9*i,10*i,15*i,o,2*o,3*o,4*o,6*o,s,2*s,5*s,10*s,25*s,50*s,100*s]),[[s,qt,ne,ne,ne,ne,ne,ne,1],[28*i,"{MMM}",Zt,ne,ne,ne,ne,ne,1],[i,$t,Zt,ne,ne,ne,ne,ne,1],[n,"{h}"+Qt,Xt,ne,Kt,ne,ne,ne,1],[l,te,Xt,ne,Kt,ne,ne,ne,1],[e,le,Xt+" "+te,ne,Kt+" "+te,ne,ee,ne,1],[t,le+".{fff}",Xt+" "+te,ne,Kt+" "+te,ne,ee,ne,1]],function(e){return(r,u,a,c,f,h)=>{let d=[],p=f>=s,m=f>=o&&s>f,w=e(a),_=R(w*t,3),b=de(w.getFullYear(),p?0:w.getMonth(),m||p?1:w.getDate()),v=R(b*t,3);if(m||p){let l=m?f/o:0,n=p?f/s:0,i=_==v?_:R(de(b.getFullYear()+n,b.getMonth()+l,1)*t,3),r=new Date(x(i/t)),u=r.getFullYear(),a=r.getMonth();for(let o=0;c>=i;o++){let s=de(u+n*o,a+l*o,1),r=s-e(R(s*t,3));i=R((+s+r)*t,3),i>c||d.push(i)}}else{let o=i>f?f:i,s=v+(g(a)-g(_))+F(_-v,o);d.push(s);let p=e(s),m=p.getHours()+p.getMinutes()/l+p.getSeconds()/n,x=f/n,w=h/r.axes[u]._space;for(;s=R(s+f,1==t?0:3),c>=s;)if(x>1){let t=g(R(m+x,6))%24,l=e(s).getHours()-t;l>1&&(l=-1),s-=l*n,m=(m+x)%24,.7>R((s-d[d.length-1])/f,3)*w||d.push(s)}else d.push(s)}return d}}]}const[oe,se,re]=ie(1),[ue,ae,ce]=ie(.001);function fe(t,e){return t.map((t=>t.map(((l,n)=>0==n||8==n||null==l?l:e(1==n||0==t[8]?l:t[1]+l)))))}function he(t,e){return(l,n,i,o,s)=>{let r,u,a,c,f,h,d=e.find((t=>s>=t[0]))||e[e.length-1];return n.map((e=>{let l=t(e),n=l.getFullYear(),i=l.getMonth(),o=l.getDate(),s=l.getHours(),p=l.getMinutes(),m=l.getSeconds(),g=n!=r&&d[2]||i!=u&&d[3]||o!=a&&d[4]||s!=c&&d[5]||p!=f&&d[6]||m!=h&&d[7]||d[1];return r=n,u=i,a=o,c=s,f=p,h=m,g(l)}))}}function de(t,e,l){return new Date(t,e,l)}function pe(t,e){return e(t)}function me(t,e){return(l,n)=>e(t(n))}G(2,-53,53,[1]);const ge={show:!0,live:!0,isolate:!1,markers:{show:!0,width:2,stroke:function(t,e){let l=t.series[e];return l.width?l.stroke(t,e):l.points.width?l.points.stroke(t,e):null},fill:function(t,e){return t.series[e].fill(t,e)},dash:"solid"},idx:null,idxs:null,values:[]},xe=[0,0];function we(t,e,l){return t=>{0==t.button&&l(t)}}function _e(t,e,l){return l}const be={show:!0,x:!0,y:!0,lock:!1,move:function(t,e,l){return xe[0]=e,xe[1]=l,xe},points:{show:function(t,e){let l=t.cursor.points,n=yt(),i=l.size(t,e);vt(n,X,i),vt(n,Q,i);let o=i/-2;vt(n,"marginLeft",o),vt(n,"marginTop",o);let s=l.width(t,e,i);return s&&vt(n,"borderWidth",s),n},size:function(t,e){return Le(t.series[e].points.width,1)},width:0,stroke:function(t,e){let l=t.series[e].points;return l._stroke||l._fill},fill:function(t,e){let l=t.series[e].points;return l._fill||l._stroke}},bind:{mousedown:we,mouseup:we,click:we,dblclick:we,mousemove:_e,mouseleave:_e,mouseenter:_e},drag:{setScale:!0,x:!0,y:!1,dist:0,uni:null,_x:!1,_y:!1},focus:{prox:-1},left:-10,top:-10,idx:null,dataIdx:function(t,e,l){return l},idxs:null},ve={show:!0,stroke:"rgba(0,0,0,0.07)",width:2,filter:A},ke=Z({},ve,{size:10}),ye='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"',Me="bold "+ye,Se={show:!0,scale:"x",stroke:it,space:50,gap:5,size:50,labelGap:0,labelSize:30,labelFont:Me,side:2,grid:ve,ticks:ke,font:ye,rotate:0},ze={show:!0,scale:"x",auto:!1,sorted:1,min:z,max:-z,idxs:[]};function De(t,e){return e.map((t=>null==t?"":h(t)))}function Te(t,e,l,n,i,o,s){let r=[],u=L.get(i)||0;for(let t=l=s?l:R(F(l,i),u);n>=t;t=R(t+i,u))r.push(Object.is(t,-0)?0:t);return r}function Ee(t,e,l,n,i){const o=[],s=t.scales[t.axes[e].scale].log,r=g((10==s?y:M)(l));i=v(s,r),0>r&&(i=R(i,-r));let u=l;do{o.push(u),u=R(u+i,L.get(i)),i*s>u||(i=u)}while(n>=u);return o}function Pe(t,e,l,n,i){let o=t.scales[t.axes[e].scale].asinh,s=n>o?Ee(t,e,b(o,l),n,i):[o],r=0>n||l>0?[]:[0];return(-o>l?Ee(t,e,b(o,-n),-l,i):[o]).reverse().map((t=>-t)).concat(r,s)}const Ae=/./,We=/[12357]/,Ye=/[125]/,Ce=/1/;function Fe(t,e,l){let n=t.axes[l],i=n.scale,o=t.scales[i];if(3==o.distr&&2==o.log)return e;let s=t.valToPos,r=n._space,u=s(10,i),a=s(9,i)-u4==o.distr&&0==t||a.test(t)?t:null))}function He(t,e){return null==e?"":h(e)}const Re={show:!0,scale:"y",stroke:it,space:30,gap:5,size:50,labelGap:0,labelSize:30,labelFont:Me,side:3,grid:ve,ticks:ke,font:ye,rotate:0};function Le(t,e){return R((3+2*(t||1))*e,3)}function Ie(t,e){let l=t.scales[t.series[e].scale],n=t.bands&&t.bands.some((t=>t.series[0]==e));return 3==l.distr||n?l.min:0}const Ge={scale:"y",auto:!0,sorted:0,show:!0,spanGaps:!1,gaps:(t,e,l,n,i)=>i,alpha:1,points:{show:function(t,e){let{scale:l,idxs:n}=t.series[0],i=t._data[0],o=t.valToPos(i[n[0]],l,!0),s=t.valToPos(i[n[1]],l,!0);return m(s-o)/(t.series[e].points.space*xt)>=n[1]-n[0]},filter:null},values:null,min:z,max:-z,idxs:[],path:null,clip:null};function Oe(t,e,l){return l/10}const Ne={time:!0,auto:!0,distr:1,log:10,asinh:1,min:null,max:null,dir:1,ori:0},je=Z({},Ne,{time:!1,ori:1}),Be={};function Ve(t){let e=Be[t];return e||(e={key:t,plots:[],sub(t){e.plots.push(t)},unsub(t){e.plots=e.plots.filter((e=>e!=t))},pub(t,l,n,i,o,s,r){for(let u=0;e.plots.length>u;u++)e.plots[u]!=l&&e.plots[u].pub(t,l,n,i,o,s,r)}},null!=t&&(Be[t]=e)),e}function Ue(t,e,l){const n=t.series[e],i=t.scales,o=t.bbox;let s=t._data[0],r=t._data[e],u=i[t.series[0].scale],a=i[n.scale],c=o.left,f=o.top,h=o.width,d=o.height,p=t.valToPosH,m=t.valToPosV;return 0==u.ori?l(n,s,r,u,a,p,m,c,f,h,d,Ke,Qe,el,nl,ol):l(n,s,r,u,a,m,p,f,c,d,h,Xe,tl,ll,il,sl)}function Je(t,e,l,n,i){return Ue(t,e,((t,e,o,s,r,u,a,c,f,h,d)=>{const p=0==s.ori?Qe:tl;let m,g;1==s.dir*(0==s.ori?1:-1)?(m=l,g=n):(m=n,g=l);let x=D(u(e[m],s,h,c),.5),w=D(a(o[m],r,d,f),.5),_=D(u(e[g],s,h,c),.5),b=D(a(r.max,r,d,f),.5),v=new Path2D(i);return p(v,_,b),p(v,x,b),p(v,x,w),v}))}function qe(t,e,l,n,i,o){let s=null;if(t.length>0){s=new Path2D;const r=0==e?el:ll;let u=l;for(let e=0;t.length>e;e++){let l=t[e];l[1]>l[0]&&(r(s,u,n,l[0]-u,n+o),u=l[1])}r(s,u,n,l+i-u,n+o)}return s}function Ze(t,e,l){let n=t[t.length-1];n&&n[0]==e?n[1]=l:t.push([e,l])}function $e(t){return 0==t?P:1==t?x:e=>D(e,t)}function Ke(t,e,l){t.moveTo(e,l)}function Xe(t,e,l){t.moveTo(l,e)}function Qe(t,e,l){t.lineTo(e,l)}function tl(t,e,l){t.lineTo(l,e)}function el(t,e,l,n,i){t.rect(e,l,n,i)}function ll(t,e,l,n,i){t.rect(l,e,i,n)}function nl(t,e,l,n,i,o){t.arc(e,l,n,i,o)}function il(t,e,l,n,i,o){t.arc(l,e,n,i,o)}function ol(t,e,l,n,i,o,s){t.bezierCurveTo(e,l,n,i,o,s)}function sl(t,e,l,n,i,o,s){t.bezierCurveTo(l,e,i,n,s,o)}function rl(){return(t,e,l,n,i)=>Ue(t,e,((e,o,s,r,u,a,c,f,h,d,m)=>{let g,x,{pxRound:w,points:_}=e;0==r.ori?(g=Ke,x=nl):(g=Xe,x=il);const b=R(_.width*xt,3);let v=(_.size-_.width)/2*xt,k=R(2*v,3),y=new Path2D,M=new Path2D,{left:S,top:z,width:D,height:T}=t.bbox;el(M,S-k,z-k,D+2*k,T+2*k);const E=t=>{if(null!=s[t]){let e=w(a(o[t],r,d,f)),l=w(c(s[t],u,m,h));g(y,e+v,l),x(y,e,l,v,0,2*p)}};if(i)i.forEach(E);else for(let t=l;n>=t;t++)E(t);return{stroke:b>0?y:null,fill:y,clip:M,flags:3}}))}function ul(t){return(e,l,n,i,o,s)=>{n!=i&&(o!=n&&s!=n&&t(e,l,n),o!=i&&s!=i&&t(e,l,i),t(e,l,s))}}const al=ul(Qe),cl=ul(tl);function fl(){return(t,l,n,i)=>Ue(t,l,((o,s,r,u,a,c,f,h,d,p,m)=>{let g,x,w=o.pxRound;0==u.ori?(g=Qe,x=al):(g=tl,x=cl);const v=u.dir*(0==u.ori?1:-1),k={stroke:new Path2D,fill:null,clip:null,band:null,gaps:null,flags:1},y=k.stroke;let M,S,T,E,P=z,A=-z,W=[],Y=w(c(s[1==v?n:i],u,p,h)),C=!1,F=!1,H=e(r,n,i,1*v),R=e(r,n,i,-1*v),L=D(c(s[H],u,p,h),.5),I=D(c(s[R],u,p,h),.5);L>h&&Ze(W,h,L);for(let t=1==v?n:i;t>=n&&i>=t;t+=v){let e=w(c(s[t],u,p,h));if(e==Y)null!=r[t]?(S=w(f(r[t],a,m,d)),P==z&&(g(y,e,S),M=S),P=_(S,P),A=b(S,A)):null===r[t]&&(C=F=!0);else{let l=!1;P!=z?(x(y,Y,P,A,M,S),T=E=Y):C&&(l=!0,C=!1),null!=r[t]?(S=w(f(r[t],a,m,d)),g(y,e,S),P=A=M=S,F&&e-Y>1&&(l=!0),F=!1):(P=z,A=-z,null===r[t]&&(C=!0,e-Y>1&&(l=!0))),l&&Ze(W,T,e),Y=e}}if(P!=z&&P!=A&&E!=Y&&x(y,Y,P,A,M,S),h+p>I&&Ze(W,I,h+p),null!=o.fill){let e=k.fill=new Path2D(y),n=w(f(o.fillTo(t,l,o.min,o.max),a,m,d));g(e,I,n),g(e,L,n)}return k.gaps=W=o.gaps(t,l,n,i,W),o.spanGaps||(k.clip=qe(W,u.ori,h,d,p,m)),t.bands.length>0&&(k.band=Je(t,l,n,i,y)),k}))}function hl(t,e,l,n,i){const o=t.length;if(2>o)return null;const s=new Path2D;if(l(s,t[0],e[0]),2==o)n(s,t[1],e[1]);else{let l=Array(o),n=Array(o-1),r=Array(o-1),u=Array(o-1);for(let l=0;o-1>l;l++)r[l]=e[l+1]-e[l],u[l]=t[l+1]-t[l],n[l]=r[l]/u[l];l[0]=n[0];for(let t=1;o-1>t;t++)0===n[t]||0===n[t-1]||n[t-1]>0!=n[t]>0?l[t]=0:(l[t]=3*(u[t-1]+u[t])/((2*u[t]+u[t-1])/n[t-1]+(u[t]+2*u[t-1])/n[t]),isFinite(l[t])||(l[t]=0));l[o-1]=n[o-2];for(let n=0;o-1>n;n++)i(s,t[n]+u[n]/3,e[n]+l[n]*u[n]/3,t[n+1]-u[n]/3,e[n+1]-l[n+1]*u[n]/3,t[n+1],e[n+1])}return s}const dl=new Set;function pl(){dl.forEach((t=>{t.syncRect(!0)}))}Pt("resize",gt,pl),Pt("scroll",gt,pl,!0);const ml=fl(),gl=rl();function xl(t,e,l,n){return(n?[t[0],t[1]].concat(t.slice(2)):[t[0]].concat(t.slice(1))).map(((t,n)=>wl(t,n,e,l)))}function wl(t,e,l,n){return Z({},0==e?l:n,t)}function _l(t,e,l){return null==e?j:[e,l]}const bl=_l;function vl(t,e,l){return null==e?j:a(e,l,.1,!0)}function kl(t,e,l,n){return null==e?j:i(e,l,t.scales[n].log,!1)}const yl=kl;function Ml(t,e,l,n){return null==e?j:o(e,l,t.scales[n].log,!1)}const Sl=Ml;function zl(t){let e,l;return[t=t.replace(/(\d+)px/,((t,n)=>(e=x((l=+n)*xt))+"px")),e,l]}function Dl(t){t.show&&[t.font,t.labelFont].forEach((t=>{let e=R(t[2]*xt,1);t[0]=t[0].replace(/[0-9.]+px/,e+"px"),t[1]=e}))}function Tl(e,l,n){const r={};function u(t,e){return((3==e.distr?y(t>0?t:e.clamp(r,t,e.min,e.max,e.key)):4==e.distr?S(t,e.asinh):t)-e._min)/(e._max-e._min)}function f(t,e,l,n){let i=u(t,e);return n+l*(-1==e.dir?1-i:i)}function h(t,e,l,n){let i=u(t,e);return n+l*(-1==e.dir?i:1-i)}function k(t,e,l,n){return 0==e.ori?f(t,e,l,n):h(t,e,l,n)}r.valToPosH=f,r.valToPosV=h;let M=!1;r.status=0;const P=r.root=yt("uplot");null!=e.id&&(P.id=e.id),_t(P,e.class),e.title&&(yt("u-title",P).textContent=e.title);const H=kt("canvas"),I=r.ctx=H.getContext("2d"),G=yt("u-wrap",P),$=r.under=yt("u-under",G);G.appendChild(H);const it=r.over=yt("u-over",G),ft=+c((e=q(e)).pxAlign,1),wt=$e(ft);(e.plugins||[]).forEach((t=>{t.opts&&(e=t.opts(r,e)||e)}));const Mt=e.ms||.001,zt=r.series=xl(e.series||[],ze,Ge,!1),Tt=r.axes=xl(e.axes||[],Se,Re,!0),Et=r.scales={},Wt=r.bands=e.bands||[];Wt.forEach((t=>{t.fill=E(t.fill||null)}));const Yt=zt[0].scale,Ct={axes:function(){for(let t=0;Tt.length>t;t++){let e=Tt[t];if(!e.show||!e._show)return;let l,n,i=e.side,o=i%2,s=e.stroke(r,t),u=0==i||3==i?-1:1;if(e.label){let t=x((e._lpos+e.labelGap*u)*xt);Ul(e.labelFont[0],s,"center",2==i?tt:et),I.save(),1==o?(l=n=0,I.translate(t,x(Je+Ze/2)),I.rotate((3==i?-p:p)/2)):(l=x(Ue+qe/2),n=t),I.fillText(e.label,l,n),I.restore()}let[a,c]=e._found;if(0==c)return;let f=Et[e.scale],h=0==o?qe:Ze,d=0==o?Ue:Je,m=x(e.gap*xt),g=e._splits,w=2==f.distr?g.map((t=>Ol[t])):g,_=2==f.distr?Ol[g[1]]-Ol[g[0]]:a,b=e.ticks,v=b.show?x(b.size*xt):0,y=e._rotate*-p/180,M=wt(e._pos*xt),S=M+(v+m)*u;n=0==o?S:0,l=1==o?S:0,Ul(e.font[0],s,1==e.align?lt:2==e.align?nt:y>0?lt:0>y?nt:0==o?"center":3==i?nt:lt,y||1==o?"middle":2==i?tt:et);let z=1.5*e.font[1],D=g.map((t=>wt(k(t,f,h,d)))),T=e._values;for(let t=0;T.length>t;t++){let e=T[t];if(null!=e){0==o?l=D[t]:n=D[t],e=""+e;let i=-1==e.indexOf("\n")?[e]:e.split(/\n/gm);for(let t=0;i.length>t;t++){let e=i[t];y?(I.save(),I.translate(l,n+t*z),I.rotate(y),I.fillText(e,0,0),I.restore()):I.fillText(e,l,n+t*z)}}}b.show&&Xl(D,b.filter(r,w,t,c,_),o,i,M,v,R(b.width*xt,3),b.stroke(r,t),b.dash,b.cap);let E=e.grid;E.show&&Xl(D,E.filter(r,w,t,c,_),o,0==o?2:1,0==o?Je:Ue,0==o?Ze:qe,R(E.width*xt,3),E.stroke(r,t),E.dash,E.cap)}Xn("drawAxes")},series:function(){pl>0&&(zt.forEach(((t,e)=>{if(e>0&&t.show&&null==t._paths){let n=function(t){let e=T(Tl-1,0,pl-1),l=T(El+1,0,pl-1);for(;null==t[e]&&e>0;)e--;for(;null==t[l]&&pl-1>l;)l++;return[e,l]}(l[e]);t._paths=t.paths(r,e,n[0],n[1])}})),zt.forEach(((t,e)=>{if(e>0&&t.show){Jl(e,!1),t._paths&&ql(e,!1);{Jl(e,!0);let l=t.points.show(r,e,Tl,El),n=t.points.filter(r,e,l,t._paths?t._paths.gaps:null);(l||n)&&(t.points._paths=t.points.paths(r,e,Tl,El,n),ql(e,!0))}Xn("drawSeries",e)}})))}},Ft=(e.drawOrder||["axes","series"]).map((t=>Ct[t]));function Ht(t){let l=Et[t];if(null==l){let n=(e.scales||O)[t]||O;if(null!=n.from)Ht(n.from),Et[t]=Z({},Et[n.from],n);else{l=Et[t]=Z({},t==Yt?Ne:je,n),l.key=t;let e=l.time,i=l.range,o=B(i);if(t!=Yt&&(!o||null!=i[0]&&null!=i[1]||(i={min:null==i[0]?s:{mode:1,hard:i[0],soft:i[0]},max:null==i[1]?s:{mode:1,hard:i[1],soft:i[1]}},o=!1),!o&&U(i))){let t=i;i=(e,l,n)=>null==l?j:a(l,n,t)}l.range=E(i||(e?bl:t==Yt?3==l.distr?yl:4==l.distr?Sl:_l:3==l.distr?kl:4==l.distr?Ml:vl)),l.auto=E(!o&&l.auto),l.clamp=E(l.clamp||Oe),l._min=l._max=null}}}Ht("x"),Ht("y"),zt.forEach((t=>{Ht(t.scale)})),Tt.forEach((t=>{Ht(t.scale)}));for(let t in e.scales)Ht(t);const Rt=Et[Yt],Lt=Rt.distr;let It,Ot;0==Rt.ori?(_t(P,"u-hz"),It=f,Ot=h):(_t(P,"u-vt"),It=h,Ot=f);const Nt={};for(let t in Et){let e=Et[t];null==e.min&&null==e.max||(Nt[t]={min:e.min,max:e.max},e.min=e.max=null)}const jt=e.tzDate||(t=>new Date(x(t/Mt))),Bt=e.fmtDate||Gt,Vt=1==Mt?re(jt):ce(jt),qt=he(jt,fe(1==Mt?se:ae,Bt)),Zt=me(jt,pe("{YYYY}-{MM}-{DD} {h}:{mm}{aa}",Bt)),$t=[],Kt=r.legend=Z({},ge,e.legend),Xt=Kt.show,Qt=Kt.markers;let te;Kt.idxs=$t,Qt.width=E(Qt.width),Qt.dash=E(Qt.dash),Qt.stroke=E(Qt.stroke),Qt.fill=E(Qt.fill);let ee,le=[],ne=[],ie=!1,de={};if(Kt.live){const t=zt[1]?zt[1].values:null;ie=null!=t,ee=ie?t(r,1,0):{_:0};for(let t in ee)de[t]="--"}if(Xt)if(te=kt("table","u-legend",P),ie){let t=kt("tr","u-thead",te);for(var xe in kt("th",null,t),ee)kt("th",pt,t).textContent=xe}else _t(te,"u-inline"),Kt.live&&_t(te,"u-live");const we={show:!0},_e={show:!1},ve=new Map;function ke(t,e,l){const n=ve.get(e)||{},i=il.bind[t](r,e,l);i&&(Pt(t,e,n[t]=i),ve.set(e,n))}function ye(t,e){const l=ve.get(e)||{};for(let n in l)null!=t&&n!=t||(At(n,e,l[n]),delete l[n]);null==t&&ve.delete(e)}let Me=0,Ae=0,We=0,Ye=0,Ce=0,Be=0,Ue=0,Je=0,qe=0,Ze=0;r.bbox={};let Ke=!1,Xe=!1,Qe=!1,tl=!1,el=!1;function ll(t,e,l){(l||t!=r.width||e!=r.height)&&nl(t,e),en(!1),Qe=!0,Xe=!0,tl=el=il.left>=0,gn()}function nl(t,e){r.width=Me=We=t,r.height=Ae=Ye=e,Ce=Be=0,function(){let t=!1,e=!1,l=!1,n=!1;Tt.forEach((i=>{if(i.show&&i._show){let{side:o,_size:s}=i,r=o%2,u=s+(i.labelSize=null!=i.label?i.labelSize||30:0);u>0&&(r?(We-=u,3==o?(Ce+=u,n=!0):l=!0):(Ye-=u,0==o?(Be+=u,t=!0):e=!0))}})),al[0]=t,al[1]=l,al[2]=e,al[3]=n,We-=hl[1]+hl[3],Ce+=hl[3],Ye-=hl[2]+hl[0],Be+=hl[0]}(),function(){let t=Ce+We,e=Be+Ye,l=Ce,n=Be;function i(i,o){switch(i){case 1:return t+=o,t-o;case 2:return e+=o,e-o;case 3:return l-=o,l+o;case 0:return n-=o,n+o}}Tt.forEach((t=>{if(t.show&&t._show){let e=t.side;t._pos=i(e,t._size),null!=t.label&&(t._lpos=i(e,t.labelSize))}}))}();let l=r.bbox;Ue=l.left=D(Ce*xt,.5),Je=l.top=D(Be*xt,.5),qe=l.width=D(We*xt,.5),Ze=l.height=D(Ye*xt,.5)}r.setSize=function({width:t,height:e}){ll(t,e)};const il=r.cursor=Z({},be,e.cursor);{il.idxs=$t,il._lock=!1;let t=il.points;t.show=E(t.show),t.size=E(t.size),t.stroke=E(t.stroke),t.width=E(t.width),t.fill=E(t.fill)}const ol=r.focus=Z({},e.focus||{alpha:.3},il.focus),sl=ol.prox>=0;let rl=[null];function ul(t,e){let l=Et[t.scale].time,n=t.value;if(t.value=l?V(n)?me(jt,pe(n,Bt)):n||Zt:n||He,t.label=t.label||(l?"Time":"Value"),e>0){t.width=null==t.width?1:t.width,t.paths=t.paths||ml||W,t.fillTo=E(t.fillTo||Ie),t.pxAlign=+c(t.pxAlign,ft),t.pxRound=$e(t.pxAlign),t.stroke=E(t.stroke||null),t.fill=E(t.fill||null),t._stroke=t._fill=t._paths=t._focus=null;let e=Le(t.width,1),l=t.points=Z({},{size:e,width:b(1,.2*e),stroke:t.stroke,space:2*e,paths:gl,_stroke:null,_fill:null},t.points);l.show=E(l.show),l.filter=E(l.filter),l.fill=E(l.fill),l.stroke=E(l.stroke),l.paths=E(l.paths),l.pxAlign=t.pxAlign}if(Xt){let l=function(t,e){if(0==e&&(ie||!Kt.live))return j;let l=[],n=kt("tr","u-series",te,te.childNodes[e]);_t(n,t.class),t.show||_t(n,dt);let i=kt("th",null,n);if(Qt.show){let t=yt("u-marker",i);if(e>0){let l=Qt.width(r,e);l&&(t.style.border=l+"px "+Qt.dash(r,e)+" "+Qt.stroke(r,e)),t.style.background=Qt.fill(r,e)}}let o=yt(pt,i);for(var s in o.textContent=t.label,e>0&&(Qt.show||(o.style.color=t.width>0?Qt.stroke(r,e):Qt.fill(r,e)),ke("click",i,(e=>{if(il._lock)return;let l=zt.indexOf(t);if(e.ctrlKey!=Kt.isolate){let t=zt.some(((t,e)=>e>0&&e!=l&&t.show));zt.forEach(((e,n)=>{n>0&&Dn(n,t?n==l?we:_e:we,Qn.setSeries)}))}else Dn(l,{show:!t.show},Qn.setSeries)})),sl&&ke(ut,i,(()=>{il._lock||Dn(zt.indexOf(t),An,Qn.setSeries)}))),ee){let t=kt("td","u-value",n);t.textContent="--",l.push(t)}return[n,l]}(t,e);le.splice(e,0,l[0]),ne.splice(e,0,l[1]),Kt.values.push(null)}if(il.show){$t.splice(e,0,null);let l=function(t,e){if(e>0){let l=il.points.show(r,e);if(l)return _t(l,"u-cursor-pt"),_t(l,t.class),St(l,-10,-10,We,Ye),it.insertBefore(l,rl[e]),l}}(t,e);l&&rl.splice(e,0,l)}}r.addSeries=function(t,e){t=wl(t,e=null==e?zt.length:e,ze,Ge),zt.splice(e,0,t),ul(zt[e],e)},r.delSeries=function(t){if(zt.splice(t,1),Xt){Kt.values.splice(t,1),ne.splice(t,1);let e=le.splice(t,1)[0];ye(null,e.firstChild),e.remove()}il.show&&($t.splice(t,1),rl.length>1&&rl.splice(t,1)[0].remove())};const al=[!1,!1,!1,!1];function cl(t,e,l){let[n,i,o,s]=l,r=e%2,u=0;return 0==r&&(s||i)&&(u=0==e&&!n||2==e&&!o?x(Se.size/3):0),1==r&&(n||o)&&(u=1==e&&!i||3==e&&!s?x(Re.size/2):0),u}const fl=r.padding=(e.padding||[cl,cl,cl,cl]).map((t=>E(c(t,cl)))),hl=r._padding=fl.map(((t,e)=>t(r,e,al,0)));let pl,Tl=null,El=null;const Pl=zt[0].idxs;let Al,Wl,Yl,Cl,Fl,Hl,Rl,Ll,Il,Gl,Ol=null,Nl=!1;function jl(t,e){if((l=(t||[]).slice())[0]=l[0]||[],r.data=l.slice(),Ol=l[0],pl=Ol.length,2==Lt&&(l[0]=Ol.map(((t,e)=>e))),r._data=l,en(!0),Xn("setData"),!1!==e){let t=Rt;t.auto(r,Nl)?Bl():zn(Yt,t.min,t.max),tl=il.left>=0,el=!0,gn()}}function Bl(){let t,e;Nl=!0,pl>0?(Tl=Pl[0]=0,El=Pl[1]=pl-1,t=l[0][Tl],e=l[0][El],2==Lt?(t=Tl,e=El):1==pl&&(3==Lt?[t,e]=i(t,t,Rt.log,!1):4==Lt?[t,e]=o(t,t,Rt.log,!1):Rt.time?e=t+x(86400/Mt):[t,e]=a(t,e,.1,!0))):(Tl=Pl[0]=t=null,El=Pl[1]=e=null),zn(Yt,t,e)}function Vl(t="#0000",e,l=N,n="butt",i="#0000",o="round"){t!=Al&&(I.strokeStyle=Al=t),i!=Wl&&(I.fillStyle=Wl=i),e!=Yl&&(I.lineWidth=Yl=e),o!=Fl&&(I.lineJoin=Fl=o),n!=Hl&&(I.lineCap=Hl=n),l!=Cl&&I.setLineDash(Cl=l)}function Ul(t,e,l,n){e!=Wl&&(I.fillStyle=Wl=e),t!=Rl&&(I.font=Rl=t),l!=Ll&&(I.textAlign=Ll=l),n!=Il&&(I.textBaseline=Il=n)}function Jl(t,e){let l=e?zt[t].points:zt[t];l._stroke=l.stroke(r,t),l._fill=l.fill(r,t)}function ql(t,e){let l=e?zt[t].points:zt[t],n=l._stroke,i=l._fill,{stroke:o,fill:s,clip:u,flags:a}=l._paths,c=null,f=R(l.width*xt,3),h=f%2/2;e&&null==i&&(i=f>0?"#fff":n),Gl!=l.alpha&&(I.globalAlpha=Gl=l.alpha);let d=1==l.pxAlign;if(d&&I.translate(h,h),!e){let t=Ue,e=Je,n=qe,i=Ze,o=f*xt/2;0==l.min&&(i+=o),0==l.max&&(e-=o,i+=o),c=new Path2D,c.rect(t,e,n,i)}e?Zl(n,f,l.dash,l.cap,i,o,s,a,u,null,null):function(t,e,l,n,i,o,s,u,a,c,f){let h=!1;Wt.forEach(((d,p)=>{if(d.series[0]==t){let t=zt[d.series[1]],m=(t._paths||O).band,g=null;t.show&&m?g=d.fill(r,p)||o:m=null,Zl(e,l,n,i,g,s,u,a,c,f,m),h=!0}})),h||Zl(e,l,n,i,o,s,u,a,c,f,null)}(t,n,f,l.dash,l.cap,i,o,s,a,c,u),d&&I.translate(-h,-h),1!=Gl&&(I.globalAlpha=Gl=1)}function Zl(t,e,l,n,i,o,s,r,u,a,c){Vl(t,e,l,n,i),(u||a||c)&&(I.save(),u&&I.clip(u),a&&I.clip(a)),c?3==(3&r)?(I.clip(c),Kl(i,s),$l(t,o,e)):2&r?(Kl(i,s),I.clip(c),$l(t,o,e)):1&r&&(I.save(),I.clip(c),Kl(i,s),I.restore(),$l(t,o,e)):(Kl(i,s),$l(t,o,e)),(u||a||c)&&I.restore()}function $l(t,e,l){t&&e&&l&&I.stroke(e)}function Kl(t,e){t&&e&&I.fill(e)}function Xl(t,e,l,n,i,o,s,r,u,a){let c=s%2/2;1==ft&&I.translate(c,c),Vl(r,s,u,a,r),I.beginPath();let f,h,d,p,m=i+(0==n||3==n?-o:o);0==l?(h=i,p=m):(f=i,d=m);for(let n=0;t.length>n;n++)null!=e[n]&&(0==l?f=d=t[n]:h=p=t[n],I.moveTo(f,h),I.lineTo(d,p));I.stroke(),1==ft&&I.translate(-c,-c)}function Ql(t){let e=!0;return Tt.forEach(((l,n)=>{if(!l.show)return;let i=Et[l.scale];if(null==i.min)return void(l._show&&(e=!1,l._show=!1,en(!1)));l._show||(e=!1,l._show=!0,en(!1));let o=l.side,s=o%2,{min:u,max:a}=i,[c,f]=function(t,e,l,n){let i,o=Tt[t];if(n>0){let s=o._space=o.space(r,t,e,l,n),u=o._incrs=o.incrs(r,t,e,l,n,s);i=o._found=function(t,e,l,n,i){let o=n/(e-t),s=(""+g(t)).length;for(var r=0;l.length>r;r++){let t=l[r]*o,e=10>l[r]?L.get(l[r]):0;if(t>=i&&17>s+e)return[l[r],t]}return[0,0]}(e,l,u,n,s)}else i=[0,0];return i}(n,u,a,0==s?We:Ye);if(0==f)return;let h=l._splits=l.splits(r,n,u,a,c,f,2==i.distr),d=2==i.distr?h.map((t=>Ol[t])):h,p=2==i.distr?Ol[h[1]]-Ol[h[0]]:c,m=l._values=l.values(r,l.filter(r,d,n,f,p),n,f,p);l._rotate=2==o?l.rotate(r,m,n,f):0;let x=l._size;l._size=w(l.size(r,m,n,t)),null!=x&&l._size!=x&&(e=!1)})),e}function tn(t){let e=!0;return fl.forEach(((l,n)=>{let i=l(r,n,al,t);i!=hl[n]&&(e=!1),hl[n]=i})),e}function en(t){zt.forEach(((e,l)=>{l>0&&(e._paths=null,t&&(e.min=null,e.max=null))}))}r.setData=jl;let ln,nn,on,sn,rn,un,an,cn,fn,hn,dn,pn,mn=!1;function gn(){mn||(K(xn),mn=!0)}function xn(){Ke&&(function(){let e=q(Et,J);for(let t in e){let l=e[t],n=Nt[t];if(null!=n&&null!=n.min)Z(l,n),t==Yt&&en(!0);else if(t!=Yt)if(0==pl&&null==l.from){let e=l.range(r,null,null,t);l.min=e[0],l.max=e[1]}else l.min=z,l.max=-z}if(pl>0){zt.forEach(((n,i)=>{let o=n.scale,s=e[o],u=Nt[o];if(0==i){let e=s.range(r,s.min,s.max,o);s.min=e[0],s.max=e[1],Tl=t(s.min,l[0]),El=t(s.max,l[0]),s.min>l[0][Tl]&&Tl++,l[0][El]>s.max&&El--,n.min=Ol[Tl],n.max=Ol[El]}else if(n.show&&n.auto&&s.auto(r,Nl)&&(null==u||null==u.min)){let t=null==n.min?3==s.distr?function(t,e,l){let n=z,i=-z;for(let o=e;l>=o;o++)t[o]>0&&(n=_(n,t[o]),i=b(i,t[o]));return[n==z?1:n,i==-z?10:i]}(l[i],Tl,El):function(t,e,l,n){let i=z,o=-z;if(1==n)i=t[e],o=t[l];else if(-1==n)i=t[l],o=t[e];else for(let n=e;l>=n;n++)null!=t[n]&&(i=_(i,t[n]),o=b(o,t[n]));return[i,o]}(l[i],Tl,El,n.sorted):[n.min,n.max];s.min=_(s.min,n.min=t[0]),s.max=b(s.max,n.max=t[1])}n.idxs[0]=Tl,n.idxs[1]=El}));for(let t in e){let l=e[t],n=Nt[t];if(null==l.from&&(null==n||null==n.min)){let e=l.range(r,l.min==z?null:l.min,l.max==-z?null:l.max,t);l.min=e[0],l.max=e[1]}}}for(let t in e){let l=e[t];if(null!=l.from){let n=e[l.from],i=l.range(r,n.min,n.max,t);l.min=i[0],l.max=i[1]}}let n={},i=!1;for(let t in e){let l=e[t],o=Et[t];if(o.min!=l.min||o.max!=l.max){o.min=l.min,o.max=l.max;let e=o.distr;o._min=3==e?y(o.min):4==e?S(o.min,o.asinh):o.min,o._max=3==e?y(o.max):4==e?S(o.max,o.asinh):o.max,n[t]=i=!0}}if(i){zt.forEach((t=>{n[t.scale]&&(t._paths=null)}));for(let t in n)Qe=!0,Xn("setScale",t);il.show&&(tl=el=il.left>=0)}for(let t in Nt)Nt[t]=null}(),Ke=!1),Qe&&(function(){let t=!1,e=0;for(;!t;){e++;let l=Ql(e),n=tn(e);t=3==e||l&&n,t||(nl(r.width,r.height),Xe=!0)}}(),Qe=!1),Xe&&(vt($,lt,Ce),vt($,tt,Be),vt($,X,We),vt($,Q,Ye),vt(it,lt,Ce),vt(it,tt,Be),vt(it,X,We),vt(it,Q,Ye),vt(G,X,Me),vt(G,Q,Ae),H.width=x(Me*xt),H.height=x(Ae*xt),Nn(!1),Xn("setSize"),Xe=!1),Me>0&&Ae>0&&(I.clearRect(0,0,H.width,H.height),Xn("drawClear"),Ft.forEach((t=>t())),Xn("draw")),il.show&&tl&&(Gn(),tl=!1),M||(M=!0,r.status=1,Xn("ready")),Nl=!1,mn=!1}function wn(e,n){let i=Et[e];if(null==i.from){if(0==pl){let t=i.range(r,n.min,n.max,e);n.min=t[0],n.max=t[1]}if(n.min>n.max){let t=n.min;n.min=n.max,n.max=t}if(pl>1&&null!=n.min&&null!=n.max&&1e-16>n.max-n.min)return;e==Yt&&2==i.distr&&pl>0&&(n.min=t(n.min,l[0]),n.max=t(n.max,l[0])),Nt[e]=n,Ke=!0,gn()}}r.redraw=(t,e)=>{Qe=e||!1,!1!==t?zn(Yt,Rt.min,Rt.max):gn()},r.setScale=wn;let _n=!1;const bn=il.drag;let vn=bn.x,kn=bn.y;il.show&&(il.x&&(ln=yt("u-cursor-x",it)),il.y&&(nn=yt("u-cursor-y",it)),0==Rt.ori?(on=ln,sn=nn):(on=nn,sn=ln),dn=il.left,pn=il.top);const yn=r.select=Z({show:!0,over:!0,left:0,width:0,top:0,height:0},e.select),Mn=yn.show?yt("u-select",yn.over?it:$):null;function Sn(t,e){if(yn.show){for(let e in t)vt(Mn,e,yn[e]=t[e]);!1!==e&&Xn("setSelect")}}function zn(t,e,l){wn(t,{min:e,max:l})}function Dn(t,e,l){let n=zt[t];null!=e.focus&&function(t){if(t!=Pn){let e=null==t,l=1!=ol.alpha;zt.forEach(((n,i)=>{let o=e||0==i||i==t;n._focus=e?null:o,l&&function(t,e){zt[t].alpha=e,il.show&&rl[t]&&(rl[t].style.opacity=e),Xt&&le[t]&&(le[t].style.opacity=e)}(i,o?1:ol.alpha)})),Pn=t,l&&gn()}}(t),null!=e.show&&(n.show=e.show,function(t){let e=Xt?le[t]:null;zt[t].show?e&&bt(e,dt):(e&&_t(e,dt),rl.length>1&&St(rl[t],-10,-10,We,Ye))}(t),zn(n.scale,null,null),gn()),Xn("setSeries",t,e),l&&li("setSeries",r,t,e)}let Tn,En,Pn;r.setSelect=Sn,r.setSeries=Dn,r.addBand=function(t,e){t.fill=E(t.fill||null),Wt.splice(e=null==e?Wt.length:e,0,t)},r.setBand=function(t,e){Z(Wt[t],e)},r.delBand=function(t){null==t?Wt.length=0:Wt.splice(t,1)};const An={focus:!0},Wn={focus:!1};function Yn(t,e,l){let n=Et[e];l&&(t=t/xt-(1==n.ori?Be:Ce));let i=We;1==n.ori&&(i=Ye,t=i-t),-1==n.dir&&(t=i-t);let o=n._min,s=o+t/i*(n._max-o),r=n.distr;return 3==r?v(10,s):4==r?((t,e=1)=>d.sinh(t/e))(s,n.asinh):s}function Cn(t,e){vt(Mn,lt,yn.left=t),vt(Mn,X,yn.width=e)}function Fn(t,e){vt(Mn,tt,yn.top=t),vt(Mn,Q,yn.height=e)}Xt&&sl&&Pt(at,te,(()=>{il._lock||(Dn(null,Wn,Qn.setSeries),Gn())})),r.valToIdx=e=>t(e,l[0]),r.posToIdx=function(e,n){return t(Yn(e,Yt,n),l[0],Tl,El)},r.posToVal=Yn,r.valToPos=(t,e,l)=>0==Et[e].ori?f(t,Et[e],l?qe:We,l?Ue:0):h(t,Et[e],l?Ze:Ye,l?Je:0),r.batch=function(t){t(r),gn()},r.setCursor=(t,e)=>{dn=t.left,pn=t.top,Gn(null,null,e)};let Hn=0==Rt.ori?Cn:Fn,Rn=1==Rt.ori?Cn:Fn;function Ln(t,e){if(null!=t){let e=t.idx;Kt.idx=e,zt.forEach(((t,l)=>{(l>0||!ie)&&In(l,e)}))}Xt&&Kt.live&&function(){if(Xt&&Kt.live)for(let t=0;zt.length>t;t++){if(0==t&&ie)continue;let e=Kt.values[t],l=0;for(let n in e)ne[t][l++].firstChild.nodeValue=e[n]}}(),el=!1,!1!==e&&Xn("setLegend")}function In(t,e){let n;if(null==e)n=de;else{let i=zt[t],o=0==t&&2==Lt?Ol:l[t];n=ie?i.values(r,t,e):{_:i.value(r,o[e],t,e)}}Kt.values[t]=n}function Gn(e,n,i){let o;fn=dn,hn=pn,[dn,pn]=il.move(r,dn,pn),il.show&&(on&&St(on,x(dn),0,We,Ye),sn&&St(sn,0,x(pn),We,Ye)),Tn=z;let s=0==Rt.ori?We:Ye,u=1==Rt.ori?We:Ye;if(0>dn||0==pl||Tl>El){o=null;for(let t=0;zt.length>t;t++)t>0&&rl.length>1&&St(rl[t],-10,-10,We,Ye);if(sl&&Dn(null,An,Qn.setSeries),Kt.live){$t.fill(null),el=!0;for(let t=0;zt.length>t;t++)Kt.values[t]=de}}else{let e=Yn(0==Rt.ori?dn:pn,Yt);o=t(e,l[0],Tl,El);let n=F(It(l[0][o],Rt,s,0),.5);for(let t=0;zt.length>t;t++){let i=zt[t],a=il.dataIdx(r,t,o,e),c=l[t][a];el=el||c!=l[t][$t[t]],$t[t]=a;let f=a==o?n:F(It(l[0][a],Rt,s,0),.5);if(t>0&&i.show){let e,l,n=null==c?-10:F(Ot(c,Et[i.scale],u,0),.5);if(n>0){let e=m(n-pn);e>Tn||(Tn=e,En=t)}0==Rt.ori?(e=f,l=n):(e=n,l=f),el&&rl.length>1&&(St(rl[t],e,l,We,Ye),Dt(rl[t],il.points.fill(r,t),il.points.stroke(r,t)))}if(Kt.live){if(!el||0==t&&ie)continue;In(t,a)}}}if(el&&(Kt.idx=o,Ln()),yn.show&&_n)if(null!=n){let[t,e]=Qn.scales,[l,i]=Qn.match,[o,r]=n.cursor.sync.scales,a=n.cursor.drag;vn=a._x,kn=a._y;let c,f,h,d,p,{left:g,top:x,width:w,height:b}=n.select,v=n.scales[t].ori,k=n.posToVal,y=null!=t&&l(t,o),M=null!=e&&i(e,r);y&&(0==v?(c=g,f=w):(c=x,f=b),vn?(h=Et[t],d=It(k(c,o),h,s,0),p=It(k(c+f,o),h,s,0),Hn(_(d,p),m(p-d))):Hn(0,s),M||Rn(0,u)),M&&(1==v?(c=g,f=w):(c=x,f=b),kn?(h=Et[e],d=Ot(k(c,r),h,u,0),p=Ot(k(c+f,r),h,u,0),Rn(_(d,p),m(p-d))):Rn(0,u),y||Hn(0,s))}else{let t=m(fn-rn),e=m(hn-un);if(1==Rt.ori){let l=t;t=e,e=l}vn=bn.x&&t>=bn.dist,kn=bn.y&&e>=bn.dist;let l,n,i=bn.uni;null!=i?vn&&kn&&(vn=t>=i,kn=e>=i,vn||kn||(e>t?kn=!0:vn=!0)):bn.x&&bn.y&&(vn||kn)&&(vn=kn=!0),vn&&(0==Rt.ori?(l=an,n=dn):(l=cn,n=pn),Hn(_(l,n),m(n-l)),kn||Rn(0,u)),kn&&(1==Rt.ori?(l=an,n=dn):(l=cn,n=pn),Rn(_(l,n),m(n-l)),vn||Hn(0,s)),vn||kn||(Hn(0,0),Rn(0,0))}if(il.idx=o,il.left=dn,il.top=pn,bn._x=vn,bn._y=kn,null!=e){if(null!=ti){let[t,e]=Qn.scales;Qn.values[0]=null!=t?Yn(0==Rt.ori?dn:pn,t):null,Qn.values[1]=null!=e?Yn(1==Rt.ori?dn:pn,e):null}if(li(ot,r,dn,pn,We,Ye,o),sl){let t=Qn.setSeries,e=ol.prox;null==Pn?Tn>e||Dn(En,An,t):Tn>e?Dn(null,An,t):En!=Pn&&Dn(En,An,t)}}M&&!1!==i&&Xn("setCursor")}r.setLegend=Ln;let On=null;function Nn(t){!0===t?On=null:(On=it.getBoundingClientRect(),Xn("syncRect",On))}function jn(t,e,l,n,i,o){il._lock||(Bn(t,e,l,n,i,o,0,!1,null!=t),null!=t?Gn(1):Gn(null,e))}function Bn(t,e,l,n,i,o,s,u,a){if(null==On&&Nn(!1),null!=t)l=t.clientX-On.left,n=t.clientY-On.top;else{if(0>l||0>n)return dn=-10,void(pn=-10);let[t,s]=Qn.scales,r=e.cursor.sync,[u,a]=r.values,[c,f]=r.scales,[h,d]=Qn.match,p=1==e.scales[c].ori,m=0==Rt.ori?We:Ye,g=1==Rt.ori?We:Ye,x=p?o:i,w=p?i:o,_=p?n:l,b=p?l:n;if(l=null!=c?h(t,c)?k(u,Et[t],m,0):-10:m*(_/x),n=null!=f?d(s,f)?k(a,Et[s],g,0):-10:g*(b/w),1==Rt.ori){let t=l;l=n,n=t}}a&&(l>1&&We-1>l||(l=D(l,We)),n>1&&Ye-1>n||(n=D(n,Ye))),u?(rn=l,un=n,[an,cn]=il.move(r,l,n)):(dn=l,pn=n)}function Vn(){Sn({width:0,height:0},!1)}function Un(t,e,l,n,i,o){_n=!0,vn=kn=bn._x=bn._y=!1,Bn(t,e,l,n,i,o,0,!0,!1),null!=t&&(ke(rt,mt,Jn),li(st,r,an,cn,We,Ye,null))}function Jn(t,e,l,n,i,o){_n=bn._x=bn._y=!1,Bn(t,e,l,n,i,o,0,!1,!0);let{left:s,top:u,width:a,height:c}=yn,f=a>0||c>0;if(f&&Sn(yn),bn.setScale&&f){let t=s,e=a,l=u,n=c;if(1==Rt.ori&&(t=u,e=c,l=s,n=a),vn&&zn(Yt,Yn(t,Yt),Yn(t+e,Yt)),kn)for(let t in Et){let e=Et[t];t!=Yt&&null==e.from&&e.min!=z&&zn(t,Yn(l+n,t),Yn(l,t))}Vn()}else il.lock&&(il._lock=!il._lock,il._lock||Gn());null!=t&&(ye(rt,mt),li(rt,r,dn,pn,We,Ye,null))}function qn(t){Bl(),Vn(),null!=t&&li(ct,r,dn,pn,We,Ye,null)}function Zn(){Tt.forEach(Dl),ll(r.width,r.height,!0)}Pt(ht,gt,Zn);const $n={};$n.mousedown=Un,$n.mousemove=jn,$n.mouseup=Jn,$n.dblclick=qn,$n.setSeries=(t,e,l,n)=>{Dn(l,n)},il.show&&(ke(st,it,Un),ke(ot,it,jn),ke(ut,it,Nn),ke(at,it,(function(){if(!il._lock){let t=_n;if(_n){let t,e,l=!0,n=!0,i=10;0==Rt.ori?(t=vn,e=kn):(t=kn,e=vn),t&&e&&(l=i>=dn||dn>=We-i,n=i>=pn||pn>=Ye-i),t&&l&&(dn=an>dn?0:We),e&&n&&(pn=cn>pn?0:Ye),Gn(1),_n=!1}dn=-10,pn=-10,Gn(1),t&&(_n=t)}})),ke(ct,it,qn),dl.add(r),r.syncRect=Nn);const Kn=r.hooks=e.hooks||{};function Xn(t,e,l){t in Kn&&Kn[t].forEach((t=>{t.call(null,r,e,l)}))}(e.plugins||[]).forEach((t=>{for(let e in t.hooks)Kn[e]=(Kn[e]||[]).concat(t.hooks[e])}));const Qn=Z({key:null,setSeries:!1,filters:{pub:Y,sub:Y},scales:[Yt,zt[1]?zt[1].scale:null],match:[C,C],values:[null,null]},il.sync);il.sync=Qn;const ti=Qn.key,ei=Ve(ti);function li(t,e,l,n,i,o,s){Qn.filters.pub(t,e,l,n,i,o,s)&&ei.pub(t,e,l,n,i,o,s)}function ni(){Xn("init",e,l),jl(l||e.data,!1),Nt[Yt]?wn(Yt,Nt[Yt]):Bl(),ll(e.width,e.height),Gn(),Sn(yn,!1)}return ei.sub(r),r.pub=function(t,e,l,n,i,o,s){Qn.filters.sub(t,e,l,n,i,o,s)&&$n[t](null,e,l,n,i,o,s)},r.destroy=function(){ei.unsub(r),dl.delete(r),ve.clear(),At(ht,gt,Zn),P.remove(),Xn("destroy")},zt.forEach(ul),Tt.forEach((function(t,e){if(t._show=t.show,t.show){let l=t.side%2,n=Et[t.scale];null==n&&(t.scale=l?zt[1].scale:Yt,n=Et[t.scale]);let i=n.time;t.size=E(t.size),t.space=E(t.space),t.rotate=E(t.rotate),t.incrs=E(t.incrs||(2==n.distr?Ut:i?1==Mt?oe:ue:Jt)),t.splits=E(t.splits||(i&&1==n.distr?Vt:3==n.distr?Ee:4==n.distr?Pe:Te)),t.stroke=E(t.stroke),t.grid.stroke=E(t.grid.stroke),t.ticks.stroke=E(t.ticks.stroke);let o=t.values;t.values=B(o)&&!B(o[0])?E(o):i?B(o)?he(jt,fe(o,Bt)):V(o)?function(t,e){let l=Gt(e);return(e,n)=>n.map((e=>l(t(e))))}(jt,o):o||qt:o||De,t.filter=E(t.filter||(3>n.distr?A:Fe)),t.font=zl(t.font),t.labelFont=zl(t.labelFont),t._size=t.size(r,null,e,0),t._space=t._rotate=t._incrs=t._found=t._splits=t._values=null,t._size>0&&(al[e]=!0)}})),n?n instanceof HTMLElement?(n.appendChild(P),ni()):n(r,ni):ni(),r}Tl.assign=Z,Tl.fmtNum=h,Tl.rangeNum=a,Tl.rangeLog=i,Tl.rangeAsinh=o,Tl.orient=Ue,Tl.join=function(t,e){let l=new Set;for(let e=0;t.length>e;e++){let n=t[e][0],i=n.length;for(let t=0;i>t;t++)l.add(n[t])}let n=[Array.from(l).sort(((t,e)=>t-e))],i=n[0].length,o=new Map;for(let t=0;i>t;t++)o.set(n[0][t],t);for(let l=0;t.length>l;l++){let s=t[l],r=s[0];for(let t=1;s.length>t;t++){let u=s[t],a=Array(i).fill(void 0),c=e?e[l][t]:1,f=[];for(let t=0;u.length>t;t++){let e=u[t],l=o.get(r[t]);null===e?0!=c&&(a[l]=e,2==c&&f.push(l)):a[l]=e}$(a,f,i),n.push(a)}}return n},Tl.fmtDate=Gt,Tl.tzDate=function(t,e){let l;return"UTC"==e||"Etc/UTC"==e?l=new Date(+t+6e4*t.getTimezoneOffset()):e==Ot?l=t:(l=new Date(t.toLocaleString("en-US",{timeZone:e})),l.setMilliseconds(t.getMilliseconds())),l},Tl.sync=Ve;{Tl.addGap=Ze,Tl.clipGaps=qe;let t=Tl.paths={points:rl};t.linear=fl,t.stepped=function(t){const l=c(t.align,1),n=c(t.ascDesc,!1);return(t,i,o,s)=>Ue(t,i,((r,u,a,c,f,h,d,p,m,g,x)=>{let w=r.pxRound,_=0==c.ori?Qe:tl;const b={stroke:new Path2D,fill:null,clip:null,band:null,gaps:null,flags:1},v=b.stroke,k=1*c.dir*(0==c.ori?1:-1);o=e(a,o,s,1),s=e(a,o,s,-1);let y=[],M=!1,S=w(d(a[1==k?o:s],f,x,m)),z=w(h(u[1==k?o:s],c,g,p)),D=z;_(v,z,S);for(let t=1==k?o:s;t>=o&&s>=t;t+=k){let e=a[t],i=w(h(u[t],c,g,p));if(null==e){null===e&&(Ze(y,D,i),M=!0);continue}let o=w(d(e,f,x,m));if(M){if(Ze(y,D,i),S!=o){let t=r.width*xt/2,e=y[y.length-1];e[0]+=n||1==l?t:-t,e[1]-=n||-1==l?t:-t}M=!1}1==l?_(v,i,S):_(v,D,o),_(v,i,o),S=o,D=i}if(null!=r.fill){let e=b.fill=new Path2D(v),l=w(d(r.fillTo(t,i,r.min,r.max),f,x,m));_(e,D,l),_(e,z,l)}return b.gaps=y=r.gaps(t,i,o,s,y),r.spanGaps||(b.clip=qe(y,c.ori,p,m,g,x)),t.bands.length>0&&(b.band=Je(t,i,o,s,v)),b}))},t.bars=function(t){const l=c((t=t||O).size,[.6,z,1]),n=t.align||0,i=(t.gap||0)*xt,o=1-l[0],s=c(l[1],z)*xt,r=c(l[2],1)*xt,u=t.disp,a=c(t.each,(()=>{}));return(t,l,c,f)=>Ue(t,l,((h,d,p,g,x,w,v,k,y,M,S)=>{let z=h.pxRound;const T=g.dir*(0==g.ori?1:-1),E=x.dir*(1==x.ori?1:-1);let P,A,W=0==g.ori?el:ll,Y=0==g.ori?a:(t,e,l,n,i,o,s)=>{a(t,e,l,i,n,s,o)},C=v(h.fillTo(t,l,h.min,h.max),x,S,y),F=z(h.width*xt);if(null!=u){d=u.x0.values(t,l,c,f),2==u.x0.unit&&(d=d.map((e=>t.posToVal(k+e*M,g.key,!0))));let e=u.size.values(t,l,c,f);A=2==u.size.unit?e[0]*M:w(e[0],g,M,k)-w(0,g,M,k),A=z(A-F),P=1==T?-F/2:A+F/2}else{let t=M;if(d.length>1)for(let e=1,l=1/0;d.length>e;e++){let n=m(d[e]-d[e-1]);l>n&&(l=n,t=m(w(d[e],g,M,k)-w(d[e-1],g,M,k)))}A=z(_(s,b(r,t-t*o))-F-i),P=(0==n?A/2:n==T?0:A)-n*T*i/2}const H={stroke:new Path2D,fill:null,clip:null,band:null,gaps:null,flags:3},R=t.bands.length>0;let L;R&&(H.band=new Path2D,L=D(v(x.max,x,S,y),.5));const I=H.stroke,G=H.band;for(let n=1==T?c:f;n>=c&&f>=n;n+=T){let i=p[n];if(null==i){if(!R)continue;{let t=e(p,1==T?c:f,n,-T),l=e(p,n,1==T?f:c,T),o=p[t];i=o+(n-t)/(l-t)*(p[l]-o)}}let o=w(2!=g.distr||null!=u?d[n]:n,g,M,k),s=v(i,x,S,y),r=z(o-P),a=z(b(s,C)),h=z(_(s,C)),m=a-h;null!=p[n]&&(W(I,r,h,A,m),Y(t,l,n,r-F/2,h-F/2,A+F,m+F)),R&&(1==E?(a=h,h=L):(h=a,a=L),m=a-h,W(G,r-F/2,h+F/2,A+F,m-F))}return null!=h.fill&&(H.fill=new Path2D(I)),H}))},t.spline=function(){return function(t){return(l,n,i,o)=>Ue(l,n,((s,r,u,a,c,f,h,d,p,m,g)=>{let x,w,_,b=s.pxRound;0==a.ori?(x=Ke,_=Qe,w=ol):(x=Xe,_=tl,w=sl);const v=1*a.dir*(0==a.ori?1:-1);i=e(u,i,o,1),o=e(u,i,o,-1);let k=[],y=!1,M=b(f(r[1==v?i:o],a,m,d)),S=M,z=[],D=[];for(let t=1==v?i:o;t>=i&&o>=t;t+=v){let e=u[t],l=f(r[t],a,m,d);null!=e?(y&&(Ze(k,S,l),y=!1),z.push(S=l),D.push(h(u[t],c,g,p))):null===e&&(Ze(k,S,l),y=!0)}const T={stroke:t(z,D,x,_,w,b),fill:null,clip:null,band:null,gaps:null,flags:1},E=T.stroke;if(null!=s.fill&&null!=E){let t=T.fill=new Path2D(E),e=b(h(s.fillTo(l,n,s.min,s.max),c,g,p));_(t,S,e),_(t,M,e)}return T.gaps=k=s.gaps(l,n,i,o,k),s.spanGaps||(T.clip=qe(k,a.ori,d,p,m,g)),l.bands.length>0&&(T.band=Je(l,n,i,o,E)),T}))}(hl)}}return Tl}(); diff --git a/package.json b/package.json index 3a9474c6..15a2408f 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ }, "homepage": "https://github.com/leeoniya/uPlot#readme", "devDependencies": { - "@rollup/plugin-buble": "^0.21.3", "rollup": "^2.56.2", "rollup-plugin-terser": "^7.0.2" } diff --git a/rollup.config.js b/rollup.config.js index aa0db74f..3bb47816 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -13,7 +13,6 @@ function cssmin(css) { let minicss = cssmin(fs.readFileSync('./src/uPlot.css', 'utf8')); fs.writeFileSync('./dist/uPlot.min.css', minicss); -import buble from '@rollup/plugin-buble'; import { terser } from 'rollup-plugin-terser'; const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); @@ -94,7 +93,6 @@ export default [ }, plugins: [ bannerlessESM(), - buble({transforms: { forOf: false, arrow: false }}), ] }, { @@ -108,7 +106,6 @@ export default [ }, plugins: [ bannerlessESM(), - buble({transforms: { forOf: false, arrow: false }}), terser(terserOpts), ] }, diff --git a/src/uPlot.js b/src/uPlot.js index 9bb4bd94..d64bef4d 100644 --- a/src/uPlot.js +++ b/src/uPlot.js @@ -55,6 +55,7 @@ import { retNull, retTrue, EMPTY_OBJ, + EMPTY_ARR, nullNullTuple, retEq, autoRangePart, @@ -1099,13 +1100,33 @@ export default function uPlot(opts, data, then) { _setScale(xScaleKey, _min, _max); } - function setCtxStyle(stroke, width, dash, cap, fill) { - ctx.strokeStyle = stroke || transparent; - ctx.lineWidth = width; - ctx.lineJoin = "round"; - ctx.lineCap = cap || "butt"; // (‿|‿) - ctx.setLineDash(dash || []); - ctx.fillStyle = fill || transparent; + let ctxStroke, ctxFill, ctxWidth, ctxDash, ctxJoin, ctxCap, ctxFont, ctxAlign, ctxBaseline; + let ctxAlpha; + + function setCtxStyle(stroke = transparent, width, dash = EMPTY_ARR, cap = "butt", fill = transparent, join = "round") { + if (stroke != ctxStroke) + ctx.strokeStyle = ctxStroke = stroke; + if (fill != ctxFill) + ctx.fillStyle = ctxFill = fill; + if (width != ctxWidth) + ctx.lineWidth = ctxWidth = width; + if (join != ctxJoin) + ctx.lineJoin = ctxJoin = join; + if (cap != ctxCap) + ctx.lineCap = ctxCap = cap; // (‿|‿) + if (dash != ctxDash) + ctx.setLineDash(ctxDash = dash); + } + + function setFontStyle(font, fill, align, baseline) { + if (fill != ctxFill) + ctx.fillStyle = ctxFill = fill; + if (font != ctxFont) + ctx.font = ctxFont = font; + if (align != ctxAlign) + ctx.textAlign = ctxAlign = align; + if (baseline != ctxBaseline) + ctx.textBaseline = ctxBaseline = baseline; } function setScales() { @@ -1307,21 +1328,21 @@ export default function uPlot(opts, data, then) { let strokeStyle = s._stroke; let fillStyle = s._fill; - let { stroke, fill, clip, flags } = s._paths; + let { stroke, fill, clip: gapsClip, flags } = s._paths; + let boundsClip = null; let width = roundDec(s.width * pxRatio, 3); let offset = (width % 2) / 2; if (_points && fillStyle == null) fillStyle = width > 0 ? "#fff" : strokeStyle; - ctx.globalAlpha = s.alpha; + if (ctxAlpha != s.alpha) + ctx.globalAlpha = ctxAlpha = s.alpha; let _pxAlign = s.pxAlign == 1; _pxAlign && ctx.translate(offset, offset); - ctx.save(); - if (!_points) { let lft = plotLft, top = plotTop, @@ -1338,26 +1359,23 @@ export default function uPlot(opts, data, then) { hgt += halfWid; } - ctx.beginPath(); - ctx.rect(lft, top, wid, hgt); - ctx.clip(); + boundsClip = new Path2D(); + boundsClip.rect(lft, top, wid, hgt); } - clip && ctx.clip(clip); - + // the points pathbuilder's gapsClip is its boundsClip, since points dont need gaps clipping, and bounds depend on point size if (_points) - strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, null, flags); + strokeFill(strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags, gapsClip, null, null); else - fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags); - - ctx.restore(); + fillStroke(si, strokeStyle, width, s.dash, s.cap, fillStyle, stroke, fill, flags, boundsClip, gapsClip); _pxAlign && ctx.translate(-offset, -offset); - ctx.globalAlpha = 1; + if (ctxAlpha != 1) + ctx.globalAlpha = ctxAlpha = 1; } - function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags) { + function fillStroke(si, strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip) { let didStrokeFill = false; // for all bands where this series is the top edge, create upwards clips using the bottom edges @@ -1367,49 +1385,51 @@ export default function uPlot(opts, data, then) { if (b.series[0] == si) { let lowerEdge = series[b.series[1]]; - let clip = (lowerEdge._paths || EMPTY_OBJ).band; - - ctx.save(); + let bandClip = (lowerEdge._paths || EMPTY_OBJ).band; let _fillStyle = null; // hasLowerEdge? - if (lowerEdge.show && clip) + if (lowerEdge.show && bandClip) _fillStyle = b.fill(self, bi) || fillStyle; else - clip = null; + bandClip = null; - strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, clip, flags); - - ctx.restore(); + strokeFill(strokeStyle, lineWidth, lineDash, lineCap, _fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, bandClip); didStrokeFill = true; } }); if (!didStrokeFill) - strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, null, flags); + strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, null); } const CLIP_FILL_STROKE = BAND_CLIP_FILL | BAND_CLIP_STROKE; - function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, clip, flags) { + function strokeFill(strokeStyle, lineWidth, lineDash, lineCap, fillStyle, strokePath, fillPath, flags, boundsClip, gapsClip, bandClip) { setCtxStyle(strokeStyle, lineWidth, lineDash, lineCap, fillStyle); - if (clip) { + if (boundsClip || gapsClip || bandClip) { + ctx.save(); + boundsClip && ctx.clip(boundsClip); + gapsClip && ctx.clip(gapsClip); + } + + if (bandClip) { if ((flags & CLIP_FILL_STROKE) == CLIP_FILL_STROKE) { - ctx.clip(clip); + ctx.clip(bandClip); doFill(fillStyle, fillPath); doStroke(strokeStyle, strokePath, lineWidth); } else if (flags & BAND_CLIP_STROKE) { doFill(fillStyle, fillPath); - ctx.clip(clip); + ctx.clip(bandClip); doStroke(strokeStyle, strokePath, lineWidth); } else if (flags & BAND_CLIP_FILL) { ctx.save(); - ctx.clip(clip); + ctx.clip(bandClip); doFill(fillStyle, fillPath); ctx.restore(); doStroke(strokeStyle, strokePath, lineWidth); @@ -1419,6 +1439,9 @@ export default function uPlot(opts, data, then) { doFill(fillStyle, fillPath); doStroke(strokeStyle, strokePath, lineWidth); } + + if (boundsClip || gapsClip || bandClip) + ctx.restore(); } function doStroke(strokeStyle, strokePath, lineWidth) { @@ -1426,7 +1449,7 @@ export default function uPlot(opts, data, then) { } function doFill(fillStyle, fillPath) { - fillStyle && fillPath && ctx.fill(fillPath); + fillStyle && fillPath && ctx.fill(fillPath); } function getIncrSpace(axisIdx, min, max, fullDim) { @@ -1450,7 +1473,7 @@ export default function uPlot(opts, data, then) { pxAlign == 1 && ctx.translate(offset, offset); - setCtxStyle(stroke, width, dash, cap); + setCtxStyle(stroke, width, dash, cap, stroke); ctx.beginPath(); @@ -1465,18 +1488,17 @@ export default function uPlot(opts, data, then) { x1 = pos1; } - offs.forEach((off, i) => { - if (filts[i] == null) - return; - - if (ori == 0) - x0 = x1 = off; - else - y0 = y1 = off; + for (let i = 0; i < offs.length; i++) { + if (filts[i] != null) { + if (ori == 0) + x0 = x1 = offs[i]; + else + y0 = y1 = offs[i]; - ctx.moveTo(x0, y0); - ctx.lineTo(x1, y1); - }); + ctx.moveTo(x0, y0); + ctx.lineTo(x1, y1); + } + } ctx.stroke(); @@ -1562,7 +1584,9 @@ export default function uPlot(opts, data, then) { } function drawAxesGrid() { - axes.forEach((axis, i) => { + for (let i = 0; i < axes.length; i++) { + let axis = axes[i]; + if (!axis.show || !axis._show) return; @@ -1580,6 +1604,8 @@ export default function uPlot(opts, data, then) { let shiftAmt = axis.labelGap * shiftDir; let baseLpos = round((axis._lpos + shiftAmt) * pxRatio); + setFontStyle(axis.labelFont[0], fillStyle, "center", side == 2 ? TOP : BOTTOM); + ctx.save(); if (ori == 1) { @@ -1597,11 +1623,6 @@ export default function uPlot(opts, data, then) { 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(); @@ -1638,41 +1659,51 @@ export default function uPlot(opts, data, then) { y = ori == 0 ? finalPos : 0; x = ori == 1 ? finalPos : 0; - ctx.font = axis.font[0]; - ctx.fillStyle = fillStyle; - ctx.textAlign = axis.align == 1 ? LEFT : + let font = axis.font[0]; + let 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 || + let textBaseline = angle || ori == 1 ? "middle" : side == 2 ? TOP : BOTTOM; + setFontStyle(font, fillStyle, textAlign, textBaseline); + let lineHeight = axis.font[1] * lineMult; let canOffs = _splits.map(val => pxRound(getPos(val, scale, plotDim, plotOff))); - axis._values.forEach((val, i) => { - if (val == null) - return; + let _values = axis._values; - if (ori == 0) - x = canOffs[i]; - else - y = canOffs[i]; - - (""+val).split(/\n/gm).forEach((text, j) => { - if (angle) { - ctx.save(); - ctx.translate(x, y + j * lineHeight); - ctx.rotate(angle); - ctx.fillText(text, 0, 0); - ctx.restore(); - } + for (let i = 0; i < _values.length; i++) { + let val = _values[i]; + + if (val != null) { + if (ori == 0) + x = canOffs[i]; else - ctx.fillText(text, x, y + j * lineHeight); - }); - }); + y = canOffs[i]; + + val = "" + val; + + let _parts = val.indexOf("\n") == -1 ? [val] : val.split(/\n/gm); + + for (let j = 0; j < _parts.length; j++) { + let text = _parts[j]; + + if (angle) { + ctx.save(); + ctx.translate(x, y + j * lineHeight); // can this be replaced with position math? + ctx.rotate(angle); // can this be done once? + ctx.fillText(text, 0, 0); + ctx.restore(); + } + else + ctx.fillText(text, x, y + j * lineHeight); + } + } + } // ticks if (ticks.show) { @@ -1707,7 +1738,7 @@ export default function uPlot(opts, data, then) { grid.cap, ); } - }); + } fire("drawAxes"); } diff --git a/src/utils.js b/src/utils.js index b392dfa7..16eed48f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -317,6 +317,7 @@ export function genIncrs(base, minExp, maxExp, mults) { //export const assign = Object.assign; export const EMPTY_OBJ = {}; +export const EMPTY_ARR = []; export const nullNullTuple = [null, null];