UNPKG

@heycar-uikit/core

Version:
40 lines (38 loc) 1.46 kB
var _this = undefined; var drawCurve = function (ctx, points) { // https://stackoverflow.com/a/40978275 if (points[0]) ctx.moveTo(points[0].x, points[0].y); for (var i = 0; i < points.length - 1; i += 1) { var xMid = (points[i].x + points[i + 1].x) / 2; var yMid = (points[i].y + points[i + 1].y) / 2; var cpX1 = (xMid + points[i].x) / 2; var cpX2 = (xMid + points[i + 1].x) / 2; if (i === 0) { ctx.quadraticCurveTo(cpX1, points[i].y, xMid, yMid); } else { ctx.quadraticCurveTo(cpX1, points[i].y, xMid, yMid); } ctx.quadraticCurveTo(cpX2, points[i + 1].y, points[i + 1].x, points[i + 1].y); } }; var sanitiseRangeIndexes = function (selectedRangeIndexes, histogramData) { if (!selectedRangeIndexes) return [0, histogramData.length - 1]; var sortedIndexes = selectedRangeIndexes.sort(function (a, b) { return a - b; }); var from = Math.min(Math.max(sortedIndexes[0], 0), histogramData.length - 1); var to = Math.min(Math.max(sortedIndexes[1], 0), histogramData.length - 1); return [from, to]; }; var debounce = function (func, timeout) { if (timeout === void 0) { timeout = 100; } var timer; return function () { clearTimeout(timer); timer = setTimeout(function () { func.apply(_this); }, timeout); }; }; export { debounce, drawCurve, sanitiseRangeIndexes };