chrt
Version:
Chrt is a library for creating charts in the most spontaneous way possible.
10,192 lines • 350 kB
JavaScript
// chrt.io v0.0.170 Copyright 2024 chrt
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.chrt = global.chrt || {}));
})(this, (function (exports) { 'use strict';
var version = "0.0.170";
// chrt-core v0.0.69 Copyright 2020-2024 chrt chrt.io
function _arrayLikeToArray$j(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithHoles$1(r) {
if (Array.isArray(r)) return r;
}
function _arrayWithoutHoles$j(r) {
if (Array.isArray(r)) return _arrayLikeToArray$j(r);
}
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray$j(r)) || e) {
t && (r = t);
var n = 0,
F = function () {};
return {
s: F,
n: function () {
return n >= r.length ? {
done: !0
} : {
done: !1,
value: r[n++]
};
},
e: function (r) {
throw r;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o,
a = !0,
u = !1;
return {
s: function () {
t = t.call(r);
},
n: function () {
var r = t.next();
return a = r.done, r;
},
e: function (r) {
u = !0, o = r;
},
f: function () {
try {
a || null == t.return || t.return();
} finally {
if (u) throw o;
}
}
};
}
function _defineProperty$3(e, r, t) {
return (r = _toPropertyKey$2(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _iterableToArray$j(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _iterableToArrayLimit$1(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest$1() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableSpread$j() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function ownKeys$1(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2$1(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) {
_defineProperty$3(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _slicedToArray$1(r, e) {
return _arrayWithHoles$1(r) || _iterableToArrayLimit$1(r, e) || _unsupportedIterableToArray$j(r, e) || _nonIterableRest$1();
}
function _toConsumableArray$j(r) {
return _arrayWithoutHoles$j(r) || _iterableToArray$j(r) || _unsupportedIterableToArray$j(r) || _nonIterableSpread$j();
}
function _toPrimitive$2(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey$2(t) {
var i = _toPrimitive$2(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _unsupportedIterableToArray$j(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray$j(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$j(r, a) : void 0;
}
}
// Math.log() function returns the natural logarithm (base e) of a number,
var DEFAULT_LOG_BASE = 10;
// generic function for log with multiple bases
function baseLog() {
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_LOG_BASE;
base = isNaN(base) ? DEFAULT_LOG_BASE : base;
return base === Math.E ? Math.log : base === 10 && log10 || base === 2 && log2 || function (y) {
return getBaseLog(base, y);
};
}
// logarithm of y with base x:
function getBaseLog(x, y) {
return Math.log(y) / Math.log(x);
}
var log10 = Math.log10 = Math.log10 || function (x) {
return Math.log(x) * Math.LOG10E;
};
var log2 = Math.log2 || function (x) {
return Math.log(x) * Math.LOG2E;
};
var pow10 = function pow10(x) {
return isFinite(x) ? +('1e' + x) : x < 0 ? 0 : x;
};
var basePow = function basePow(base) {
return base === 10 ? pow10 : base === Math.E ? Math.exp : function (x) {
return Math.pow(base, x);
};
};
var DEFAULT_WIDTH = 600;
var DEFAULT_HEIGHT = 300;
var TICKS_DEFAULT$2 = 10;
var COMPONENTS_W_DATA$6 = ['chrt', 'series'];
function isNull$k(value) {
return value === null || value == null || typeof value === 'undefined';
}
function hasNull(values) {
if (!Array.isArray(values)) {
values = [values];
}
return values.some(function (value) {
return isNull$k(value);
});
}
function hasNaN(values) {
if (!Array.isArray(values)) {
values = [values];
}
return values.some(function (value) {
return isNaN(value);
});
}
function uuid$6() {
return 'c' + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
function hasData$6(obj) {
return !isNull$k(obj.type) && COMPONENTS_W_DATA$6.indexOf(obj.type) > -1;
}
function isInfinity$b(value) {
if (typeof value === 'string') {
return false;
}
return !isFinite(value);
}
function arraysEqual(array1, array2) {
if (!Array.isArray(array1) || !Array.isArray(array2)) {
console.warn('arraysEqual(array1, array2)', 'Both parameters should be arrays');
return false;
}
if (array1.length === 0 && array2.length === 0) {
return true;
}
return array1.length == array2.length && array1.every(function (element, index) {
return element === array2[index];
});
}
function data$6 (data, accessor) {
// console.log('---------------> data', data, accessor, this);
if (!data) {
// console.log('NO DATA return', hasData(this), this._data, hasData(this) ? this._data : this)
return hasData$6(this) ? this._data || null : this;
}
// TODO: not sure what this is doing...
if (!hasData$6(this)) {
// console.log('NO HAS DATA')
return this;
}
// console.log('HAS DATA')
// // console.log('chrt or series', this.type)
// passing only accessor to inherit/reuse data
if (typeof arguments[0] === 'function') {
this._accessor = arguments[0];
return this;
}
// Object.values(this.scales).forEach(scale => {
// Object.values(scale).forEach(d => {
// d.clear();
// });
// })
// data is passed
this._orginalData = data;
// // console.log('DATA', this, this._data, data);
// define accessor function to map values
var accessorFunction = accessor || this._accessor;
this._accessor = accessorFunction;
this._data = accessorFunction ? data.map(function (d, i, arr) {
if (d instanceof Object) {
return Object.assign({}, d, accessorFunction(d, i, arr));
}
return accessorFunction(d, i, arr);
}) : data;
// console.log('DATA', this._data)
return this;
}
/**
* node - Returns the DOM element that contains a chart element
*
* @param {type} node Set this as root node
*
* @return {type} Description
*/
function node$6 (node) {
if (!node) {
return this.g || this.root;
}
node.appendChild(this.root);
// this.currentNode = this.root;
this.root = node;
return this;
}
function memoize(func) {
var cache = {};
return function () {
// // // console.log('CURRENT CACHE', cache);
var args = Array.prototype.slice.call(arguments);
var key = JSON.stringify({
func: func.name,
args: args
});
if (cache[key]) {
// // // console.log('MEMOIZE USING CACHE', arguments, cache);
return cache[key];
} else {
// // // console.log('MEMOIZE NO CACHE', arguments);
var val = func.apply(null, arguments);
cache[key] = val;
return val;
}
};
}
function args(func) {
return (func + '').replace(/[/][/].*$/gm, '') // strip single-line comments
.replace(/\s+/g, '') // strip white space
.replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments
.split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters
.replace(/=[^,]+/g, '') // strip any ES6 defaults
.split(',').filter(Boolean); // split & filter [""]
}
function getMethods(obj) {
var properties = new Set();
var currentObj = obj;
do {
Object.getOwnPropertyNames(currentObj).map(function (item) {
return properties.add(item);
});
} while (currentObj = Object.getPrototypeOf(currentObj));
return _toConsumableArray$j(properties.entries()).filter(function (item) {
return typeof obj[item[0]] === 'function';
});
}
function help (obj) {
var funcs = getMethods(obj);
return funcs.map(function (func) {
return {
name: func[0],
parameters: args(obj[func[0]])
};
});
}
function precisionRound(number) {
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
var factor = Math.pow(10, precision);
var n = precision < 0 ? number : 0.01 / factor + number;
return Math.round(n * factor) / factor;
}
function add$8(obj) {
//console.log('LAYOUT ADD', obj)
var id = uuid$6();
// console.log('adding', obj.type, id);
// console.log('HERE!!!', obj.hasData(), obj.data())
// console.log('CALLING DATA on', obj)
// console.log('DATA', obj.hasData() ? obj.data() : this._orginalData)
// console.log('ACCESSOR', obj.accessor() || this._accessor)
var data = obj.hasData() ? obj.data() : this.data();
//data = data.length ? data : this._orginalData
// console.log('DATA DATA DATA', data, this._data, this.data())
obj.id(id).parent(this).node(this.currentNode).data(data || this.data())
//.data(this.data())
//.data(obj.hasData() ? obj.data() : this._orginalData, obj.accessor() || this._accessor)
.render(obj._stacked || obj._group);
this.objects.push(obj);
// TODO: verify if the obj.updater condition is needed
if (hasData$6(obj) || obj.updater) {
//if(hasData(obj)) {
// // console.log('BECAUSE THE OBJ HAS DATA > UPDATE')
return this.update();
}
return this;
}
function append(d) {
if (typeof d === 'string') {
var node = document.createElement(d);
var currentNode = this.currentNode || this.root;
currentNode.appendChild(node);
this.currentNode = node;
}
return this;
}
/*
export default function() {
var callback = arguments[0];
arguments[0] = this;
callback.apply(null, arguments);
return this;
}
*/
function border() {
if (this.currentNode) {
this.root.querySelector('svg').style.border = '1px solid #000';
}
return this;
}
function rollup() {
if (this.currentNode.parentNode) {
this.currentNode = this.currentNode.parentNode;
}
return this;
}
function size$1() {
for (var _len = arguments.length, dimensions = new Array(_len), _key = 0; _key < _len; _key++) {
dimensions[_key] = arguments[_key];
}
if (!dimensions.length) {
return {
width: this.width,
height: this.height
};
}
// console.log('size', dimensions)
var width = dimensions[0],
height = dimensions[1],
_dimensions$ = dimensions[2],
update = _dimensions$ === void 0 ? true : _dimensions$;
var oldWidth = this.width;
var oldHeight = this.height;
this.width = (width !== 'auto' ? width : null) || oldWidth || DEFAULT_WIDTH;
this.height = (height !== 'auto' ? height : null) || oldHeight || DEFAULT_HEIGHT;
this.autoWidth = null;
if (width === 'auto') {
var _this$root$parentElem, _this$root$parentElem2;
this.autoWidth = 'auto';
this.width = (_this$root$parentElem = (_this$root$parentElem2 = this.root.parentElement) === null || _this$root$parentElem2 === void 0 ? void 0 : _this$root$parentElem2.clientWidth) !== null && _this$root$parentElem !== void 0 ? _this$root$parentElem : this.width;
}
this.autoHeight = null;
if (height === 'auto') {
var _this$root$parentElem3, _this$root$parentElem4;
this.autoHeight = 'auto';
this.height = (_this$root$parentElem3 = (_this$root$parentElem4 = this.root.parentElement) === null || _this$root$parentElem4 === void 0 ? void 0 : _this$root$parentElem4.clientHeight) !== null && _this$root$parentElem3 !== void 0 ? _this$root$parentElem3 : this.height;
}
var svg = this.root.querySelector('svg');
if (!svg) {
this.svg(false);
}
svg = this.root.querySelector('svg');
svg.setAttribute('width', this.width);
svg.setAttribute('height', this.height);
svg.setAttribute('font-family', 'system-ui');
svg.setAttribute('viewBox', "0 0 ".concat(this.width, " ").concat(this.height));
svg.style.maxWidth = '100%';
svg.parentNode.style.width = "".concat(this.width, "px");
svg.parentNode.style.height = "".concat(this.height, "px");
// if(!oldWidth || !oldHeight || oldWidth !== width || oldHeight !== height) {
if (update) {
return this.update();
}
//return this;
}
function create$g(tag) {
return document.createElement(tag);
}
function createSVG$6(tag) {
return document.createElementNS('http://www.w3.org/2000/svg', tag);
}
function svg() {
var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
var svgNode = this.root.querySelector('svg');
if (!svgNode) {
svgNode = createSVG$6('svg');
svgNode.setAttribute('preserveAspectRatio', 'none');
// svgNode.setAttribute('width', '100%');
// svgNode.setAttribute('height', '100%');
// not needed for inling svg, should be added on export
// svgNode.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
// svgNode.style.overflow = 'visible';
this.currentNode.appendChild(svgNode);
// this.svg = svgNode;
}
var g = svgNode.querySelector('g:first-of-type');
if (!g) {
g = svgNode.appendChild(createSVG$6('g'));
}
this.currentNode = g;
if (update) {
this.update();
}
return this;
}
function setMargins$1(margins) {
if (isNull$k(margins)) {
return this._margins;
}
var top = margins.top,
bottom = margins.bottom,
left = margins.left,
right = margins.right;
this._margins.top = !isNull$k(top) ? top : this._margins.top;
this._margins.bottom = !isNull$k(bottom) ? bottom : this._margins.bottom;
this._margins.left = !isNull$k(left) ? left : this._margins.left;
this._margins.right = !isNull$k(right) ? right : this._margins.right;
return this.update();
}
function setPadding(padding) {
var saveOriginal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (isNull$k(padding)) {
return this._padding;
}
var top = padding.top,
bottom = padding.bottom,
left = padding.left,
right = padding.right;
this._padding.top = !isNull$k(top) ? top : this._padding.top;
this._padding.bottom = !isNull$k(bottom) ? bottom : this._padding.bottom;
this._padding.left = !isNull$k(left) ? left : this._padding.left;
this._padding.right = !isNull$k(right) ? right : this._padding.right;
if (saveOriginal) {
this.originalPadding = this._padding;
}
return this.update();
}
function ExtendedWilkinson(_ref) {
var _this = this;
var _ref2 = _slicedToArray$1(_ref, 2),
dmin = _ref2[0],
dmax = _ref2[1];
var ticksN = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TICKS_DEFAULT$2;
var Q = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [1, 5, 2, 2.5, 4, 3];
var onlyLoose = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var w = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [0.25, 0.2, 0.5, 0.05];
var nice = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
var eps = Number.EPSILON * 100;
this._ticks = [];
if (dmin > dmax) {
var temp = dmin;
dmin = dmax;
dmax = temp;
}
// const n = Q.length;
var best = {
score: -2
};
this.ticks = function (ticksNumber) {
// // console.log('EWILKS CALLED TICKS WITH', ticksNumber)
if (dmax - dmin < eps) {
return range$2(dmin, dmax, (dmax - dmin) / ticksNumber);
}
// // console.log('RUNNING TICKS WITH', ticksNumber)
best = {
score: -2
};
var j = 1;
while (j < Infinity) {
var _iterator = _createForOfIteratorHelper(Q),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var q = _step.value;
var sm = simplicity.max(q, Q, j);
if (w[0] * sm + w[1] + w[2] + w[3] < best.score) {
j = Infinity;
break;
}
var k = 2;
while (k < Infinity) {
var dm = density.max(k, ticksNumber);
if (w[0] * sm + w[1] + w[2] * dm + w[3] < best.score) {
break;
}
var delta = (dmax - dmin) / (k + 1) / j / q;
var z = Math.ceil(Math.log10(delta));
while (z < Infinity) {
var step = j * q * Math.pow(10, z);
var cm = coverage.max(dmin, dmax, step * (k - 1));
if (w[0] * sm + w[1] * cm + w[2] * dm + w[3] < best.score) {
break;
}
var min_start = Math.floor(dmax / step) * j - (k - 1) * j;
var max_start = Math.ceil(dmin / step) * j;
if (min_start > max_start) {
z += 1;
continue;
}
// const range = range(min_start, max_start);
for (var start = min_start; start <= max_start; start++) {
var lmin = start * (step / j);
var lmax = lmin + step * (k - 1);
var lstep = step;
var s = simplicity(q, Q, j, lmin, lmax, lstep);
var c = coverage(dmin, dmax, lmin, lmax);
var g = density(k, ticksNumber, dmin, dmax, lmin, lmax);
var l = legibility(lmin, lmax, lstep);
var score = w[0] * s + w[1] * c + w[2] * g + w[3] * l;
if (score > best.score && (!onlyLoose || lmin <= dmin && lmax >= dmax)) {
best.lmin = lmin;
best.lmax = lmax;
if (nice) {
best.lmin = lmin < lmax ? Math.floor(dmin / lstep) * lstep : Math.ceil(dmin / lstep) * lstep;
best.lmax = lmax > lmin ? Math.ceil(dmax / lstep) * lstep : Math.floor(dmax / lstep) * lstep;
}
// // console.log('lstep', lstep);
best.lstep = lstep;
best.score = score;
}
}
z += 1;
}
k += 1;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
j += 1;
}
// // console.log('range',best.lmin, best.lmax + best.lstep, best.lstep)
_this._ticks = range$2(best.lmin, best.lmax + best.lstep, best.lstep);
// // console.log('E-WILK RETURNING', this._ticks)
return _this._ticks;
};
this.ticks(ticksN);
// // console.log('BEST', best);
// best.ticks = d3.range(best.lmin, best.lmax + best.lstep, best.lstep);
this.getMin = function () {
return best.lmin;
};
this.getMax = function () {
return best.lmax;
};
this.getStep = function () {
return best.lstep;
};
return this;
}
function simplicity(q, Q, j, lmin, lmax, lstep) {
var eps = Number.EPSILON * 100;
var n = Q.length;
var i = match(q, Q)[0];
var v = (lmin % lstep < eps || lstep - lmin % lstep < eps) && lmin <= 0 && lmin >= 0 ? 1 : 0;
return 1 - (i - 1) / (n - 1) - j + v;
}
simplicity.max = function (q, Q, j) {
var n = Q.length;
var i = match(q, Q)[0];
var v = 1;
return 1 - (i - 1) / (n - 1) - j + v;
};
function coverage(dmin, dmax, lmin, lmax) {
var range = dmax - dmin;
return 1 - 0.5 * (Math.pow(dmax - lmax, 2) + Math.pow(dmin - lmin, 2)) / Math.pow(0.1 * range, 2);
}
coverage.max = function (dmin, dmax, span) {
var range = dmax - dmin;
if (span > range) {
var half = (span - range) / 2;
return 1 - 0.5 * (Math.pow(half, 2) + Math.pow(half, 2)) / Math.pow(0.1 * range, 2);
} else {
return 1;
}
};
function density(k, m, dmin, dmax, lmin, lmax) {
var r = (k - 1) / (lmax - lmin);
var rt = (m - 1) / (Math.max(lmax, dmax) - Math.min(dmin, lmin));
return 2 - Math.max(r / rt, rt / r);
}
density.max = function (k, m) {
return k >= m ? 2 - (k - 1) / (m - 1) : 1;
};
var legibility = function legibility() {
return 1;
};
function match(a, b) {
if (Array.isArray(a)) {
return a.map(function (d) {
return b.indexOf(d);
}).map(function (d) {
return d > -1 ? d : null;
});
} else {
var index = b.indexOf(a);
return index > -1 ? [index + 1] : [null];
}
}
function range$2() {
var min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
var step = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
var arr = [];
for (var i = min; i < max; i += step) {
arr.push(i);
}
return arr;
}
var DEFAULT_DOMAIN$2 = [0, 1];
function scale$4(name, type, domain) {
var _this = this;
var range = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [0, DEFAULT_WIDTH];
var field = arguments.length > 4 ? arguments[4] : undefined;
var margins = arguments.length > 5 ? arguments[5] : undefined;
var padding = arguments.length > 6 ? arguments[6] : undefined;
// console.log(`LINEAR scale(${name}, ${type}, ${domain}, ${range}, ${field})`)
var _scale = this.scales[type][name];
// console.log(`LINEAR: this.scales[${type}][${name}]=`,_scale);
var fixedDomain = domain || (_scale ? _scale.fixedDomain : null);
var copyOfFixedDomain = !isNull$k(fixedDomain) ? _toConsumableArray$j(fixedDomain) : null;
var _ticks = [];
var _padding = padding || this._padding;
// TODO: this should be removed and calculated somewhere else
range[0] += type === 'x' ? _padding.left : -_padding.bottom;
range[1] -= type === 'x' ? _padding.right : -_padding.top;
// console.log(name,'RANGE',range)
// const currentDomain =
// _scale && !_scale.isLog()
// ? _scale.domain
// : [];
var domainExtent = copyOfFixedDomain || domain || []; // currentDomain;
// console.log('DOMAIN', name, [...domainExtent], this.scales[name])
// console.log('FIXED DOMAIN', name, fixedDomain)
// console.log('CURRENT DOMAIN', name, currentDomain);
// if (arguments.length === 1) {
// // this code is never reached
// return this.scales.x[arguments[0]] || this.scales.y[arguments[0]];
// }
// if no domain defined or new domain is different from current domain
// calculate the new domain based on all the data
// console.log(name, "fixedDomain", fixedDomain);
// console.log(name, "domainExtent", domainExtent);
// console.log(name, "currentDomain", currentDomain);
if (isNull$k(fixedDomain) || hasNull(fixedDomain) ||
// hasNaN(currentDomain) ||
!domainExtent || !domainExtent.length // ||
// domainExtent[0] !== currentDomain[0] ||
// domainExtent[1] !== currentDomain[1]
) {
// if(isNull(fixedDomain)) {
// console.log('CALCULATE DOMAIN BASED ON THE DATA', name, field, this._data)
this._data.forEach(function (d) {
[field, "".concat(field, "0")].forEach(function (f) {
// // console.log(name, domainExtent[0],d[name],domainExtent[1])
// console.log('getting min of', [!isNull(d) ? d[f || name] : null, domainExtent[0], !isNull(d) ? d[`stacked_${field || name}`] : null])
domainExtent[0] = isNull$k(domainExtent[0]) ? d[f || name] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || name] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(f || name)] : null].filter(function (value) {
return !isNull$k(value) && !isNaN(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[f || name] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || name] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(f || name)] : null].filter(function (value) {
return !isNull$k(value) && !isNaN(value);
})));
});
});
// console.log('DOMAIN EXTENT', name, domainExtent)
// console.log('CALCULATE DOMAIN BASED ON OBJECTS', name, field, this.objects)
this.objects.forEach(function (obj) {
var _data = !isNull$k(obj._data) && obj._data.length ? obj._data : _this._data;
if (_data) {
// console.log('FIELDS', [field, `${field}0`])
// console.log('OBJ/CHART', obj)
// console.log('DATA', _data)
_data.forEach(function (d) {
[field, "".concat(field, "0")].forEach(function (f) {
domainExtent[0] = isNull$k(domainExtent[0]) ? d[f || obj.fields[name]] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || obj.fields[name]] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(f || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[f || obj.fields[name]] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || obj.fields[name]] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(f || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value);
})));
});
});
}
});
// console.log('DOMAIN EXTENT', name, field, domainExtent)
}
if (domainExtent[0] === domainExtent[1]) {
if (domainExtent[0] < 0) {
domainExtent[1] = Math.abs(domainExtent[1]);
} else if (domainExtent[0] === 0) {
domainExtent[0] = -1;
domainExtent[1] = 1;
} else {
domainExtent[0] = 0;
domainExtent[1] = domainExtent[1] * 2;
}
}
domainExtent = [isNull$k(domainExtent[0]) || isNaN(domainExtent[0]) ? DEFAULT_DOMAIN$2[0] : domainExtent[0], isNull$k(domainExtent[1]) || isNaN(domainExtent[1]) ? DEFAULT_DOMAIN$2[1] : domainExtent[1]];
// console.log('DOMAIN AFTER IMPROVEMENT', name, [...domainExtent])
// const numScale = new Heckbert(domainExtent);
//domainExtent = domainExtent.map((d,i) => isNaN(d) ? i : d)
var eNumScale = new ExtendedWilkinson(domainExtent);
// console.log('E WILK', eNumScale.ticks())
// console.log(eNumScale.getMin(),eNumScale.getMax())
// re-assign domain based on, max/min of heckbert nice scale
// console.log(domainExtent[0],domainExtent[1],'after WILKINSON', eNumScale.getMin(), eNumScale.getMax())
// TODO: not sure which one is best between the 2 following:
// if(!currentDomain) {
// domainExtent[0] = eNumScale.getMin();
// domainExtent[1] = eNumScale.getMax();
// }
// console.log('fixedDomain', fixedDomain);
if (isNull$k(fixedDomain)) {
// console.log('--->eNumScale',eNumScale.getMin(), eNumScale.getMax())
domainExtent[0] = !isNull$k(domainExtent[0]) ? Math.min(domainExtent[0], eNumScale.getMin()) : eNumScale.getMin();
domainExtent[1] = !isNull$k(domainExtent[1]) ? Math.max(domainExtent[1], eNumScale.getMax()) : eNumScale.getMax();
}
// console.log('new domain is ', domainExtent)
// console.log('AFTER WILK DOMAIN', name, [...domainExtent])
// // console.log('new this.scalingFunction', domainExtent, range, rangeWidth)
var scalingFunction = function scalingFunction(d) {
var domainWidth = domainExtent[1] - domainExtent[0];
var direction = range[1] >= range[0] ? 1 : -1;
var _margins = margins || _this._margins;
var rangeWidth = range[1] - range[0] - (type === 'x' ? _margins.left + _margins.right : _margins.top + _margins.bottom) * direction;
var startCoord = range[0] + (type === 'x' ? _margins.left : _margins.bottom) * direction;
var valueToDomain = (d - domainExtent[0]) / domainWidth;
return startCoord + rangeWidth * valueToDomain;
};
var ticks = function ticks() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : TICKS_DEFAULT$2;
// TODO: n can never be null...this needs to be reviews, it doesn't work well, _ticks?!?
// if (isNull(n) && _ticks.length > 0) {
// // this code can never be reached
// return _ticks;
// }
var fixedTicks = Array.isArray(n) && n.length;
_ticks = fixedTicks ? n : eNumScale.ticks(n + 1);
// TODO: Verify this, I can't remember why this was done.
// if (_ticks.length > 1 && _ticks[0] < _ticks[1]) {
// _ticks.reverse();
// }
// console.log('#### TICKS', _ticks);
return _ticks.map(function (value, index) {
return {
index: index,
value: precisionRound(value),
x: scalingFunction(value),
isMinor: fixedTicks ? 0 : index % 2,
isZero: value === 0
};
});
// return _ticks;
};
// console.log('DOMAIN', domain, fixedDomain)
scalingFunction.getName = function () {
return name;
};
scalingFunction.getType = function () {
return type;
};
scalingFunction.transformation = 'linear';
scalingFunction.getField = function () {
return field;
};
scalingFunction.isLog = function () {
return false;
};
scalingFunction.fixedDomain = fixedDomain;
scalingFunction.domain = domainExtent;
scalingFunction.field = field;
scalingFunction.range = range;
scalingFunction.step = eNumScale.getStep();
scalingFunction.barwidth = Math.abs(scalingFunction(domainExtent[0] + scalingFunction.step) - scalingFunction(domainExtent[0]));
scalingFunction.ticks = memoize(ticks);
scalingFunction.clear = function () {
console.log('CLEARING SCALE', _this);
_this.fixedDomain = null;
_this.domain = null;
};
this.scales[type][name] = scalingFunction;
return this;
}
var DEFAULT_BASE = 10;
var DEFAULT_MIN = 1;
var DEFAULT_MAX = 10;
function logTicks(_ref, ticksNumber) {
var _this = this;
var _ref2 = _slicedToArray$1(_ref, 2),
dmin = _ref2[0],
dmax = _ref2[1];
var base = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_BASE;
this.ticksNumber = ticksNumber || TICKS_DEFAULT$2;
this._ticks = [];
var log = baseLog(base);
var pow = basePow(base);
this.improveRange = function (range) {
var min = range[0];
var max = range[1];
if (min === max) {
if (min <= 0) {
// includes null
min = DEFAULT_MIN;
max = DEFAULT_MAX;
} else {
min = pow(Math.floor(log(min)) - 1);
max = pow(Math.floor(log(max)) + 1);
}
}
if (min <= 0) {
min = pow(Math.floor(log(max)) - 1);
}
if (max <= 0) {
max = pow(Math.floor(log(min)) + 1);
}
return [min, max];
};
this.ticks = function () {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.ticksNumber;
// if(this._ticks.length && n === this.ticksNumber) {
// return this._ticks;
// }
_this.ticksNumber = n;
_this._ticks = [];
_this.range = _this.improveRange([dmin, dmax]);
// console.log(this.range, [dmin,dmax])
// not working well, it keeps lowering and increasing bounds
_this.lmin = Math.floor(log(_this.range[0])) !== log(_this.range[0]) ? pow(Math.floor(log(_this.range[0])) - 1) : _this.range[0];
_this.lmax = Math.floor(log(_this.range[1])) !== log(_this.range[1]) ? pow(Math.floor(log(_this.range[1])) + 1) : _this.range[1];
// this.lmin = this.range[0];
// this.lmax = this.range[1];
// console.log('TICKS', n, [dmin, dmax], this.range, [this.lmin, this.lmax]);
var ticksRange = [log(_this.lmin), log(_this.lmax)];
var ticksDiff = Math.abs(ticksRange[1] - ticksRange[0]);
var ticksStep = Math.max(1, Math.ceil(ticksDiff / n));
// console.log(n, 'ticksRange', ticksRange, ticksDiff, '->', ticksStep)
if (ticksRange[0] > 0) {
for (var i = ticksRange[0]; i <= ticksRange[1]; ++i) {
if (!(i % ticksStep)) {
for (var k = 1; k < base; ++k) {
var tick = pow(i) * k;
// // console.log('k1',k,base,tick)
// if (tick > this.lmax) break;
if (tick >= _this.lmin) {
_this._ticks.push(tick);
}
}
}
}
} else for (var _i = ticksRange[0]; _i <= ticksRange[1]; ++_i) {
if (!(_i % ticksStep)) {
for (var _k = base - 1; _k >= 1; --_k) {
var _tick = pow(_i) * _k;
// console.log('i',i,'k',k,base,'->',tick, this.lmax)
// if (tick > this.lmax) break;
if (_tick >= _this.lmin) {
_this._ticks.push(_tick);
}
}
}
}
// // console.log('TICKS ARE', this._ticks)
return _this._ticks;
};
this.ticks(this.ticksNumber);
this.getMin = function () {
return _this.lmin;
};
this.getMax = function () {
return _this.lmax;
};
return this;
}
var DEFAULT_DOMAIN$1 = [1, 10];
function scale$3(name, type, domain) {
var _this = this;
var range = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [0, DEFAULT_WIDTH];
var field = arguments.length > 4 ? arguments[4] : undefined;
var transformation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'log10';
var margins = arguments.length > 6 ? arguments[6] : undefined;
var padding = arguments.length > 7 ? arguments[7] : undefined;
// console.log('LOG SCALE', name, type, domain, range, 'field:', field, transformation);
// console.log('this.scales[',name,'].domain','=',this.scales[name].domain, 'isLog?',this.scales[name].isLog())
var _scale = this.scales[type][name];
// console.log(`LOG: this.scales[${type}][${name}]=`,_scale);
// console.log('transformation', transformation, transformation.replace(/log/,''))
var base = +(transformation === 'log' ? 'log10' : transformation).replace(/log/, '');
var log = baseLog(base);
// console.log('BASE', base)
var fixedDomain = domain || (_scale ? _scale.fixedDomain : null);
// console.log('setting fixedDomain to', fixedDomain)
var copyOfFixedDomain = !isNull$k(fixedDomain) ? _toConsumableArray$j(fixedDomain) : null;
var _ticks = [];
var _padding = padding || this._padding;
range[0] += type === 'x' ? _padding.left : -_padding.bottom;
range[1] -= type === 'x' ? _padding.right : -_padding.top;
// // console.log(name,'RANGE',range)
// const currentDomain =
// _scale && _scale.isLog()
// ? _scale.domain
// : [];
var domainExtent = copyOfFixedDomain || domain || []; // currentDomain;
// console.log('using domainExtent', domainExtent[0], domainExtent[1]);
if (arguments.length === 1) {
return this.scales.x[arguments[0]] || this.scales.y[arguments[0]];
}
// console.log('domainExtent', domainExtent)
if (isNull$k(fixedDomain) ||
// hasNaN(currentDomain) ||
!domainExtent || !domainExtent.length // ||
// domainExtent[0] !== currentDomain[0] ||
// domainExtent[1] !== currentDomain[1]
) {
this._data.filter(function (d) {
return d[field] > 0;
}).forEach(function (d) {
[field, "".concat(field, "0")].forEach(function (f) {
domainExtent[0] = isNull$k(domainExtent[0]) ? d[f || name] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || name] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(f || name)] : null].filter(function (value) {
return !isNull$k(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[f || name] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || name] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(f || name)] : null].filter(function (value) {
return !isNull$k(value);
})));
});
});
// console.log('AFTER GLOBAL DATA DOMAIN', [...domainExtent])
this.objects.forEach(function (obj) {
var _data = !isNull$k(obj._data) && obj._data.length ? obj._data : _this._data;
if (_data) {
_data.forEach(function (d) {
[field, "".concat(field, "0")].forEach(function (f) {
domainExtent[0] = isNull$k(domainExtent[0]) ? d[obj.fields[f || name]] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || obj.fields[name]] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(f || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value) && value !== 0;
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[obj.fields[f || name]] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || obj.fields[name]] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(f || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value) && value !== 0;
})));
});
});
}
});
// console.log('AFTER OBJECTS ->', domainExtent[0], domainExtent[1])
}
//console.log('domainExtent', ...domainExtent)
domainExtent = [isNull$k(domainExtent[0]) || isNaN(domainExtent[0]) ? DEFAULT_DOMAIN$1[0] : domainExtent[0], isNull$k(domainExtent[1]) || isNaN(domainExtent[1]) ? DEFAULT_DOMAIN$1[1] : domainExtent[1]];
var numScale = new logTicks(domainExtent, TICKS_DEFAULT$2, base);
// re-assign domain based on max/min of logTicks nice scale
domainExtent[0] = numScale.getMin();
domainExtent[1] = numScale.getMax();
if (isNull$k(fixedDomain)) {
// console.log('--->eNumScale',eNumScale.getMin(), eNumScale.getMax())
domainExtent[0] = !isNull$k(domainExtent[0]) ? Math.min(domainExtent[0], numScale.getMin()) : numScale.getMin();
domainExtent[1] = !isNull$k(domainExtent[1]) ? Math.max(domainExtent[1], numScale.getMax()) : numScale.getMax();
}
// console.log('NEW domain extent', domainExtent[0], domainExtent[1])
var domainWidth = log(domainExtent[1]) - log(domainExtent[0]);
var direction = range[1] >= range[0] ? 1 : -1;
var _margins = margins || this._margins;
var rangeWidth = range[1] - range[0] - (type === 'x' ? _margins.left + _margins.right : _margins.top + _margins.bottom) * direction;
var startCoord = range[0] + (type === 'x' ? _margins.left : _margins.bottom) * direction;
// // console.log('new this.scalingFunction', domainExtent, range, rangeWidth)
var scalingFunction = function scalingFunction(d) {
//if(d > 0) {
if (isInfinity$b(log(domainExtent[0])) || isInfinity$b(log(d))) {
return NaN;
}
var valueToDomain = (log(d) - log(domainExtent[0])) / domainWidth;
//// // console.log('LOG scalingFunction',domainExtent, d,log(d),log(domainExtent[0]),log(domainExtent[1]),valueToDomain);
// // console.log('LOG', d, startCoord + rangeWidth * valueToDomain)
return startCoord + rangeWidth * valueToDomain;
// }
//return null;
};
var ticks = function ticks() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : TICKS_DEFAULT$2;
_ticks = numScale.ticks(n).map(function (value, index) {
return {
index: index,
value: precisionRound(value),
x: scalingFunction(value),
isMinor: log(value) % 1 // === 0,
};
});
return _ticks;
};
// console.log('scaleLog NAME', name)
// console.log('scaleLog FIELD', field)
// console.log('scaleLog TRANSFORMATION', transformation)
scalingFunction.getName = function () {
return name;
};
scalingFunction.getType = function () {
return type;
};
scalingFunction.getTransformation = function () {
return transformation;
};
scalingFunction.transformation = transformation;
scalingFunction.getField = function () {
return field;
};
scalingFunction.field = field;
scalingFunction.isLog = function () {
return true;
};
scalingFunction.fixedDomain = fixedDomain;
scalingFunction.domain = domainExtent;
scalingFunction.range = range;
scalingFunction.ticks = memoize(ticks);
this.scales[type][name] = scalingFunction;
return this;
}
// import { memoize } from '~/util';
//import Heckbert from './util/Heckbert';
//import ExtendedWilkinson from './util/ExtendedWilkinson';
function scale$2(name, type, domain) {
var _this = this;
var range = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [0, DEFAULT_WIDTH];
var field = arguments.length > 4 ? arguments[4] : undefined;
var margins = arguments.length > 5 ? arguments[5] : undefined;
var padding = arguments.length > 6 ? arguments[6] : undefined;
// console.log('scaleOrdinal', name, type, domain, range, field)
var _scale = this.scales[type][name];
var fixedDomain = domain || (_scale && _scale.transformation === 'ordinal' ? _scale.fixedDomain : null);
var copyOfFixedDomain = !isNull$k(fixedDomain) ? _toConsumableArray$j(fixedDomain) : null;
var _ticks = [];
var _padding = padding || this._padding;
// // console.log('rrrrange', range)
range[0] += type === 'x' ? _padding.left : -_padding.bottom;
range[1] -= type === 'x' ? _padding.right : -_padding.top;
// // console.log(name,'RANGE',range)
// console.log('ORDINAL', _scale, _scale.getName(), _scale.transformation)
var currentDomain = _scale && _scale.transformation === 'ordinal' ? _scale.domain : [];
var domainExtent = copyOfFixedDomain || domain || currentDomain;
// console.log('DOMAIN', name, [...domainExtent].join(','), this.scales[name])
// console.log('FIXED DOMAIN', name, fixedDomain)
// console.log('CURRENT DOMAIN', name, currentDomain);
if (arguments.length === 1) {
return this.scales.x[arguments[0]] || this.scales.y[arguments[0]];
}
// if no domain defined or new domain is different from current domain
// calculate the new domain based on all the data
// console.log("fixedDomain", fixedDomain);
// console.log("domainExtent", domainExtent);
// console.log("currentDomain", currentDomain, hasNaN(currentDomain));
if (isNull$k(fixedDomain) || !domainExtent || !domainExtent.length || !arraysEqual(domainExtent, currentDomain)) {
// if(isNull(fixedDomain)) {
// console.log('CALCULATE DOMAIN BASED ON THE DATA', name, this._data)
this._data.forEach(function (d) {
[field, "".concat(field, "0")].forEach(function (f) {
var datum = d[f || name];
if (typeof datum !== 'undefined' && domainExtent.indexOf(datum) === -1) {
// console.log('pushing',f,datum)
domainExtent.push(datum);
}
});
});
// console.log('DOMAIN EXTENT', name, domainExtent.join(','))
// console.log('CALCULATE DOMAIN BASED ON OBJECTS', this.objects)
this.objects.forEach(function (obj) {
var _data = !isNull$k(obj._data) && obj._data.length ? obj._data : _this._data;
// console.log('OBJ', obj, _data)
if (_data) {
_data.forEach(function (d) {
// console.log('test',type,name,'||',obj.fields[name],'->',d[field || obj.fields[name]],'in',domainExtent)
[field, "".concat(field, "0")].forEach(function (f) {
var datum = d[f || obj.fields[name]];
if (typeof datum !== 'undefined' && domainExtent.indexOf(datum) === -1) {
domainExtent.push(datum);
}
});
});
}
});
// console.log('DOMAIN EXTENT AFTER OBJECTS', name, domainExtent.join(','))
}
var domainWidth = domainExtent.length;
var direction = range[1] >= range[0] ? 1 : -1;
var _margins = margins || this._margins;
var rangeWidth = range[1] - range[0] - (type === 'x' ? _margins.left + _margins.right : _margins.top + _margins.bottom) * direction;
var startCoord = range[0] + (type === 'x' ? _margins.left : _margins.bottom) * direction;
var barwidth = rangeWidth / domainExtent.length;
var scalingFunction = function scalingFunction(d) {
var valueToDomain = domainExtent.indexOf(d) / domainWidth;
return startCoord + barwidth / 2 + rangeWidth * valueToDomain;
};
var ticks = function ticks() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : domainExtent.length;
// // console.log('LINEAR SCALE', 'ticks', n)
if (isNull$k(n) && _ticks.length > 0) {
return _ticks;
}
// console.log('calculate ticks', domainExtent)
_ticks = domainExtent;
return _ticks.map(function (value, index) {
return {
index: index,
value: value,
x: scalingFunction(value)
};
});
// return _ticks;
};
scalingFunction.getName = function () {
return name;
};
scalingFunction.getType = function () {
return type;
};
scalingFunction.transformation = 'ordinal';
scalingFunction.getField = function () {
return field;
};
scalingFunction.field = field;
scalingFunction.isLog = function () {
return false;
};
scalingFunction.fixedDomain = fixedDomain;
scalingFunction.domain = domainExtent;
scalingFunction.range = range;
scalingFunction.step = 1;
scalingFunction.barwidth = barwidth;
// console.log(scalingFunction.domain)
scalingFunction.ticks = ticks;
this.scales[type][name] = scalingFunction;
return this;
}
//import Heckbert from './util/Heckbert';
// import ExtendedWilkinson from './util/ExtendedWilkinson';
var DURATION_SECOND = 1000;
var UNITS = {
second: DURATION_SECOND,
minute: DURATION_SECOND * 60
};
UNITS.hour = UNITS.minute * 60;
UNITS.day = UNITS.hour * 24;
Object.keys(UNITS).forEach(function (unit) {
return UNITS["".concat(unit, "s")] = UNITS[unit];
});
var LONGER_UNITS = {
bidiurnal: UNITS.day * 2,
week: UNITS.day * 7,
fortnight: UNITS.day * 14,
month: UNITS.day * 30,
// depending on year/month
year: UNITS.day * 365 // depending on year
};
Object.keys(LONGER_UNITS).forEach(function (unit) {
return LONGER_UNITS["".concat(unit, "s")] = LONGER_UNITS[unit];
});
function scale$1(name, type, domain) {
var _this = this;
var range = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [0, DEFAULT_WIDTH];
var field = arguments.length > 4 ? arguments[4] : undefined;
var margins = arguments.length > 5 ? arguments[5] : undefined;
var padding = arguments.length > 6 ? arguments[6] : undefined;
// console.log(`TIME scale(${name}, ${type}, [${domain ? domain.join(',') : 'null'}], ${range}, ${field})`)
// console.log('domain in date:', domain ? domain.join(',') : 'null')
var step = UNITS.day;
var _scale = this.scales[type][name];
// console.log(`LINEAR: this.scales[${type}][${name}]=`,_scale);
var fixedDomain = domain || (_scale ? _scale.fixedDomain : null);
var copyOfFixedDomain = !isNull$k(fixedDomain) ? _toConsumableArray$j(fixedDomain) : null;
var _ticks = [];
var _padding = padding || this._padding;
// TODO: this should be removed and calculated somewhere else
range[0] += type === 'x' ? _padding.left : -_padding.bottom;
range[1] -= type === 'x' ? _padding.right : -_padding.top;
// // console.log(name,'RANGE',range)
var currentDomain = _scale && !_scale.isLog() ? _scale.domain : [];
var domainExtent = copyOfFixedDomain || domain || currentDomain;
// console.log('---------------------> DOMAIN', name, [...domainExtent], this.scales[name])
// console.log('FIXED DOMAIN', name, fixedDomain)
// console.log('CURRENT DOMAIN', name, currentDomain);
if (arguments.length === 1) {
return this.scales.x[arguments[0]] || this.scales.y[arguments[0]];
}
// if no domain defined or new domain is different from current domain
// calculate the new domain based on all the data
// console.log("fixedDomain", fixedDomain);
// console.log("domainExtent", domainExtent);
// console.log("currentDomain", currentDomain);
if (isNull$k(fixedDomain) || hasNaN(currentDomain) || !domainExtent || !domainExtent.length || domainExtent[0] !== currentDomain[0] || domainExtent[1] !== currentDomain[1]) {
// if(isNull(fixedDomain)) {
// console.log('CALCULATE DOMAIN BASED ON THE DATA', name, field, this._data)
this._data.forEach(function (d) {
// // console.log(name, domainExtent[0],d[name],domainExtent[1])
[field, "".concat(field, "0")].forEach(function (f) {
domainExtent[0] = isNull$k(domainExtent[0]) ? d[f || name] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || name] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(f || name)] : null].filter(function (value) {
return !isNull$k(value) && !isNaN(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[f || name] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || name] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(f || name)] : null].filter(function (value) {
return !isNull$k(value) && !isNaN(value);
})));
});
});
// console.log('AFTER DATA DOMAIN EXTENT', name, domainExtent)
// console.log('CALCULATE DOMAIN BASED ON OBJECTS', name, field, this.objects)
this.objects.forEach(function (obj) {
var _data = !isNull$k(obj._data) && obj._data.length ? obj._data : _this._data;
if (_data) {
// console.log('OBJ/CHART', obj, _data)
_data.forEach(function (d) {
[field, "".concat(field, "0")].forEach(function (f) {
domainExtent[0] = isNull$k(domainExtent[0]) ? +d[f || obj.fields[name]] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? +d[f || obj.fields[name]] : null, domainExtent[0], !isNull$k(d) ? +d["stacked_".concat(f || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? +d[f || obj.fields[name]] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? +d[f || obj.fields[name]] : null, domainExtent[1], !isNull$k(d) ? +d["stacked_".concat(f || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value);
})));
});
});
}
});
// console.log('AFTER OBJS DOMAIN EXTENT', name, field, [...domainExtent])
}
if (domainExtent.length > 1 && domainExtent[0] === domainExtent[1]) {
if (domainExtent[0] < 0) {
domainExtent[1] = Math.abs(domainExtent[1]);
} else if (domainExtent[0] === 0) {
domainExtent[0] = -1;
domainExtent[1] = 1;
} else {
domainExtent[0] = domainExtent[0] - 1;
domainExtent[1] = domainExtent[1] + 1;
}
// console.log('SAME domainExtent, so ->', domainExtent)
}
if (isNull$k(fixedDomain) || !domainExtent || !domainExtent.length || !arraysEqual(domainExtent, currentDomain)) {
// if(isNull(fixedDomain)) {
// console.log('CALCULATE DOMAIN BASED ON THE DATA', name, this._data)
this._data.forEach(function (d) {
// // console.log(name, domainExtent[0],d[name],domainExtent[1])
domainExtent[0] = isNull$k(domainExtent[0]) ? d[field || name] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[field || name] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(field || name)] : null].filter(function (value) {
return !isNull$k(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[field || name] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[field || name] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(field || name)] : null].filter(function (value) {
return !isNull$k(value);
})));
});
// console.log('DOMAIN EXTENT', name, domainExtent.join(','), domainExtent.map(d => new Date(d)).join(','))
// console.log('CALCULATE DOMAIN BASED ON OBJECTS', this.objects)
this.objects.forEach(function (obj) {
var _data = !isNull$k(obj._data) && obj._data.length ? obj._data : _this._data;
if (_data) {
// console.log('OBJ/CHART', obj)
_data.forEach(function (d) {
domainExtent[0] = isNull$k(domainExtent[0]) ? d[field || obj.fields[name]] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[field || obj.fields[name]] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(field || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[field || obj.fields[name]] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[field || obj.fields[name]] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(field || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value);
})));
});
}
});
// console.log('DOMAIN EXTENT', name, domainExtent, domainExtent.map(d => new Date(d)))
}
// console.log('new domain is ', domainExtent, domainExtent.map(d => new Date(d)))
// console.log('AFTER WILK DOMAIN', name, [...domainExtent])
var calculateTimeDomain = function calculateTimeDomain(interval) {
if (domainExtent.length) {
var _domainExtent = _toConsumableArray$j(domainExtent);
// console.log('---->', interval, '_domainExtent', _domainExtent, _domainExtent.map(d => new Date(d)))
if (isNull$k(interval)) {
// console.log('NEED TO FIND BEST UNIT');
interval = UNITS.seconds;
Object.keys(UNITS).forEach(function (d) {
// console.log(domainWidth, '>=', d, UNITS[d])
// console.log('testing',d,_domainExtent[1] - _domainExtent[0],'>=',UNITS[d])
if (Math.abs(_domainExtent[1] - _domainExtent[0]) >= UNITS[d]) {
interval = d;
// console.log('!!!', unit)
}
});
// console.log('FOUND', interval)
// step = UNITS[interval] || LONGER_UNITS[interval] || UNITS.day;
}
step = UNITS[interval] || LONGER_UNITS[interval] || UNITS.day;
//domainExtent[0] = new Date(domainExtent)
// console.log('original dates', domainExtent.map(d => new Date(d)))
if (step >= UNITS.day) {
var d0 = new Date(_domainExtent[0]);
var d1 = new Date(_domainExtent[1]);
switch (interval) {
case 'month':
case 'months':
_domainExtent[0] = new Date(d0.getFullYear(), d0.getMonth(), 1);
_domainExtent[1] = new Date(d1.getFullYear(), d1.getMonth() + 1, 1);
break;
case 'year':
case 'years':
_domainExtent[0] = new Date(d0.getFullYear(), 0, 1);
_domainExtent[1] = new Date(d1.getFullYear(), 0, 1);
break;
case 'day':
default:
_domainExtent[0] = new Date(d0.getFullYear(), +d0.getMonth(), d0.getDate());
_domainExtent[1] = new Date(d1.getFullYear(), +d1.getMonth(), d1.getDate());
// break;
}
return _domainExtent;
}
// console.log('new dates', domainExtent.map(d => new Date(d)))
// console.log('DEFINE DOMAIN EXTENTS WITH', interval, step, _domainExtent)
// console.log('_domainExtent', _domainExtent, _domainExtent.map(d => new Date(d)))
return [Math.floor(_domainExtent[0] / step) * step, Math.ceil(_domainExtent[1] / step) * step
// _domainExtent[0],
// _domainExtent[1],
];
}
return [];
};
// console.log('domainExtent', domainExtent.map(d => new Date(d)))
var roundedDomainExtent = domainExtent;
roundedDomainExtent = calculateTimeDomain();
// console.log('ORIGINAL DOMAIN', domainExtent)
// console.log('ROUNDED DOMAIN', roundedDomainExtent)
var direction = range[1] >= range[0] ? 1 : -1;
var _margins = margins || this._margins;
var rangeWidth = range[1] - range[0] - (type === 'x' ? _margins.left + _margins.right : _margins.top + _margins.bottom) * direction;
var startCoord = range[0] + (type === 'x' ? _margins.left : _margins.bottom) * direction;
// console.log('roundedDomainExtent', roundedDomainExtent.map(d => new Date(d)))
// const domainWidth = roundedDomainExtent[1] - roundedDomainExtent[0];
// const barwidth = rangeWidth / Math.floor(domainWidth / step);
// console.log('barwidth', barwidth, 'domainWidth', domainWidth, step, Math.floor(domainWidth/step))
// // console.log('new this.scalingFunction', domainExtent, range, rangeWidth)
var scalingFunction = function scalingFunction(d) {
var valueToDomain = (d - roundedDomainExtent[0]) / (roundedDomainExtent[1] - roundedDomainExtent[0]);
return startCoord + rangeWidth * valueToDomain;
};
var setTimeInterval = function setTimeInterval(interval) {
if (isNull$k(interval)) {
return interval;
}
if (typeof interval === 'number') {
console.error('Please use a string for now');
return;
}
if (UNITS[interval] || LONGER_UNITS[interval]) {
roundedDomainExtent = calculateTimeDomain(interval);
} else {
console.error('The selected interval does not exists.');
}
};
var ticks = function ticks() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : TICKS_DEFAULT$2;
var interval = arguments.length > 1 ? arguments[1] : undefined;
if (!domainExtent.length) {
return [];
}
// console.log('ticks', n, interval)
var _domainExtent = calculateTimeDomain(interval);
// console.log('time domain', _domainExtent, _domainExtent.map(d => new Date(d)))
var _domainWidth = _domainExtent[1] - _domainExtent[0];
// console.log("TICKS", _domainExtent, _domainExtent.map(d => new Date(d)))
// console.log('TICKS TIME SCALE', 'ticks', n, interval)
// TODO: n can never be null...this needs to be reviews, it doesn't work well, _ticks?!?
if (isNull$k(n) && isNull$k(interval) && _ticks.length > 0) {
return _ticks;
}
var step = LONGER_UNITS[interval] || UNITS[interval] || UNITS.day;
var fixedTicks = Array.isArray(n) && n.length;
// console.log('create array of', Math.floor(domainWidth / step), domainWidth, step)
// console.log('STEP IS', step, 'FROM', interval, UNITS, LONGER_UNITS)
if (step <= LONGER_UNITS.fortnight) {
_ticks = _toConsumableArray$j(Array(fixedTicks ? n : Math.floor(_domainWidth / step) + 1).keys()).map(function (d) {
return +_domainExtent[0] + d * step;
});
} else {
if (step === LONGER_UNITS.month) {
// console.log('OPTIONAL DOMAIN', _domainExtent.map(d => new Date(d)))
_ticks = [new Date(_domainExtent[0])];
var d = _ticks[0];
var i = _ticks[0].getMonth();
var startingYear = new Date(_domainExtent[0]).getFullYear();
while (i < 10000 && +d < +_domainExtent[1]) {
d = new Date(startingYear, i, 1);
_ticks.push(d);
// console.log('pushing', d, startingYear)
i++;
}
} else if (step === LONGER_UNITS.year) {
// console.log('YEAR DOMAIN', _domainExtent.map(d => new Date(d)))
_ticks = [new Date(_domainExtent[0])];
var _d = _ticks[0];
var _startingYear = _ticks[0].getFullYear();
var _i = _ticks[0].getFullYear();
// console.log('starting year', i)
while (+_d < +_domainExtent[1] && _i < _startingYear + 10000) {
_d = new Date(_i, 0, 1);
_ticks.push(_d);
// console.log('pushing', d, _ticks[0].getYear())
_i++;
}
// console.log('_ticks', _ticks)
}
}
// console.log('MY TICKS ARE', _ticks, _ticks.map(d => new Date(d)))
return _ticks.map(function (value, index) {
return {
index: index,
value: value,
x: scalingFunction(value)
};
});
// return _ticks;
};
scalingFunction.getName = function () {
return name;
};
scalingFunction.getType = function () {
return type;
};
scalingFunction.transformation = 'time';
scalingFunction.getField = function () {
return field;
};
scalingFunction.isLog = function () {
return false;
};
scalingFunction.fixedDomain = fixedDomain;
scalingFunction.interval = setTimeInterval;
scalingFunction.domain = domainExtent;
scalingFunction.roundedDomainExtent = roundedDomainExtent;
scalingFunction.field = field;
scalingFunction.range = range;
scalingFunction.step = step;
scalingFunction.barwidth = scalingFunction(roundedDomainExtent[0] + scalingFunction.step) - scalingFunction(roundedDomainExtent[0]);
scalingFunction.ticks = memoize(ticks);
this.scales[type][name] = scalingFunction;
return this;
}
var DEFAULT_DOMAIN = [0, 1];
function scale(name, type, domain) {
var _this = this;
var range = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [0, DEFAULT_WIDTH];
var field = arguments.length > 4 ? arguments[4] : undefined;
var pow = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 1;
var margins = arguments.length > 7 ? arguments[7] : undefined;
var padding = arguments.length > 8 ? arguments[8] : undefined;
// console.log(`POW scale(${name}, ${type}, ${domain}, ${range}, ${field}, ${transformation}, ${pow}, ${margins}, ${padding})`)
var _scale = this.scales[type][name];
// console.log(`LINEAR: this.scales[${type}][${name}]=`,_scale);
var fixedDomain = domain || (_scale ? _scale.fixedDomain : null);
var copyOfFixedDomain = !isNull$k(fixedDomain) ? _toConsumableArray$j(fixedDomain) : null;
var _ticks = [];
var _padding = padding || this._padding;
// TODO: this should be removed and calculated somewhere else
range[0] += type === 'x' ? _padding.left : -_padding.bottom;
range[1] -= type === 'x' ? _padding.right : -_padding.top;
// console.log(name,'RANGE',range)
var currentDomain = _scale && !_scale.isLog() ? _scale.domain : [];
var domainExtent = copyOfFixedDomain || domain || currentDomain;
// console.log('DOMAIN', name, [...domainExtent], this.scales[name])
// console.log('FIXED DOMAIN', name, fixedDomain)
// console.log('CURRENT DOMAIN', name, currentDomain);
// if (arguments.length === 1) {
// // this code is never reached
// return this.scales.x[arguments[0]] || this.scales.y[arguments[0]];
// }
// if no domain defined or new domain is different from current domain
// calculate the new domain based on all the data
// console.log(name, "fixedDomain", fixedDomain);
// console.log(name, "domainExtent", domainExtent);
// console.log(name, "currentDomain", currentDomain);
if (isNull$k(fixedDomain) || hasNull(fixedDomain) || hasNaN(currentDomain) || !domainExtent || !domainExtent.length || domainExtent[0] !== currentDomain[0] || domainExtent[1] !== currentDomain[1]) {
if (this._data.length && !this._data.some(function (d) {
return !isNull$k(d[field]);
})) {
throw new Error("Field ".concat(field, " not found in the data"));
}
// if(isNull(fixedDomain)) {
// console.log('CALCULATE DOMAIN BASED ON THE DATA', name, field, this._data)
this._data.forEach(function (d) {
// // console.log(name, domainExtent[0],d[name],domainExtent[1])
// console.log('getting min of', [!isNull(d) ? d[field || name] : null, domainExtent[0], !isNull(d) ? d[`stacked_${field || name}`] : null])
[field, "".concat(field, "0")].forEach(function (f) {
domainExtent[0] = isNull$k(domainExtent[0]) ? d[f || name] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || name] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(f || name)] : null].filter(function (value) {
return !isNull$k(value) && !isNaN(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[f || name] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || name] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(f || name)] : null].filter(function (value) {
return !isNull$k(value) && !isNaN(value);
})));
});
});
// console.log('DOMAIN EXTENT', name, domainExtent)
// console.log('CALCULATE DOMAIN BASED ON OBJECTS', name, field, this.objects)
this.objects.forEach(function (obj) {
var _data = !isNull$k(obj._data) && obj._data.length ? obj._data : _this._data;
if (_data) {
if (_data.length && !_data.some(function (d) {
return !isNull$k(d[field]);
})) {
throw new Error("Field ".concat(field, " not found in the data"));
}
_data.forEach(function (d) {
[field, "".concat(field, "0")].forEach(function (f) {
domainExtent[0] = isNull$k(domainExtent[0]) ? d[f || obj.fields[name]] : Math.min.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || obj.fields[name]] : null, domainExtent[0], !isNull$k(d) ? d["stacked_".concat(f || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value);
})));
domainExtent[1] = isNull$k(domainExtent[1]) ? d[f || obj.fields[name]] : Math.max.apply(Math, _toConsumableArray$j([!isNull$k(d) ? d[f || obj.fields[name]] : null, domainExtent[1], !isNull$k(d) ? d["stacked_".concat(f || obj.fields[name])] : null].filter(function (value) {
return !isNull$k(value) && !hasNaN(value);
})));
});
});
}
});
// console.log('DOMAIN EXTENT', name, field, domainExtent)
}
if (domainExtent[0] === domainExtent[1]) {
if (domainExtent[0] < 0) {
domainExtent[1] = Math.abs(domainExtent[1]);
} else if (domainExtent[0] === 0) {
domainExtent[0] = -1;
domainExtent[1] = 1;
} else {
domainExtent[0] = 0;
domainExtent[1] = domainExtent[1] * 2;
}
}
domainExtent = [isNull$k(domainExtent[0]) || isNaN(domainExtent[0]) ? DEFAULT_DOMAIN[0] : domainExtent[0], isNull$k(domainExtent[1]) || isNaN(domainExtent[1]) ? DEFAULT_DOMAIN[1] : domainExtent[1]];
// const numScale = new Heckbert(domainExtent);
var eNumScale = new ExtendedWilkinson(domainExtent);
// // console.log('E WILK', eNumScale.ticks())
// re-assign domain based on, max/min of heckbert nice scale
// console.log(domainExtent[0],domainExtent[1],'after WILKINSON', eNumScale.getMin(), eNumScale.getMax())
// TODO: not sure which one is best between the 2 following:
// if(!currentDomain) {
// domainExtent[0] = eNumScale.getMin();
// domainExtent[1] = eNumScale.getMax();
// }
// console.log('fixedDomain', fixedDomain);
if (isNull$k(fixedDomain)) {
// console.log('--->eNumScale',eNumScale.getMin(), eNumScale.getMax())
domainExtent[0] = !isNull$k(currentDomain[0]) ? Math.min(currentDomain[0], eNumScale.getMin()) : eNumScale.getMin();
domainExtent[1] = !isNull$k(currentDomain[1]) ? Math.max(currentDomain[1], eNumScale.getMax()) : eNumScale.getMax();
}
// console.log('new domain is ', domainExtent)
// console.log('AFTER WILK DOMAIN', name, [...domainExtent])
var powFunction = function powFunction(d, exponent) {
return d < 0 ? -Math.pow(-d, exponent) : Math.pow(d, exponent);
};
// // console.log('new this.scalingFunction', domainExtent, range, rangeWidth)
var scalingFunction = function scalingFunction(d) {
domainExtent[1] - domainExtent[0];
var direction = range[1] >= range[0] ? 1 : -1;
var _margins = margins || _this._margins;
var rangeWidth = range[1] - range[0] - (type === 'x' ? _margins.left + _margins.right : _margins.top + _margins.bottom) * direction;
var startCoord = range[0] + (type === 'x' ? _margins.left : _margins.bottom) * direction;
var valueToDomain = (powFunction(d, pow) - powFunction(domainExtent[0], pow)) / (powFunction(domainExtent[1], pow) - powFunction(domainExtent[0], pow)); // - powFunction(domainExtent[0], pow)) / powFunction(domainWidth, pow);
// console.log('_margins', _margins)
// console.log('POW',domainExtent, range,d,pow,'--->', valueToDomain, )
return startCoord + rangeWidth * valueToDomain;
};
var ticks = function ticks() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : TICKS_DEFAULT$2;
// TODO: n can never be null...this needs to be reviews, it doesn't work well, _ticks?!?
// if (isNull(n) && _ticks.length > 0) {
// // this code can never be reached
// return _ticks;
// }
var fixedTicks = Array.isArray(n) && n.length;
_ticks = fixedTicks ? n : eNumScale.ticks(n + 1);
// TODO: Verify this, I can't remember why this was done.
// if (_ticks.length > 1 && _ticks[0] < _ticks[1]) {
// _ticks.reverse();
// }
// console.log('#### TICKS', _ticks);
return _ticks.map(function (value, index) {
return {
index: index,
value: precisionRound(value),
x: scalingFunction(value),
isMinor: fixedTicks ? 0 : index % 2,
isZero: value === 0
};
});
// return _ticks;
};
scalingFunction.getName = function () {
return name;
};
scalingFunction.getType = function () {
return type;
};
scalingFunction.transformation = 'pow';
scalingFunction.pow = pow;
scalingFunction.getField = function () {
return field;
};
scalingFunction.isLog = function () {
return false;
};
scalingFunction.fixedDomain = fixedDomain;
scalingFunction.domain = domainExtent;
scalingFunction.field = field;
scalingFunction.range = range;
scalingFunction.step = eNumScale.getStep();
scalingFunction.barwidth = Math.abs(scalingFunction(domainExtent[0] + scalingFunction.step) - scalingFunction(domainExtent[0]));
scalingFunction.ticks = memoize(ticks);
this.scales[type][name] = scalingFunction;
return this;
}
function Chrt() {
var _this = this;
var _data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var _node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : create$g('div');
// console.log('Chrt', _data);
this.type = 'chrt';
this._data = _data;
this._orginalData = this._data;
this.root = _node;
this.currentNode = _node;
this._accessor = function (d, i) {
return {
x: !isNull$k(d) && Object.prototype.hasOwnProperty.call(d, 'x') ? d.x : i,
y: isNull$k(d) ? null : Object.prototype.hasOwnProperty.call(d, 'y') ? d.y : d
};
};
this.width = null; // default width
this.height = null; // default height
this._margins = {
top: 20,
bottom: 20,
left: 40,
right: 20
};
this._padding = {
top: 0,
bottom: 0,
left: 0,
right: 0
};
this.scales = {
x: {},
y: {}
};
this.objects = [];
var _scaleLinear = function _scaleLinear(name, type, domain, range, field, margins, padding) {
// console.log('----> _scaleLinear name:',name,'type:',type,domain,range,field)
// console.log('this.scales', this.scales)
var _scale = _this.scales[type][name];
var oldDomain = _scale ? _toConsumableArray$j(_scale.domain) : [];
var oldRange = _scale ? _toConsumableArray$j(_scale.range) : [];
scale$4.apply(_this, [name, type, domain,
// || (this._data.length ? domain : null), // [0, 10] -> this messes up with the later assignement of data
range, field, margins, padding]);
if (!isNull$k(_scale) && (!arraysEqual(oldDomain, _this.scales[type][name].domain) || !arraysEqual(oldRange, _this.scales[type][name].range))) {
_this.objects.forEach(function (obj) {
return obj.update();
});
}
return _this;
};
var _scaleSqrt = function _scaleSqrt(name, type, domain, range, field) {
var _this$scales$type;
var transformation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'sqrt';
var margins = arguments.length > 6 ? arguments[6] : undefined;
var padding = arguments.length > 7 ? arguments[7] : undefined;
// console.log('scaleLog', name, type, domain, range, 'field:', field, transformation)
_this.scales[type] = (_this$scales$type = _this.scales[type]) !== null && _this$scales$type !== void 0 ? _this$scales$type : {};
var _scale = _this.scales[type][name];
var oldDomain = _scale ? _toConsumableArray$j(_scale.domain) : [];
var oldRange = _scale ? _toConsumableArray$j(_scale.range) : [];
scale.apply(_this, [name, type, domain, range, field, transformation, 0.5, margins, padding]);
if (!isNull$k(_scale) && (!arraysEqual(oldDomain, _this.scales[type][name].domain) || !arraysEqual(oldRange, _this.scales[type][name].range))) {
_this.objects.forEach(function (obj) {
return obj.update();
});
}
return _this;
};
var _scaleLog = function _scaleLog(name, type, domain, range, field) {
var transformation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'log10';
var margins = arguments.length > 6 ? arguments[6] : undefined;
var padding = arguments.length > 7 ? arguments[7] : undefined;
// console.log('scaleLog', name, type, domain, range, 'field:', field, transformation)
var _scale = _this.scales[type][name];
var oldDomain = _scale ? _toConsumableArray$j(_scale.domain) : [];
var oldRange = _scale ? _toConsumableArray$j(_scale.range) : [];
scale$3.apply(_this, [name, type,
// (domain || this._data.length) ? domain : [1, 10],
domain, range, field, transformation, margins, padding]);
if (!isNull$k(_scale) && (!arraysEqual(oldDomain, _this.scales[type][name].domain) || !arraysEqual(oldRange, _this.scales[type][name].range))) {
_this.objects.forEach(function (obj) {
return obj.update();
});
}
return _this;
};
var _scaleOrdinal = function _scaleOrdinal(name, type, domain, range, field, margins, padding) {
// console.log('_scaleOrdinal', name, type, domain, range, 'field:', field)
var _scale = _this.scales[type][name];
var oldDomain = _scale ? _toConsumableArray$j(_scale.domain) : [];
var oldRange = _scale ? _toConsumableArray$j(_scale.range) : [];
scale$2.apply(_this, [name, type, _this._data.length ? domain : [], range, field, margins, padding]);
if (!isNull$k(_scale) && (!arraysEqual(oldDomain, _this.scales[type][name].domain) || !arraysEqual(oldRange, _this.scales[type][name].range))) {
_this.objects.forEach(function (obj) {
return obj.update();
});
}
return _this;
};
var _scaleTime = function _scaleTime(name, type, domain, range, field, margins, padding) {
// console.log('scaleTime', name, type, domain, range, 'field:', field)
var _scale = _this.scales[type][name];
var oldDomain = _scale ? _toConsumableArray$j(_scale.domain) : [];
var oldRange = _scale ? _toConsumableArray$j(_scale.range) : [];
scale$1.apply(_this, [name, type, domain || [], range, field, margins, padding]);
// console.log('----->', this.scales)
if (!isNull$k(_scale) && (!arraysEqual(oldDomain, _this.scales[type][name].domain) || !arraysEqual(oldRange, _this.scales[type][name].range))) {
_this.objects.forEach(function (obj) {
return obj.update();
});
}
return _this;
};
function isObject(value) {
var prototype = Object.prototype.toString.call(value);
return prototype === '[object Object]';
}
this.scale = function () {
var _options$scale, _options$name, _options$field;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (args.length === 1 && isObject(args[0])) {
args = [args[0].domain, args[0].range, args[0].options || args[0]];
}
var _ref = args || [],
_ref2 = _slicedToArray$1(_ref, 3),
domain = _ref2[0],
range = _ref2[1],
_ref2$ = _ref2[2],
options = _ref2$ === void 0 ? {} : _ref2$;
var transformation = (_options$scale = options === null || options === void 0 ? void 0 : options.scale) !== null && _options$scale !== void 0 ? _options$scale : 'linear';
options.name = (_options$name = options.name) !== null && _options$name !== void 0 ? _options$name : options.field;
options.field = (_options$field = options.field) !== null && _options$field !== void 0 ? _options$field : options.name;
switch (transformation) {
case 'log':
case 'log10':
case 'log2':
return _scaleLog(options.name, options.type, domain, range, options.field, transformation, options.margins, options.padding);
case 'pow':
case 'sqrt':
return _scaleSqrt(options.name, options.type, domain, range, options.field, transformation, options.margins, options.padding);
case 'time':
// console.log('this.x','time', domain, options.name,options.field)
return _scaleTime.apply(_this, [options.name, options.type, domain, range, options.field, options.margins, options.padding]);
case 'ordinal':
return _scaleOrdinal.apply(_this, [options.name, options.type, domain, range, options.field, options.margins, options.padding]);
case 'linear':
default:
return _scaleLinear.apply(_this, [options.name, options.type, domain, range, options.field, options.margins, options.padding]);
}
};
this.x = function () {
var _options$name2, _options$field2;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
if (args.length === 1 && isObject(args[0])) {
args = [args[0].domain, args[0].range, args[0].options || args[0]];
}
var _ref3 = args || [],
_ref4 = _slicedToArray$1(_ref3, 3),
domain = _ref4[0],
range = _ref4[1],
_ref4$ = _ref4[2],
options = _ref4$ === void 0 ? {} : _ref4$;
var name = (_options$name2 = options.name) !== null && _options$name2 !== void 0 ? _options$name2 : options.field;
var field = (_options$field2 = options.field) !== null && _options$field2 !== void 0 ? _options$field2 : name;
return _this.scale(domain, range || [0, _this.width], _objectSpread2$1(_objectSpread2$1({}, options), {}, {
name: name !== null && name !== void 0 ? name : 'x',
type: 'x',
field: field !== null && field !== void 0 ? field : 'x'
}));
};
this.y = function () {
var _options$name3, _options$field3;
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
if (args.length === 1 && isObject(args[0])) {
args = [args[0].domain, args[0].range, args[0].options || args[0]];
}
var _ref5 = args || [],
_ref6 = _slicedToArray$1(_ref5, 3),
domain = _ref6[0],
range = _ref6[1],
_ref6$ = _ref6[2],
options = _ref6$ === void 0 ? {} : _ref6$;
var name = (_options$name3 = options.name) !== null && _options$name3 !== void 0 ? _options$name3 : options.field;
var field = (_options$field3 = options.field) !== null && _options$field3 !== void 0 ? _options$field3 : name;
return _this.scale(domain, range || [_this.height, 0], _objectSpread2$1(_objectSpread2$1({}, options), {}, {
name: name !== null && name !== void 0 ? name : 'y',
type: 'y',
field: field !== null && field !== void 0 ? field : 'y'
}));
};
this.update = function () {
if (_this.autoWidth || _this.autoHeight) {
_this.size(_this.autoWidth || _this.width, _this.autoHeight || _this.height, false);
}
if (!Object.values(_this.scales.x).length) {
// console.log('no scales x -> create a default linear scale')
_this.x({
range: [0, _this.width]
});
} else {
Object.values(_this.scales.x).forEach(function (scale) {
// console.log('scale x exists:', scale.getName(), scale.getType(), scale.transformation)
_this.x({
domain: scale.fixedDomain,
// range: scale.range || [0, this.width], // this would allow custom ranges
range: [0, _this.width],
options: {
name: scale.getName(),
type: scale.getType(),
field: scale.field,
scale: scale.transformation
}
});
});
}
if (!Object.values(_this.scales.y).length) {
_this.y({
range: [_this.height, 0]
});
} else {
Object.values(_this.scales.y).forEach(function (scale) {
_this.y({
domain: scale.fixedDomain,
// range: scale.range || [this.height, 0], // this would allow custom ranges
range: [_this.height, 0],
options: {
name: scale.getName(),
type: scale.getType(),
field: scale.field,
scale: scale.transformation
}
});
});
}
Object.values(_this.scales.other || {}).forEach(function (scale) {
// console.log('scale other exists:', scale.getName(), scale.getType(), scale.transformation)
_this.scale({
domain: scale.fixedDomain,
range: scale.range || [0, 10],
options: {
name: scale.getName(),
type: scale.getType(),
field: scale.field,
scale: scale.transformation,
margins: scale.margins || {
top: 0,
left: 0,
right: 0,
bottom: 0
},
padding: scale.margins || {
top: 0,
left: 0,
right: 0,
bottom: 0
}
}
});
});
_this.objects.forEach(function (obj) {
obj.update();
});
return _this;
};
this.getAxis = function (name, orientation) {
return _this.objects.find(function (obj) {
return obj.type === 'axis' && obj.name === name && (!orientation || obj.orientation === orientation);
});
};
this.help = function (obj) {
return help(obj !== null && obj !== void 0 ? obj : _this);
};
this.class = function (prefix) {
if (!isNull$k(prefix) && typeof prefix !== 'string') {
console.warn("CSS prefix should be a string. Setting main class name to 'chrt'.");
prefix = null;
}
_this._css = "".concat(prefix ? prefix.replace(/-$/, '') : '').concat(prefix ? '-' : '', "chrt");
_this.root.classList.add(_this._css);
return _this;
};
this.setWidth = function (width) {
return size$1.call(_this, width);
};
this.setHeight = function (height) {
return size$1.call(_this, null, height);
};
this.css = this.class;
// this sets size and svg with default size
size$1.apply(this, [this.width, this.height]).svg();
}
function chrt$6(data, node) {
return new Chrt(data, node);
}
Chrt.prototype = chrt$6.prototype = {
data: data$6,
node: node$6,
append: append,
add: add$8,
snap: add$8,
rollup: rollup,
svg: svg,
border: border,
size: size$1,
margins: setMargins$1,
padding: setPadding
};
// chrt-object v0.0.17 Copyright 2020-2023 chrt chrt.io
function _toConsumableArray$i(arr) {
return _arrayWithoutHoles$i(arr) || _iterableToArray$i(arr) || _unsupportedIterableToArray$i(arr) || _nonIterableSpread$i();
}
function _arrayWithoutHoles$i(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$i(arr);
}
function _iterableToArray$i(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$i(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$i(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$i(o, minLen);
}
function _arrayLikeToArray$i(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$i() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var COMPONENTS_W_DATA$5 = ['chrt', 'series'];
function isNull$j(value) {
return value === null || value == null || typeof value === 'undefined';
}
function uuid$5() {
return 'c' + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
function hasData$5(obj) {
return !isNull$j(obj.type) && COMPONENTS_W_DATA$5.indexOf(obj.type) > -1;
}
function isInfinity$a(value) {
return !isFinite(value);
}
function oppositeSigns$5(x, y) {
return (x ^ y) < 0;
}
function getCoords$7(data) {
var _this = this;
if (!(this !== null && this !== void 0 && this.fields)) {
return [];
}
return data.map(function (d) {
var x = isNull$j(d[_this.fields.x]) || isInfinity$a(d[_this.fields.x]) ? null : _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = isNull$j(d[_this.fields.y]) || isInfinity$a(d[_this.fields.y]) ? null : _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
return [isInfinity$a(x) ? 0 : x, isInfinity$a(y) ? 0 : y];
}); //.filter(d => !isNull(d[0]) && !isNull(d[1]))
}
function create$f(tag) {
return document.createElement(tag);
}
function createSVG$5(tag) {
return document.createElementNS('http://www.w3.org/2000/svg', tag);
}
function getStrokeStyle$6(style) {
var strokeWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var strokeLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
var strokeStyle = null;
switch (style) {
case 'dashed':
strokeStyle = "".concat(strokeWidth * strokeLength, " ").concat(strokeWidth * strokeLength);
break;
case 'dotted':
strokeStyle = "".concat(strokeWidth, " ").concat(strokeWidth);
break;
case 'solid':
default:
strokeStyle = null;
}
return strokeStyle;
}
function add$7(obj) {
var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var id = obj._id || uuid$5();
// console.log('adding to', this, obj.type, id, obj);
obj.id(id).parent(this);
// .render();
if (prepend) {
this.objects = [obj].concat(_toConsumableArray$i(this.objects));
} else {
this.objects.push(obj);
}
//return this.update();
return this;
}
// export { add } from '../charts/util'
var index$6 = /*#__PURE__*/Object.freeze({
__proto__: null,
add: add$7,
create: create$f,
createSVG: createSVG$5,
getCoords: getCoords$7,
getStrokeStyle: getStrokeStyle$6,
hasData: hasData$5,
isInfinity: isInfinity$a,
isNull: isNull$j,
oppositeSigns: oppositeSigns$5,
uuid: uuid$5
});
function render$5(parent) {
// console.log('RENDER', this, parent)
if (this.g) {
// avoid duplication of g
return this;
}
this.g = createSVG$5('g');
if (this._id) {
this.g.setAttribute('id', this._id);
}
// console.log('RENDER', this, this.parentNode)
if (hasData$5(this)) {
// series
// in case of group or stack we want the chart to be added to svg g of the group/stack
if (parent) {
// if it's a stack we want the order of the charts in the dom to be opposite, so the stroke
// of the charts below is not covered by the area above
if (parent.type === 'stack' || parent.group === 'group') {
parent.g.prepend(this.g);
} else {
parent.g.append(this.g);
}
} else {
this.currentNode.append(this.g);
}
} else {
// const grid = (this.parentNode.objects || []).slice().reverse().find(obj => obj.type === 'grid');
// if(grid && this.type === 'axis') {
// // // console.log('THIS IS AN',this.type,'AND THERE IS A GRID',grid,'INSERT BEFORE',grid.node(), grid.node().nextSibling)
// this.currentNode.insertBefore(this.g, grid.node().nextSibling);
// } else {
// // console.log('THIS IS A', this.type, 'PREPEND')
// this.currentNode.append(this.g);
// }
this.currentNode.append(this.g);
}
this.update();
return this; // .parentNode;
}
function update$5() {
if (this.parentNode && this.parentNode.scales.x[this.scales.x] && this.parentNode.scales.y[this.scales.y]) {
this.draw();
}
return this;
}
function curve$5(interpolationFunction) {
if (isNull$j(interpolationFunction)) {
return this.interpolationFunction;
}
this.interpolationFunction = interpolationFunction;
return this;
}
function attribute$5(name, fn) {
var accessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (value) {
return value;
};
if (isNull$j(name)) {
console.warn('name missing: attr method requires a name for the attribute');
return this;
}
if (!isNull$j(name) && typeof fn === 'undefined') {
var _this$attrs;
// this.name()
return ((_this$attrs = this.attrs) === null || _this$attrs === void 0 ? void 0 : _this$attrs[name]) || function () {};
}
if (typeof fn === 'function') {
// something will go here
this.attrs[name] = fn;
} else {
// fn is a Boolean, String, Number or any other type but function
this.attrs[name] = function () {
return accessor(fn);
};
}
return this;
}
function data$5 (data, accessor) {
// console.log('---------------> data', data, accessor, this);
if (!data) {
// console.log('NO DATA return', hasData(this), this._data, hasData(this) ? this._data : this)
return hasData$5(this) ? this._data || null : this;
}
// TODO: not sure what this is doing...
if (!hasData$5(this)) {
// console.log('NO HAS DATA')
return this;
}
// console.log('HAS DATA')
// // console.log('chrt or series', this.type)
// passing only accessor to inherit/reuse data
if (typeof arguments[0] === 'function') {
this._accessor = arguments[0];
return this;
}
// data is passed
this._orginalData = this._orginalData || data;
// define accessor function to map values
var accessorFunction = accessor || this._accessor;
this._accessor = accessorFunction;
this._data = accessorFunction && !this._accessorApplied ? data.map(function (d, i, arr) {
if (d instanceof Object) {
return Object.assign({}, d, accessorFunction(d, i, arr));
}
return accessorFunction(d, i, arr);
}) : data;
// console.log('DATA', data)
this._accessorApplied = true; // do not apply the accessor multiple times
return this;
}
/**
* node - Returns the DOM element that contains a chart element
*
* @param {type} node Set this as root node
*
* @return {type} Description
*/
function node$5 (node) {
if (!node) {
return this.g || this.root;
}
this.root = node;
this.currentNode = this.root;
return this;
}
function parent$5 (obj) {
if (!obj) {
return this.parentNode;
}
this.parentNode = obj;
return this;
}
function display$5(value) {
return attribute$5.call(this, 'display', value);
}
function show$5() {
return display$5.call(this, true);
}
function hide$5() {
return display$5.call(this, false);
}
function cssDisplay$5(value) {
var DOMNode = node$5.call(this);
if (!DOMNode) {
return this;
}
var currentDisplay = DOMNode.style.display;
this._display = typeof this._display !== 'undefined' ? this._display : DOMNode.style.display;
if (!value) {
DOMNode.style.display = 'none';
} else {
if (currentDisplay === 'none' && value) {
DOMNode.style.display = this._display;
}
}
return this;
}
function chrtObject$5() {
var _this = this;
this._id = null;
this.objects = [];
this.type = 'chrt-object';
this.fields = {
x: null,
y: null
};
this.scales = {
x: 'x',
y: 'y'
};
this._classNames = [];
this._accessor = function (d, i) {
return {
x: !isNull$j(d) && Object.prototype.hasOwnProperty.call(d, 'x') ? d.x : i,
y: isNull$j(d) ? null : Object.prototype.hasOwnProperty.call(d, 'y') ? d.y : d
};
};
this.interpolationFunction = null;
// list of getter/setter function for custom attributes
this.attrs = [];
attribute$5.call(this, 'display', true);
this.id = function (id) {
// console.log('chrtObject.id', id, this._id);
if (isNull$j(id)) {
return _this._id;
}
_this._id = id || _this._id;
if (_this.g) {
_this.g.setAttribute('id', _this._id);
}
return _this;
};
this.aria = function (ariaLabel) {
attribute$5.call(_this, 'aria', ariaLabel);
// if(isNull(ariaLabel)) {
// return this.ariaLabel;
// }
// this.ariaLabel = ariaLabel || this.ariaLabel;
//
// if(this.g && this.ariaLabel) {
// this.g.setAttribute('aria-label', this.ariaLabel);
// }
return _this;
};
this.class = function (className) {
if (isNull$j(className)) {
return _this._classNames;
}
var classNames = (Array.isArray(className) ? className : className.split(' ')).map(function (d) {
return d.replace(/\s\s+/g, ' ').trim();
}).filter(function (d) {
return d !== '';
});
_this.original_classNames = _this.original_classNames || _this._classNames;
_this._classNames = _toConsumableArray$i(new Set([].concat(_toConsumableArray$i(_this.original_classNames), _toConsumableArray$i(classNames))));
if (_this.g) {
var _this$g$classList, _this$g$classList2;
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$i(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$i(_this._classNames));
}
return _this;
};
this.hasData = function () {
return hasData$5(_this);
};
var setScale = function setScale(scale, scaleName) {
if (!isNull$j(scaleName)) {
_this.scales[scale] = scaleName;
}
};
this.x = function (scale) {
if (isNull$j(scale)) {
return _this.scales.x;
}
setScale('x', scale || 'x');
return _this;
};
this.y = function (scale) {
if (isNull$j(scale)) {
return _this.scales.y;
}
setScale('y', scale || 'y');
return _this;
};
this.getObjectTypeIndex = function () {
var _this$parent$objects, _this$parent;
return ((_this$parent$objects = (_this$parent = _this.parent()) === null || _this$parent === void 0 ? void 0 : _this$parent.objects) !== null && _this$parent$objects !== void 0 ? _this$parent$objects : []).filter(function (d) {
return d.constructor.name === _this.constructor.name;
}).indexOf(_this);
};
return this;
}
function chrt$5() {
return new chrtObject$5();
}
chrtObject$5.prototype = Object.create(chrt$5.prototype);
// chrtObject.prototype = chrt.prototype = Object.assign(chrt.prototype, {
chrtObject$5.prototype = Object.assign(chrt$5.prototype, {
node: node$5,
data: data$5,
add: add$7,
snap: add$7,
parent: parent$5,
render: render$5,
update: update$5,
curve: curve$5,
attr: attribute$5,
show: show$5,
hide: hide$5
});
// chrt-axis v0.0.59 Copyright 2024 chrt
var create$4$1 = index$6.createSVG;
function generateTicks(ticks, name, callback) {
var _this = this;
ticks.forEach(function (tick, i, arr) {
var dataID = encodeURIComponent("tick-".concat(name, "-").concat(tick.value));
var tickGroup = _this.g.querySelector("[data-id='".concat(dataID, "']"));
if (!tickGroup) {
var _this$ticksColor;
tickGroup = create$4$1("g");
tickGroup.setAttribute("data-id", dataID);
if (tick !== null && tick !== void 0 && tick.isMinor) {
tickGroup.classList.add("tick-minor");
}
_this.g.appendChild(tickGroup);
var tickLine = create$4$1("line");
var color = (_this$ticksColor = _this.ticksColor()(tick, i, arr)) !== null && _this$ticksColor !== void 0 ? _this$ticksColor : _this.stroke()();
tickLine.setAttribute("stroke", color);
tickLine.setAttribute("stroke-width", _this.ticksWidth()(tick, i, arr));
tickGroup.appendChild(tickLine);
}
if (callback) {
callback(tickGroup, tick, i, arr);
}
});
}
function lineColor$3(value) {
return this.attr('stroke', value);
}
function lineWidth$3(value) {
return this.attr('strokeWidth', value);
}
function setTickLength(value) {
return this.attr('ticksLength', value);
}
function setTickPosition(value) {
return this.attr('ticksPosition', value);
}
function setLabelsPosition(value) {
return this.attr('labelsPosition', value);
}
function showAxis() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
return this.attr('showAxisLine', value);
}
function hideAxis() {
return showAxis.call(this, false);
}
var isNull$4$2 = index$6.isNull;
function ticks$1(ticks) {
if (isNull$4$2(ticks)) {
return this._ticks;
}
this._fixedTicks = ticks;
return this;
}
// showTicks and hideTicks can get different type of parameters and they filter the ticks based on the parameters
function showTicks$1(filter) {
// default true
if (isNull$4$2(filter)) {
this.ticksFilter = function () {
return true;
};
return this;
}
// filter-in with a function
// showTicks((d,i) => !(i % 2))
if (typeof filter === 'function') {
this.ticksFilter = function (d, i, arr) {
return filter(d, i, arr);
};
return this;
}
// show/hide all ticks
// showTicks(false|true)
if (typeof filter === 'boolean') {
this.ticksFilter = function () {
return filter;
};
return this;
}
// show only one tick
// showTicks(10)
if (Number.isFinite(filter)) {
this.ticksFilter = function (d) {
return filter === d;
};
return this;
}
// show based on an array of values
// showTicks([10, 20, 30])
if (Array.isArray(filter)) {
this.ticksFilter = function (d) {
return filter.indexOf(d) > -1;
};
return this;
}
return this;
}
// hideTicks is the opposite of showTicks and it filters out
function hideTicks$1(filter) {
showTicks$1.call(this, filter);
var ticksFilter = this.ticksFilter;
this.ticksFilter = function (d, i, arr) {
return !ticksFilter(d, i, arr);
};
return this;
}
function firstTick$1() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showTicks$1.call(this, function (d, i) {
return i === 0;
});
} else {
hideTicks$1.call(this, function (d, i) {
return i === 0;
});
}
return this;
}
function lastTick$1() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showTicks$1.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
} else {
hideTicks$1.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
}
return this;
}
function firstAndLastTicks$1() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showTicks$1.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
} else {
hideTicks$1.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
}
return this;
}
function orient$1(value) {
return this.attr("orientation", value);
}
function format(labelFormat) {
return this.attr('labelFormat', labelFormat);
}
function minor$1() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this.attr('showMinorTicks', value);
this.attr('showMinorLabels', value);
return this;
}
function minorTicks() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
return this.attr('showMinorTicks', value);
}
function minorLabels() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
return this.attr('showMinorLabels', value);
}
// set the position of the axis to value
function zero$1(value) {
return this.attr('zero', value);
}
// legacy method, we can remove it from and use labelFormat
var isNull$3$2 = index$6.isNull;
function label(text) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options = Object.assign({
position: 'last'
}, options);
return format.call(this, function (d, i, arr) {
if (!isNull$3$2(_options.value)) {
return d !== _options.value ? d : "".concat(d).concat(text);
}
if (_options.position === 'last' && i !== arr.length - 1) {
return d;
}
if (_options.position === 'first' && i !== 0) {
return d;
}
return "".concat(d).concat(text);
});
}
function interval(value) {
return this.attr('interval', value);
}
function title(value) {
return this.attr('title', value);
}
var isNull$2$3 = index$6.isNull;
function labels(labels) {
if (isNull$2$3(labels)) {
return this._labels;
}
this._fixedLabels = labels;
return this;
}
// showLabels and hideLabels can get different type of parameters and they filter the labels based on the parameters
function showLabels(filter) {
// default true
if (isNull$2$3(filter)) {
this.labelsFilter = function () {
return true;
};
return this;
}
// filter-in with a function
// showLabels((d,i) => !(i % 2))
if (typeof filter === 'function') {
this.labelsFilter = function (d, i, arr) {
return filter(d, i, arr);
};
return this;
}
// show/hide all labels
// showLabels(false|true)
if (typeof filter === 'boolean') {
this.labelsFilter = function () {
return filter;
};
return this;
}
// show only one label
// showLabels(10)
if (Number.isFinite(filter)) {
this.labelsFilter = function (d) {
return filter === d;
};
return this;
}
// show based on an array of values
// showLabels([10, 20, 30])
if (Array.isArray(filter)) {
this.labelsFilter = function (d) {
return filter.indexOf(d) > -1;
};
return this;
}
return this;
}
// hideLabels is the opposite of showLabels and it filters out
function hideLabels$1(filter) {
showLabels.call(this, filter);
var labelsFilter = this.labelsFilter;
this.labelsFilter = function (d, i, arr) {
return !labelsFilter(d, i, arr);
};
return this;
}
function firstLabel$1() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showLabels.call(this, function (d, i) {
return i === 0;
});
} else {
hideLabels$1.call(this, function (d, i) {
return i === 0;
});
}
return this;
}
function lastLabel$1() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showLabels.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
} else {
hideLabels$1.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
}
return this;
}
function firstAndLastLabels$1() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showLabels.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
} else {
hideLabels$1.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
}
return this;
}
function labelsColor(value) {
return this.attr('labelsColor', value);
}
function labelOffset(value) {
if (Number.isFinite(value)) {
value = [value, value];
}
return this.attr('labelsOffset', value);
}
function labelPadding(value) {
return this.attr("labelsPadding", value);
}
function labelsClass(value) {
return this.attr("labelClass", value);
}
function ticksColor(value) {
return this.attr('ticksColor', value);
}
function ticksWidth(value) {
return this.attr('ticksWidth', value);
}
var DEFAULT_LINE_WIDTH$2 = 1;
var DEAULT_LINE_COLOR$3 = "#000";
var TICK_LENGTH = 5;
var TICK_POSITION = "outside";
var LABEL_POSITION = "outside";
function chrtAxis(name) {
var _this = this;
chrtObject$5.call(this);
this.type = "axis";
this.updater = true;
this.name = name;
this.attr("stroke", DEAULT_LINE_COLOR$3);
this.attr("strokeWidth", DEFAULT_LINE_WIDTH$2);
this.attr("labelsColor", null);
this.attr("labelsOffset", [0, 0]);
this.attr("labelsPadding", 0);
this.attr("labelsClass", null);
this.attr("ticksColor", null);
this.attr("ticksWidth", DEFAULT_LINE_WIDTH$2);
this.attr("ticksLength", TICK_LENGTH);
this.attr("ticksPosition", TICK_POSITION);
this.attr("labelsPosition", LABEL_POSITION);
this.attr("interval", null);
this.attr("labelFormat", function (d) {
return d;
});
// this.tickTextColor = DEAULT_TICK_TEXT_COLOR;
this.attr("showAxisLine", true);
this.attr("zero", null);
this.ticksFilter = null;
this.labelsFilter = null;
this.attr("showMinorLabels", false);
this.attr("showMinorTicks", false);
this._ticks = [];
this._fixedTicks = null;
this._classNames = ["chrt-axis"];
this.draw = function () {
return _this;
};
}
chrtAxis.prototype = Object.create(chrtObject$5.prototype);
chrtAxis.prototype.constructor = chrtAxis;
chrtAxis.parent = chrtObject$5.prototype;
chrtAxis.prototype = Object.assign(chrtAxis.prototype, {
width: lineWidth$3,
strokeWidth: lineWidth$3,
lineWidth: lineWidth$3,
color: lineColor$3,
stroke: lineColor$3,
setTickLength: setTickLength,
ticksLength: setTickLength,
tickLength: setTickLength,
setTickPosition: setTickPosition,
setLabelPosition: setLabelsPosition,
tickPosition: setTickPosition,
labelPosition: setLabelsPosition,
ticksPosition: setTickPosition,
labelsPosition: setLabelsPosition,
showAxis: showAxis,
hideAxis: hideAxis,
ticksColor: ticksColor,
ticksWidth: ticksWidth,
ticks: ticks$1,
filterTicks: showTicks$1,
filter: showTicks$1,
showTicks: showTicks$1,
hideTicks: hideTicks$1,
firstTick: firstTick$1,
lastTick: lastTick$1,
firstAndLastTicks: firstAndLastTicks$1,
labels: labels,
filterLabels: showLabels,
labelsColor: labelsColor,
labelColor: labelsColor,
showLabels: showLabels,
hideLabels: hideLabels$1,
firstLabel: firstLabel$1,
lastLabel: lastLabel$1,
firstAndLastLabels: firstAndLastLabels$1,
labelsOffset: labelOffset,
labelsPadding: labelPadding,
labelOffset: labelOffset,
labelPadding: labelPadding,
labelsClass: labelsClass,
labelClass: labelsClass,
orient: orient$1,
format: format,
minor: minor$1,
minorTicks: minorTicks,
minorLabels: minorLabels,
zero: zero$1,
label: label,
interval: interval,
title: title
});
function _arrayLikeToArray$h(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithoutHoles$h(r) {
if (Array.isArray(r)) return _arrayLikeToArray$h(r);
}
function _defineProperty$2(e, r, t) {
return (r = _toPropertyKey$1(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _iterableToArray$h(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _nonIterableSpread$h() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty$2(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _toConsumableArray$h(r) {
return _arrayWithoutHoles$h(r) || _iterableToArray$h(r) || _unsupportedIterableToArray$h(r) || _nonIterableSpread$h();
}
function _toPrimitive$1(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey$1(t) {
var i = _toPrimitive$1(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _unsupportedIterableToArray$h(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray$h(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$h(r, a) : void 0;
}
}
var create$3$1 = index$6.createSVG;
function createSVGWithWrappedText(textContent, maxWidth, options) {
var _options$align, _options$color;
// Create the foreignObject element
var foreignObject = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
foreignObject.setAttribute("width", "".concat(maxWidth, "px"));
foreignObject.setAttribute("height", "100%");
foreignObject.style.overflow = "visible";
// Create the XHTML div element
var div = document.createElementNS("http://www.w3.org/1999/xhtml", "div");
div.style.wordWrap = typeof textContent === "number" ? "no-wrap" : "break-word";
div.style.maxWidth = "".concat(maxWidth, "px");
div.style.width = "".concat(maxWidth, "px");
div.style.padding = "0 0.5em";
div.style.textAlign = (_options$align = options.align) !== null && _options$align !== void 0 ? _options$align : "center";
div.style.color = (_options$color = options.color) !== null && _options$color !== void 0 ? _options$color : "inherit";
// div.style.transform = "translateX(-50%)";
div.textContent = textContent;
div.innerText = textContent;
if (options.class) {
div.classList.add(options.class);
}
// console.log("createSVGWithWrappedText", textContent, maxWidth, options);
// Append elements to build the hierarchy
foreignObject.appendChild(div);
return foreignObject;
}
function generateLabels(labels, name) {
var _this = this;
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var callback = arguments.length > 3 ? arguments[3] : undefined;
labels.forEach(function (d, i, arr) {
var dataID = encodeURIComponent("label-".concat(name, "-").concat(d.value));
var labelGroup = _this.g.querySelector("[data-id='".concat(dataID, "']"));
if (!labelGroup) {
var _this$format, _ref, _this$labelsColor;
labelGroup = create$3$1("g");
labelGroup.setAttribute("data-id", dataID);
if (d.isMinor) {
labelGroup.classList.add("label-minor");
}
// console.log("generateLabels", d, this);
_this.g.appendChild(labelGroup);
// console.log("CLASS", this.labelsClass()(d, i, arr));
var label = createSVGWithWrappedText((_this$format = _this.format()) === null || _this$format === void 0 ? void 0 : _this$format(d.value, i, arr), options.getTickDistance ? options.getTickDistance(d, i) : 100, _objectSpread2(_objectSpread2({}, options), {}, {
color: (_ref = (_this$labelsColor = _this.labelsColor()(d, i, arr)) !== null && _this$labelsColor !== void 0 ? _this$labelsColor : _this.ticksColor()(d, i, arr)) !== null && _ref !== void 0 ? _ref : _this.stroke()(),
class: _this.labelsClass()(d, i, arr)
}));
labelGroup.appendChild(label);
}
if (callback) {
callback(labelGroup, d, i, arr);
}
});
}
var TICKS_DEFAULT$1 = 10;
var DEFAULT_ORIENTATION = {
x: 'bottom',
y: 'left'
};
var ARIA_LABELS = {
x: 'x axis',
y: 'y axis'
};
var isNull$1$5 = index$6.isNull,
create$2$2 = index$6.createSVG;
function xAxis() {
var _this = this;
var ticksNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : TICKS_DEFAULT$1;
var customName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "x";
if (typeof arguments[0] === "string") {
customName = arguments[0];
ticksNumber = TICKS_DEFAULT$1;
}
chrtAxis.call(this, customName);
var coords = {
x: "x",
y: "y"
};
// this.coord = coords.x;
this.attr("orientation", DEFAULT_ORIENTATION[coords.x]);
this._classNames = [].concat(_toConsumableArray$h(this._classNames), ["chrt-x-axis"]);
this._name = "x";
var xAxisTick = function xAxisTick(tickGroup, visible, orientationDirection) {
tickGroup.style.display = visible ? "block" : "none";
var tickLine = tickGroup.querySelector("line");
var tickLength = _this.attr("ticksLength")();
if (tickLine) {
tickLine.setAttribute("x1", 0);
tickLine.setAttribute("x2", 0);
tickLine.setAttribute("y1", 0);
tickLine.setAttribute("y2", (_this.attr("ticksPosition")() === "outside" ? tickLength : -tickLength) * orientationDirection);
// tickLine.setAttribute('stroke-width', this.ticksWidth()());
}
};
var xAxisLabel = function xAxisLabel(tickGroup, visible, compositePosition) {
var label = tickGroup.querySelector("foreignObject > div");
if (label) {
var tickLength = _this.attr("ticksLength")();
// horizontal centered alignment
label.style.textAlign = "center";
// if orientationDirection is positive, the label is below the axis
_this.attr("labelsPosition")();
// the distance from the axis is the tickLength (then the tickGroup is translated by the labelsPadding and labelsOffset )
var y = "".concat(compositePosition === "below" ? tickLength + 1 : -(tickLength + 1));
label.style.transform = "translate(-50%,".concat(compositePosition === "below" ? "".concat(y, "px") : "calc(-100% + ".concat(y, "px)"), ")");
}
};
this.draw = function () {
var _this$g$classList, _this$g$classList2, _this$ariaLabel;
if (!_this.parentNode.scales[coords.x][_this.name]) {
return _this.parentNode;
}
cssDisplay$5.call(_this, _this.attr("display")());
var _this$parentNode = _this.parentNode,
_margins = _this$parentNode._margins,
width = _this$parentNode.width,
height = _this$parentNode.height,
scales = _this$parentNode.scales;
var orientation = _this.attr("orientation")();
var orientationDirection = orientation === DEFAULT_ORIENTATION[coords.x] ? 1 : -1;
var ticks = scales[coords.x][_this.name].ticks(_this._fixedTicks || ticksNumber * 2, _this.attr("interval")());
if (_this._label && _this._label.position === "last") {
ticks.reverse();
}
_this._ticks = ticks.map(function (tick, i, arr) {
tick.position = scales[coords.x][_this.name](tick.value);
var visible = tick.position >= _margins.left && tick.position <= width - _margins.right;
visible = visible && (_this.attr("showMinorTicks")() || !tick.isMinor);
tick.visible = visible;
if (_this.ticksFilter) {
tick.visible = tick.visible && _this.ticksFilter(tick.value, i, arr);
}
tick.visibleLabel = visible && (_this.attr("showMinorLabels")() || !tick.isMinor);
if (_this.labelsFilter) {
tick.visibleLabel = tick.visibleLabel && _this.labelsFilter(tick.value, i, arr);
}
return tick;
}).filter(function (d) {
return d.visible || d.visibleLabel;
}); // decrease the number of ticks rendered in the DOM
_this.g.setAttribute("id", "".concat(_this.name, "Axis-").concat(_this.id()));
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$h(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$h(_this._classNames));
_this.g.setAttribute("aria-label", (_this$ariaLabel = _this.ariaLabel) !== null && _this$ariaLabel !== void 0 ? _this$ariaLabel : ARIA_LABELS[coords.x]);
_this.g.setAttribute("data-orientation", orientation);
var axisY = orientation === DEFAULT_ORIENTATION[coords.x] ? height - _margins.bottom : _margins.top;
_this.g.setAttribute("transform", "translate(0,".concat(axisY, ")"));
var dataID = encodeURIComponent("tick-".concat(_this.name, "-axis-line"));
var axisLine = _this.g.querySelector("line[data-id='".concat(dataID, "']"));
if (!axisLine) {
axisLine = create$2$2("line");
axisLine.setAttribute("data-id", dataID);
_this.g.appendChild(axisLine);
}
axisLine.setAttribute("stroke", _this.stroke()());
axisLine.setAttribute("stroke-width", _this.strokeWidth()());
axisLine.setAttribute("x1", _margins.left);
axisLine.setAttribute("x2", width - _margins.right);
var scaleY = scales[coords.y][coords.y] || Object.values(scales[coords.y])[0];
var _zero = _this.attr("zero")();
var zero = isNull$1$5(_zero) ? scaleY.domain[0] : _zero;
var axisLineY = scaleY.isLog() ? scaleY.range[1] : scaleY(zero) - (height - _margins.bottom);
if (scaleY.transformation === "ordinal" && (isNull$1$5(_zero) || !~scaleY.domain.indexOf(zero))) {
axisLineY = 0;
}
axisLine.setAttribute("y1", !isNaN(axisLineY) ? axisLineY : 0);
axisLine.setAttribute("y2", !isNaN(axisLineY) ? axisLineY : 0);
// if no axis remove the axis line after creating it
if (!_this.attr("showAxisLine")()) {
axisLine.remove();
}
var title = _this.attr("title") ? _this.attr("title")() : null;
if (!isNull$1$5(title)) {
var axisTitleText = _this.g.querySelector("text.title");
if (isNull$1$5(axisTitleText)) {
axisTitleText = create$2$2("text");
axisTitleText.classList.add("title");
}
axisTitleText.textContent = title;
var _orientationDirection = orientation === DEFAULT_ORIENTATION[coords.x] ? -1 : 1;
var y = (5 + _this.strokeWidth()()) * _orientationDirection;
axisTitleText.setAttribute("x", width - _margins.right);
axisTitleText.setAttribute("y", y);
axisTitleText.setAttribute("dy", "".concat(0.9 * ~_orientationDirection, "em"));
axisTitleText.setAttribute("text-anchor", "end");
if (!_this.ariaLabel) {
_this.g.setAttribute("aria-describedby", axisTitleText.textContent);
}
_this.g.appendChild(axisTitleText);
}
_this.g.querySelectorAll("g").forEach(function (d) {
var tickName = d.getAttribute("data-id");
var tick = _this._ticks.find(function (tick) {
return tickName === "tick-".concat(_this.name, "-").concat(tick);
});
if (!tick) {
d.remove();
}
});
generateTicks.call(_this, _this._ticks, _this.name, function (tickGroup, tick) {
tickGroup.setAttribute("transform", "translate(".concat(tick.position, ", 0)"));
xAxisTick(tickGroup, tick.visible, orientationDirection);
});
var compositePosition = "below";
var labelPosition = _this.attr("labelsPosition")();
if (orientationDirection > 0) {
compositePosition = labelPosition === "outside" ? "below" : "above";
} else {
compositePosition = labelPosition === "outside" ? "above" : "below";
}
var labelsPadding = _this.attr("labelsPadding")();
generateLabels.call(_this, _this._ticks, _this.name, {
getTickDistance: function getTickDistance(tick, i) {
var _this$_ticks, _this$_ticks2;
var nextTick = ((_this$_ticks = _this._ticks) === null || _this$_ticks === void 0 ? void 0 : _this$_ticks[i + 1]) || ((_this$_ticks2 = _this._ticks) === null || _this$_ticks2 === void 0 ? void 0 : _this$_ticks2[i - 1]);
return nextTick ? Math.abs(nextTick.position - tick.position) : 0;
}
}, function (labelGroup, tick, i) {
// labelGroup.setAttribute(
// 'transform',
// `translate(${
// tick.position + this.attr('labelsOffset')(tick, i)[0]
// }, ${
// this.attr('labelsOffset')(tick, i)[1] +
// labelsPadding * (compositePosition === 'below' ? 1 : -1)
// })`,
// );
labelGroup.querySelector("foreignObject").setAttribute("x", tick.position + _this.attr("labelsOffset")(tick, i)[0]);
labelGroup.querySelector("foreignObject").setAttribute("y", _this.attr("labelsOffset")(tick, i)[1] + labelsPadding * (compositePosition === "below" ? 1 : -1));
xAxisLabel(labelGroup, tick.visibleLabel, compositePosition);
});
_this.objects.forEach(function (obj) {
return obj.draw();
});
return _this;
};
}
xAxis.prototype = Object.create(chrtAxis.prototype);
xAxis.prototype.constructor = xAxis;
xAxis.parent = chrtAxis.prototype;
function xAxis$1 (ticksNumber, customName) {
return new xAxis(ticksNumber, customName);
}
var isNull$i = index$6.isNull,
create$1$2 = index$6.createSVG;
function yAxis() {
var _this = this;
var ticksNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : TICKS_DEFAULT$1;
var customName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "y";
if (typeof arguments[0] === "string") {
customName = arguments[0];
ticksNumber = TICKS_DEFAULT$1;
}
chrtAxis.call(this, customName);
var coords = {
x: "x",
y: "y"
};
// this.coord = coords.y;
this.attr("orientation", DEFAULT_ORIENTATION[coords.y]);
this._classNames = [].concat(_toConsumableArray$h(this._classNames), ["chrt-y-axis"]);
this._name = "y";
var yAxisTick = function yAxisTick(tickGroup, visible, orientationDirection) {
tickGroup.style.display = visible ? "block" : "none";
var tickLength = _this.attr("ticksLength")();
var tickLine = tickGroup.querySelector("line");
if (tickLine) {
tickLine.setAttribute("x1", 0);
tickLine.setAttribute("x2", (_this.attr("ticksPosition")() === "outside" ? -tickLength : tickLength) * orientationDirection);
}
};
var yAxisLabel = function yAxisLabel(tickGroup, visible, compositePosition) {
_this.attr("labelsPosition")();
var tickLength = _this.attr("ticksLength")();
var label = tickGroup.querySelector("foreignObject > div");
if (label) {
label.style.textAlign = compositePosition === "left" ? "right" : "left";
// the distance from the axis is the tickLength (then the tickGroup is translated by the labelsPadding and labelsOffset )
var x = "".concat(compositePosition === "left" ? -(tickLength + 1) : tickLength + 1);
label.style.transform = "translate(".concat(compositePosition === "left" ? "calc(-100% + ".concat(x, "px)") : "".concat(x, "px"), ", -50%)");
}
};
this.draw = function () {
var _this$g$classList, _this$g$classList2, _this$ariaLabel;
if (!_this.parentNode.scales[coords.y][_this.name]) {
return _this.parentNode;
}
var _this$parentNode = _this.parentNode,
_margins = _this$parentNode._margins,
scales = _this$parentNode.scales,
width = _this$parentNode.width,
height = _this$parentNode.height;
cssDisplay$5.call(_this, _this.attr("display")());
var orientation = _this.attr("orientation")();
var orientationDirection = orientation === DEFAULT_ORIENTATION[coords.y] ? 1 : -1;
_this.g.setAttribute("id", "".concat(_this.name, "Axis-").concat(_this.id()));
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$h(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$h(_this._classNames));
_this.g.setAttribute("aria-label", (_this$ariaLabel = _this.ariaLabel) !== null && _this$ariaLabel !== void 0 ? _this$ariaLabel : ARIA_LABELS[coords.y]);
var axisX = orientation === DEFAULT_ORIENTATION[coords.y] ? _margins.left : width - _margins.right;
_this.g.setAttribute("transform", "translate(".concat(axisX, ",0)"));
var _interval = _this.attr("interval")();
var ticks = scales[coords.y][_this.name].ticks(_this._fixedTicks || ticksNumber * 2, _interval);
if (_this._label && _this._label.position === "last") {
ticks.reverse();
}
_this._ticks = ticks.map(function (tick, i, arr) {
tick.position = scales[coords.y][_this.name](tick.value);
var visible = tick.position >= _margins.top && tick.position <= height - _margins.bottom;
visible = visible && (_this.attr("showMinorTicks")() || !tick.isMinor);
tick.visible = visible;
if (_this.ticksFilter) {
tick.visible = tick.visible && _this.ticksFilter(tick.value, i, arr);
}
tick.visibleLabel = visible && (_this.attr("showMinorLabels")() || !tick.isMinor);
if (_this.labelsFilter) {
tick.visibleLabel = tick.visibleLabel && _this.labelsFilter(tick.value, i, arr);
}
return tick;
}).filter(function (d) {
return d.visible || d.visibleLabel;
}); // decrease the number of ticks rendered in the DOM
var dataID = encodeURIComponent("tick-".concat(_this.name, "-axis-line"));
var axisLine = _this.g.querySelector("line[data-id='".concat(dataID, "']"));
if (!axisLine) {
axisLine = create$1$2("line");
axisLine.setAttribute("data-id", dataID);
_this.g.appendChild(axisLine);
}
var labelPosition = _this.attr("labelsPosition")();
axisLine.setAttribute("stroke", _this.stroke()());
axisLine.setAttribute("stroke-width", _this.strokeWidth()());
var scaleX = scales[coords.x][coords.x] || Object.values(scales[coords.x])[0];
var _zero = _this.attr("zero")();
var zero = isNull$i(_zero) ? scaleX.domain[0] : _zero;
var axisLineX = isNull$i(_zero) ? scaleX.range[0] : scaleX(zero) - _margins.left;
if (scaleX.transformation === "ordinal" && (isNull$i(_zero) || !~scaleX.domain.indexOf(zero))) {
axisLineX = 0;
}
axisLineX = axisLineX - _this.parentNode._padding.left;
axisLine.setAttribute("x1", !isNaN(axisLineX) ? axisLineX : 0);
axisLine.setAttribute("x2", !isNaN(axisLineX) ? axisLineX : 0);
axisLine.setAttribute("y1", _margins.top);
axisLine.setAttribute("y2", height - _margins.bottom);
// if no axis remove the axis line after creating it
if (!_this.attr("showAxisLine")()) {
axisLine.remove();
}
var title = _this.attr("title") ? _this.attr("title")() : null;
if (!isNull$i(title)) {
var axisTitleText = _this.g.querySelector("text.title");
if (isNull$i(axisTitleText)) {
axisTitleText = create$1$2("text");
axisTitleText.classList.add("title");
}
axisTitleText.textContent = title;
var x = (labelPosition === "outside" ? _this.tickLength()() : 0) * orientationDirection;
axisTitleText.setAttribute("x", x);
axisTitleText.setAttribute("y", _margins.top);
axisTitleText.setAttribute("dy", labelPosition === "outside" ? "0.9em" : "-0.9em");
axisTitleText.setAttribute("dx", labelPosition === "outside" ? "".concat(5 * orientationDirection, "px") : "".concat(-2 * orientationDirection, "px"));
axisTitleText.setAttribute("text-anchor", ~orientationDirection ? "start" : "end");
if (!_this.ariaLabel) {
_this.g.setAttribute("aria-describedby", axisTitleText.textContent);
}
_this.g.appendChild(axisTitleText);
}
_this.g.querySelectorAll("g").forEach(function (d) {
var tickName = d.getAttribute("data-id");
var tick = _this._ticks.find(function (tick) {
return tickName === "tick-".concat(name, "-").concat(tick);
});
if (!tick) {
d.remove();
}
});
generateTicks.call(_this, _this._ticks, _this.name, function (tickGroup, tick) {
tickGroup.setAttribute("transform", "translate(0, ".concat(tick.position, ")"));
yAxisTick(tickGroup, tick.visible, orientationDirection);
});
var labelsPadding = _this.attr("labelsPadding")();
var compositePosition = "left";
var labelWidth = 100;
if (orientationDirection > 0) {
compositePosition = labelPosition === "outside" ? "left" : "right";
labelWidth = compositePosition === "left" ? _margins.left : width / 2;
} else {
compositePosition = labelPosition === "outside" ? "right" : "left";
labelWidth = compositePosition === "right" ? _margins.right : width / 2;
}
labelWidth = labelWidth - labelsPadding - _this.attr("ticksLength")();
generateLabels.call(_this, _this._ticks, _this.name, {
align: "left",
getTickDistance: function getTickDistance(tick, i) {
return labelWidth;
}
}, function (labelGroup, tick) {
// labelGroup.setAttribute(
// 'transform',
// `translate(${
// this.attr('labelsOffset')()[0] +
// labelsPadding * (compositePosition === 'left' ? -1 : 1)
// }, ${tick.position + this.attr('labelsOffset')()[1]})`,
// );
labelGroup.querySelector("foreignObject").setAttribute("x", _this.attr("labelsOffset")()[0] + labelsPadding * (compositePosition === "left" ? -1 : 1));
// console.log("y", tick.position, this.attr("labelsOffset")());
labelGroup.querySelector("foreignObject").setAttribute("y", tick.position + _this.attr("labelsOffset")()[1]);
yAxisLabel(labelGroup, tick.visibleLabel, compositePosition);
});
_this.objects.forEach(function (obj) {
return obj.draw();
});
return _this;
};
}
yAxis.prototype = Object.create(chrtAxis.prototype);
yAxis.prototype.constructor = yAxis;
yAxis.parent = chrtAxis.prototype;
function yAxis$1 (ticksNumber, customName) {
return new yAxis(ticksNumber, customName);
}
function color$3(value) {
return this.attr('fill', value);
// if(!value) {
// return this._fill;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// this._fill = value;
// }
// return this;
}
function align$2(value) {
return this.attr('align', value);
// if(!value) {
// return this._fill;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// this._fill = value;
// }
// return this;
}
function valign$2(value) {
return this.attr('valign', value);
// if(!value) {
// return this._fill;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// this._fill = value;
// }
// return this;
}
function offset$2(value) {
var currentOffset = this.attr('offset')();
return this.attr('offset', Object.assign({}, currentOffset || {}, value));
// if(!value) {
// return this._fill;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// this._fill = value;
// }
// return this;
}
var create$e = index$6.createSVG;
var DEFAULT_COLOR = '#000';
var DEFAULT_ALIGNMENT = 'right';
var DEFAULT_VERTICAL_ALIGNMENT = 'top';
function chrtAxisTitle(text) {
var _this = this;
// console.log('chrtAxisTitle', this, 'text ->', text);
chrtObject$5.call(this);
this.type = 'axis-title';
this.g = null;
this.attr('fill', DEFAULT_COLOR);
this.attr('align', DEFAULT_ALIGNMENT);
this.attr('valign', DEFAULT_VERTICAL_ALIGNMENT);
this.attr('offset', {
x: 0,
y: 0
});
this._classNames = ['chrt-axis-title'];
var xAxisDraw = function xAxisDraw() {
var fill = _this.attr('fill')();
var _this$parentNode$pare = _this.parentNode.parentNode,
width = _this$parentNode$pare.width,
_margins = _this$parentNode$pare._margins;
var x = 0;
var textAnchor = 'start';
switch (_this.attr('align')()) {
case 'left':
x = _margins.left;
textAnchor = 'start';
break;
case 'center':
x = width / 2;
textAnchor = 'middle';
break;
case 'right':
default:
x = width - _margins.right;
textAnchor = 'end';
}
var dy = '0.25em';
var y = 0;
switch (_this.attr('valign')()) {
case 'bottom':
y = 0;
dy = '1em';
break;
case 'middle':
y = 0;
dy = '0.25em';
break;
case 'top':
default:
y = 0;
dy = '-1em';
}
var offset = _this.attr('offset')();
_this.text.textContent = text;
_this.text.setAttribute('text-anchor', textAnchor);
_this.text.setAttribute('x', x + offset.x);
_this.text.setAttribute('y', y + offset.y);
_this.text.setAttribute('dy', dy);
_this.text.setAttribute('fill', fill);
};
var yAxisDraw = function yAxisDraw() {
var fill = _this.attr('fill')();
// const fillOpacity = this.attr('fillOpacity')();
// const stroke = this.attr('stroke')();
// const strokeOpacity = this.attr('strokeOpacity')();
// const strokeWidth = this.attr('strokeWidth')();
var _this$parentNode$pare2 = _this.parentNode.parentNode,
height = _this$parentNode$pare2.height,
_margins = _this$parentNode$pare2._margins;
var x = 0;
var textAnchor = 'start';
switch (_this.attr('align')()) {
case 'left':
x = -5;
textAnchor = 'end';
break;
case 'center':
case 'middle':
x = 0;
textAnchor = 'middle';
break;
case 'right':
default:
x = 5;
textAnchor = 'start';
}
var dy = '0.25em';
var y = 0;
switch (_this.attr('valign')()) {
case 'bottom':
y = height - _margins.bottom;
dy = '0';
break;
case 'center':
case 'middle':
y = 0;
dy = '0.25em';
break;
case 'top':
default:
y = _margins.top - 1;
dy = '0';
}
var offset = _this.attr('offset')();
_this.text.textContent = text;
_this.text.setAttribute('text-anchor', textAnchor);
_this.text.setAttribute('x', x + offset.x);
_this.text.setAttribute('y', y + offset.y);
_this.text.setAttribute('dy', dy);
_this.text.setAttribute('fill', fill);
};
this.draw = function () {
var _this$g$classList, _this$g$classList2, _this$ariaLabel;
// console.log('chrtAxisTitle draw', this);
if (!_this.parentNode.parentNode.scales) {
return _this.parentNode.parentNode;
}
if (!_this.g) {
_this.g = create$e('g');
// this.g.setAttribute('data-id', this._id);
_this.g.setAttribute('data-name', 'axis-title');
}
if (!_this.parentNode.g.querySelector("".concat(name, "AxisTitle-").concat(_this.id()))) {
_this.parentNode.g.appendChild(_this.g);
}
cssDisplay$5.call(_this, _this.attr('display')());
_this.g.setAttribute('id', "".concat(name, "AxisTitle-").concat(_this.id()));
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$h(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$h(_this._classNames));
_this.g.setAttribute('aria-label', (_this$ariaLabel = _this.ariaLabel) !== null && _this$ariaLabel !== void 0 ? _this$ariaLabel : text);
// if (scales && scales.x[this.parentNode.name]) {
// const _scale = scales.x[this.parentNode.name];
// from = isNull(this._range.from) ? from : _scale(this._range.from);
// to = isNull(this._range.to) ? to : _scale(this._range.to);
// }
if (!_this.text) {
_this.text = create$e('text');
_this.g.appendChild(_this.text);
}
if (_this.parentNode._name === 'x') {
xAxisDraw();
} else {
yAxisDraw();
}
return _this.parentNode;
};
}
chrtAxisTitle.prototype = Object.create(chrtObject$5.prototype);
chrtAxisTitle.prototype.constructor = chrtAxisTitle;
chrtAxisTitle.parent = chrtObject$5.prototype;
chrtAxisTitle.prototype = Object.assign(chrtAxisTitle.prototype, {
color: color$3,
fill: color$3,
align: align$2,
valign: valign$2,
offset: offset$2
});
// export default chrtAxisTitle;
function chrtAxisTitle$1 (text) {
return new chrtAxisTitle(text);
}
function index$5 (text) {
return new chrtAxisTitle$1(text);
}
// chrt-object v0.0.19 Copyright 2020-2024 chrt chrt.io
function _toConsumableArray$g(arr) {
return _arrayWithoutHoles$g(arr) || _iterableToArray$g(arr) || _unsupportedIterableToArray$g(arr) || _nonIterableSpread$g();
}
function _arrayWithoutHoles$g(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$g(arr);
}
function _iterableToArray$g(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$g(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$g(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$g(o, minLen);
}
function _arrayLikeToArray$g(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$g() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var COMPONENTS_W_DATA$4 = ['chrt', 'series'];
function isNull$h(value) {
return value === null || value == null || typeof value === 'undefined';
}
function uuid$4() {
return 'c' + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
function hasData$4(obj) {
return !isNull$h(obj.type) && COMPONENTS_W_DATA$4.indexOf(obj.type) > -1;
}
function isInfinity$9(value) {
return !isFinite(value);
}
function oppositeSigns$4(x, y) {
return (x ^ y) < 0;
}
function getCoords$6(data) {
var _this = this;
if (!(this !== null && this !== void 0 && this.fields)) {
return [];
}
return data.map(function (d) {
var x = isNull$h(d[_this.fields.x]) || isInfinity$9(d[_this.fields.x]) ? null : _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = isNull$h(d[_this.fields.y]) || isInfinity$9(d[_this.fields.y]) ? null : _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
return [isInfinity$9(x) ? 0 : x, isInfinity$9(y) ? 0 : y];
}); //.filter(d => !isNull(d[0]) && !isNull(d[1]))
}
function create$d(tag) {
return document.createElement(tag);
}
function createSVG$4(tag) {
return document.createElementNS('http://www.w3.org/2000/svg', tag);
}
function getStrokeStyle$5(style) {
var strokeWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var strokeLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
var strokeStyle = null;
switch (style) {
case 'dashed':
strokeStyle = "".concat(strokeWidth * strokeLength, " ").concat(strokeWidth * strokeLength);
break;
case 'dotted':
strokeStyle = "".concat(strokeWidth, " ").concat(strokeWidth);
break;
case 'solid':
default:
strokeStyle = null;
}
return strokeStyle;
}
function add$6(obj) {
var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var id = obj._id || uuid$4();
// console.log('adding to', this, obj.type, id, obj);
obj.id(id).parent(this);
// .render();
if (prepend) {
this.objects = [obj].concat(_toConsumableArray$g(this.objects));
} else {
this.objects.push(obj);
}
//return this.update();
return this;
}
// export { add } from '../charts/util'
var index$4 = /*#__PURE__*/Object.freeze({
__proto__: null,
add: add$6,
create: create$d,
createSVG: createSVG$4,
getCoords: getCoords$6,
getStrokeStyle: getStrokeStyle$5,
hasData: hasData$4,
isInfinity: isInfinity$9,
isNull: isNull$h,
oppositeSigns: oppositeSigns$4,
uuid: uuid$4
});
function render$4(parent) {
// console.log('RENDER', this, parent)
if (this.g) {
// avoid duplication of g
return this;
}
this.g = createSVG$4('g');
if (this._id) {
this.g.setAttribute('id', this._id);
}
// console.log('RENDER', this, this.parentNode)
if (hasData$4(this)) {
// series
// in case of group or stack we want the chart to be added to svg g of the group/stack
if (parent) {
// if it's a stack we want the order of the charts in the dom to be opposite, so the stroke
// of the charts below is not covered by the area above
if (parent.type === 'stack' || parent.group === 'group') {
parent.g.prepend(this.g);
} else {
parent.g.append(this.g);
}
} else {
this.currentNode.append(this.g);
}
} else {
// const grid = (this.parentNode.objects || []).slice().reverse().find(obj => obj.type === 'grid');
// if(grid && this.type === 'axis') {
// // // console.log('THIS IS AN',this.type,'AND THERE IS A GRID',grid,'INSERT BEFORE',grid.node(), grid.node().nextSibling)
// this.currentNode.insertBefore(this.g, grid.node().nextSibling);
// } else {
// // console.log('THIS IS A', this.type, 'PREPEND')
// this.currentNode.append(this.g);
// }
this.currentNode.append(this.g);
}
this.update();
return this; // .parentNode;
}
function update$4() {
if (this.parentNode && this.parentNode.scales.x[this.scales.x] && this.parentNode.scales.y[this.scales.y]) {
this.draw();
}
return this;
}
function curve$4(interpolationFunction) {
if (isNull$h(interpolationFunction)) {
return this.interpolationFunction;
}
this.interpolationFunction = interpolationFunction;
return this;
}
function attribute$4(name, fn) {
var accessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (value) {
return value;
};
if (isNull$h(name)) {
console.warn('name missing: attr method requires a name for the attribute');
return this;
}
if (!isNull$h(name) && typeof fn === 'undefined') {
var _this$attrs;
// this.name()
return ((_this$attrs = this.attrs) === null || _this$attrs === void 0 ? void 0 : _this$attrs[name]) || function () {};
}
if (typeof fn === 'function') {
// something will go here
this.attrs[name] = fn;
} else {
// fn is a Boolean, String, Number or any other type but function
this.attrs[name] = function () {
return accessor(fn);
};
}
return this;
}
function data$4 (data, accessor) {
// console.log('---------------> data', data, accessor, this);
if (!data) {
// console.log('NO DATA return', hasData(this), this._data, hasData(this) ? this._data : this)
return hasData$4(this) ? this._data || null : this;
}
// TODO: not sure what this is doing...
if (!hasData$4(this)) {
// console.log('NO HAS DATA')
return this;
}
// console.log('HAS DATA')
// // console.log('chrt or series', this.type)
// passing only accessor to inherit/reuse data
if (typeof arguments[0] === 'function') {
this._accessor = arguments[0];
return this;
}
// data is passed
this._orginalData = this._orginalData || data;
// define accessor function to map values
var accessorFunction = accessor || this._accessor;
this._accessor = accessorFunction;
this._data = accessorFunction && !this._accessorApplied ? data.map(function (d, i, arr) {
if (d instanceof Object) {
return Object.assign({}, d, accessorFunction(d, i, arr));
}
return accessorFunction(d, i, arr);
}) : data;
// console.log('DATA', data)
this._accessorApplied = true; // do not apply the accessor multiple times
return this;
}
/**
* node - Returns the DOM element that contains a chart element
*
* @param {type} node Set this as root node
*
* @return {type} Description
*/
function node$4 (node) {
if (!node) {
return this.g || this.root;
}
this.root = node;
this.currentNode = this.root;
return this;
}
function parent$4 (obj) {
if (!obj) {
return this.parentNode;
}
this.parentNode = obj;
return this;
}
function display$4(value) {
return attribute$4.call(this, 'display', value);
}
function show$4() {
return display$4.call(this, true);
}
function hide$4() {
return display$4.call(this, false);
}
function cssDisplay$4(value) {
var DOMNode = node$4.call(this);
if (!DOMNode) {
return this;
}
var currentDisplay = DOMNode.style.display;
this._display = typeof this._display !== 'undefined' ? this._display : DOMNode.style.display;
if (!value) {
DOMNode.style.display = 'none';
} else {
if (currentDisplay === 'none' && value) {
DOMNode.style.display = this._display;
}
}
return this;
}
function chrtObject$4() {
var _this = this;
this._id = null;
this.objects = [];
this.type = 'chrt-object';
this.fields = {
x: null,
y: null
};
this.scales = {
x: 'x',
y: 'y'
};
this._classNames = [];
this._accessor = function (d, i) {
return {
x: !isNull$h(d) && Object.prototype.hasOwnProperty.call(d, 'x') ? d.x : i,
y: isNull$h(d) ? null : Object.prototype.hasOwnProperty.call(d, 'y') ? d.y : d
};
};
this.interpolationFunction = null;
// list of getter/setter function for custom attributes
this.attrs = [];
attribute$4.call(this, 'display', true);
this.id = function (id) {
// console.log('chrtObject.id', id, this._id);
if (isNull$h(id)) {
return _this._id;
}
_this._id = id || _this._id;
if (_this.g) {
_this.g.setAttribute('id', _this._id);
}
return _this;
};
this.aria = function (ariaLabel) {
attribute$4.call(_this, 'aria', ariaLabel);
// if(isNull(ariaLabel)) {
// return this.ariaLabel;
// }
// this.ariaLabel = ariaLabel || this.ariaLabel;
//
// if(this.g && this.ariaLabel) {
// this.g.setAttribute('aria-label', this.ariaLabel);
// }
return _this;
};
this.class = function (className) {
if (isNull$h(className)) {
return _this._classNames;
}
var classNames = (Array.isArray(className) ? className : className.split(' ')).map(function (d) {
return d.replace(/\s\s+/g, ' ').trim();
}).filter(function (d) {
return d !== '';
});
_this.original_classNames = _this.original_classNames || _this._classNames;
_this._classNames = _toConsumableArray$g(new Set([].concat(_toConsumableArray$g(_this.original_classNames), _toConsumableArray$g(classNames))));
if (_this.g) {
var _this$g$classList, _this$g$classList2;
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$g(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$g(_this._classNames));
}
return _this;
};
this.hasData = function () {
return hasData$4(_this);
};
var setScale = function setScale(scale, scaleName) {
if (!isNull$h(scaleName)) {
_this.scales[scale] = scaleName;
}
};
this.x = function (scale) {
if (isNull$h(scale)) {
return _this.scales.x;
}
setScale('x', scale || 'x');
return _this;
};
this.y = function (scale) {
if (isNull$h(scale)) {
return _this.scales.y;
}
setScale('y', scale || 'y');
return _this;
};
this.getObjectTypeIndex = function () {
var _this$parent$objects, _this$parent;
return ((_this$parent$objects = (_this$parent = _this.parent()) === null || _this$parent === void 0 ? void 0 : _this$parent.objects) !== null && _this$parent$objects !== void 0 ? _this$parent$objects : []).filter(function (d) {
return d.constructor.name === _this.constructor.name;
}).indexOf(_this);
};
return this;
}
function chrt$4() {
return new chrtObject$4();
}
chrtObject$4.prototype = Object.create(chrt$4.prototype);
// chrtObject.prototype = chrt.prototype = Object.assign(chrt.prototype, {
chrtObject$4.prototype = Object.assign(chrt$4.prototype, {
node: node$4,
data: data$4,
add: add$6,
snap: add$6,
parent: parent$4,
render: render$4,
update: update$4,
curve: curve$4,
attr: attribute$4,
show: show$4,
hide: hide$4
});
// chrt-grid v0.0.28 Copyright 2024 chrt
function _arrayLikeToArray$f(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithoutHoles$f(r) {
if (Array.isArray(r)) return _arrayLikeToArray$f(r);
}
function _iterableToArray$f(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _nonIterableSpread$f() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray$f(r) {
return _arrayWithoutHoles$f(r) || _iterableToArray$f(r) || _unsupportedIterableToArray$f(r) || _nonIterableSpread$f();
}
function _unsupportedIterableToArray$f(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray$f(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$f(r, a) : void 0;
}
}
var TICKS_DEFAULT = 10;
function lineWidth$2(value) {
return this.attr('strokeWidth', value);
}
function lineColor$2(value) {
return this.attr('stroke', value);
}
function lineStyle$1(value) {
return this.attr('strokeStyle', value);
// this._lineStyle = value;
// if(!value) {
// return this.strokeStyle;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// switch(value) {
// case 'dashed':
// this.strokeStyle = `${this.strokeWidth * 4} ${this.strokeWidth * 4}`;
// break;
// case 'dotted':
// this.strokeStyle = `${this.strokeWidth} ${this.strokeWidth}`;
// break;
// case 'solid':
// default:
// this.strokeStyle = null;
// }
// }
// return this;
}
function minor() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (typeof value === 'function') ; else {
this.showMinorTicks = value;
}
return this;
}
var isNull$1$4 = index$4.isNull;
function ticks(ticks) {
if (isNull$1$4(ticks)) {
return this._ticks;
}
this._fixedTicks = ticks;
return this;
}
// showTicks and hideTicks can get different type of parameters and they filter the ticks based on the parameters
function showTicks() {
var filter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this._filter = filter;
// filter-in with a function
// showTicks((d,i) => !(i % 2))
if (typeof filter === 'function') {
this.ticksFilter = function (d, i, arr) {
return filter(d, i, arr);
};
return this;
}
// show/hide all ticks
// showTicks(false|true)
if (typeof filter === 'boolean') {
this.ticksFilter = function () {
return filter;
};
return this;
}
// show only one tick
// showTicks(10)
if (Number.isFinite(filter)) {
this.ticksFilter = function (d) {
return filter === d;
};
return this;
}
// show based on an array of values
// showTicks([10, 20, 30])
if (Array.isArray(filter)) {
this.ticksFilter = function (d) {
return filter.indexOf(d) > -1;
};
return this;
}
return this;
}
// hideTicks is the opposite of showTicks and it filters out
function hideTicks(filter) {
showTicks.call(this, filter);
var ticksFilter = this.ticksFilter;
this.ticksFilter = function (d, i, arr) {
return !ticksFilter(d, i, arr);
};
return this;
}
function firstTick() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
// // console.log('FIRST TICK', this, show)
if (show) {
showTicks.call(this, function (d, i) {
return i === 0;
});
} else {
hideTicks.call(this, function (d, i) {
return i === 0;
});
}
return this;
}
function lastTick() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showTicks.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
} else {
hideTicks.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
}
return this;
}
function firstAndLastTicks() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showTicks.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
} else {
hideTicks.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
}
return this;
}
var isNull$g = index$4.isNull,
getStrokeStyle$4 = index$4.getStrokeStyle,
create$c = index$4.createSVG;
var DEFAULT_LINE_WIDTH$1 = 1;
var DEAULT_LINE_COLOR$2 = '#000';
function chrtGrid(type) {
var _this = this;
var ticksNumber = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TICKS_DEFAULT;
var name = arguments.length > 2 ? arguments[2] : undefined;
chrtObject$4.call(this);
this.type = 'grid';
// ticksNumber *= 2;
// console.log('GRID', type, ticksNumber, name);
// this.type = type;
this.name = name || type;
this.attr('stroke', DEAULT_LINE_COLOR$2);
this.attr('strokeWidth', DEFAULT_LINE_WIDTH$1);
this.attr('strokeStyle', null);
this._classNames = ['chrt-grid', type === 'x' ? 'vertical-grid' : 'horizontal-grid'];
this.showMinorTicks = false;
this.ticksFilter = null;
this._interval = null;
var verticalGridLine = function verticalGridLine(gridLine, position, y1, y2) {
var visible = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
gridLine.style.display = visible ? 'block' : 'none';
gridLine.setAttribute('x1', position);
gridLine.setAttribute('x2', position);
gridLine.setAttribute('y1', y1);
gridLine.setAttribute('y2', y2);
};
var horizontalGridLine = function horizontalGridLine(gridLine, position, x1, x2) {
var visible = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
gridLine.style.display = visible ? 'block' : 'none';
gridLine.setAttribute('x1', x1);
gridLine.setAttribute('x2', x2);
gridLine.setAttribute('y1', position);
gridLine.setAttribute('y2', position);
};
this.draw = function () {
var _this$g$classList, _this$g$classList2;
if (!_this.parentNode.scales[type][_this.name]) {
return;
}
cssDisplay$4.call(_this, _this.attr('display')());
var _scale = _this.parentNode.scales[type][_this.name];
var _this$parentNode = _this.parentNode,
_margins = _this$parentNode._margins,
width = _this$parentNode.width,
height = _this$parentNode.height;
var isLog = _scale.isLog();
var interval = _this._interval;
var axis = _this.parentNode.getAxis(type);
if (axis) {
interval = axis.interval()();
}
var ticks = _scale.ticks(_this._fixedTicks || ticksNumber * 2, interval).map(function (tick, i, arr) {
tick.position = _scale(tick.value);
var visible = tick.position >= _margins.top && tick.position <= height - _margins.bottom;
if (type === 'x') {
visible = tick.position >= _margins.left && tick.position <= width - _margins.right;
}
visible = visible && (_this.showMinorTicks || tick.isZero && _this.showZero || !tick.isMinor);
visible = visible && (!isLog || isLog && !tick.isMinor);
if (_this.ticksFilter) {
visible = visible && _this.ticksFilter(tick.value, i, arr);
}
tick.visible = visible;
return tick;
});
// console.log('GRID!', type, name, 'TICKS', ticks)
// .filter(tick => tick.visible) // TO BE REVIEWED
// .filter((tick, i, arr) => this.ticksFilter ? this.ticksFilter(tick.value, i, arr) : true);
// const ticks = this.parentNode.scales[type].ticks(
// //ticksNumber * (this.showMinorTicks ? 2 : 1)
// ticksNumber * 2
// )
// // .filter((tick, i, arr) => this.ticksFilter(tick.value, i, arr));
// .filter((tick, i, arr) => this.ticksFilter ? this.ticksFilter(tick.value, i, arr) : true);
// console.log('got this ticks', type, ticksNumber, ticks);
_this.g.setAttribute('id', "".concat(type, "Grid-").concat(_this.id()));
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$f(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$f(_this._classNames));
_this.g.querySelectorAll('line').forEach(function (gridLine) {
return gridLine.setAttribute('toBeHidden', true);
});
ticks.forEach(function (tick, i, arr) {
var dataID = escape("gridLine-".concat(type, "-").concat(tick.value));
var gridLine = _this.g.querySelector("[data-id='".concat(dataID, "']"));
if (!gridLine) {
gridLine = create$c('line');
gridLine.setAttribute('data-id', dataID);
if (tick.isMinor) {
gridLine.classList.add('tick-minor');
}
_this.g.appendChild(gridLine);
}
gridLine.setAttribute('stroke', _this.attr('stroke')(tick, i, arr));
var strokeWidth = Math.max(_this.attr('strokeWidth')(tick, i, arr), 0);
gridLine.setAttribute('stroke-width', strokeWidth);
gridLine.setAttribute('shape-rendering', 'crispEdges');
var strokeStyle = _this.attr('strokeStyle')(tick, i, arr);
if (!isNull$g(strokeStyle)) {
gridLine.setAttribute('stroke-dasharray', getStrokeStyle$4(strokeStyle, strokeWidth));
}
gridLine.removeAttribute('toBeHidden');
var position = _scale(tick.value);
if (type === 'x') {
// const isLog = this.parentNode.scales[type][name].isLog();
// const visible =
// this.showMinorTicks || (!isLog && !tick.isMinor) || (isLog && !tick.isMinor); // TODO: improve this check
verticalGridLine(gridLine, position, height - _margins.bottom, _margins.top, tick.visible);
}
if (type === 'y') {
// const isLog = this.parentNode.scales[type][name].isLog();
// let visible =
// position >= _margins.top && position <= height - _margins.bottom;
// visible = visible && (this.showMinorTicks || (tick.isZero && this.showZero) || !tick.isMinor);
// visible = visible && ((!isLog) || (isLog && !tick.isMinor));
// if(this.ticksFilter) {
// visible = this.ticksFilter(tick.value, i, arr);
// }
horizontalGridLine(gridLine, position, _margins.left, width - _margins.right, tick.visible);
}
});
_this.g.querySelectorAll('line[toBeHidden=true]').forEach(function (gridLine) {
return gridLine.remove();
});
return _this.parentNode;
};
this.solid = function () {
return lineStyle$1.call(_this, 'solid');
};
this.dashed = function () {
return lineStyle$1.call(_this, 'dashed');
};
this.dotted = function () {
return lineStyle$1.call(_this, 'dotted');
};
}
function grid(type, ticksNumber) {
return new chrtGrid(type, ticksNumber);
}
chrtGrid.prototype = Object.create(chrtObject$4.prototype);
chrtGrid.prototype.constructor = chrtGrid;
chrtGrid.parent = chrtObject$4.prototype;
chrtGrid.prototype = Object.assign(chrtGrid.prototype, {
width: lineWidth$2,
color: lineColor$2,
minor: minor,
ticks: ticks,
firstTick: firstTick,
lastTick: lastTick,
filter: showTicks,
showTicks: showTicks,
hideTicks: hideTicks,
firstAndLastTicks: firstAndLastTicks
});
// export default chrtGrid;
// export { default as chrtGrid, horizontalGrid, verticalGrid } from './chrtGrid';
function verticalGrid(ticksNumber, name) {
return grid.call(this, 'x', ticksNumber, name);
}
function horizontalGrid(ticksNumber, name) {
return grid.call(this, 'y', ticksNumber, name);
}
// chrt-object v0.0.16 Copyright 2020-2022 chrt chrt.io
function _toConsumableArray$e(arr) {
return _arrayWithoutHoles$e(arr) || _iterableToArray$e(arr) || _unsupportedIterableToArray$e(arr) || _nonIterableSpread$e();
}
function _arrayWithoutHoles$e(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$e(arr);
}
function _iterableToArray$e(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$e(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$e(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$e(o, minLen);
}
function _arrayLikeToArray$e(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$e() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var COMPONENTS_W_DATA$3 = ['chrt', 'series'];
function isNull$f(value) {
return value === null || value == null || typeof value === 'undefined';
}
function uuid$3() {
return 'c' + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
function hasData$3(obj) {
return !isNull$f(obj.type) && COMPONENTS_W_DATA$3.indexOf(obj.type) > -1;
}
function isInfinity$8(value) {
return !isFinite(value);
}
function oppositeSigns$3(x, y) {
return (x ^ y) < 0;
}
function getCoords$5(data) {
var _this = this;
if (!(this !== null && this !== void 0 && this.fields)) {
return [];
}
return data.map(function (d) {
var x = isNull$f(d[_this.fields.x]) || isInfinity$8(d[_this.fields.x]) ? null : _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = isNull$f(d[_this.fields.y]) || isInfinity$8(d[_this.fields.y]) ? null : _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
return [isInfinity$8(x) ? 0 : x, isInfinity$8(y) ? 0 : y];
}); //.filter(d => !isNull(d[0]) && !isNull(d[1]))
}
function create$b(tag) {
return document.createElement(tag);
}
function createSVG$3(tag) {
return document.createElementNS('http://www.w3.org/2000/svg', tag);
}
function getStrokeStyle$3(style) {
var strokeWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var strokeLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
var strokeStyle = null;
switch (style) {
case 'dashed':
strokeStyle = "".concat(strokeWidth * strokeLength, " ").concat(strokeWidth * strokeLength);
break;
case 'dotted':
strokeStyle = "".concat(strokeWidth, " ").concat(strokeWidth);
break;
case 'solid':
default:
strokeStyle = null;
}
return strokeStyle;
}
function add$5(obj) {
var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var id = obj._id || uuid$3(); // console.log('adding to', this, obj.type, id, obj);
obj.id(id).parent(this); // .render();
if (prepend) {
this.objects = [obj].concat(_toConsumableArray$e(this.objects));
} else {
this.objects.push(obj);
} //return this.update();
return this;
}
// export { add } from '../charts/util'
var index$3 = /*#__PURE__*/Object.freeze({
__proto__: null,
add: add$5,
isNull: isNull$f,
uuid: uuid$3,
hasData: hasData$3,
isInfinity: isInfinity$8,
oppositeSigns: oppositeSigns$3,
getCoords: getCoords$5,
create: create$b,
createSVG: createSVG$3,
getStrokeStyle: getStrokeStyle$3
});
function render$3(parent) {
// console.log('RENDER', this, parent)
if (this.g) {
// avoid duplication of g
return this;
}
this.g = createSVG$3('g');
if (this._id) {
this.g.setAttribute('id', this._id);
} // console.log('RENDER', this, this.parentNode)
if (hasData$3(this)) {
// series
// in case of group or stack we want the chart to be added to svg g of the group/stack
if (parent) {
// if it's a stack we want the order of the charts in the dom to be opposite, so the stroke
// of the charts below is not covered by the area above
if (parent.type === 'stack' || parent.group === 'group') {
parent.g.prepend(this.g);
} else {
parent.g.append(this.g);
}
} else {
this.currentNode.append(this.g);
}
} else {
// const grid = (this.parentNode.objects || []).slice().reverse().find(obj => obj.type === 'grid');
// if(grid && this.type === 'axis') {
// // // console.log('THIS IS AN',this.type,'AND THERE IS A GRID',grid,'INSERT BEFORE',grid.node(), grid.node().nextSibling)
// this.currentNode.insertBefore(this.g, grid.node().nextSibling);
// } else {
// // console.log('THIS IS A', this.type, 'PREPEND')
// this.currentNode.append(this.g);
// }
this.currentNode.append(this.g);
}
this.update();
return this; // .parentNode;
}
function update$3() {
if (this.parentNode && this.parentNode.scales.x[this.scales.x] && this.parentNode.scales.y[this.scales.y]) {
this.draw();
}
return this;
}
function curve$3(interpolationFunction) {
if (isNull$f(interpolationFunction)) {
return this.interpolationFunction;
}
this.interpolationFunction = interpolationFunction;
return this;
}
function attribute$3(name, fn) {
var accessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (value) {
return value;
};
if (isNull$f(name)) {
console.warn('name missing: attr method requires a name for the attribute');
return this;
}
if (!isNull$f(name) && typeof fn === 'undefined') {
var _this$attrs;
// this.name()
return ((_this$attrs = this.attrs) === null || _this$attrs === void 0 ? void 0 : _this$attrs[name]) || function () {};
}
if (typeof fn === 'function') {
// something will go here
this.attrs[name] = fn;
} else {
// fn is a Boolean, String, Number or any other type but function
this.attrs[name] = function () {
return accessor(fn);
};
}
return this;
}
function data$3 (data, accessor) {
// console.log('---------------> data', data, accessor, this);
if (!data) {
// console.log('NO DATA return', hasData(this), this._data, hasData(this) ? this._data : this)
return hasData$3(this) ? this._data || null : this;
} // TODO: not sure what this is doing...
if (!hasData$3(this)) {
// console.log('NO HAS DATA')
return this;
} // console.log('HAS DATA')
// // console.log('chrt or series', this.type)
// passing only accessor to inherit/reuse data
if (typeof arguments[0] === 'function') {
this._accessor = arguments[0];
return this;
} // data is passed
this._orginalData = this._orginalData || data; // define accessor function to map values
var accessorFunction = accessor || this._accessor;
this._accessor = accessorFunction;
this._data = accessorFunction && !this._accessorApplied ? data.map(function (d, i, arr) {
if (d instanceof Object) {
return Object.assign({}, d, accessorFunction(d, i, arr));
}
return accessorFunction(d, i, arr);
}) : data; // console.log('DATA', data)
this._accessorApplied = true; // do not apply the accessor multiple times
return this;
}
/**
* node - Returns the DOM element that contains a chart element
*
* @param {type} node Set this as root node
*
* @return {type} Description
*/
function node$3 (node) {
if (!node) {
return this.g || this.root;
}
this.root = node;
this.currentNode = this.root;
return this;
}
function parent$3 (obj) {
if (!obj) {
return this.parentNode;
}
this.parentNode = obj;
return this;
}
function display$3(value) {
return attribute$3.call(this, 'display', value);
}
function show$3() {
return display$3.call(this, true);
}
function hide$3() {
return display$3.call(this, false);
}
function cssDisplay$3(value) {
var DOMNode = node$3.call(this);
if (!DOMNode) {
return this;
}
var currentDisplay = DOMNode.style.display;
this._display = typeof this._display !== 'undefined' ? this._display : DOMNode.style.display;
if (!value) {
DOMNode.style.display = 'none';
} else {
if (currentDisplay === 'none' && value) {
DOMNode.style.display = this._display;
}
}
return this;
}
function chrtObject$3() {
var _this = this;
this._id = null;
this.objects = [];
this.type = 'chrt-object';
this.fields = {
x: null,
y: null
};
this.scales = {
x: 'x',
y: 'y'
};
this._classNames = [];
this._accessor = function (d, i) {
return {
x: !isNull$f(d) && Object.prototype.hasOwnProperty.call(d, 'x') ? d.x : i,
y: isNull$f(d) ? null : Object.prototype.hasOwnProperty.call(d, 'y') ? d.y : d
};
};
this.interpolationFunction = null; // list of getter/setter function for custom attributes
this.attrs = [];
attribute$3.call(this, 'display', true);
this.id = function (id) {
// console.log('chrtObject.id', id, this._id);
if (isNull$f(id)) {
return _this._id;
}
_this._id = id || _this._id;
if (_this.g) {
_this.g.setAttribute('id', _this._id);
}
return _this;
};
this.aria = function (ariaLabel) {
if (isNull$f(ariaLabel)) {
return _this.ariaLabel;
}
_this.ariaLabel = ariaLabel || _this.ariaLabel;
if (_this.g && _this.ariaLabel) {
_this.g.setAttribute('aria-label', _this.ariaLabel);
}
return _this;
};
this.class = function (className) {
if (isNull$f(className)) {
return _this._classNames;
}
var classNames = (Array.isArray(className) ? className : className.split(' ')).map(function (d) {
return d.replace(/\s\s+/g, ' ').trim();
}).filter(function (d) {
return d !== '';
});
_this.original_classNames = _this.original_classNames || _this._classNames;
_this._classNames = _toConsumableArray$e(new Set([].concat(_toConsumableArray$e(_this.original_classNames), _toConsumableArray$e(classNames))));
if (_this.g) {
var _this$g$classList, _this$g$classList2;
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$e(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$e(_this._classNames));
}
return _this;
};
this.hasData = function () {
return hasData$3(_this);
};
var setScale = function setScale(scale, scaleName) {
if (!isNull$f(scaleName)) {
_this.scales[scale] = scaleName;
}
};
this.x = function (scale) {
if (isNull$f(scale)) {
return _this.scales.x;
}
setScale('x', scale || 'x');
return _this;
};
this.y = function (scale) {
if (isNull$f(scale)) {
return _this.scales.y;
}
setScale('y', scale || 'y');
return _this;
};
return this;
}
function chrt$3() {
return new chrtObject$3();
}
chrtObject$3.prototype = Object.create(chrt$3.prototype); // chrtObject.prototype = chrt.prototype = Object.assign(chrt.prototype, {
chrtObject$3.prototype = Object.assign(chrt$3.prototype, {
node: node$3,
data: data$3,
add: add$5,
snap: add$5,
parent: parent$3,
render: render$3,
update: update$3,
curve: curve$3,
attr: attribute$3,
show: show$3,
hide: hide$3
});
// chrt-interpolations v0.0.14 Copyright 2020-2022 chrt chrt.io
function _toConsumableArray$d(arr) {
return _arrayWithoutHoles$d(arr) || _iterableToArray$d(arr) || _unsupportedIterableToArray$d(arr) || _nonIterableSpread$d();
}
function _arrayWithoutHoles$d(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$d(arr);
}
function _iterableToArray$d(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$d(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$d(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$d(o, minLen);
}
function _arrayLikeToArray$d(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$d() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function isNull$e(value) {
return value === null || value == null || typeof value === 'undefined';
}
function isInfinity$7(value) {
return typeof value === 'number' && !isFinite(value);
}
function getCoords$4(data) {
var _this = this;
if (!(this !== null && this !== void 0 && this.fields)) {
return [];
}
return data.map(function (d) {
var x = isNull$e(d[_this.fields.x]) || isInfinity$7(d[_this.fields.x]) ? null : _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = isNull$e(d[_this.fields.y]) || isInfinity$7(d[_this.fields.y]) ? null : _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
return [isInfinity$7(x) ? 0 : x, isInfinity$7(y) ? 0 : y];
}); //.filter(d => !isNull(d[0]) && !isNull(d[1]))
}
// I: - points (array): points coordinates
// - command (function)
// I: - point (array) [x,y]: current point coordinates
// - i (integer): index of 'point' in the array 'a'
// - a (array): complete array of points coordinates
// O: - (string) a svg path command
// O: - (string): a Svg <path> element
var svgPath$1 = function svgPath(points, command) {
var _ref;
// build the d attributes by looping over the points
var splitByNullPoints = points.reduce(function (acc, point) {
if (isNull$e(point[1])) {
acc.push([]);
} else {
acc[acc.length - 1].push(point);
}
return acc;
}, [[]]);
var paths = splitByNullPoints.map(function (points) {
return points.reduce(function (acc, point, i, a) {
acc.push(i === 0 ? // if first point
"M".concat(isNaN(point[0]) ? 0 : point[0], ",").concat(isNaN(point[1]) ? 0 : point[1]) : // else
"".concat(command(point, i, a)));
return acc;
}, []);
});
return (_ref = []).concat.apply(_ref, _toConsumableArray$d(paths));
};
function linearInterpolation$1(data) {
return svgPath$1(getCoords$4.call(this, data), lineCommand$1);
}
var lineCommand$1 = function lineCommand(point) {
return "L".concat(isNaN(point[0]) ? 0 : point[0], ",").concat(isNaN(point[1]) ? 0 : point[1]);
};
// chrt-line v0.0.46 Copyright 2020-2023 chrt chrt.io
function _defineProperty$1(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _toConsumableArray$c(arr) {
return _arrayWithoutHoles$c(arr) || _iterableToArray$c(arr) || _unsupportedIterableToArray$c(arr) || _nonIterableSpread$c();
}
function _arrayWithoutHoles$c(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$c(arr);
}
function _iterableToArray$c(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$c(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$c(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$c(o, minLen);
}
function _arrayLikeToArray$c(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$c() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function lineWidth$1(value) {
return this.attr('strokeWidth', value);
}
function lineColor$1(value) {
return this.attr('stroke', value);
}
function lineOpacity(value) {
return this.attr('strokeOpacity', value);
}
function fillColor$1(value) {
return this.attr('fill', value);
}
function fillOpacity$3(value) {
return this.attr('fillOpacity', value);
}
function area() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'bottom';
return this.attr('area', value);
}
function zero(value) {
return this.attr('zero', value);
}
function sort(value) {
return this.attr('sortedData', value);
}
var isNull$d = index$3.isNull,
create$a = index$3.createSVG;
var DEFAULT_LINE_WIDTH = 1;
var DEAULT_LINE_COLOR$1 = '#000';
var DEFAULT_LINE_OPACITY = 1;
var DEAULT_FILL_COLOR$1 = '#000';
var DEFAULT_FILL_OPACITY$3 = 1;
function chrtLine() {
var _this = this;
chrtObject$3.call(this);
this.type = 'series';
// _area = false;
this.attr('area', false);
this._stacked = null;
this.attr('sortedData', true);
var coords = {
x: 'x',
y: 'y',
x0: 'x0',
y0: 'y0'
};
this.interpolationFunction = linearInterpolation$1;
this.attr('strokeWidth', DEFAULT_LINE_WIDTH);
this.attr('stroke', DEAULT_LINE_COLOR$1);
this.attr('strokeOpacity', DEFAULT_LINE_OPACITY);
this.attr('fill', DEAULT_FILL_COLOR$1);
this.attr('fillOpacity', DEFAULT_FILL_OPACITY$3);
this.paths = [];
this.areaPaths = [];
this._classNames = ['chrt-line'];
this.draw = function () {
var _this$g$classList, _this$g$classList2;
var _data = _this._data.length ? _this._data : _this.parentNode._data;
var _area = _this.attr('area')();
cssDisplay$3.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$c(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$c(_this._classNames));
if (isNull$d(_this.fields[coords.x])) {
_this.fields[coords.x] = _this.parentNode.scales[coords.x][_this.scales[coords.x]].field;
}
if (isNull$d(_this.fields[coords.y])) {
//console.log('this.scales', this.scales)
//console.log('this.parentNode.scales', this.parentNode.scales)
_this.fields[coords.y] = _this.parentNode.scales[coords.y][_this.scales[coords.y]].field;
}
if (isNull$d(_this.fields[coords.y0])) {
_this.fields[coords.y0] = "".concat(_this.parentNode.scales[coords.y][_this.scales[coords.y]].field, "0");
}
// console.log('LINECHART FIELDS', this.fields)
// console.log('LINECHART COORDS:', coords)
// console.log('_data', _data)
if (!isNull$d(_data)) {
var _this$attr;
var yDomain = _this.parentNode.scales[coords.y][_this.scales[coords.y]].domain;
var xDomain = _this.parentNode.scales[coords.x][_this.scales[coords.x]].domain;
// console.log(this.fields.x,coords.x,this.scales,'---->',this.scales[coords.x])
var _zero = 0;
switch (_area) {
case 'left':
_zero = xDomain[0] < 0 || xDomain[1] < 0 ? 0 : Math.min.apply(Math, _toConsumableArray$c(xDomain));
break;
case 'right':
_zero = xDomain[0] < 0 || xDomain[1] < 0 ? 0 : Math.max.apply(Math, _toConsumableArray$c(xDomain));
break;
case 'top':
_zero = yDomain[0] < 0 || yDomain[1] < 0 ? 0 : Math.max.apply(Math, _toConsumableArray$c(yDomain));
break;
case 'bottom':
default:
_zero = yDomain[0] < 0 || yDomain[1] < 0 ? 0 : Math.min.apply(Math, _toConsumableArray$c(yDomain));
}
_zero = (_this$attr = _this.attr('zero')()) !== null && _this$attr !== void 0 ? _this$attr : _zero;
_this.hasCustomBaseline = _area && _data.some(function (d) {
return !isNull$d(d[_this.fields[coords.y0]]);
});
var _scaleY = _this.parentNode.scales[coords.y][_this.scales[coords.y]];
var datasetsForLine = _data.reduce(function (acc, d) {
var _ref;
if (isNull$d(d) || isNull$d(d[_this.fields[coords.y]]) || isNaN(_scaleY(d[_this.fields[coords.y]]))) {
acc.push([]);
return acc;
}
if (!acc.length) {
acc.push([]);
}
var datumForLine = _this._stacked || _this.hasCustomBaseline ? (_ref = {}, _defineProperty$1(_ref, _this.fields[coords.x], d[_this.fields[coords.x]]), _defineProperty$1(_ref, _this.fields[coords.y], d[_this.fields[coords.y]]), _defineProperty$1(_ref, "x", d[_this.fields[coords.x]]), _defineProperty$1(_ref, "y", d["".concat(_this._stacked ? 'stacked_' : '').concat(_this.fields[coords.y])]), _defineProperty$1(_ref, "y0", !isNull$d(d["".concat(_this._stacked ? 'stacked_' : '').concat(_this.fields[coords.y0])]) ? d["".concat(_this._stacked ? 'stacked_' : '').concat(_this.fields[coords.y0])] : _zero), _ref) : d;
acc[acc.length - 1].push(datumForLine);
return acc;
}, []);
if (_this.attr('sortedData')()) {
var _scaleX = _this.parentNode.scales[coords.x][_this.scales[coords.x]];
datasetsForLine.forEach(function (dataset) {
dataset.sort(function (a, b) {
if (_scaleX.transformation === 'ordinal') {
return (1) * (_scaleX.domain.indexOf(a[_this.fields[coords.x]]) - _scaleX.domain.indexOf(b[_this.fields[coords.x]]));
} else {
return (1) * (a[_this.fields[coords.x]] - b[_this.fields[coords.x]]);
}
});
});
}
var datasetsForPoints = datasetsForLine.filter(function (dataset) {
return dataset.length === 1;
});
datasetsForLine = datasetsForLine.filter(function (dataset) {
return dataset.length > 1;
});
datasetsForLine.forEach(function (dataset, i) {
if (!_this.paths[i]) {
_this.paths[i] = create$a('path');
_this.paths[i].setAttribute('data-id', "path-".concat(i));
_this.g.appendChild(_this.paths[i]);
}
if (_area && !_this.areaPaths[i]) {
_this.areaPaths[i] = create$a('path');
_this.areaPaths[i].setAttribute('data-id', "area-path-".concat(i));
_this.g.appendChild(_this.areaPaths[i]);
}
});
var datasetsForArea = [];
if (_area) {
var horizontalArea = ['left', 'right'].indexOf(_area) > -1;
// console.log(
// "AREA",
// _area,
// "zero",
// zero,
// "xDomain:",
// xDomain,
// "yDomain:",
// yDomain
// );
datasetsForLine.forEach(function (dataset) {
var _ref4, _ref5, _ref6, _ref7;
var dataForAreaBaseline = _this._stacked || _this.hasCustomBaseline ? _toConsumableArray$c(dataset).reverse().map(function (d) {
var _ref2, _ref3;
return horizontalArea ? (_ref2 = {
x: d[_this.fields[coords.x0]],
y: d[_this.fields[coords.y]]
}, _defineProperty$1(_ref2, _this.fields[coords.x0], d["".concat(_this._stacked ? 'stacked_' : '').concat(_this.fields[coords.x0])]), _defineProperty$1(_ref2, _this.fields[coords.y], d[_this.fields[coords.y]]), _ref2) : (_ref3 = {
x: d[_this.fields[coords.x]],
y: d[_this.fields[coords.y0]]
}, _defineProperty$1(_ref3, _this.fields[coords.x], d[_this.fields[coords.x]]), _defineProperty$1(_ref3, _this.fields[coords.y0], d["".concat(_this._stacked ? 'stacked_' : '').concat(_this.fields[coords.y0])]), _ref3);
}) : [horizontalArea ? (_ref4 = {
x: _zero,
y: dataset[dataset.length - 1][_this.fields[coords.y]]
}, _defineProperty$1(_ref4, _this.fields[coords.x], _zero), _defineProperty$1(_ref4, _this.fields[coords.y], dataset[dataset.length - 1][_this.fields[coords.y]]), _ref4) : (_ref5 = {
x: dataset[dataset.length - 1][_this.fields[coords.x]],
y: _zero
}, _defineProperty$1(_ref5, _this.fields[coords.x], dataset[dataset.length - 1][_this.fields[coords.x]]), _defineProperty$1(_ref5, _this.fields[coords.y], _zero), _ref5), horizontalArea ? (_ref6 = {
x: _zero,
y: dataset[0][_this.fields[coords.y]]
}, _defineProperty$1(_ref6, _this.fields[coords.x], _zero), _defineProperty$1(_ref6, _this.fields[coords.y], dataset[0][_this.fields[coords.y]]), _ref6) : (_ref7 = {
x: dataset[0][_this.fields[coords.x]],
y: _zero
}, _defineProperty$1(_ref7, _this.fields[coords.x], dataset[0][_this.fields[coords.x]]), _defineProperty$1(_ref7, _this.fields[coords.y], _zero), _ref7)];
// console.log('dataForAreaBaseline', dataForAreaBaseline)
datasetsForArea.push(dataForAreaBaseline);
// console.log('NOW datasetsForArea is', datasetsForArea)
});
}
if (_area && _this.areaPaths.length > 0) {
// console.log("datasetsForArea", datasetsForArea);
datasetsForArea.forEach(function (dataset, i) {
var _dAreas$;
var areaPath = _this.areaPaths[i];
// const dArea = this.interpolationFunction(
// //[].concat(datasetsForLine[i])
// [].concat(datasetsForLine[i], dataset)
// );
var dAreas = [_this.interpolationFunction([].concat(datasetsForLine[i])), _this.interpolationFunction([].concat(dataset))];
dAreas[1][0] = (dAreas === null || dAreas === void 0 || (_dAreas$ = dAreas[1]) === null || _dAreas$ === void 0 ? void 0 : _dAreas$[0].replace(/M/, 'L')) || [];
//console.log("dArea", dArea, 'from', datasetsForLine[i], dataset);
// console.log('dAreas', dAreas)
areaPath.setAttribute('d', [].concat(_toConsumableArray$c(dAreas[0]), _toConsumableArray$c(dAreas[1])).join(''));
areaPath.setAttribute('fill', _this.attr('fill')());
areaPath.setAttribute('fill-opacity', _this.attr('fillOpacity')());
areaPath.setAttribute('stroke', 'none');
});
}
// console.log('LINE CHART', datasetsForLine)
// console.log(this)
datasetsForLine.forEach(function (dataset, i) {
// console.log('interpolationFunction', this.interpolationFunction)
var d = _this.interpolationFunction([].concat(dataset));
var path = _this.paths[i];
path.setAttribute('d', d.join(''));
path.setAttribute('stroke', _this.attr('stroke')());
path.setAttribute('stroke-width', _this.attr('strokeWidth')());
path.setAttribute('stroke-opacity', _this.attr('strokeOpacity')());
path.setAttribute('stroke-linejoin', 'round');
path.setAttribute('fill', 'none');
});
datasetsForPoints.forEach(function (dataset) {
var singlePoints = dataset.filter(function (d, i, points) {
return (isNull$d(points[i - 1]) || isNull$d(points[i - 1][_this.fields[coords.y]])) && !isNull$d(d[_this.fields[coords.y]]) && (isNull$d(points[i + 1]) || isNull$d(points[i + 1][_this.fields[coords.y]]));
});
// TODO: if the data changes and new single points are added they won't be rendered
if (!_this.points) {
_this.points = [];
_this.g.querySelectorAll('circle').forEach(function (d) {
return d.remove();
});
singlePoints.forEach(function (point) {
var circle = create$a('circle');
_this.points.push({
circle: circle,
point: point
});
_this.g.appendChild(circle);
});
}
_this.points.forEach(function (d) {
var cx = _this.parentNode.scales[coords.x][_this.scales[coords.x]](d.point[_this.fields[coords.x]]);
if (!isNaN(cx)) {
d.circle.setAttribute('cx', cx);
}
var cy = _this.parentNode.scales[coords.y][_this.scales[coords.y]](d.point[_this.fields[coords.y]]);
if (!isNaN(cy)) {
d.circle.setAttribute('cy', cy);
}
d.circle.setAttribute('fill', _this.attr('stroke')());
d.circle.setAttribute('r', _this.attr('strokeWidth')());
});
});
// Setting anchors
// console.log('anchors', _data)
_data.filter(function (d) {
return d;
}).forEach(function (d) {
var cx = _this.parentNode.scales[coords.x][_this.scales[coords.x]](_this._stacked ? d["stacked_".concat(_this.fields[coords.x])] : d === null || d === void 0 ? void 0 : d[_this.fields[coords.x]]);
var cy = _this.parentNode.scales[coords.y][_this.scales[coords.y]](_this._stacked ? d["stacked_".concat(_this.fields[coords.y])] : d === null || d === void 0 ? void 0 : d[_this.fields[coords.y]]);
d.anchorPoints = {
x: cx,
width: 0,
y: cy,
height: 0,
relativePosition: [0, -1],
directions: {
x: 1,
y: 1
},
alignment: {
horizontal: 'middle',
vertical: 'top'
}
};
});
if (_this.paths.length || _this.areaPaths.length) {
_this.objects.forEach(function (obj) {
return obj.draw();
});
}
}
return _this;
};
}
chrtLine.prototype = Object.create(chrtObject$3.prototype);
chrtLine.prototype.constructor = chrtLine;
chrtLine.parent = chrtObject$3.prototype;
chrtLine.prototype = Object.assign(chrtLine.prototype, {
width: lineWidth$1,
strokeWidth: lineWidth$1,
color: lineColor$1,
stroke: lineColor$1,
opacity: lineOpacity,
strokeOpacity: lineOpacity,
area: area,
fill: fillColor$1,
fillOpacity: fillOpacity$3,
zero: zero,
sort: sort
});
// export default chrtLine;
function chrtLine$1 () {
return new chrtLine();
}
// chrt-bars v0.0.49 Copyright 2020-2024 chrt chrt.io
function _toConsumableArray$b(arr) {
return _arrayWithoutHoles$b(arr) || _iterableToArray$b(arr) || _unsupportedIterableToArray$b(arr) || _nonIterableSpread$b();
}
function _arrayWithoutHoles$b(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$b(arr);
}
function _iterableToArray$b(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$b(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$b(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$b(o, minLen);
}
function _arrayLikeToArray$b(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$b() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function lineWidth(value) {
return this.attr('strokeWidth', value);
}
function lineColor(value) {
return this.attr('stroke', value);
}
function fillColor(value) {
return this.attr('fill', value);
}
function fillOpacity$2(value) {
return this.attr('fillOpacity', value);
}
function strokeOpacity$3(value) {
return this.attr('strokeOpacity', value);
}
function width(value) {
return this.attr('barRatioWidth', value, function (value) {
return Math.max(0, Math.min(value, 1));
});
}
function inset(value) {
return this.attr('inset', value, function (value) {
return Math.max(0, value);
});
}
function binwidth(value) {
return this.attr('binwidth', value, function (value) {
return Math.max(0, value);
});
}
// export const DEFAULT_WIDTH = 600;
// export const DEFAULT_HEIGHT = 300;
//
// export const TICKS_DEFAULT = 10;
//
// export const COMPONENTS_W_DATA = ['chrt', 'series'];
//
// export const ORIENTATIONS = {
// x: ['top', 'bottom'],
// y: ['left', 'right'],
// }
//
// export const DEFAULT_ORIENTATION = {
// x: 'bottom',
// y: 'left',
// }
var DEFAULT_STROKE_WIDTH$2 = 0;
var DEAULT_LINE_COLOR = '#000';
var DEAULT_FILL_COLOR = '#ddd';
var DEFAULT_STROKE_OPACITY$2 = 1;
var DEFAULT_FILL_OPACITY$2 = 1;
var DEFAULT_BAR_WIDTH = 3;
var DEFAULT_BAR_RADIO_WIDTH = 1;
var DEFAULT_BAR_INSET = 1;
var MIN_BAR_SIZE = 1;
var isNull$2$2 = index$3.isNull,
isInfinity$2$1 = index$3.isInfinity,
create$2$1 = index$3.createSVG;
function chrtBars() {
var _this = this;
chrtObject$3.call(this);
this.type = 'series';
this._stacked = null;
this._grouped = 1;
this._groupIndex = 0; //this.strokeWidth = DEFAULT_STROKE_WIDTH;
var _barWidth = DEFAULT_BAR_WIDTH;
this.attr('barRatioWidth', DEFAULT_BAR_RADIO_WIDTH);
this.attr('inset', DEFAULT_BAR_INSET);
this.attr('stroke', DEAULT_LINE_COLOR);
this.attr('fill', DEAULT_FILL_COLOR);
this.attr('fillOpacity', DEFAULT_FILL_OPACITY$2);
this.attr('strokeWidth', DEFAULT_STROKE_WIDTH$2);
this.attr('strokeOpacity', DEFAULT_STROKE_OPACITY$2);
this._classNames = ['chrt-bars'];
this.getXScale = function () {
var _this$parentNode2;
if (isNull$2$2(_this.fields.x)) {
var _this$parentNode;
_this.fields.x = (_this$parentNode = _this.parentNode) === null || _this$parentNode === void 0 ? void 0 : _this$parentNode.scales.x[_this.scales.x].field;
}
return (_this$parentNode2 = _this.parentNode) === null || _this$parentNode2 === void 0 ? void 0 : _this$parentNode2.scales.x[_this.scales.x];
};
this.barWidth = function () {
return _barWidth;
};
this.draw = function () {
var _this$g$classList, _this$g$classList2;
if (!_this.parentNode) {
return _this;
}
var _this$parentNode3 = _this.parentNode,
_margins = _this$parentNode3._margins,
scales = _this$parentNode3.scales;
cssDisplay$3.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$b(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$b(_this._classNames)); // if(this.ariaLabel) {
//this.g.setAttribute('aria-label', this.ariaLabel.label ?? this.ariaLabel);
_this.g.setAttribute('aria-label', _this.attr('aria')()); //}
if (isNull$2$2(_this.fields.y)) {
_this.fields.y = scales.y[_this.scales.y].field;
}
if (isNull$2$2(_this.fields.x)) {
_this.fields.x = scales.x[_this.scales.x].field;
}
if (isNull$2$2(_this.fields.x0)) {
_this.fields.x0 = "".concat(scales.x[_this.scales.x].field, "0");
}
var _scaleX = scales.x[_this.scales.x];
var _scaleY = scales.y[_this.scales.y];
var _data = _this._data.length ? _this._data : _this.parentNode._data;
if (!isNull$2$2(_data)) {
var padding = _this.parentNode.padding();
var rangeWidth = Math.abs(_scaleY.range[1] - _scaleY.range[0]) - (_margins.top + _margins.bottom);
if (_scaleY.transformation === 'ordinal') {
_barWidth = rangeWidth / (_data.length || 1);
} else {
var n = Math.max(_scaleY.ticks().length, _data.length);
_barWidth = rangeWidth / (_scaleY.ticks(n).filter(function (d) {
return _scaleY.isLog() ? !d.isMinor : true;
}).length - 1 || 1);
}
var getBarModifier = function getBarModifier() {
var barWidthModifier = _data.reduce(function (overlap, d, i, arr) {
if (d && arr[i + 1]) {
var field0 = _scaleY(d[_this.fields.y]);
var field1 = _scaleY(arr[i + 1][_this.fields.y]);
overlap = Math.abs(field1 - field0) / _barWidth;
}
return Math.min(1, overlap);
}, 1);
return barWidthModifier;
};
_barWidth = _barWidth * getBarModifier.call(_this);
var barWidth = (_barWidth) || MIN_BAR_SIZE;
if (isNaN(barWidth) || isInfinity$2$1(barWidth)) {
barWidth = MIN_BAR_SIZE;
}
barWidth = barWidth * (_this._group ? _this._group.width() : 1);
var _grouped = _this._stacked ? _this._stacked._grouped : _this._grouped || _this._grouped;
var _groupIndex = _this._stacked ? _this._stacked._groupIndex : _this._groupIndex || _this._groupIndex;
_barWidth = barWidth / _grouped; // _barWidth = Math.max(_barWidth - (this.attr('inset')()), MIN_BAR_SIZE);
var deltaY = barWidth / _grouped * _groupIndex + barWidth / _grouped / 2 - barWidth / 2;
_this.g.setAttribute('transform', "translate(0, ".concat(deltaY, ")"));
var yAxis = _this.parentNode.getAxis('y');
var axisLineWidth = yAxis ? yAxis.width()() : 0; // redefine padding to accomodate bars withing the chart area
if (_data.length && _scaleY.barwidth > 0) {
var _padding$bottom, _padding$top;
var w = Math.abs(_scaleY.range[1] - _scaleY.range[0]) - (_margins.top + _margins.bottom);
var bw = _scaleY.transformation === 'ordinal' ? w / _data.length : w / _scaleY.ticks().length;
var _deltaY = _scaleY.range[1] - _barWidth / 2;
if (!_this.parentNode.originalPadding && _scaleY.transformation !== 'ordinal' && (_deltaY < ((_padding$bottom = padding === null || padding === void 0 ? void 0 : padding.bottom) !== null && _padding$bottom !== void 0 ? _padding$bottom : 0) || _deltaY > ((_padding$top = padding === null || padding === void 0 ? void 0 : padding.top) !== null && _padding$top !== void 0 ? _padding$top : 0))) {
var _padding = _this.parentNode.padding();
var newPadding = Object.assign({}, _padding, {
bottom: bw / 2 + _padding.bottom,
top: bw / 2 + _padding.top
});
return _this.parentNode.padding(newPadding, true);
}
} // remove old points from SVG
var dataChildrenDelta = _this.g.childElementCount - _this._data.length; // console.log('dataChildrenDelta', dataChildrenDelta)
if (dataChildrenDelta > 0) {
Array.from({
length: dataChildrenDelta
}, function (_, i) {
return i + _this._data.length;
}).forEach(function (d) {
var dataID = escape("rect-".concat(name, "-").concat(d));
_this.g.querySelector("[data-id='".concat(dataID, "']")).remove();
});
}
_data.forEach(function (d, i, arr) {
var dataID = escape("rect-".concat(name, "-").concat(i));
var rect = _this.g.querySelector("[data-id='".concat(dataID, "']"));
if (!rect) {
rect = create$2$1('rect');
rect.setAttribute('data-id', dataID);
rect.setAttribute('shape-rendering', 'crispEdges');
rect.setAttribute('role', 'graphics-symbol');
rect.setAttribute('aria-roledescription', 'bar');
rect.setAttribute('tabindex', 0);
_this.g.appendChild(rect);
}
var ariaLabel = _this.attr('aria')(d, i, arr);
if (ariaLabel) {
rect.setAttribute('aria-label', ariaLabel);
}
var y = _scaleY(d[_this.fields.y]);
if (isNaN(y)) {
return;
}
var x = _scaleX(d[_this._stacked ? "stacked_".concat(_this.fields.x) : _this.fields.x]);
var x0 = !isNull$2$2(d[_this._stacked ? "stacked_".concat(_this.fields.x, "0") : _this.fields.x0]) ? _scaleX.isLog() ? _scaleX.range[0] + _margins.left : _scaleX(d[_this._stacked ? "stacked_".concat(_this.fields.x, "0") : _this.fields.x0]) : null;
if (isNull$2$2(x0)) {
x0 = _scaleX.isLog() ? _scaleX.range[0] + _margins.left : _scaleX(_scaleX.domain[0] || 0);
if ((_scaleX.domain[0] || 0) * (_scaleX.domain[1] || 0) < 0) {
x0 = _scaleX.isLog() ? _scaleX.range[0] + _margins.left : _scaleX(0);
}
}
var _barLength = !isNaN(x) ? Math.max(Math.abs(x - x0), Math.abs(x - x0) - axisLineWidth / 2) : 0;
var _barX = x > x0 ? x0 : x;
if (typeof _this.binwidth()() !== 'undefined') {
_barWidth = Math.abs(_scaleY(d[_this.fields.y] + _this.binwidth()(d, i, arr)) - _scaleY(d[_this.fields.y]));
}
var strokeWidth = _this.attr('strokeWidth')(d, i, arr);
var anchorPoints = {};
anchorPoints.x = (isNaN(_barX) || isInfinity$2$1(_barX) ? _scaleX.range[0] : _barX) + strokeWidth * 0.5;
anchorPoints.directions = {
x: x > x0 ? 1 : 0,
y: 1
};
anchorPoints.y = y - _barWidth / 2 + _barWidth / 2 * (1 - _this.attr('barRatioWidth')(d, i, arr)) + strokeWidth * 0.5 + _this.attr('inset')(d, i, arr) * 0.5;
anchorPoints.width = Math.max(0, _barLength - strokeWidth);
anchorPoints.height = Math.max(0, _barWidth * _this.attr('barRatioWidth')(d, i, arr) - strokeWidth - _this.attr('inset')(d, i, arr));
anchorPoints.left = anchorPoints.x;
anchorPoints.top = anchorPoints.y;
anchorPoints.right = anchorPoints.x + anchorPoints.width;
anchorPoints.bottom = anchorPoints.y + anchorPoints.height;
anchorPoints.relativePosition = [1, 0.5];
d.anchorPoints = anchorPoints;
rect.setAttribute('x', anchorPoints.x);
rect.setAttribute('y', anchorPoints.y);
rect.setAttribute('width', anchorPoints.width);
rect.setAttribute('height', anchorPoints.height);
rect.setAttribute('fill', _this.attr('fill')(d, i, arr));
rect.setAttribute('fill-opacity', _this.attr('fillOpacity')(d, i, arr));
rect.setAttribute('stroke', _this.attr('stroke')(d, i, arr));
rect.setAttribute('stroke-width', strokeWidth);
rect.setAttribute('stroke-opacity', _this.attr('strokeOpacity')(d, i, arr));
});
}
_this.objects.forEach(function (obj) {
return obj.draw();
});
return _this;
};
}
chrtBars.prototype = Object.create(chrtObject$3.prototype);
chrtBars.prototype.constructor = chrtBars;
chrtBars.parent = chrtObject$3.prototype;
chrtBars.prototype = Object.assign(chrtBars.prototype, {
width: width,
inset: inset,
strokeWidth: lineWidth,
color: lineColor,
stroke: lineColor,
fill: fillColor,
fillOpacity: fillOpacity$2,
strokeOpacity: strokeOpacity$3,
binwidth: binwidth
});
function chrtBars$1 () {
return new chrtBars();
}
var isNull$1$3 = index$3.isNull,
isInfinity$1$1 = index$3.isInfinity,
create$1$1 = index$3.createSVG;
function chrtColumns() {
var _this = this;
chrtObject$3.call(this);
this.type = 'series';
this._stacked = null;
this._grouped = 1;
this._groupIndex = 0;
var _barWidth = DEFAULT_BAR_WIDTH;
this.attr('barRatioWidth', DEFAULT_BAR_RADIO_WIDTH);
this.attr('inset', DEFAULT_BAR_INSET);
this.attr('stroke', DEAULT_LINE_COLOR);
this.attr('fill', DEAULT_FILL_COLOR);
this.attr('fillOpacity', DEFAULT_FILL_OPACITY$2);
this.attr('strokeWidth', DEFAULT_STROKE_WIDTH$2);
this.attr('strokeOpacity', DEFAULT_STROKE_OPACITY$2); // this.attr('binwidth', null);
this._classNames = ['chrt-columns'];
this.getXScale = function () {
var _this$parentNode2;
if (isNull$1$3(_this.fields.x)) {
var _this$parentNode;
_this.fields.x = (_this$parentNode = _this.parentNode) === null || _this$parentNode === void 0 ? void 0 : _this$parentNode.scales.x[_this.scales.x].field;
}
return (_this$parentNode2 = _this.parentNode) === null || _this$parentNode2 === void 0 ? void 0 : _this$parentNode2.scales.x[_this.scales.x];
};
this.draw = function () {
var _this$g$classList, _this$g$classList2;
if (!_this.parentNode) {
return _this;
}
var _this$parentNode3 = _this.parentNode,
_margins = _this$parentNode3._margins,
scales = _this$parentNode3.scales;
cssDisplay$3.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$b(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$b(_this._classNames));
if (isNull$1$3(_this.fields.x)) {
_this.fields.x = scales.x[_this.scales.x].field;
}
if (isNull$1$3(_this.fields.y)) {
_this.fields.y = scales.y[_this.scales.y].field;
}
if (isNull$1$3(_this.fields.y0)) {
_this.fields.y0 = "".concat(scales.y[_this.scales.y].field, "0");
}
var _scaleX = scales.x[_this.scales.x];
var _scaleY = scales.y[_this.scales.y];
var _data = _this._data.length ? _this._data : _this.parentNode._data;
if (!isNull$1$3(_data)) {
var padding = _this.parentNode.padding();
var rangeWidth = Math.abs(_scaleX.range[1] - _scaleX.range[0]) - (_margins.left + _margins.right);
if (_scaleX.transformation === 'ordinal') {
_barWidth = rangeWidth / (_data.length || 1);
} else {
var n = Math.max(_scaleX.ticks().length, _data.length);
_barWidth = rangeWidth / (_scaleX.ticks(n).filter(function (d) {
return _scaleX.isLog() ? !d.isMinor : true;
}).length - 1 || 1);
}
var getBarModifier = function getBarModifier() {
var barWidthModifier = _data.reduce(function (overlap, d, i, arr) {
if (d && arr[i + 1]) {
var field0 = _scaleX(d[_this.fields.x]);
var field1 = _scaleX(arr[i + 1][_this.fields.x]);
overlap = Math.abs(field1 - field0) / _barWidth;
}
return Math.min(1, overlap);
}, 1);
return barWidthModifier;
};
_barWidth = _barWidth * getBarModifier.call(_this);
var barWidth = (_barWidth) || MIN_BAR_SIZE;
if (isNaN(barWidth) || isInfinity$1$1(barWidth)) {
barWidth = MIN_BAR_SIZE;
}
barWidth = barWidth * (_this._group ? _this._group.width() : 1);
var _grouped = _this._stacked ? _this._stacked._grouped : _this._grouped || _this._grouped;
var _groupIndex = _this._stacked ? _this._stacked._groupIndex : _this._groupIndex || _this._groupIndex;
_barWidth = barWidth / _grouped;
var deltaX = barWidth / _grouped * _groupIndex + barWidth / _grouped / 2 - barWidth / 2;
_this.g.setAttribute('transform', "translate(".concat(deltaX, ", 0)"));
var xAxis = _this.parentNode.getAxis('x');
var axisLineWidth = xAxis ? xAxis.lineWidth()() : 0; // redefine padding to accomodate bars withing the chart area
if (_data.length && _scaleX.barwidth > 0) {
var _padding$left, _padding$right;
var w = _scaleX.range[1] - _scaleX.range[0] - (_margins.left + _margins.right);
var bw = _scaleX.transformation === 'ordinal' ? w / _data.length : w / _scaleX.ticks().length;
var _deltaX = _scaleX.range[0] - _barWidth / 2;
if (!_this.parentNode.originalPadding && _scaleX.transformation !== 'ordinal' && (_deltaX < ((_padding$left = padding === null || padding === void 0 ? void 0 : padding.left) !== null && _padding$left !== void 0 ? _padding$left : 0) || _deltaX > ((_padding$right = padding === null || padding === void 0 ? void 0 : padding.right) !== null && _padding$right !== void 0 ? _padding$right : 0))) {
var _padding = _this.parentNode.padding();
var newPadding = Object.assign({}, _padding, {
left: bw / 2 + _padding.left,
right: bw / 2 + _padding.right
});
return _this.parentNode.padding(newPadding, true);
}
} // remove old points from SVG
var dataChildrenDelta = _this.g.childElementCount - _this._data.length; // console.log('dataChildrenDelta', dataChildrenDelta)
if (dataChildrenDelta > 0) {
Array.from({
length: dataChildrenDelta
}, function (_, i) {
return i + _this._data.length;
}).forEach(function (d) {
var dataID = escape("rect-".concat(name, "-").concat(d));
_this.g.querySelector("[data-id='".concat(dataID, "']")).remove();
});
}
_data.forEach(function (d, i, arr) {
var dataID = escape("rect-".concat(name, "-").concat(i));
var rect = _this.g.querySelector("[data-id='".concat(dataID, "']"));
if (!rect) {
rect = create$1$1('rect');
rect.setAttribute('data-id', dataID);
rect.setAttribute('shape-rendering', 'crispEdges');
_this.g.appendChild(rect);
}
var x = _scaleX(d[_this.fields.x]); // - _barWidth / 2;
if (isNaN(x)) {
return;
}
var y = _scaleY(d[_this._stacked ? "stacked_".concat(_this.fields.y) : _this.fields.y]); //let y0 = !isNull(d[this.fields.y0]) ? _scaleY(d[this.fields.y0]) : null;
var y0 = !isNull$1$3(d[_this._stacked ? "stacked_".concat(_this.fields.y, "0") : _this.fields.y0]) ? _scaleY(d[_this._stacked ? "stacked_".concat(_this.fields.y, "0") : _this.fields.y0]) : null;
if (isNull$1$3(y0)) {
y0 = _scaleY.isLog() ? _scaleY.range[0] - _margins.bottom : _scaleY(_scaleY.domain[0] || 0);
if ((_scaleY.domain[0] || 0) * (_scaleY.domain[1] || 0) < 0) {
y0 = _scaleY.isLog() ? _scaleY.range[0] - _margins.bottom : _scaleY(0);
}
}
var _barLength = !isNaN(y) ? Math.max(Math.abs(y - y0), Math.abs(y - y0) - axisLineWidth / 2) : 0;
var _barY = y > y0 ? y0 : y;
if (typeof _this.binwidth()() !== 'undefined') {
_barWidth = Math.abs(_scaleX(d[_this.fields.x] + _this.binwidth()(d, i, arr)) - _scaleX(d[_this.fields.x]));
}
var strokeWidth = _this.attr('strokeWidth')(d, i, arr);
var anchorPoints = {};
anchorPoints.x = x - _barWidth / 2 + _barWidth / 2 * (1 - _this.attr('barRatioWidth')(d, i, arr)) + strokeWidth * 0.5 + _this.attr('inset')(d, i, arr) / 2;
anchorPoints.y = (isNaN(_barY) || isInfinity$1$1(_barY) ? _scaleY.range[0] : _barY) + strokeWidth * 0.5;
anchorPoints.directions = {
x: 1,
y: y > y0 ? 0 : 1
};
anchorPoints.width = Math.max(0, _barWidth * _this.attr('barRatioWidth')(d, i, arr) - strokeWidth - _this.attr('inset')(d, i, arr));
anchorPoints.height = Math.max(0, isNaN(_barLength) ? 0 : _barLength - strokeWidth);
anchorPoints.left = anchorPoints.x;
anchorPoints.right = anchorPoints.x + anchorPoints.width;
anchorPoints.top = anchorPoints.y;
anchorPoints.bottom = anchorPoints.y - anchorPoints.height;
anchorPoints.relativePosition = [0.5, 0];
anchorPoints.alignment = {
horizontal: 'middle',
vertical: 'top'
};
d.anchorPoints = anchorPoints;
rect.setAttribute('x', anchorPoints.x);
rect.setAttribute('y', anchorPoints.y);
rect.setAttribute('width', anchorPoints.width);
rect.setAttribute('height', anchorPoints.height);
rect.setAttribute('fill', _this.attr('fill')(d, i, arr));
rect.setAttribute('fill-opacity', _this.attr('fillOpacity')(d, i, arr));
rect.setAttribute('stroke', _this.attr('stroke')(d, i, arr));
rect.setAttribute('stroke-width', strokeWidth);
rect.setAttribute('stroke-opacity', _this.attr('strokeOpacity')(d, i, arr)); // rect.setAttribute('stroke-linecap', 'square');
});
}
_this.objects.forEach(function (obj) {
return obj.draw();
});
return _this.parentNode;
};
}
chrtColumns.prototype = Object.create(chrtObject$3.prototype);
chrtColumns.prototype.constructor = chrtColumns;
chrtColumns.parent = chrtObject$3.prototype;
chrtColumns.prototype = Object.assign(chrtColumns.prototype, {
width: width,
inset: inset,
strokeWidth: lineWidth,
color: lineColor,
stroke: lineColor,
fill: fillColor,
fillOpacity: fillOpacity$2,
strokeOpacity: strokeOpacity$3,
binwidth: binwidth
});
function chrtColumns$1 () {
return new chrtColumns();
}
var isNull$c = index$3.isNull,
isInfinity$6 = index$3.isInfinity,
create$9 = index$3.createSVG;
function chrtHistograms() {
var _this = this;
chrtObject$3.call(this);
this.type = 'series';
this._stacked = null;
this._grouped = 1;
this._groupIndex = 0;
var _barWidth = DEFAULT_BAR_WIDTH;
this.attr('barRatioWidth', DEFAULT_BAR_RADIO_WIDTH);
this.attr('inset', DEFAULT_BAR_INSET);
this.attr('stroke', DEAULT_LINE_COLOR);
this.attr('fill', DEAULT_FILL_COLOR);
this.attr('fillOpacity', DEFAULT_FILL_OPACITY$2);
this.attr('strokeWidth', DEFAULT_STROKE_WIDTH$2);
this.attr('strokeOpacity', DEFAULT_STROKE_OPACITY$2); // this.attr('binwidth', null);
this._classNames = ['chrt-columns'];
this.getXScale = function () {
var _this$parentNode2;
if (isNull$c(_this.fields.x)) {
var _this$parentNode;
_this.fields.x = (_this$parentNode = _this.parentNode) === null || _this$parentNode === void 0 ? void 0 : _this$parentNode.scales.x[_this.scales.x].field;
}
return (_this$parentNode2 = _this.parentNode) === null || _this$parentNode2 === void 0 ? void 0 : _this$parentNode2.scales.x[_this.scales.x];
};
this.draw = function () {
var _this$g$classList, _this$g$classList2;
if (!_this.parentNode) {
return _this;
}
var _this$parentNode3 = _this.parentNode,
_margins = _this$parentNode3._margins,
scales = _this$parentNode3.scales;
cssDisplay$3.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$b(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$b(_this._classNames));
if (isNull$c(_this.fields.x)) {
_this.fields.x = scales.x[_this.scales.x].field;
}
if (isNull$c(_this.fields.y)) {
_this.fields.y = scales.y[_this.scales.y].field;
}
if (isNull$c(_this.fields.y0)) {
_this.fields.y0 = "".concat(scales.y[_this.scales.y].field, "0");
}
var _scaleX = scales.x[_this.scales.x];
var _scaleY = scales.y[_this.scales.y];
var _data = _this._data.length ? _this._data : _this.parentNode._data;
if (!isNull$c(_data)) {
// console.log(_data)
if (!_data.some(function (d) {
return !isNull$c(d.x0) || !isNull$c(d.x);
})) {
console.warn('chrtHistograms expects data points to contain x0 and x1 fields');
return _this;
}
if (!_data.some(function (d) {
return !isNull$c(d.x1);
})) {
console.warn('chrtHistograms expects data points to contain x0 and x1 fields');
return _this;
}
var binsData = [].concat(_toConsumableArray$b(_data.map(function (d) {
return d.x0;
})), _toConsumableArray$b(_data.map(function (d) {
return d.x1;
})));
var binsExtents = [Math.min.apply(Math, _toConsumableArray$b(binsData)), Math.max.apply(Math, _toConsumableArray$b(binsData))]; // console.log(_scaleX.domain,binsExtents)
if (isNaN(_scaleX.domain[0]) || isNaN(_scaleX.domain[1]) || _scaleX.domain[0] > binsExtents[0] || _scaleX.domain[1] < binsExtents[1]) {
_this.parentNode.x({
domain: binsExtents
});
}
if (_scaleY.domain[0] > 0) {
_this.parentNode.y({
domain: [0, _scaleY.domain[1]]
});
}
var xAxis = _this.parentNode.getAxis('x');
var axisLineWidth = xAxis ? xAxis.lineWidth()() : 0;
_data.forEach(function (d, i, arr) {
var rect = _this.g.querySelector("[data-id='rect-".concat(name, "-").concat(i, "']"));
if (!rect) {
rect = create$9('rect');
rect.setAttribute('data-id', "rect-".concat(name, "-").concat(i));
rect.setAttribute('shape-rendering', 'crispEdges');
_this.g.appendChild(rect);
}
var x0 = _scaleX(isNull$c(d["".concat(_this.fields.x, "0")]) ? d[_this.fields.x] : d["".concat(_this.fields.x, "0")]); // console.log('x0', d[`${this.fields.x}0`], x0)
if (isNaN(x0)) {
return;
}
var x1 = _scaleX(d["".concat(_this.fields.x, "1")]);
if (isNaN(x1)) {
return;
}
_barWidth = Math.abs(x1 - x0);
var y = _scaleY(d[_this._stacked ? "stacked_".concat(_this.fields.y) : _this.fields.y]); // let y0 = !isNull(d[this.fields.y0]) ? _scaleY(d[this.fields.y0]) : null;
//let y0 = _scaleY(d[this._stacked ? `stacked_${this.fields.y}0` : `${this.fields.y}0`]);
var y0 = !isNull$c(d[_this._stacked ? "stacked_".concat(_this.fields.y, "0") : _this.fields.y0]) ? _scaleY(d[_this._stacked ? "stacked_".concat(_this.fields.y, "0") : _this.fields.y0]) : null; // console.log('y0',d)
if (isNull$c(y0)) {
y0 = _scaleY.isLog() ? _scaleY.range[0] - _margins.bottom : _scaleY(_scaleY.domain[0] || 0);
if ((_scaleY.domain[0] || 0) * (_scaleY.domain[1] || 0) < 0) {
y0 = _scaleY.isLog() ? _scaleY.range[0] - _margins.bottom : _scaleY(0);
}
}
var _barLength = !isNaN(y) ? Math.max(Math.abs(y - y0), Math.abs(y - y0) - axisLineWidth / 2) : 0; // console.log(y,'-',y0,'=',_barLength)
var _barY = y > y0 ? y0 : y;
var strokeWidth = _this.attr('strokeWidth')(d, i, arr);
var anchorPoints = {};
anchorPoints.x = x0; //(x0 - _barWidth/2) + _barWidth/2 * (1 - this.attr('barRatioWidth')(d, i, arr)) + strokeWidth * 0.5 + this.attr('inset')(d, i, arr)/2;
anchorPoints.y = (isNaN(_barY) || isInfinity$6(_barY) ? _scaleY.range[0] : _barY) + strokeWidth * 0.5;
anchorPoints.directions = {
x: 1,
y: y > y0 ? 0 : 1
};
var barWidthRatio = _this.attr('barRatioWidth')(d, i, arr);
var barWidthMargins = strokeWidth + _this.attr('inset')(d, i, arr);
anchorPoints.width = Math.max(0, _barWidth * barWidthRatio - barWidthMargins);
anchorPoints.height = Math.max(0, isNaN(_barLength) ? 0 : _barLength - strokeWidth);
anchorPoints.x = anchorPoints.x + (_barWidth - anchorPoints.width) / 2;
anchorPoints.left = anchorPoints.x;
anchorPoints.right = anchorPoints.x + anchorPoints.width;
anchorPoints.top = anchorPoints.y;
anchorPoints.bottom = anchorPoints.y - anchorPoints.height;
anchorPoints.relativePosition = [0.5, 0];
anchorPoints.alignment = {
horizontal: 'middle',
vertical: 'top'
};
d.anchorPoints = anchorPoints;
rect.setAttribute('x', anchorPoints.x);
rect.setAttribute('y', anchorPoints.y);
rect.setAttribute('width', anchorPoints.width);
rect.setAttribute('height', anchorPoints.height);
rect.setAttribute('fill', _this.attr('fill')(d, i, arr));
rect.setAttribute('fill-opacity', _this.attr('fillOpacity')(d, i, arr));
rect.setAttribute('stroke', _this.attr('stroke')(d, i, arr));
rect.setAttribute('stroke-width', strokeWidth);
rect.setAttribute('stroke-opacity', _this.attr('strokeOpacity')(d, i, arr)); // rect.setAttribute('stroke-linecap', 'square');
});
}
_this.objects.forEach(function (obj) {
return obj.draw();
});
return _this.parentNode;
};
}
chrtHistograms.prototype = Object.create(chrtObject$3.prototype);
chrtHistograms.prototype.constructor = chrtHistograms;
chrtHistograms.parent = chrtObject$3.prototype;
chrtHistograms.prototype = Object.assign(chrtHistograms.prototype, {
width: width,
inset: inset,
strokeWidth: lineWidth,
color: lineColor,
stroke: lineColor,
fill: fillColor,
fillOpacity: fillOpacity$2,
strokeOpacity: strokeOpacity$3,
binwidth: binwidth
});
function chrtHistograms$1 () {
return new chrtHistograms();
}
// chrt.io v0.0.42 Copyright 2024 chrt
function _toConsumableArray$a(arr) {
return _arrayWithoutHoles$a(arr) || _iterableToArray$a(arr) || _unsupportedIterableToArray$a(arr) || _nonIterableSpread$a();
}
function _arrayWithoutHoles$a(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$a(arr);
}
function _iterableToArray$a(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$a(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$a(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$a(o, minLen);
}
function _arrayLikeToArray$a(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$a() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
// pointRadius has only one modality: radius length in pixel
function pointRadius(value) {
return this.attr('radius', value);
}
// pointSize has 2 modalities:
// 1. pass the size in px, the radius will be calculated as a sqrt function of the area
// 2. pass the size in value and scale options, this will calculate the radius with a custom
// srqt scale
function pointSize$1(value) {
return this.attr('size', value);
}
function pointColor$1(value) {
return this.attr('fill', value);
}
function pointStroke$1(value) {
return this.attr('stroke', value);
}
function pointStrokeWidth$1(value) {
return this.attr('strokeWidth', value);
}
function pointOpacity$1(value) {
return this.attr('fillOpacity', value);
}
function strokeOpacity$2(value) {
return this.attr('strokeOpacity', value);
}
function pointColor$2(value, option) {
return this.attr('symbol', {
symbol: value,
option: option
});
}
function pointRotate(value) {
return this.attr('rotate', value);
}
var DEFAULT_POINT_RADIUS$1 = 3;
var circle = function circle(point) {
var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var r = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_POINT_RADIUS$1;
point.setAttribute('cx', cx);
point.setAttribute('cy', cy);
point.setAttribute('r', Math.max(0, isNaN(r) ? 0 : r));
};
var square = function square(point) {
var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var r = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_POINT_RADIUS$1;
var path = "M".concat(x - r, ",").concat(y - r, "h").concat(r * 2, "v").concat(r * 2, "h").concat(-r * 2, "Z");
point.setAttribute('d', path);
};
var plus = function plus(point) {
var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var r = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_POINT_RADIUS$1;
var path = "M".concat(x, ",").concat(y - r, "v").concat(r * 2, "M").concat(x - r, ",").concat(y, "h").concat(r * 2, "Z");
point.setAttribute('d', path);
};
var times = function times(point) {
var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var r = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_POINT_RADIUS$1;
var path = "M".concat(x - r, ",").concat(y - r, "l").concat(r * 2, ",").concat(r * 2, "m", 0, ",").concat(-r * 2, "l").concat(-r * 2, ",").concat(r * 2);
point.setAttribute('d', path);
};
var custom = function custom(point, path) {
point.setAttribute('d', path);
};
var text = function text(point, _text, r) {
point.setAttribute('x', 0);
point.setAttribute('y', 0);
point.setAttribute('text-anchor', 'middle');
point.setAttribute('dominant-baseline', 'middle');
point.setAttribute('font-size', r);
point.textContent = _text;
};
var shapes = /*#__PURE__*/Object.freeze({
__proto__: null,
circle: circle,
square: square,
plus: plus,
times: times,
custom: custom,
text: text
});
var isNull$b = index$3.isNull,
isInfinity$5 = index$3.isInfinity;
var DEFAULT_POINT_RADIUS = 3;
var DEFAULT_POINT_COLOR$1 = '#000';
var DEFAULT_POINT_ROTATION = 0;
var POINT_SYMBOLS = ['circle', 'square'];
function chrtPoints() {
var _this = this;
chrtObject$3.call(this);
// console.log(this.create)
this.type = 'series';
this.attr('radius', DEFAULT_POINT_RADIUS);
this.attr('stroke', DEFAULT_POINT_COLOR$1);
this.attr('fill', DEFAULT_POINT_COLOR$1);
this.attr('strokeWidth', 0);
this.attr('strokeOpacity', 1);
this.attr('fillOpacity', 1);
this.attr('size', null);
this.attr('rotate', DEFAULT_POINT_ROTATION);
this.attr('symbol', {
symbol: POINT_SYMBOLS[0]
});
this._classNames = ['chrt-points'];
this.getXScale = function () {
if (isNull$b(_this.fields.x)) {
_this.fields.x = _this.parentNode.scales.x[_this.scales.x].field;
}
return _this.parentNode.scales.x[_this.scales.x];
};
this.draw = function () {
var _this$g$classList, _this$g$classList2;
cssDisplay$3.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$a(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$a(_this._classNames));
if (!isNull$b(_this._data)) {
if (isNull$b(_this.fields.x)) {
_this.fields.x = _this.parentNode.scales.x[_this.scales.x].field;
}
if (isNull$b(_this.fields.y)) {
//console.log('this.scales', this.scales)
//console.log('this.parentNode.scales', this.parentNode.scales)
_this.fields.y = _this.parentNode.scales.y[_this.scales.y].field;
}
var rScale = function rScale(d) {
return Math.sqrt(d / Math.PI);
};
var size = _this.attr('size');
var sizeScale = size({});
// console.log('sizeScale', sizeScale)
if (sizeScale !== null && sizeScale !== void 0 && sizeScale.scale) {
// this.parentNode.scale({
// range: sizeValue.options.range || [0,10],
// scale:'sqrt',
// field: sizeValue.options.field || 'r',
// type:'x',
// name: sizeValue.options.field || 'r',
// margins:{top:0, bottom:0, left:0, right:0},
// padding:{top:0, bottom:0, left:0, right:0}
// });
// console.log('REDEFINE rScale')
rScale = function rScale(d) {
var _scale = _this.parentNode.scales.other[sizeScale.scale];
var field = _scale.field;
// console.log(
// '--->',
// d,
// sizeScale.scale,
// field,
// 'domain:',
// _scale.domain,
// 'range:',
// _scale.range,
// d[field],
// this.parentNode.scales.other[sizeScale.scale](d[field])
// )
return _scale(d[field]);
};
}
if (sizeScale !== null && sizeScale !== void 0 && sizeScale.range) {
_this.parentNode.scale({
domain: sizeScale.domain,
range: sizeScale.range || [0, 10],
scale: 'sqrt',
field: sizeScale.field || 'r',
type: 'other',
name: sizeScale.field || 'r',
margins: {
top: 0,
bottom: 0,
left: 0,
right: 0
},
padding: {
top: 0,
bottom: 0,
left: 0,
right: 0
}
});
// console.log('DEFINE rScale', this.parentNode.scales.other)
rScale = function rScale(d) {
var field = sizeScale.field || 'r';
var _scale = _this.parentNode.scales.other[field];
return _scale(d[field]);
};
}
// remove old points from SVG
var dataChildrenDelta = _this.g.childElementCount - _this._data.length;
if (dataChildrenDelta > 0) {
Array.from({
length: dataChildrenDelta
}, function (_, i) {
return i + _this._data.length;
}).forEach(function (i) {
_this.g.querySelector("[data-id='".concat(escape("point-".concat(name, "-").concat(i)), "']")).remove();
});
}
_this._data.forEach(function (d, i, arr) {
if (!isNull$b(_this.parentNode.scales.x[_this.scales.x]) && !isNull$b(_this.parentNode.scales.y[_this.scales.y])) {
var x = _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
var cx = !isNaN(x) && !isInfinity$5(x) ? x : 0;
var cy = !isNaN(y) && !isInfinity$5(y) ? y : 0;
var r = _this.attr('radius')(d, i, arr);
var _size = _this.attr('size')(d, i, arr);
if (!isNull$b(_size)) {
// console.log('d',d,'->',rScale(size(d,i,arr)))
r = rScale(_size !== null && _size !== void 0 && _size.scale || _size !== null && _size !== void 0 && _size.range ? d : _size);
// console.log('rScale', d, size, r)
}
d.anchorPoints = {
x: cx,
width: r,
y: cy,
height: r,
relativePosition: [0, -1],
directions: {
x: 1,
y: 1
},
alignment: {
horizontal: 'middle',
vertical: 'top'
}
};
var _this$attr = _this.attr('symbol')(),
symbol = _this$attr.symbol,
option = _this$attr.option;
var dataID = escape("point-".concat(name, "-").concat(i));
var point = _this.g.querySelector("[data-id='".concat(dataID, "']"));
if (!point) {
//console.log(obj.attr)
//circle = obj.create.call(this, 'circle');
point = index$3.createSVG.call(_this, symbol !== 'circle' && symbol !== 'text' ? 'path' : symbol);
point.setAttribute('data-id', dataID);
_this.g.appendChild(point);
}
d.anchorPoints.node = point;
// console.log('POINT', symbol, point)
if (symbol === 'custom') {
custom(point, option);
} else if (symbol === 'text') {
text(point, option, r * 10);
} else {
shapes[symbol](point, 0, 0, r);
}
point.setAttribute('fill', _this.attr('fill')(d, i, arr));
point.setAttribute('fill-opacity', _this.attr('fillOpacity')(d, i, arr) || 1);
point.setAttribute('stroke', _this.attr('stroke')(d, i, arr));
point.setAttribute('stroke-width', _this.attr('strokeWidth')(d, i, arr));
point.setAttribute('stroke-opacity', _this.attr('strokeOpacity')(d, i, arr));
point.setAttribute('transform-origin', "0 0");
point.setAttribute('transform', "translate(".concat(cx, ", ").concat(cy, ") rotate(").concat(_this.attr('rotate')(d, i, arr), ")"));
}
});
// // // console.log('points', points);
}
_this.objects.forEach(function (obj) {
return obj.draw();
});
// console.log(this);
return _this;
};
}
chrtPoints.prototype = Object.create(chrtObject$3.prototype);
chrtPoints.prototype.constructor = chrtPoints;
chrtPoints.parent = chrtObject$3.prototype;
chrtPoints.prototype = Object.assign(chrtPoints.prototype, {
pointSize: pointSize$1,
size: pointSize$1,
radius: pointRadius,
color: pointColor$1,
fill: pointColor$1,
stroke: pointStroke$1,
strokeWidth: pointStrokeWidth$1,
opacity: pointOpacity$1,
fillOpacity: pointOpacity$1,
rotate: pointRotate,
symbol: pointColor$2,
strokeOpacity: strokeOpacity$2
});
// export default chrtPoints;
function chrtPoints$1 () {
return new chrtPoints();
}
// chrt-object v0.0.19 Copyright 2020-2024 chrt chrt.io
function _toConsumableArray$9(arr) {
return _arrayWithoutHoles$9(arr) || _iterableToArray$9(arr) || _unsupportedIterableToArray$9(arr) || _nonIterableSpread$9();
}
function _arrayWithoutHoles$9(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$9(arr);
}
function _iterableToArray$9(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$9(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$9(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$9(o, minLen);
}
function _arrayLikeToArray$9(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$9() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var COMPONENTS_W_DATA$2 = ['chrt', 'series'];
function isNull$a(value) {
return value === null || value == null || typeof value === 'undefined';
}
function uuid$2() {
return 'c' + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
function hasData$2(obj) {
return !isNull$a(obj.type) && COMPONENTS_W_DATA$2.indexOf(obj.type) > -1;
}
function isInfinity$4(value) {
return !isFinite(value);
}
function oppositeSigns$2(x, y) {
return (x ^ y) < 0;
}
function getCoords$3(data) {
var _this = this;
if (!(this !== null && this !== void 0 && this.fields)) {
return [];
}
return data.map(function (d) {
var x = isNull$a(d[_this.fields.x]) || isInfinity$4(d[_this.fields.x]) ? null : _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = isNull$a(d[_this.fields.y]) || isInfinity$4(d[_this.fields.y]) ? null : _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
return [isInfinity$4(x) ? 0 : x, isInfinity$4(y) ? 0 : y];
}); //.filter(d => !isNull(d[0]) && !isNull(d[1]))
}
function create$8(tag) {
return document.createElement(tag);
}
function createSVG$2(tag) {
return document.createElementNS('http://www.w3.org/2000/svg', tag);
}
function getStrokeStyle$2(style) {
var strokeWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var strokeLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
var strokeStyle = null;
switch (style) {
case 'dashed':
strokeStyle = "".concat(strokeWidth * strokeLength, " ").concat(strokeWidth * strokeLength);
break;
case 'dotted':
strokeStyle = "".concat(strokeWidth, " ").concat(strokeWidth);
break;
case 'solid':
default:
strokeStyle = null;
}
return strokeStyle;
}
function add$4(obj) {
var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var id = obj._id || uuid$2();
// console.log('adding to', this, obj.type, id, obj);
obj.id(id).parent(this);
// .render();
if (prepend) {
this.objects = [obj].concat(_toConsumableArray$9(this.objects));
} else {
this.objects.push(obj);
}
//return this.update();
return this;
}
// export { add } from '../charts/util'
var index$2 = /*#__PURE__*/Object.freeze({
__proto__: null,
add: add$4,
create: create$8,
createSVG: createSVG$2,
getCoords: getCoords$3,
getStrokeStyle: getStrokeStyle$2,
hasData: hasData$2,
isInfinity: isInfinity$4,
isNull: isNull$a,
oppositeSigns: oppositeSigns$2,
uuid: uuid$2
});
function render$2(parent) {
// console.log('RENDER', this, parent)
if (this.g) {
// avoid duplication of g
return this;
}
this.g = createSVG$2('g');
if (this._id) {
this.g.setAttribute('id', this._id);
}
// console.log('RENDER', this, this.parentNode)
if (hasData$2(this)) {
// series
// in case of group or stack we want the chart to be added to svg g of the group/stack
if (parent) {
// if it's a stack we want the order of the charts in the dom to be opposite, so the stroke
// of the charts below is not covered by the area above
if (parent.type === 'stack' || parent.group === 'group') {
parent.g.prepend(this.g);
} else {
parent.g.append(this.g);
}
} else {
this.currentNode.append(this.g);
}
} else {
// const grid = (this.parentNode.objects || []).slice().reverse().find(obj => obj.type === 'grid');
// if(grid && this.type === 'axis') {
// // // console.log('THIS IS AN',this.type,'AND THERE IS A GRID',grid,'INSERT BEFORE',grid.node(), grid.node().nextSibling)
// this.currentNode.insertBefore(this.g, grid.node().nextSibling);
// } else {
// // console.log('THIS IS A', this.type, 'PREPEND')
// this.currentNode.append(this.g);
// }
this.currentNode.append(this.g);
}
this.update();
return this; // .parentNode;
}
function update$2() {
if (this.parentNode && this.parentNode.scales.x[this.scales.x] && this.parentNode.scales.y[this.scales.y]) {
this.draw();
}
return this;
}
function curve$2(interpolationFunction) {
if (isNull$a(interpolationFunction)) {
return this.interpolationFunction;
}
this.interpolationFunction = interpolationFunction;
return this;
}
function attribute$2(name, fn) {
var accessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (value) {
return value;
};
if (isNull$a(name)) {
console.warn('name missing: attr method requires a name for the attribute');
return this;
}
if (!isNull$a(name) && typeof fn === 'undefined') {
var _this$attrs;
// this.name()
return ((_this$attrs = this.attrs) === null || _this$attrs === void 0 ? void 0 : _this$attrs[name]) || function () {};
}
if (typeof fn === 'function') {
// something will go here
this.attrs[name] = fn;
} else {
// fn is a Boolean, String, Number or any other type but function
this.attrs[name] = function () {
return accessor(fn);
};
}
return this;
}
function data$2 (data, accessor) {
// console.log('---------------> data', data, accessor, this);
if (!data) {
// console.log('NO DATA return', hasData(this), this._data, hasData(this) ? this._data : this)
return hasData$2(this) ? this._data || null : this;
}
// TODO: not sure what this is doing...
if (!hasData$2(this)) {
// console.log('NO HAS DATA')
return this;
}
// console.log('HAS DATA')
// // console.log('chrt or series', this.type)
// passing only accessor to inherit/reuse data
if (typeof arguments[0] === 'function') {
this._accessor = arguments[0];
return this;
}
// data is passed
this._orginalData = this._orginalData || data;
// define accessor function to map values
var accessorFunction = accessor || this._accessor;
this._accessor = accessorFunction;
this._data = accessorFunction && !this._accessorApplied ? data.map(function (d, i, arr) {
if (d instanceof Object) {
return Object.assign({}, d, accessorFunction(d, i, arr));
}
return accessorFunction(d, i, arr);
}) : data;
// console.log('DATA', data)
this._accessorApplied = true; // do not apply the accessor multiple times
return this;
}
/**
* node - Returns the DOM element that contains a chart element
*
* @param {type} node Set this as root node
*
* @return {type} Description
*/
function node$2 (node) {
if (!node) {
return this.g || this.root;
}
this.root = node;
this.currentNode = this.root;
return this;
}
function parent$2 (obj) {
if (!obj) {
return this.parentNode;
}
this.parentNode = obj;
return this;
}
function display$2(value) {
return attribute$2.call(this, 'display', value);
}
function show$2() {
return display$2.call(this, true);
}
function hide$2() {
return display$2.call(this, false);
}
function cssDisplay$2(value) {
var DOMNode = node$2.call(this);
if (!DOMNode) {
return this;
}
var currentDisplay = DOMNode.style.display;
this._display = typeof this._display !== 'undefined' ? this._display : DOMNode.style.display;
if (!value) {
DOMNode.style.display = 'none';
} else {
if (currentDisplay === 'none' && value) {
DOMNode.style.display = this._display;
}
}
return this;
}
function chrtObject$2() {
var _this = this;
this._id = null;
this.objects = [];
this.type = 'chrt-object';
this.fields = {
x: null,
y: null
};
this.scales = {
x: 'x',
y: 'y'
};
this._classNames = [];
this._accessor = function (d, i) {
return {
x: !isNull$a(d) && Object.prototype.hasOwnProperty.call(d, 'x') ? d.x : i,
y: isNull$a(d) ? null : Object.prototype.hasOwnProperty.call(d, 'y') ? d.y : d
};
};
this.interpolationFunction = null;
// list of getter/setter function for custom attributes
this.attrs = [];
attribute$2.call(this, 'display', true);
this.id = function (id) {
// console.log('chrtObject.id', id, this._id);
if (isNull$a(id)) {
return _this._id;
}
_this._id = id || _this._id;
if (_this.g) {
_this.g.setAttribute('id', _this._id);
}
return _this;
};
this.aria = function (ariaLabel) {
attribute$2.call(_this, 'aria', ariaLabel);
// if(isNull(ariaLabel)) {
// return this.ariaLabel;
// }
// this.ariaLabel = ariaLabel || this.ariaLabel;
//
// if(this.g && this.ariaLabel) {
// this.g.setAttribute('aria-label', this.ariaLabel);
// }
return _this;
};
this.class = function (className) {
if (isNull$a(className)) {
return _this._classNames;
}
var classNames = (Array.isArray(className) ? className : className.split(' ')).map(function (d) {
return d.replace(/\s\s+/g, ' ').trim();
}).filter(function (d) {
return d !== '';
});
_this.original_classNames = _this.original_classNames || _this._classNames;
_this._classNames = _toConsumableArray$9(new Set([].concat(_toConsumableArray$9(_this.original_classNames), _toConsumableArray$9(classNames))));
if (_this.g) {
var _this$g$classList, _this$g$classList2;
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$9(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$9(_this._classNames));
}
return _this;
};
this.hasData = function () {
return hasData$2(_this);
};
var setScale = function setScale(scale, scaleName) {
if (!isNull$a(scaleName)) {
_this.scales[scale] = scaleName;
}
};
this.x = function (scale) {
if (isNull$a(scale)) {
return _this.scales.x;
}
setScale('x', scale || 'x');
return _this;
};
this.y = function (scale) {
if (isNull$a(scale)) {
return _this.scales.y;
}
setScale('y', scale || 'y');
return _this;
};
this.getObjectTypeIndex = function () {
var _this$parent$objects, _this$parent;
return ((_this$parent$objects = (_this$parent = _this.parent()) === null || _this$parent === void 0 ? void 0 : _this$parent.objects) !== null && _this$parent$objects !== void 0 ? _this$parent$objects : []).filter(function (d) {
return d.constructor.name === _this.constructor.name;
}).indexOf(_this);
};
return this;
}
function chrt$2() {
return new chrtObject$2();
}
chrtObject$2.prototype = Object.create(chrt$2.prototype);
// chrtObject.prototype = chrt.prototype = Object.assign(chrt.prototype, {
chrtObject$2.prototype = Object.assign(chrt$2.prototype, {
node: node$2,
data: data$2,
add: add$4,
snap: add$4,
parent: parent$2,
render: render$2,
update: update$2,
curve: curve$2,
attr: attribute$2,
show: show$2,
hide: hide$2
});
// chrt-label v0.0.44 Copyright 2024 chrt
function _arrayLikeToArray$8(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithoutHoles$8(r) {
if (Array.isArray(r)) return _arrayLikeToArray$8(r);
}
function _iterableToArray$8(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _nonIterableSpread$8() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray$8(r) {
return _arrayWithoutHoles$8(r) || _iterableToArray$8(r) || _unsupportedIterableToArray$8(r) || _nonIterableSpread$8();
}
function _unsupportedIterableToArray$8(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray$8(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$8(r, a) : void 0;
}
}
function color$2(value) {
return this.attr('fill', value);
}
function position$1(coords) {
var _position = this.attr('position')();
return this.attr('position', Object.assign({}, _position, coords));
}
function top$1(y) {
return position$1.call(this, {
y: y
});
}
function left$1(x) {
return position$1.call(this, {
x: x
});
}
var isNull$5$1 = index$2.isNull;
function getHorizontalPosition(position) {
if (typeof position === "function") {
return position;
}
var horizontal = "start";
switch (position) {
case "end":
horizontal = "end";
break;
case "center":
case "middle":
horizontal = "middle";
break;
case "start":
default:
horizontal = "start";
}
return function () {
return horizontal;
};
}
function getVerticalPosition(position) {
if (typeof position === "function") {
return position;
}
var vertical = "top";
switch (position) {
case "bottom":
vertical = "bottom";
break;
case "middle":
case "center":
vertical = "middle";
break;
case "top":
default:
vertical = "top";
}
return function () {
return vertical;
};
}
function alignment$1(align) {
// this is never called
// if(isNull(align)) {
// return this._alignment;
// }
// console.log("alignment", align);
// if (typeof align === "function") {
// this._alignment = Object.assign({}, this._alignment, align);
// } else {
// this._alignment = Object.assign({}, this._alignment, align);
// }
this._alignment = Object.assign({}, this._alignment, align);
return this;
}
function align$1(position) {
if (isNull$5$1(position)) {
var _this$_alignment;
return ((_this$_alignment = this._alignment) === null || _this$_alignment === void 0 ? void 0 : _this$_alignment.horizontal) || this.defaultAlignment.horizontal;
}
// return alignment.call(this, { horizontal: getHorizontalPosition(position) });
return alignment$1.call(this, {
horizontal: getHorizontalPosition(position)
});
}
function valign$1(position) {
if (isNull$5$1(position)) {
var _this$_alignment2;
return ((_this$_alignment2 = this._alignment) === null || _this$_alignment2 === void 0 ? void 0 : _this$_alignment2.vertical) || this.defaultAlignment.vertical;
}
return alignment$1.call(this, {
vertical: getVerticalPosition(position)
});
}
var isNull$4$1 = index$2.isNull;
function setMargins(margins) {
if (isNull$4$1(margins)) {
return this._margins;
}
var top = margins.top,
bottom = margins.bottom,
left = margins.left,
right = margins.right;
this._margins.top = !isNull$4$1(top) ? top : this._margins.top;
this._margins.bottom = !isNull$4$1(bottom) ? bottom : this._margins.bottom;
this._margins.left = !isNull$4$1(left) ? left : this._margins.left;
this._margins.right = !isNull$4$1(right) ? right : this._margins.right;
return this;
}
var isNull$3$1 = index$2.isNull;
function offset$1() {
for (var _len = arguments.length, offsets = new Array(_len), _key = 0; _key < _len; _key++) {
offsets[_key] = arguments[_key];
}
if (!(offsets !== null && offsets !== void 0 && offsets.length)) {
return this._offsets;
}
var leftOffset = offsets[0],
topOffset = offsets[1];
var top = this._offsets[0];
if (!isNull$3$1(topOffset)) {
top = typeof topOffset === 'function' ? topOffset : function () {
return topOffset;
};
}
var left = this._offsets[1];
if (!isNull$3$1(leftOffset)) {
left = typeof leftOffset === 'function' ? leftOffset : function () {
return leftOffset;
};
}
this._offsets = [top, left];
return this;
}
var isNull$2$1 = index$2.isNull;
function relativePosition(position) {
if (isNull$2$1(position)) {
return this._rposition;
}
// let [leftPosition, topPosition] = position;
// let top = this._rposition[1];
// if(!isNull(topPosition)) {
// top = typeof topPosition === 'function' ? topPosition : () => topPosition;
// }
//
// let left = this._rposition[0];
// if(!isNull(leftPosition)) {
// left = typeof leftPosition === 'function' ? leftPosition : () => leftPosition;
// }
this._rposition = position; // [leftPosition || 0, topPosition || 0];
return this;
}
// filterLabels and hideLabels can get different type of parameters and they filter the labels based on the parameters
function filterLabels(filter) {
// default true
if (typeof filter === 'undefined') {
this.labelsFilter = function () {
return true;
};
return this;
}
// filter-in with a function
// filterLabels((d,i) => !(i % 2))
if (typeof filter === 'function') {
this.labelsFilter = function (d, i, arr) {
return filter(d, i, arr);
};
return this;
}
// show/hide all labels
// filterLabels(false|true)
if (typeof filter === 'boolean') {
this.labelsFilter = function () {
return filter;
};
return this;
}
// show only one label
// filterLabels(10)
if (Number.isFinite(filter)) {
this.labelsFilter = function (d) {
return filter === d;
};
return this;
}
// show based on an array of values
// filterLabels([10, 20, 30])
if (Array.isArray(filter)) {
this.labelsFilter = function (d) {
return filter.indexOf(d) > -1;
};
return this;
}
// generic, valid for all other types, including null
this.labelsFilter = function (d) {
return filter === d;
};
return this;
}
// hideLabels is the opposite of filterLabels and it filters out
function hideLabels(filter) {
filterLabels.call(this, filter);
var labelsFilter = this.labelsFilter;
this.labelsFilter = function (d, i, arr) {
return !labelsFilter(d, i, arr);
};
return this;
}
function firstLabel() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
filterLabels.call(this, function (d, i) {
return i === 0;
});
} else {
hideLabels.call(this, function (d, i) {
return i === 0;
});
}
return this;
}
function lastLabel() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
filterLabels.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
} else {
hideLabels.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
}
return this;
}
function firstAndLastLabels() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
filterLabels.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
} else {
hideLabels.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
}
return this;
}
var DEFAULT_FILL_COLOR$2 = '#000';
var isNull$1$2 = index$2.isNull,
isInfinity$3 = index$2.isInfinity,
create$7 = index$2.createSVG;
function chrtLabel(text) {
var _this = this;
chrtObject$2.call(this);
// console.log('chrtLabel', this);
this.type = "label";
this.g = null;
this.attr("datum", null);
this.attr("fill", null);
this.attr("text", null);
this.attr("position", {});
this.attr("anchor", null);
this.defaultAlignment = {
horizontal: function horizontal() {
return "start";
},
vertical: function vertical() {
return "text-after-edge";
}
};
this._margins = {
top: 0,
right: 0,
bottom: 0,
left: 0
};
this._offsets = [function () {
return 0;
}, function () {
return 0;
}];
this._classNames = ["chrt-label"];
this.value = function (text) {
return _this.attr("text", text);
};
this.text = this.value;
this.value(text);
this.anchor = function (anchor) {
return _this.attr("anchor", anchor);
};
this.datum = function (datum) {
return _this.attr("datum", datum);
};
this.draw = function () {
var _this$parentNode, _this$parentNode2, _this$g$classList, _this$g$classList2, _this$parentNode$pare, _this$parentNode3, _this$parentNode$fiel, _this$parentNode4, _this$parentNode4$str;
// console.log('LABEL DRAWING', text, this.g, this);
var parentNode = (_this === null || _this === void 0 || (_this$parentNode = _this.parentNode) === null || _this$parentNode === void 0 ? void 0 : _this$parentNode.type) === "chrt" ? _this.parentNode : _this === null || _this === void 0 || (_this$parentNode2 = _this.parentNode) === null || _this$parentNode2 === void 0 ? void 0 : _this$parentNode2.parentNode;
// if (!parentNode.scales) {
// return parentNode;
// }
if (!_this.g) {
var _parentNode$currentNo;
_this.g = create$7("g");
//this.parentNode.g.parentNode.appendChild(this.g);
parentNode === null || parentNode === void 0 || (_parentNode$currentNo = parentNode.currentNode) === null || _parentNode$currentNo === void 0 || _parentNode$currentNo.appendChild(_this.g);
}
_this.g.setAttribute("id", _this.id());
cssDisplay$2.call(_this, _this.attr("display")());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$8(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$8(_this._classNames));
var getPosition = function getPosition(position) {
return function (field) {
if (isNull$1$2(position[field])) {
if (!isNull$1$2(_this.parentNode._data) && _this.parentNode._data.length) {
// console.log('--->', this.parentNode._data)
return _this.parentNode._data[_this.parentNode._data.length - 1][field];
} else {
return 0;
}
}
return position[field];
};
};
var anchor = _this.attr("anchor")();
var _ref = (_this$parentNode$pare = (_this$parentNode3 = _this.parentNode) === null || _this$parentNode3 === void 0 ? void 0 : _this$parentNode3.parentNode) !== null && _this$parentNode$pare !== void 0 ? _this$parentNode$pare : _this.parentNode,
scales = _ref.scales;
var fields = (_this$parentNode$fiel = _this.parentNode.fields) !== null && _this$parentNode$fiel !== void 0 ? _this$parentNode$fiel : {
x: "x",
y: "y"
};
if (!anchor && scales && scales.x[fields.x]) {
// console.log('position', this.attr('position')());
// console.log(`getPosition(position)(${(this.parentNode.fields.x)})`, getPosition(this.attr('position')())(this.parentNode.fields.x))
var x = scales.x[fields.x](getPosition(_this.attr("position")())(fields.x)) + _this._margins.left - _this._margins.right + _this._offsets[1]();
// console.log('x', x, this._margins)
// if y is not defined by the user, it should be calculated based on the closest Y value based on X
var y = scales.y[fields.y](getPosition(_this.attr("position")())(fields.y)) + _this._margins.top - _this._margins.bottom + _this._offsets[0]();
_this.g.setAttribute("transform", "translate(".concat(isNaN(x) || isInfinity$3(x) ? 0 : x, ",").concat(isNaN(y) || isInfinity$3(y) ? 0 : y, ")"));
// console.log('drawing label', this._offsets[0](), this._offsets[1]())
}
var label = _this.g.querySelector("text");
if (!label) {
label = create$7("text");
var _text = _this.attr("text")();
label.setAttribute("data-id", escape("label-".concat(_text)));
_this.g.appendChild(label);
}
label.setAttribute("fill", _this.color()() || ((_this$parentNode4 = _this.parentNode) === null || _this$parentNode4 === void 0 || (_this$parentNode4$str = _this$parentNode4.stroke) === null || _this$parentNode4$str === void 0 ? void 0 : _this$parentNode4$str.call(_this$parentNode4)()) || DEFAULT_FILL_COLOR$2);
label.textContent = _this.attr("text")();
// console.log(this._alignment, anchor?.alignment, this.defaultAlignment)
var alignment = _this._alignment || (anchor === null || anchor === void 0 ? void 0 : anchor.alignment) || _this.defaultAlignment;
// console.log(
// "ALIGNMENT",
// this._alignment,
// anchor?.alignment,
// this.defaultAlignment,
// );
// console.log("?????", this._alignment);
// console.log("--->", this.attr("horizontalAlignment")());
var textAnchor = alignment.horizontal(_this.datum()()); // alignment.horizontal;
var dominantAlignment = "";
switch (alignment.vertical(_this.datum()())) {
case "bottom":
dominantAlignment = "text-before-edge";
break;
case "top":
dominantAlignment = "text-after-edge";
break;
default:
case "middle":
dominantAlignment = "middle";
}
// anchor is used by chrtLabels to anchor labels to points
if (anchor) {
// console.log("anchor", anchor);
// console.log('this._alignment', this._alignment);
var relativePosition = anchor.relativePosition;
var _x = anchor.x + anchor.width * (1 - anchor.directions.x) + anchor.width * relativePosition[0] * (anchor.directions.x || -1); // + (anchor.width * anchor.directions.x) * relativePosition[0];
// const _y = anchor.y + (anchor.height * relativePosition[1]);
var _y = anchor.y + anchor.height * (1 - anchor.directions.y) + anchor.height * relativePosition[1] * (anchor.directions.y || -1);
var translate = {
x: (isNaN(_x) || isInfinity$3(_x) ? 0 : _x) + _this._offsets[1](_this.datum()()),
y: (isNaN(_y) || isInfinity$3(_y) ? 0 : _y) + _this._offsets[0](_this.datum()())
};
if (!anchor.directions.x) {
if (textAnchor === "start") {
textAnchor = "end";
} else if (textAnchor === "end") {
textAnchor = "start";
}
}
if (!anchor.directions.y) {
if (dominantAlignment === "text-after-edge") {
dominantAlignment = "text-before-edge";
} else if (dominantAlignment === "text-before-edge") {
dominantAlignment = "text-after-edge";
}
}
_this.g.setAttribute("transform", "translate(".concat(translate.x, ", ").concat(translate.y, ")"));
}
label.setAttribute("text-anchor", textAnchor);
label.setAttribute("dominant-baseline", dominantAlignment);
return _this;
};
}
chrtLabel.prototype = Object.create(chrtObject$2.prototype);
// console.log('WHAT IS THIS?')
// console.log(Object.create(chrtObject.prototype))
chrtLabel.prototype.constructor = chrtLabel;
// chrtLabel.parent = chrtObject.prototype;
chrtLabel.prototype = Object.assign(chrtLabel.prototype, {
color: color$2,
fill: color$2,
position: position$1,
top: top$1,
left: left$1,
align: align$1,
valign: valign$1,
margins: setMargins,
offset: offset$1,
offsets: offset$1
});
// export default chrtLabel;
function chrtLabel$1 (text) {
return new chrtLabel(text);
}
var isNull$9 = index$2.isNull;
function chrtLabels() {
var _this = this;
chrtObject$2.call(this);
// console.log("HI WE ARE LABELS", this);
this.type = "labels";
this.labels = [];
// this.g = null;
this.labelsFilter = function () {
return true;
};
this._alignment = null;
this.attr("fill", DEFAULT_FILL_COLOR$2);
this._offsets = [function () {
return 0;
}, function () {
return 0;
}];
this.value = function (field) {
return _this.attr("textField", field);
};
// this.position = (position) => {
// return this.attr('position', position);
// }
this.draw = function () {
var _this$parentNode, _this$parentNode2, _this$labels;
var parentData = _this.parentNode.data();
var data = parentData.length ? parentData : _this.parentNode.parentNode._data || [];
~((_this$parentNode = _this.parentNode) === null || _this$parentNode === void 0 ? void 0 : _this$parentNode.class().indexOf("chrt-bars"));
~((_this$parentNode2 = _this.parentNode) === null || _this$parentNode2 === void 0 ? void 0 : _this$parentNode2.class().indexOf("chrt-columns"));
// remove old labels
if ((_this$labels = _this.labels) !== null && _this$labels !== void 0 && _this$labels.length) {
var dataLabelsDelta = _this.labels.length - data.length;
if (dataLabelsDelta > 0) {
Array.from({
length: dataLabelsDelta
}, function (_, i) {
return i + data.length;
}).forEach(function (d) {
var _this$labels$d;
(_this$labels$d = _this.labels[d]) === null || _this$labels$d === void 0 || _this$labels$d.node().remove();
_this.labels[d] = null;
});
_this.labels = _this.labels.filter(function (d) {
return d;
});
}
}
data.forEach(function (label, i) {
var _label$anchorPoints, _this$_offsets$, _this$_offsets$2;
if (_this.labelsFilter && !_this.labelsFilter(label, i, data)) {
return;
}
// const offsets = {
// top: () => 0,
// left: () => 0,
// };
if (!_this.labels[i]) {
_this.labels[i] = chrtLabel$1();
// console.log('adding label',i,'with value',textField,'to',this.parentNode)
_this.parentNode.add(_this.labels[i]);
}
// console.log('now we I have', this.labels.length, 'labels')
var textFieldAccessor = _this.attr("textField")(label, i, _this.labels);
var textField = !isNull$9(textFieldAccessor) ? textFieldAccessor : label[_this.parentNode.fields.y];
var classNames = _this.class();
if (classNames.length) {
_this.labels[i].class(classNames.join(" "));
}
// console.log("ANCHORPOINTS", label.anchorPoints);
_this.labels[i].value(textField).datum(label);
_this.labels[i].anchor(label.anchorPoints ? Object.assign({}, label.anchorPoints, {
alignment: (_label$anchorPoints = label.anchorPoints) !== null && _label$anchorPoints !== void 0 && _label$anchorPoints.alignment ? {
horizontal: function horizontal() {
var _label$anchorPoints$a, _label$anchorPoints2;
return (_label$anchorPoints$a = (_label$anchorPoints2 = label.anchorPoints) === null || _label$anchorPoints2 === void 0 || (_label$anchorPoints2 = _label$anchorPoints2.alignment) === null || _label$anchorPoints2 === void 0 ? void 0 : _label$anchorPoints2.horizontal) !== null && _label$anchorPoints$a !== void 0 ? _label$anchorPoints$a : "middle";
},
vertical: function vertical() {
var _label$anchorPoints$a2, _label$anchorPoints3;
return (_label$anchorPoints$a2 = (_label$anchorPoints3 = label.anchorPoints) === null || _label$anchorPoints3 === void 0 || (_label$anchorPoints3 = _label$anchorPoints3.alignment) === null || _label$anchorPoints3 === void 0 ? void 0 : _label$anchorPoints3.vertical) !== null && _label$anchorPoints$a2 !== void 0 ? _label$anchorPoints$a2 : "top";
}
} : null,
relativePosition: _this._rposition || label.anchorPoints.relativePosition
}) : null).offset((_this$_offsets$ = _this._offsets[1](label, i, _this.labels)) !== null && _this$_offsets$ !== void 0 ? _this$_offsets$ : 0, // + offsets.left(),
(_this$_offsets$2 = _this._offsets[0](label, i, _this.labels)) !== null && _this$_offsets$2 !== void 0 ? _this$_offsets$2 : 0 // + offsets.top(),
).color(_this.color()(label, i, _this.labels));
if (_this._alignment) {
var _this$_alignment, _this$_alignment2;
_this.labels[i].align(((_this$_alignment = _this._alignment) === null || _this$_alignment === void 0 ? void 0 : _this$_alignment.horizontal) || "middle").valign(((_this$_alignment2 = _this._alignment) === null || _this$_alignment2 === void 0 ? void 0 : _this$_alignment2.vertical) || "top");
}
_this.labels[i].attr(_this.attr("display")(label, i, data));
// console.log("this._alignment", this._alignment);
_this.labels[i].draw();
});
return _this;
};
}
chrtLabels.prototype = Object.create(chrtObject$2.prototype);
chrtLabels.prototype.constructor = chrtLabels;
chrtLabels.parent = chrtObject$2.prototype;
chrtLabels.prototype = Object.assign(chrtLabels.prototype, {
align: align$1,
valign: valign$1,
relativePosition: relativePosition,
filter: filterLabels,
show: filterLabels,
hide: hideLabels,
filterLabels: filterLabels,
hideLabels: hideLabels,
firstLabel: firstLabel,
lastLabel: lastLabel,
firstAndLastLabels: firstAndLastLabels,
offset: offset$1,
offsets: offset$1,
color: color$2,
fill: color$2
});
function chrtLabels$1 () {
return new chrtLabels();
}
// chrt-object v0.0.19 Copyright 2020-2024 chrt chrt.io
function _toConsumableArray$7(arr) {
return _arrayWithoutHoles$7(arr) || _iterableToArray$7(arr) || _unsupportedIterableToArray$7(arr) || _nonIterableSpread$7();
}
function _arrayWithoutHoles$7(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$7(arr);
}
function _iterableToArray$7(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$7(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$7(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$7(o, minLen);
}
function _arrayLikeToArray$7(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$7() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var COMPONENTS_W_DATA$1 = ['chrt', 'series'];
function isNull$8(value) {
return value === null || value == null || typeof value === 'undefined';
}
function uuid$1() {
return 'c' + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
function hasData$1(obj) {
return !isNull$8(obj.type) && COMPONENTS_W_DATA$1.indexOf(obj.type) > -1;
}
function isInfinity$2(value) {
return !isFinite(value);
}
function oppositeSigns$1(x, y) {
return (x ^ y) < 0;
}
function getCoords$2(data) {
var _this = this;
if (!(this !== null && this !== void 0 && this.fields)) {
return [];
}
return data.map(function (d) {
var x = isNull$8(d[_this.fields.x]) || isInfinity$2(d[_this.fields.x]) ? null : _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = isNull$8(d[_this.fields.y]) || isInfinity$2(d[_this.fields.y]) ? null : _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
return [isInfinity$2(x) ? 0 : x, isInfinity$2(y) ? 0 : y];
}); //.filter(d => !isNull(d[0]) && !isNull(d[1]))
}
function create$6(tag) {
return document.createElement(tag);
}
function createSVG$1(tag) {
return document.createElementNS('http://www.w3.org/2000/svg', tag);
}
function getStrokeStyle$1(style) {
var strokeWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var strokeLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
var strokeStyle = null;
switch (style) {
case 'dashed':
strokeStyle = "".concat(strokeWidth * strokeLength, " ").concat(strokeWidth * strokeLength);
break;
case 'dotted':
strokeStyle = "".concat(strokeWidth, " ").concat(strokeWidth);
break;
case 'solid':
default:
strokeStyle = null;
}
return strokeStyle;
}
function add$3(obj) {
var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var id = obj._id || uuid$1();
// console.log('adding to', this, obj.type, id, obj);
obj.id(id).parent(this);
// .render();
if (prepend) {
this.objects = [obj].concat(_toConsumableArray$7(this.objects));
} else {
this.objects.push(obj);
}
//return this.update();
return this;
}
// export { add } from '../charts/util'
var index$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
add: add$3,
create: create$6,
createSVG: createSVG$1,
getCoords: getCoords$2,
getStrokeStyle: getStrokeStyle$1,
hasData: hasData$1,
isInfinity: isInfinity$2,
isNull: isNull$8,
oppositeSigns: oppositeSigns$1,
uuid: uuid$1
});
function render$1(parent) {
// console.log('RENDER', this, parent)
if (this.g) {
// avoid duplication of g
return this;
}
this.g = createSVG$1('g');
if (this._id) {
this.g.setAttribute('id', this._id);
}
// console.log('RENDER', this, this.parentNode)
if (hasData$1(this)) {
// series
// in case of group or stack we want the chart to be added to svg g of the group/stack
if (parent) {
// if it's a stack we want the order of the charts in the dom to be opposite, so the stroke
// of the charts below is not covered by the area above
if (parent.type === 'stack' || parent.group === 'group') {
parent.g.prepend(this.g);
} else {
parent.g.append(this.g);
}
} else {
this.currentNode.append(this.g);
}
} else {
// const grid = (this.parentNode.objects || []).slice().reverse().find(obj => obj.type === 'grid');
// if(grid && this.type === 'axis') {
// // // console.log('THIS IS AN',this.type,'AND THERE IS A GRID',grid,'INSERT BEFORE',grid.node(), grid.node().nextSibling)
// this.currentNode.insertBefore(this.g, grid.node().nextSibling);
// } else {
// // console.log('THIS IS A', this.type, 'PREPEND')
// this.currentNode.append(this.g);
// }
this.currentNode.append(this.g);
}
this.update();
return this; // .parentNode;
}
function update$1() {
if (this.parentNode && this.parentNode.scales.x[this.scales.x] && this.parentNode.scales.y[this.scales.y]) {
this.draw();
}
return this;
}
function curve$1(interpolationFunction) {
if (isNull$8(interpolationFunction)) {
return this.interpolationFunction;
}
this.interpolationFunction = interpolationFunction;
return this;
}
function attribute$1(name, fn) {
var accessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (value) {
return value;
};
if (isNull$8(name)) {
console.warn('name missing: attr method requires a name for the attribute');
return this;
}
if (!isNull$8(name) && typeof fn === 'undefined') {
var _this$attrs;
// this.name()
return ((_this$attrs = this.attrs) === null || _this$attrs === void 0 ? void 0 : _this$attrs[name]) || function () {};
}
if (typeof fn === 'function') {
// something will go here
this.attrs[name] = fn;
} else {
// fn is a Boolean, String, Number or any other type but function
this.attrs[name] = function () {
return accessor(fn);
};
}
return this;
}
function data$1 (data, accessor) {
// console.log('---------------> data', data, accessor, this);
if (!data) {
// console.log('NO DATA return', hasData(this), this._data, hasData(this) ? this._data : this)
return hasData$1(this) ? this._data || null : this;
}
// TODO: not sure what this is doing...
if (!hasData$1(this)) {
// console.log('NO HAS DATA')
return this;
}
// console.log('HAS DATA')
// // console.log('chrt or series', this.type)
// passing only accessor to inherit/reuse data
if (typeof arguments[0] === 'function') {
this._accessor = arguments[0];
return this;
}
// data is passed
this._orginalData = this._orginalData || data;
// define accessor function to map values
var accessorFunction = accessor || this._accessor;
this._accessor = accessorFunction;
this._data = accessorFunction && !this._accessorApplied ? data.map(function (d, i, arr) {
if (d instanceof Object) {
return Object.assign({}, d, accessorFunction(d, i, arr));
}
return accessorFunction(d, i, arr);
}) : data;
// console.log('DATA', data)
this._accessorApplied = true; // do not apply the accessor multiple times
return this;
}
/**
* node - Returns the DOM element that contains a chart element
*
* @param {type} node Set this as root node
*
* @return {type} Description
*/
function node$1 (node) {
if (!node) {
return this.g || this.root;
}
this.root = node;
this.currentNode = this.root;
return this;
}
function parent$1 (obj) {
if (!obj) {
return this.parentNode;
}
this.parentNode = obj;
return this;
}
function display$1(value) {
return attribute$1.call(this, 'display', value);
}
function show$1() {
return display$1.call(this, true);
}
function hide$1() {
return display$1.call(this, false);
}
function cssDisplay$1(value) {
var DOMNode = node$1.call(this);
if (!DOMNode) {
return this;
}
var currentDisplay = DOMNode.style.display;
this._display = typeof this._display !== 'undefined' ? this._display : DOMNode.style.display;
if (!value) {
DOMNode.style.display = 'none';
} else {
if (currentDisplay === 'none' && value) {
DOMNode.style.display = this._display;
}
}
return this;
}
function chrtObject$1() {
var _this = this;
this._id = null;
this.objects = [];
this.type = 'chrt-object';
this.fields = {
x: null,
y: null
};
this.scales = {
x: 'x',
y: 'y'
};
this._classNames = [];
this._accessor = function (d, i) {
return {
x: !isNull$8(d) && Object.prototype.hasOwnProperty.call(d, 'x') ? d.x : i,
y: isNull$8(d) ? null : Object.prototype.hasOwnProperty.call(d, 'y') ? d.y : d
};
};
this.interpolationFunction = null;
// list of getter/setter function for custom attributes
this.attrs = [];
attribute$1.call(this, 'display', true);
this.id = function (id) {
// console.log('chrtObject.id', id, this._id);
if (isNull$8(id)) {
return _this._id;
}
_this._id = id || _this._id;
if (_this.g) {
_this.g.setAttribute('id', _this._id);
}
return _this;
};
this.aria = function (ariaLabel) {
attribute$1.call(_this, 'aria', ariaLabel);
// if(isNull(ariaLabel)) {
// return this.ariaLabel;
// }
// this.ariaLabel = ariaLabel || this.ariaLabel;
//
// if(this.g && this.ariaLabel) {
// this.g.setAttribute('aria-label', this.ariaLabel);
// }
return _this;
};
this.class = function (className) {
if (isNull$8(className)) {
return _this._classNames;
}
var classNames = (Array.isArray(className) ? className : className.split(' ')).map(function (d) {
return d.replace(/\s\s+/g, ' ').trim();
}).filter(function (d) {
return d !== '';
});
_this.original_classNames = _this.original_classNames || _this._classNames;
_this._classNames = _toConsumableArray$7(new Set([].concat(_toConsumableArray$7(_this.original_classNames), _toConsumableArray$7(classNames))));
if (_this.g) {
var _this$g$classList, _this$g$classList2;
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$7(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$7(_this._classNames));
}
return _this;
};
this.hasData = function () {
return hasData$1(_this);
};
var setScale = function setScale(scale, scaleName) {
if (!isNull$8(scaleName)) {
_this.scales[scale] = scaleName;
}
};
this.x = function (scale) {
if (isNull$8(scale)) {
return _this.scales.x;
}
setScale('x', scale || 'x');
return _this;
};
this.y = function (scale) {
if (isNull$8(scale)) {
return _this.scales.y;
}
setScale('y', scale || 'y');
return _this;
};
this.getObjectTypeIndex = function () {
var _this$parent$objects, _this$parent;
return ((_this$parent$objects = (_this$parent = _this.parent()) === null || _this$parent === void 0 ? void 0 : _this$parent.objects) !== null && _this$parent$objects !== void 0 ? _this$parent$objects : []).filter(function (d) {
return d.constructor.name === _this.constructor.name;
}).indexOf(_this);
};
return this;
}
function chrt$1() {
return new chrtObject$1();
}
chrtObject$1.prototype = Object.create(chrt$1.prototype);
// chrtObject.prototype = chrt.prototype = Object.assign(chrt.prototype, {
chrtObject$1.prototype = Object.assign(chrt$1.prototype, {
node: node$1,
data: data$1,
add: add$3,
snap: add$3,
parent: parent$1,
render: render$1,
update: update$1,
curve: curve$1,
attr: attribute$1,
show: show$1,
hide: hide$1
});
// chrt-markers v0.0.23 Copyright 2020-2024 chrt chrt.io
function _arrayLikeToArray$6(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithoutHoles$6(r) {
if (Array.isArray(r)) return _arrayLikeToArray$6(r);
}
function _iterableToArray$6(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _nonIterableSpread$6() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray$6(r) {
return _arrayWithoutHoles$6(r) || _iterableToArray$6(r) || _unsupportedIterableToArray$6(r) || _nonIterableSpread$6();
}
function _unsupportedIterableToArray$6(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray$6(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$6(r, a) : void 0;
}
}
function size(value) {
return this.attr('radius', value);
}
function fill(value) {
return this.attr('fill', value);
}
function stroke$1(value) {
return this.attr('stroke', value);
}
function strokeWidth$1(value) {
return this.attr('strokeWidth', value);
}
function strokeOpacity$1(value) {
return this.attr('strokeOpacity', value);
}
function fillOpacity$1(value) {
return this.attr('fillOpacity', value);
}
// showMarkers and hideTicks can get different type of parameters and they filter the markers based on the parameters
function showMarkers(filter) {
// default true
if (typeof filter === 'undefined') {
this.markersFilter = function () {
return true;
};
return this;
}
// filter-in with a function
// showMarkers((d,i) => !(i % 2))
if (typeof filter === 'function') {
this.markersFilter = function (d, i, arr) {
return filter(d, i, arr);
};
return this;
}
// show/hide all markers
// showMarkers(false|true)
if (typeof filter === 'boolean') {
this.markersFilter = function () {
return filter;
};
return this;
}
// show only one marker
// showMarkers(10)
if (Number.isFinite(filter)) {
this.markersFilter = function (d) {
return filter === d;
};
return this;
}
// show based on an array of values
// showMarkers([10, 20, 30])
if (Array.isArray(filter)) {
this.markersFilter = function (d) {
return filter.indexOf(d) > -1;
};
return this;
}
// generic, valid for all other types, including null
this.markersFilter = function (d) {
return filter === d;
};
return this;
}
function hideMarkers(filter) {
showMarkers.call(this, filter);
var markersFilter = this.markersFilter;
this.markersFilter = function (d, i, arr) {
return !markersFilter(d, i, arr);
};
return this;
}
function firstMarker() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
// // console.log('FIRST TICK', this, show)
if (show) {
showMarkers.call(this, function (d, i) {
return i === 0;
});
} else {
hideMarkers.call(this, function (d, i) {
return i === 0;
});
}
return this;
}
function lastMarker() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showMarkers.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
} else {
hideMarkers.call(this, function (d, i, arr) {
return i === arr.length - 1;
});
}
return this;
}
function firstAndLastMarkers() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (show) {
showMarkers.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
} else {
hideMarkers.call(this, function (d, i, arr) {
return i === 0 || i === arr.length - 1;
});
}
return this;
}
var create$5 = index$1.createSVG;
var DEFAULT_RADIUS = 2;
var DEFAULT_FILL_COLOR$1 = '#000';
var DEFAULT_STROKE$1 = '#000';
var DEFAULT_STROKE_OPACITY$1 = 1;
var DEFAULT_STROKE_WIDTH$1 = 1;
var DEFAULT_FILL_OPACITY$1 = 1;
function chrtMarkers() {
var _this = this;
chrtObject$1.call(this);
// console.log('HI WE ARE MARKERS', this);
this.type = 'markers';
this.markers = [];
this.g = null;
this.markersFilter = function () {
return true;
};
this.attr('strokeWidth', null);
this.attr('stroke', null);
this.attr('strokeOpacity', null);
this.attr('fill', null);
this.attr('fillOpacity', null);
this.attr('radius', DEFAULT_RADIUS);
this._classNames = ['chrt-markers'];
this.draw = function () {
var _this$g$classList, _this$g$classList2;
// console.log('DRAW MARKERS', this.parentNode.data(), this.parentNode.parentNode._data);
// console.log(this)
var parentData = _this.parentNode.data();
// this might be broken when only local data to the component is updated - to be tested
var data = parentData.length ? parentData : _this.parentNode.parentNode._data || [];
var radius = _this.size()();
var fill = _this.fill()() || _this.parentNode.stroke()() || DEFAULT_FILL_COLOR$1;
var opacity = _this.fillOpacity()() || _this.parentNode.strokeOpacity()() || DEFAULT_FILL_OPACITY$1;
var stroke = _this.stroke()() || _this.parentNode.stroke()() || DEFAULT_STROKE$1;
var strokeOpacity = _this.strokeOpacity()() || _this.parentNode.strokeOpacity()() || DEFAULT_STROKE_OPACITY$1;
var strokeWidth = _this.strokeWidth()() || _this.parentNode.strokeWidth()() || DEFAULT_STROKE_WIDTH$1;
if (!_this.g) {
_this.g = create$5('g');
// console.log('---> appending markers to ', this.parentNode)
_this.parentNode.g.appendChild(_this.g);
}
cssDisplay$1.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$6(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$6(_this._classNames));
data.forEach(function (marker, i) {
if (_this.markers[i]) {
// if the marker exists, just update its data
_this.markers[i].marker = marker;
} else {
// if the marker does not exists, create a new one
var circle = create$5('circle');
_this.markers.push({
circle: circle,
marker: marker
});
_this.g.appendChild(circle);
}
});
_this.markers.filter(function (marker, i, arr) {
return _this.markersFilter(marker.marker, i, arr);
}).forEach(function (d) {
var cx = _this.parentNode.parentNode.scales.x[_this.parentNode.scales.x](d.marker[_this.parentNode.fields.x]);
d.circle.setAttribute('cx', isNaN(cx) ? 0 : cx);
var cy = _this.parentNode.parentNode.scales.y[_this.parentNode.scales.y](d.marker[_this.parentNode.fields.y]);
d.circle.setAttribute('cy', isNaN(cy) ? 0 : cy);
d.circle.setAttribute('fill', fill);
d.circle.setAttribute('fill-opacity', opacity);
d.circle.setAttribute('r', radius);
d.circle.setAttribute('stroke', stroke);
d.circle.setAttribute('stroke-width', strokeWidth);
d.circle.setAttribute('stroke-opacity', strokeOpacity);
});
return _this; // .parentNode;
};
}
chrtMarkers.prototype = Object.create(chrtObject$1.prototype);
chrtMarkers.prototype.constructor = chrtMarkers;
chrtMarkers.parent = chrtObject$1.prototype;
chrtMarkers.prototype = Object.assign(chrtMarkers.prototype, {
fill: fill,
size: size,
radius: size,
stroke: stroke$1,
strokeWidth: strokeWidth$1,
strokeOpacity: strokeOpacity$1,
fillOpacity: fillOpacity$1,
showMarkers: showMarkers,
filter: showMarkers,
hideMarkers: hideMarkers,
firstMarker: firstMarker,
lastMarker: lastMarker,
firstAndLastMarkers: firstAndLastMarkers
});
// export default chrtMarkers;
function chrtMarkers$1 () {
return new chrtMarkers();
}
// chrt-object v0.0.15 Copyright 2020-2022 chrt chrt.io
function _toConsumableArray$5(arr) {
return _arrayWithoutHoles$5(arr) || _iterableToArray$5(arr) || _unsupportedIterableToArray$5(arr) || _nonIterableSpread$5();
}
function _arrayWithoutHoles$5(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$5(arr);
}
function _iterableToArray$5(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$5(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$5(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$5(o, minLen);
}
function _arrayLikeToArray$5(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$5() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var COMPONENTS_W_DATA = ['chrt', 'series'];
function isNull$7(value) {
return value === null || value == null || typeof value === 'undefined';
}
function uuid() {
return 'c' + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
function hasData(obj) {
return !isNull$7(obj.type) && COMPONENTS_W_DATA.indexOf(obj.type) > -1;
}
function isInfinity$1(value) {
return !isFinite(value);
}
function oppositeSigns(x, y) {
return (x ^ y) < 0;
}
function getCoords$1(data) {
var _this = this;
if (!(this !== null && this !== void 0 && this.fields)) {
return [];
}
return data.map(function (d) {
var x = isNull$7(d[_this.fields.x]) || isInfinity$1(d[_this.fields.x]) ? null : _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = isNull$7(d[_this.fields.y]) || isInfinity$1(d[_this.fields.y]) ? null : _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
return [isInfinity$1(x) ? 0 : x, isInfinity$1(y) ? 0 : y];
}); //.filter(d => !isNull(d[0]) && !isNull(d[1]))
}
function create$4(tag) {
return document.createElement(tag);
}
function createSVG(tag) {
return document.createElementNS('http://www.w3.org/2000/svg', tag);
}
function getStrokeStyle(style) {
var strokeWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var strokeLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
var strokeStyle = null;
switch (style) {
case 'dashed':
strokeStyle = "".concat(strokeWidth * strokeLength, " ").concat(strokeWidth * strokeLength);
break;
case 'dotted':
strokeStyle = "".concat(strokeWidth, " ").concat(strokeWidth);
break;
case 'solid':
default:
strokeStyle = null;
}
return strokeStyle;
}
function add$2(obj) {
var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var id = obj._id || uuid(); // console.log('adding to', this, obj.type, id, obj);
obj.id(id).parent(this); // .render();
if (prepend) {
this.objects = [obj].concat(_toConsumableArray$5(this.objects));
} else {
this.objects.push(obj);
} //return this.update();
return this;
}
// export { add } from '../charts/util'
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
add: add$2,
isNull: isNull$7,
uuid: uuid,
hasData: hasData,
isInfinity: isInfinity$1,
oppositeSigns: oppositeSigns,
getCoords: getCoords$1,
create: create$4,
createSVG: createSVG,
getStrokeStyle: getStrokeStyle
});
function render(parent) {
// console.log('RENDER', this, parent)
if (this.g) {
// avoid duplication of g
return this;
}
this.g = createSVG('g');
if (this._id) {
this.g.setAttribute('id', this._id);
} // console.log('RENDER', this, this.parentNode)
if (hasData(this)) {
// series
// in case of group or stack we want the chart to be added to svg g of the group/stack
if (parent) {
// if it's a stack we want the order of the charts in the dom to be opposite, so the stroke
// of the charts below is not covered by the area above
if (parent.type === 'stack' || parent.group === 'group') {
parent.g.prepend(this.g);
} else {
parent.g.append(this.g);
}
} else {
this.currentNode.append(this.g);
}
} else {
// const grid = (this.parentNode.objects || []).slice().reverse().find(obj => obj.type === 'grid');
// if(grid && this.type === 'axis') {
// // // console.log('THIS IS AN',this.type,'AND THERE IS A GRID',grid,'INSERT BEFORE',grid.node(), grid.node().nextSibling)
// this.currentNode.insertBefore(this.g, grid.node().nextSibling);
// } else {
// // console.log('THIS IS A', this.type, 'PREPEND')
// this.currentNode.append(this.g);
// }
this.currentNode.append(this.g);
}
this.update();
return this; // .parentNode;
}
function update() {
if (this.parentNode && this.parentNode.scales.x[this.scales.x] && this.parentNode.scales.y[this.scales.y]) {
this.draw();
}
return this;
}
function curve(interpolationFunction) {
if (isNull$7(interpolationFunction)) {
return this.interpolationFunction;
}
this.interpolationFunction = interpolationFunction;
return this;
}
function attribute(name, fn) {
var accessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (value) {
return value;
};
if (isNull$7(name)) {
console.warn('name missing: attr method requires a name for the attribute');
return this;
}
if (!isNull$7(name) && typeof fn === 'undefined') {
var _this$attrs;
// this.name()
return ((_this$attrs = this.attrs) === null || _this$attrs === void 0 ? void 0 : _this$attrs[name]) || function () {};
}
if (typeof fn === 'function') {
// something will go here
this.attrs[name] = fn;
} else {
// fn is a Boolean, String, Number or any other type but function
this.attrs[name] = function () {
return accessor(fn);
};
}
return this;
}
function data (data, accessor) {
// console.log('---------------> data', data, accessor, this);
if (!data) {
// console.log('NO DATA return', hasData(this), this._data, hasData(this) ? this._data : this)
return hasData(this) ? this._data || null : this;
} // TODO: not sure what this is doing...
if (!hasData(this)) {
// console.log('NO HAS DATA')
return this;
} // console.log('HAS DATA')
// // console.log('chrt or series', this.type)
// passing only accessor to inherit/reuse data
if (typeof arguments[0] === 'function') {
this._accessor = arguments[0];
return this;
} // data is passed
this._orginalData = this._orginalData || data; // define accessor function to map values
var accessorFunction = accessor || this._accessor;
this._accessor = accessorFunction;
this._data = accessorFunction && !this._accessorApplied ? data.map(function (d, i, arr) {
if (d instanceof Object) {
return Object.assign({}, d, accessorFunction(d, i, arr));
}
return accessorFunction(d, i, arr);
}) : data; // console.log('DATA', data)
this._accessorApplied = true; // do not apply the accessor multiple times
return this;
}
/**
* node - Returns the DOM element that contains a chart element
*
* @param {type} node Set this as root node
*
* @return {type} Description
*/
function node (node) {
if (!node) {
return this.g || this.root;
}
this.root = node;
this.currentNode = this.root;
return this;
}
function parent (obj) {
if (!obj) {
return this.parentNode;
}
this.parentNode = obj;
return this;
}
function display(value) {
return attribute.call(this, 'display', value);
}
function show() {
return display.call(this, true);
}
function hide() {
return display.call(this, false);
}
function cssDisplay(value) {
var DOMNode = node.call(this);
if (!DOMNode) {
return this;
}
var currentDisplay = DOMNode.style.display;
this._display = typeof this._display !== 'undefined' ? this._display : DOMNode.style.display;
if (!value) {
DOMNode.style.display = 'none';
} else {
if (currentDisplay === 'none' && value) {
DOMNode.style.display = this._display;
}
}
return this;
}
function chrtObject() {
var _this = this;
this._id = null;
this.objects = [];
this.type = 'chrt-object';
this.fields = {
x: null,
y: null
};
this.scales = {
x: 'x',
y: 'y'
};
this._classNames = [];
this._accessor = function (d, i) {
return {
x: !isNull$7(d) && Object.prototype.hasOwnProperty.call(d, 'x') ? d.x : i,
y: isNull$7(d) ? null : Object.prototype.hasOwnProperty.call(d, 'y') ? d.y : d
};
};
this.interpolationFunction = null; // list of getter/setter function for custom attributes
this.attrs = [];
attribute.call(this, 'display', true);
this.id = function (id) {
// console.log('chrtObject.id', id, this._id);
if (isNull$7(id)) {
return _this._id;
}
_this._id = id || _this._id;
if (_this.g) {
_this.g.setAttribute('id', _this._id);
}
return _this;
};
this.class = function (className) {
if (isNull$7(className)) {
return _this._classNames;
}
var classNames = (Array.isArray(className) ? className : className.split(' ')).map(function (d) {
return d.replace(/\s\s+/g, ' ').trim();
}).filter(function (d) {
return d !== '';
});
_this.original_classNames = _this.original_classNames || _this._classNames;
_this._classNames = _toConsumableArray$5(new Set([].concat(_toConsumableArray$5(_this.original_classNames), _toConsumableArray$5(classNames))));
if (_this.g) {
var _this$g$classList, _this$g$classList2;
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$5(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$5(_this._classNames));
}
return _this;
};
this.hasData = function () {
return hasData(_this);
};
var setScale = function setScale(scale, scaleName) {
if (!isNull$7(scaleName)) {
_this.scales[scale] = scaleName;
}
};
this.x = function (scale) {
if (isNull$7(scale)) {
return _this.scales.x;
}
setScale('x', scale || 'x');
return _this;
};
this.y = function (scale) {
if (isNull$7(scale)) {
return _this.scales.y;
}
setScale('y', scale || 'y');
return _this;
};
return this;
}
function chrt() {
return new chrtObject();
}
chrtObject.prototype = Object.create(chrt.prototype); // chrtObject.prototype = chrt.prototype = Object.assign(chrt.prototype, {
chrtObject.prototype = Object.assign(chrt.prototype, {
node: node,
data: data,
add: add$2,
snap: add$2,
parent: parent,
render: render,
update: update,
curve: curve,
attr: attribute,
show: show,
hide: hide
});
// chrt-set v0.0.12 Copyright 2020-2022 chrt chrt.io
function _toConsumableArray$4(arr) {
return _arrayWithoutHoles$4(arr) || _iterableToArray$4(arr) || _unsupportedIterableToArray$4(arr) || _nonIterableSpread$4();
}
function _arrayWithoutHoles$4(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$4(arr);
}
function _iterableToArray$4(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$4(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$4(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$4(o, minLen);
}
function _arrayLikeToArray$4(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$4() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var isNull$1$1 = index.isNull,
add$1 = index.add;
function chrtStack() {
var _this = this;
//console.log('chrtStack')
chrtObject.call(this);
this.type = 'stack';
this._grouped = 1;
this._groupIndex = 0;
this._orientation = 'bottom';
this._dataMap = {
x: {},
y: {}
};
this._classNames = ['chrt-stack'];
this.orientation = function (orientation) {
if (isNull$1$1(orientation)) {
return _this._orientation;
}
var orientations = ['bottom', 'left'];
_this._orientation = orientations.indexOf(orientation) > -1 ? orientation : _this._orientation;
return _this;
};
this.add = function (chart) {
// console.log('chrtStack','add',chart, chart._area)
chart._stacked = _this;
add$1.call(_this, chart); // console.log('add', this.parentNode)
var dataFunction = chart.data;
chart.data = function (data, accessor) {
//console.log('chrtStack','data!', this._dataMap)
if (!isNull$1$1(data)) {
data = data.map(function (d) {
var _d$x, _d$y;
var x = (_d$x = d.x) !== null && _d$x !== void 0 ? _d$x : d.x0;
var y = (_d$y = d.y) !== null && _d$y !== void 0 ? _d$y : d.y0;
if (!_this._dataMap.x[x]) {
_this._dataMap.x[x] = {
x: x,
values: []
};
}
_this._dataMap.x[x].values.push(d);
var y0 = !isNull$1$1(_this._dataMap.x[x].y0) ? _this._dataMap.x[x].y0 : null;
var y0_neg = !isNull$1$1(_this._dataMap.x[x].y0_neg) ? _this._dataMap.x[x].y0_neg : null;
if (d.y >= 0) {
_this._dataMap.x[x].y0 = _this._orientation !== 'bottom' ? null : (y0 || 0) + y;
} else {
_this._dataMap.x[x].y0_neg = _this._orientation !== 'bottom' ? null : (y0_neg || 0) + y;
}
if (!_this._dataMap.y[y]) {
_this._dataMap.y[y] = {
y: y,
values: []
};
}
_this._dataMap.y[y].values.push(d);
var x0 = !isNull$1$1(_this._dataMap.y[y].x0) ? _this._dataMap.y[y].x0 : null;
var x0_neg = !isNull$1$1(_this._dataMap.y[y].x0_neg) ? _this._dataMap.y[y].x0_neg : null;
if (d.x >= 0) {
_this._dataMap.y[y].x0 = _this._orientation !== 'left' ? null : (x0 || 0) + x;
} else {
_this._dataMap.y[y].x0_neg = _this._orientation !== 'left' ? null : (x0_neg || 0) + x;
} // check if d.y is a number, if not then most probably it's a
// ordinal scale, to avoid odd chaining of numbers and string
// chrt doesn't add them but keeps only d.y
var valueWithStack = Object.assign({}, d, {
stacked_y: isNaN(y) ? y : (y >= 0 ? y0 : y0_neg || 0) + y,
stacked_y0: y >= 0 ? y0 : y0_neg,
stacked_x: isNaN(x) ? x : ((x >= 0 ? x0 : x0_neg) || 0) + x,
stacked_x0: x >= 0 ? x0 : x0_neg
});
return valueWithStack;
}); // console.log(this._dataMap)
} // console.log('CALLING DATA ON',chart,'WITH', data)
return dataFunction.call(chart, data, accessor);
};
return _this;
};
this.snap = this.add;
this.draw = function () {
var _this$g$classList, _this$g$classList2;
// console.log('chrtStack', 'draw', this.objects);
var parentNode = _this.parentNode.type === 'group' ? _this.parentNode.parentNode : _this.parentNode;
_this.objects.forEach(function (obj) {
if (parentNode.objects.map(function (d) {
return d._id;
}).indexOf(obj._id) === -1) {
parentNode.add(obj);
} // console.log('--->', obj)
});
cssDisplay.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$4(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$4(_this._classNames));
_this.objects.forEach(function (obj) {
return obj.draw();
});
return _this;
};
}
chrtStack.prototype = Object.create(chrtObject.prototype);
chrtStack.prototype.constructor = chrtStack;
chrtStack.parent = chrtObject.prototype;
chrtStack.prototype = Object.assign(chrtStack.prototype, {});
function chrtStack$1 () {
return new chrtStack();
}
var isNull$6 = index.isNull,
add = index.add;
function chrtGroup() {
var _this = this;
chrtObject.call(this);
this.type = 'group';
this.attr('width', 1);
this._classNames = ['chrt-group'];
this.width = function (width) {
if (isNull$6(width)) {
return _this.attr('width')();
}
_this.attr('width', Math.min(Math.max(width, 0), 1));
return _this;
};
this.add = function (chart) {
// console.log('chrtGroup','add',chart)
add.call(_this, chart);
chart._groupIndex = _this.objects.length - 1;
_this.objects.forEach(function (obj) {
obj._group = _this;
obj._grouped = _this.objects.length;
});
return _this;
};
this.snap = this.add;
this.draw = function () {
var _this$g$classList, _this$g$classList2;
_this.objects.forEach(function (obj) {
if (_this.parentNode.objects.map(function (d) {
return d._id;
}).indexOf(obj._id) === -1) {
_this.parentNode.add(obj);
} // console.log('--->', obj)
});
_this.objects.forEach(function (obj) {
return obj.draw();
});
cssDisplay.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$4(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$4(_this._classNames));
return _this;
};
}
chrtGroup.prototype = Object.create(chrtObject.prototype);
chrtGroup.prototype.constructor = chrtGroup;
chrtGroup.parent = chrtObject.prototype;
chrtGroup.prototype = Object.assign(chrtGroup.prototype, {
snap: add
});
function chrtGroup$1 () {
return new chrtGroup();
}
// chrt.io v0.0.22 Copyright 2022 chrt
function _toConsumableArray$3(arr) {
return _arrayWithoutHoles$3(arr) || _iterableToArray$3(arr) || _unsupportedIterableToArray$3(arr) || _nonIterableSpread$3();
}
function _arrayWithoutHoles$3(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$3(arr);
}
function _iterableToArray$3(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$3(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$3(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen);
}
function _arrayLikeToArray$3(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$3() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function color$1(value) {
return this.attr('color', value);
}
// import { isNull } from '~/helpers';
function position(coords) {
var currentPosition = this.attr('position')();
if (typeof coords === 'undefined') {
return currentPosition;
}
return this.attr('position', Object.assign({}, currentPosition, coords));
}
function top(y) {
return position.call(this, {
y: y
});
}
function left(x) {
return position.call(this, {
x: x
});
}
// import { isNull } from '~/helpers';
function alignment(align) {
var currentAlignment = this.attr('alignment')();
if (typeof align === 'undefined') {
return currentAlignment;
}
return this.attr('alignment', Object.assign({}, currentAlignment, align));
}
function valign(position) {
if (typeof position === 'undefined') {
return alignment.call(this).vertical;
}
return alignment.call(this, {
vertical: position
});
}
function align(position) {
if (typeof position === 'undefined') {
return alignment.call(this).horizontal;
}
return alignment.call(this, {
horizontal: position
});
}
function offset() {
for (var _len = arguments.length, offsets = new Array(_len), _key = 0; _key < _len; _key++) {
offsets[_key] = arguments[_key];
}
if (!offsets.length) {
return this.attr('offset')();
}
var currentOffset = this.attr('offset')();
var left = offsets[0],
top = offsets[1];
return this.attr('offset', [left !== null && left !== void 0 ? left : currentOffset[0], top !== null && top !== void 0 ? top : currentOffset[1]]);
}
var isNull$5 = index$3.isNull,
create$3 = index$3.create;
function chrtAnnotation(text) {
var _this = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
x: 'x',
y: 'y'
};
chrtObject$3.call(this);
this.type = 'annnotation';
this.div = null;
this.attr('text', text !== null && text !== void 0 ? text : '');
this.attr('color', null);
this.attr('position', {});
this.attr('alignment', {
horizontal: 'middle',
vertical: 'middle'
});
this.attr('offset', [0, 0]);
this._classNames = ['chrt-annotation']; // console.log('chrtAnnotation', options)
this.text = function (text) {
return _this.attr('text', text);
};
this.draw = function () {
var _this$div$classList, _this$div$classList2;
// annotations can only added to the main chrtCore component
if (_this.parentNode.type !== 'chrt') {
return _this;
} // TODO: probably should be the last one
var scales = {
x: _this.parentNode.scales.x[options.x] || Object.values(_this.parentNode.scales.x)[0],
y: _this.parentNode.scales.y[options.y] || Object.values(_this.parentNode.scales.y)[0]
}; // console.log('options', options)
// console.log('scales', scales)
if (!_this.div) {
var _this$parentNode$root, _this$parentNode$root2;
_this.div = create$3('div');
_this.parentNode.root.appendChild(_this.div);
if (((_this$parentNode$root = _this.parentNode.root) === null || _this$parentNode$root === void 0 ? void 0 : (_this$parentNode$root2 = _this$parentNode$root.style) === null || _this$parentNode$root2 === void 0 ? void 0 : _this$parentNode$root2.position) === '') {
_this.parentNode.root.style.position = 'relative';
}
_this.div.style.position = 'absolute';
_this.g = _this.div;
}
console.log('display', _this.attr('display')());
cssDisplay$3.call(_this, _this.attr('display')());
_this.div.setAttribute('id', _this.id());
(_this$div$classList = _this.div.classList).remove.apply(_this$div$classList, _toConsumableArray$3(_this.div.classList));
(_this$div$classList2 = _this.div.classList).add.apply(_this$div$classList2, _toConsumableArray$3(_this._classNames));
if (scales && scales['x']) {
var _position = _this.attr('position')();
var x = isNull$5(_position.x) ? 0 : scales.x(_position.x); // if y is not defined by the user, it should be calculated based on the closest Y value based on X
var y = isNull$5(_position.y) ? 0 : scales.y(_position.y);
var _offsets = _this.attr('offset')(); // offset.call(this)();
_this.div.style.left = "".concat(x + _offsets[0], "px");
_this.div.style.top = "".concat(y + _offsets[1], "px");
}
var transform = {
x: 0,
y: 0
};
var _alignment = _this.attr('alignment')();
switch (_alignment.horizontal) {
case 'left':
transform.x = '0';
break;
case 'right':
transform.x = '-100%';
break;
case 'center':
case 'middle':
default:
transform.x = '-50%';
}
switch (_alignment.vertical) {
case 'bottom':
transform.y = '0';
break;
case 'top':
transform.y = '-100%';
break;
case 'center':
case 'middle':
default:
transform.y = '-50%';
}
_this.div.style.transform = "translate(".concat(transform.x, ",").concat(transform.y, ")");
var label = _this.div.querySelector('span');
if (!label) {
var _this$color;
label = create$3('span');
label.style.color = (_this$color = _this.color()()) !== null && _this$color !== void 0 ? _this$color : 'inherit';
_this.div.appendChild(label);
}
label.innerHTML = _this.attr('text')();
return _this;
};
}
chrtAnnotation.prototype = Object.create(chrtObject$3.prototype);
chrtAnnotation.prototype.constructor = chrtAnnotation;
chrtAnnotation.parent = chrtObject$3.prototype;
chrtAnnotation.prototype = Object.assign(chrtAnnotation.prototype, {
color: color$1,
position: position,
top: top,
left: left,
align: align,
valign: valign,
offset: offset
}); // export default chrtAnnotation;
function chrtAnnotation$1 (text, options) {
return new chrtAnnotation(text, options);
}
// chrt-interpolations v0.0.15 Copyright 2020-2024 chrt chrt.io
function _arrayLikeToArray$2(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _arrayWithoutHoles$2(r) {
if (Array.isArray(r)) return _arrayLikeToArray$2(r);
}
function _iterableToArray$2(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableSpread$2() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray$2(r, e) || _nonIterableRest();
}
function _toConsumableArray$2(r) {
return _arrayWithoutHoles$2(r) || _iterableToArray$2(r) || _unsupportedIterableToArray$2(r) || _nonIterableSpread$2();
}
function _unsupportedIterableToArray$2(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray$2(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$2(r, a) : void 0;
}
}
function isNull$4(value) {
return value === null || value == null || typeof value === 'undefined';
}
function isInfinity(value) {
return typeof value === 'number' && !isFinite(value);
}
function getCoords(data) {
var _this = this;
if (!(this !== null && this !== void 0 && this.fields)) {
return [];
}
return data.map(function (d) {
var x = isNull$4(d[_this.fields.x]) || isInfinity(d[_this.fields.x]) ? null : _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = isNull$4(d[_this.fields.y]) || isInfinity(d[_this.fields.y]) ? null : _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
return [isInfinity(x) ? 0 : x, isInfinity(y) ? 0 : y];
}); //.filter(d => !isNull(d[0]) && !isNull(d[1]))
}
// Render the svg <path> element
// I: - points (array): points coordinates
// - command (function)
// I: - point (array) [x,y]: current point coordinates
// - i (integer): index of 'point' in the array 'a'
// - a (array): complete array of points coordinates
// O: - (string) a svg path command
// O: - (string): a Svg <path> element
var svgPath = function svgPath(points, command) {
var _ref;
// build the d attributes by looping over the points
var splitByNullPoints = points.reduce(function (acc, point) {
if (isNull$4(point[1])) {
acc.push([]);
} else {
acc[acc.length - 1].push(point);
}
return acc;
}, [[]]);
var paths = splitByNullPoints.map(function (points) {
return points.reduce(function (acc, point, i, a) {
acc.push(i === 0 ? // if first point
"M".concat(isNaN(point[0]) ? 0 : point[0], ",").concat(isNaN(point[1]) ? 0 : point[1]) : // else
"".concat(command(point, i, a)));
return acc;
}, []);
});
return (_ref = []).concat.apply(_ref, _toConsumableArray$2(paths));
};
function linearInterpolation(data) {
return svgPath(getCoords.call(this, data), lineCommand);
}
var lineCommand = function lineCommand(point) {
return "L".concat(isNaN(point[0]) ? 0 : point[0], ",").concat(isNaN(point[1]) ? 0 : point[1]);
};
function splineInterpolation(data) {
return svgPath(getCoords.call(this, data), bezierCommand);
}
// Properties of a line
// I: - pointA (array) [x,y]: coordinates
// - pointB (array) [x,y]: coordinates
// O: - (object) { length: l, angle: a }: properties of the line
var line = function line(pointA, pointB) {
var lengthX = pointB[0] - pointA[0];
var lengthY = pointB[1] - pointA[1];
return {
length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)),
angle: Math.atan2(lengthY, lengthX)
};
};
// Position of a control point
// I: - current (array) [x, y]: current point coordinates
// - previous (array) [x, y]: previous point coordinates
// - next (array) [x, y]: next point coordinates
// - reverse (boolean, optional): sets the direction
// O: - (array) [x,y]: a tuple of coordinates
var controlPoint = function controlPoint(current, previous, next, reverse) {
// When 'current' is the first or last point of the array
// 'previous' or 'next' don't exist.
// Replace with 'current'
var p = previous || current;
var n = next || current;
// The smoothing ratio
var smoothing = 0.1;
// Properties of the opposed-line
var o = line(p, n);
// If is end-control-point, add PI to the angle to go backward
var angle = o.angle + (reverse ? Math.PI : 0);
var length = o.length * smoothing;
// The control point position is relative to the current point
var x = current[0] + Math.cos(angle) * length;
var y = current[1] + Math.sin(angle) * length;
return [x, y];
};
// Create the bezier curve command
// I: - point (array) [x,y]: current point coordinates
// - i (integer): index of 'point' in the array 'a'
// - a (array): complete array of points coordinates
// O: - (string) 'C x2,y2 x1,y1 x,y': SVG cubic bezier C command
var bezierCommand = function bezierCommand(point, i, a) {
if (isNaN(point[0]) || isNaN(point[1])) {
return '';
}
// start control point
var _controlPoint = controlPoint(a[i - 1], a[i - 2], point),
_controlPoint2 = _slicedToArray(_controlPoint, 2),
cpsX = _controlPoint2[0],
cpsY = _controlPoint2[1];
// end control point
var _controlPoint3 = controlPoint(point, a[i - 1], a[i + 1], true),
_controlPoint4 = _slicedToArray(_controlPoint3, 2),
cpeX = _controlPoint4[0],
cpeY = _controlPoint4[1];
return "C ".concat(cpsX, ",").concat(cpsY, " ").concat(cpeX, ",").concat(cpeY, " ").concat(point[0], ",").concat(point[1]);
};
//
// function splineCurve(firstPoint, middlePoint, afterPoint, t = 1) {
// // Props to Rob Spencer at scaled innovation for his post on splining between points
// // http://scaledinnovation.com/analytics/splines/aboutSplines.html
//
// // This function must also respect "skipped" points
//
// // console.log('splineCurve', firstPoint, middlePoint, afterPoint);
//
// const previous = firstPoint.skip ? middlePoint : firstPoint;
// const current = middlePoint;
// const next = afterPoint.skip ? middlePoint : afterPoint;
//
// const d01 = Math.sqrt(
// Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2)
// );
// const d12 = Math.sqrt(
// Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2)
// );
//
// let s01 = d01 / (d01 + d12);
// let s12 = d12 / (d01 + d12);
//
// // If all points are the same, s01 & s02 will be inf
// s01 = isNaN(s01) ? 0 : s01;
// s12 = isNaN(s12) ? 0 : s12;
//
// const fa = t * s01; // scaling factor for triangle Ta
// const fb = t * s12;
//
// return {
// previous: {
// x: current.x - fa * (next.x - previous.x),
// y: current.y - fa * (next.y - previous.y)
// },
// next: {
// x: current.x + fb * (next.x - previous.x),
// y: current.y + fb * (next.y - previous.y)
// }
// };
// }
function stepInterpolation(data) {
var command = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : stepCommand;
return svgPath(getCoords.call(this, data), command);
}
function stepAfterInterpolation(data) {
return stepInterpolation.call(this, data, stepCommandAfter);
}
function stepBeforeInterpolation(data) {
return stepInterpolation.call(this, data, stepCommandBefore);
}
var stepCommand = function stepCommand(point, i, a) {
var xMiddle = ((isNaN(point[0]) ? 0 : point[0]) + (isNaN(a[i - 1][0]) ? 0 : a[i - 1][0])) / 2;
return "L".concat(isNaN(xMiddle) ? 0 : xMiddle, ",").concat(isNaN(a[i - 1][1]) ? 0 : a[i - 1][1], "\n L").concat(isNaN(xMiddle) ? 0 : xMiddle, ",").concat(isNaN(point[1]) ? 0 : point[1], "\n L").concat(isNaN(point[0]) ? 0 : point[0], ",").concat(isNaN(point[1]) ? 0 : point[1]);
};
var stepCommandAfter = function stepCommandAfter(point, i, a) {
return "L".concat(isNaN(point[0]) ? 0 : point[0], ",").concat(isNaN(a[i - 1][1]) ? 0 : a[i - 1][1], "\n L").concat(isNaN(point[0]) ? 0 : point[0], ",").concat(isNaN(point[1]) ? 0 : point[1]);
};
var stepCommandBefore = function stepCommandBefore(point, i, a) {
return "L".concat(isNaN(a[i - 1][0]) ? 0 : a[i - 1][0], ",").concat(isNaN(point[1]) ? 0 : point[1], "\n L").concat(isNaN(point[0]) ? 0 : point[0], ",").concat(isNaN(point[1]) ? 0 : point[1]);
};
var chrtInterpolations_esm = /*#__PURE__*/Object.freeze({
__proto__: null,
linear: linearInterpolation,
spline: splineInterpolation,
step: stepInterpolation,
stepAfter: stepAfterInterpolation,
stepBefore: stepBeforeInterpolation
});
// chrt.io v0.0.8 Copyright 2022 chrt
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _toConsumableArray$1(arr) {
return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread$1();
}
function _arrayWithoutHoles$1(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
}
function _iterableToArray$1(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$1(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
}
function _arrayLikeToArray$1(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread$1() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function pointSize(value) {
return this.attr('radius', value);
}
function pointColor(value) {
return this.attr('fill', value);
}
function pointStroke(value) {
return this.attr('stroke', value);
}
function pointStrokeWidth(value) {
return this.attr('strokeWidth', value);
}
function pointOpacity(value) {
return this.attr('fillOpacity', value);
}
function strokeOpacity(value) {
return this.attr('strokeOpacity', value);
}
function range$1() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
return this.attr('range', value);
}
function rangeColor(value) {
return this.attr('rangeColor', value);
}
function rangeWidth(value) {
return this.attr('rangeWidth', value);
}
function orient(value) {
return this.attr('orient', value);
}
function horizontal() {
return orient.call(this, 'horizontal');
}
function vertical() {
return orient.call(this, 'vertical');
}
var isNull$3 = index$3.isNull,
create$2 = index$3.createSVG;
var DEFAULT_POINT_SIZE = 3;
var DEFAULT_POINT_COLOR = '#000';
function chrtDotPlot() {
var _this = this;
chrtObject$3.call(this);
this.type = 'series'; // this.size = DEFAULT_POINT_SIZE;
// this.fill = DEFAULT_POINT_COLOR;
// this.stroke = DEFAULT_POINT_COLOR;
// this.strokeWidth = 0;
// this._opacity = 1;
this.attr('radius', DEFAULT_POINT_SIZE);
this.attr('stroke', DEFAULT_POINT_COLOR);
this.attr('fill', DEFAULT_POINT_COLOR);
this.attr('strokeWidth', 0);
this.attr('strokeOpacity', 1);
this.attr('fillOpacity', 1);
this.attr('range', false);
this.attr('rangeWidth', DEFAULT_POINT_SIZE);
this.attr('rangeColor', DEFAULT_POINT_COLOR);
horizontal.call(this);
this._classNames = ['chrt-dotplot'];
this.getXScale = function () {
if (isNull$3(_this.fields.x)) {
_this.fields.x = _this.parentNode.scales.x[_this.scales.x].field;
}
return _this.parentNode.scales.x[_this.scales.x];
};
this.draw = function () {
var _this$g$classList, _this$g$classList2;
cssDisplay$3.call(_this, _this.attr('display')());
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray$1(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray$1(_this._classNames));
if (!isNull$3(_this._data)) {
if (isNull$3(_this.fields.x)) {
_this.fields.x = _this.parentNode.scales.x[_this.scales.x].field;
}
if (isNull$3(_this.fields.y)) {
//console.log('this.scales', this.scales)
//console.log('this.parentNode.scales', this.parentNode.scales)
_this.fields.y = _this.parentNode.scales.y[_this.scales.y].field;
}
if (_this.attr('range')()) {
// console.log('ORIENT', this.attr('orient')())
var _rangeWidth = _this.attr('rangeWidth')();
var _rangeColor = _this.attr('rangeColor')();
var rangeType = _this.attr('orient')() === 'vertical' ? 'x' : 'y';
var ranges = _this._data.reduce(function (acc, d) {
var _ref;
var otherField = rangeType === 'x' ? _this.fields.y : _this.fields.x;
acc[d[_this.fields[rangeType]]] = acc[d[_this.fields[rangeType]]] || (_ref = {}, _defineProperty(_ref, rangeType, d[_this.fields[rangeType]]), _defineProperty(_ref, "data", []), _defineProperty(_ref, "field", rangeType), _defineProperty(_ref, "otherField", otherField), _ref);
acc[d[_this.fields[rangeType]]].data.push(d);
var otherData = acc[d[_this.fields[rangeType]]].data.map(function (d) {
return d[otherField];
});
acc[d[_this.fields[rangeType]]].max = Math.max.apply(Math, _toConsumableArray$1(otherData));
acc[d[_this.fields[rangeType]]].min = Math.min.apply(Math, _toConsumableArray$1(otherData));
return acc;
}, {}); // console.log('ranges', ranges);
Object.values(ranges).forEach(function (r, rangeIndex) {
var dataID = escape("range-".concat(r[rangeType], "-").concat(rangeIndex));
var range = _this.g.querySelector("[data-id='".concat(dataID, "']"));
if (!range) {
range = create$2('line');
range.setAttribute('data-id', dataID);
_this.g.appendChild(range);
}
if (!isNull$3(_this.parentNode.scales.x[_this.scales.x]) && !isNull$3(_this.parentNode.scales.y[_this.scales.y])) {
var _coords;
// const x = this.parentNode.scales.x[this.scales.x](range.min);
// const y = this.parentNode.scales.y[this.scales.y](d[this.fields.y]);
var coords = (_coords = {}, _defineProperty(_coords, r.field, _this.parentNode.scales[r.field][_this.scales[r.field]](r[r.field])), _defineProperty(_coords, "".concat(r.otherField, "Min"), _this.parentNode.scales[r.otherField][_this.scales[r.otherField]](r.min)), _defineProperty(_coords, "".concat(r.otherField, "Max"), _this.parentNode.scales[r.otherField][_this.scales[r.otherField]](r.max)), _coords); // console.log(coords);
if (rangeType === 'y') {
range.setAttribute('x1', !isNaN(coords["".concat(r.otherField, "Min")]) ? coords["".concat(r.otherField, "Min")] : 0);
range.setAttribute('x2', !isNaN(coords["".concat(r.otherField, "Max")]) ? coords["".concat(r.otherField, "Max")] : 0);
range.setAttribute('y1', !isNaN(coords[r.field]) ? coords[r.field] : 0);
range.setAttribute('y2', !isNaN(coords[r.field]) ? coords[r.field] : 0);
} else {
range.setAttribute('y1', !isNaN(coords["".concat(r.otherField, "Min")]) ? coords["".concat(r.otherField, "Min")] : 0);
range.setAttribute('y2', !isNaN(coords["".concat(r.otherField, "Max")]) ? coords["".concat(r.otherField, "Max")] : 0);
range.setAttribute('x1', !isNaN(coords[r.field]) ? coords[r.field] : 0);
range.setAttribute('x2', !isNaN(coords[r.field]) ? coords[r.field] : 0);
}
range.setAttribute('stroke-width', _rangeWidth);
range.setAttribute('stroke', _rangeColor);
}
});
}
_this._data.forEach(function (d, i, arr) {
var dataID = escape("circle-".concat(name, "-").concat(i));
var circle = _this.g.querySelector("[data-id='".concat(dataID, "']"));
if (!circle) {
circle = create$2('circle');
circle.setAttribute('data-id', dataID);
_this.g.appendChild(circle);
}
if (!isNull$3(_this.parentNode.scales.x[_this.scales.x]) && !isNull$3(_this.parentNode.scales.y[_this.scales.y])) {
var x = _this.parentNode.scales.x[_this.scales.x](d[_this.fields.x]);
var y = _this.parentNode.scales.y[_this.scales.y](d[_this.fields.y]);
var cx = !isNaN(x) ? x : 0;
var cy = !isNaN(y) ? y : 0;
var r = _this.attr('radius')(d, i, arr);
d.anchorPoints = {
x: cx,
width: r,
y: cy,
height: r,
relativePosition: [0, 0],
directions: {
x: 1,
y: 1
},
alignment: {
horizontal: 'middle',
vertical: 'top'
}
};
circle.setAttribute('cx', cx);
circle.setAttribute('cy', cy);
circle.setAttribute('r', r);
circle.setAttribute('fill', _this.attr('fill')(d, i, arr));
circle.setAttribute('fill-opacity', _this.attr('fillOpacity')(d, i, arr) || 1);
circle.setAttribute('stroke', _this.attr('stroke')(d, i, arr));
circle.setAttribute('stroke-width', _this.attr('strokeWidth')(d, i, arr));
circle.setAttribute('stroke-opacity', _this.attr('strokeOpacity')(d, i, arr));
}
}); // // // console.log('points', points);
}
_this.objects.forEach(function (obj) {
return obj.draw();
});
return _this.parentNode;
};
}
chrtDotPlot.prototype = Object.create(chrtObject$3.prototype);
chrtDotPlot.prototype.constructor = chrtDotPlot;
chrtDotPlot.parent = chrtObject$3.prototype;
chrtDotPlot.prototype = Object.assign(chrtDotPlot.prototype, {
pointSize: pointSize,
size: pointSize,
radius: pointSize,
color: pointColor,
stroke: pointStroke,
width: pointStrokeWidth,
strokeWidth: pointStrokeWidth,
opacity: pointOpacity,
strokeOpacity: strokeOpacity,
range: range$1,
rangeColor: rangeColor,
rangeWidth: rangeWidth,
orient: orient,
horizontal: horizontal,
vertical: vertical
}); // export default chrtDotPlot;
function chrtDotPlot$1 () {
return new chrtDotPlot();
}
// chrt.io v0.0.9 Copyright 2024 chrt
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function color(value) {
return this.attr('fill', value); // if(!value) {
// return this._fill;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// this._fill = value;
// }
// return this;
}
var isNull$2 = index$3.isNull;
function range(values) {
if (isNull$2(values)) {
return this;
}
if (typeof values === 'function') ; else {
this._range = Object.assign({}, this._range, values);
}
return this;
}
function from(value) {
return range.call(this, {
from: value
});
}
function to(value) {
return range.call(this, {
to: value
});
}
function stroke(value) {
return this.attr('stroke', value);
}
function strokeWidth(value) {
return this.attr('strokeWidth', value); // if(!value) {
// return this._strokeWidth;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// this._strokeWidth = value;
// }
// return this;
}
function lineStyle(value) {
return this.attr('lineStyle', value); // return;
// if(!value) {
// return this._strokeStyle;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// const strokeWidth = this.attr('strokeWidth')();
// switch(value) {
// case 'dashed':
// this._strokeStyle = `${strokeWidth * 4} ${strokeWidth * 4}`;
// break;
// case 'dotted':
// this._strokeStyle = `${strokeWidth} ${strokeWidth}`;
// break;
// case 'solid':
// default:
// this._strokeStyle = null;
// }
// }
// return this;
}
function fillOpacity(value) {
return this.attr('fillOpacity', value); // if(!value) {
// return this._strokeWidth;
// }
//
// if (typeof value === 'function') {
// // something will go here
// } else {
// this._strokeWidth = value;
// }
// return this;
}
var DEFAULT_FILL_COLOR = '#ddd';
var DEFAULT_STROKE = '#000';
var DEFAULT_STROKE_OPACITY = 1;
var DEFAULT_STROKE_WIDTH = 1;
var DEFAULT_FILL_OPACITY = 1;
function chrtRange() {
var _this = this;
// console.log('chrtAxisRange', this)
chrtObject$3.call(this);
this.type = 'range';
this.g = null;
this.attr('fill', DEFAULT_FILL_COLOR);
this.attr('stroke', DEFAULT_STROKE);
this.attr('fillOpacity', DEFAULT_FILL_OPACITY);
this.attr('strokeOpacity', DEFAULT_STROKE_OPACITY);
this.attr('strokeWidth', DEFAULT_STROKE_WIDTH);
this.attr('lineStyle', 'solid');
this._range = {};
this._classNames = ['chrt-range'];
this.solid = function () {
return lineStyle.call(_this, 'solid');
};
this.dashed = function () {
return lineStyle.call(_this, 'dashed');
};
this.dotted = function () {
return lineStyle.call(_this, 'dotted');
};
this.strokeOpacity = function (value) {
return _this.attr('strokeOpacity', value);
};
return this.parentNode;
}
chrtRange.prototype = Object.create(chrtObject$3.prototype);
chrtRange.prototype.constructor = chrtRange;
chrtRange.parent = chrtObject$3.prototype;
chrtRange.prototype = Object.assign(chrtRange.prototype, {
color: color,
fill: color,
stroke: stroke,
strokeWidth: strokeWidth,
fillOpacity: fillOpacity,
lineStyle: lineStyle,
from: from,
to: to
});
var isNull$1 = index$3.isNull,
create$1 = index$3.createSVG;
function chrtHorizontalRange() {
var _this = this;
chrtRange.call(this); // this.class('chrt-y-axis-range')
this.class(['chrt-range', 'chrt-horizontal-range']);
this.draw = function () {
var _this$g$classList, _this$g$classList2, _this$parentNode$name, _this$parentNode2;
if (!['chrt'].includes(_this.parentNode.type)) {
return _this.parentNode;
}
_this.parentNode.type === 'chrt'; // if (!this.parentNode.parentNode.scales) {
// return this.parentNode.parentNode;
// }
if (!_this.g) {
_this.g = create$1('g'); // this.g.setAttribute('data-id', this._id);
_this.g.setAttribute('data-name', "".concat(_this.parentNode.type, "-range"));
}
cssDisplay$3.call(_this, _this.attr('display')());
_this.g.setAttribute('id', "".concat(_this.parentNode.type, "Range-").concat(_this.id()));
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray(_this._classNames));
var fill = _this.attr('fill')();
var fillOpacity = _this.attr('fillOpacity')();
var stroke = _this.attr('stroke')();
var strokeOpacity = _this.attr('strokeOpacity')();
var strokeWidth = _this.attr('strokeWidth')();
var _this$parentNode = _this.parentNode,
scales = _this$parentNode.scales,
width = _this$parentNode.width,
_margins = _this$parentNode._margins;
var from = null;
var to = null;
if (scales && scales.y[(_this$parentNode$name = _this === null || _this === void 0 ? void 0 : (_this$parentNode2 = _this.parentNode) === null || _this$parentNode2 === void 0 ? void 0 : _this$parentNode2.name) !== null && _this$parentNode$name !== void 0 ? _this$parentNode$name : 'y']) {
var _this$parentNode$name2, _this$parentNode3;
var _scale = scales.y[(_this$parentNode$name2 = _this === null || _this === void 0 ? void 0 : (_this$parentNode3 = _this.parentNode) === null || _this$parentNode3 === void 0 ? void 0 : _this$parentNode3.name) !== null && _this$parentNode$name2 !== void 0 ? _this$parentNode$name2 : 'y'];
from = isNull$1(_this._range.from) ? from : _scale(_this._range.from);
to = isNull$1(_this._range.to) ? to : _scale(_this._range.to);
}
if (isNaN(from) || isNaN(to)) {
return;
}
if (!_this.path) {
_this.path = create$1('path');
_this.g.appendChild(_this.path);
}
if (isNull$1(from) && isNull$1(to) || isNaN(from) && isNaN(to)) {
return;
}
_this.g.setAttribute('transform', "translate(".concat(_margins.left, ",0)"));
from = isNull$1(from) ? to : from;
to = isNull$1(to) ? from : to;
if (from === to) {
_this.path.remove();
_this.path = null;
} else {
var d = [[0, from], [0, to], [width - (_margins.right + _margins.left), to], [width - (_margins.right + _margins.left), from]];
_this.path.setAttribute('d', "M".concat(d.join('L'), "z"));
_this.path.setAttribute('fill', fill);
_this.path.setAttribute('fill-opacity', fillOpacity);
}
var strokeStyle = _this.attr('lineStyle')();
if (!isNull$1(strokeStyle)) {
switch (strokeStyle) {
case 'dashed':
_this._strokeStyle = "".concat(strokeWidth * 4, " ").concat(strokeWidth * 4);
break;
case 'dotted':
_this._strokeStyle = "".concat(strokeWidth, " ").concat(strokeWidth);
break;
case 'solid':
default:
_this._strokeStyle = null;
}
}
var lines = _toConsumableArray(new Set([from, to]));
if (isNull$1(_this.lines)) {
_this.lines = [];
}
lines.forEach(function (position, index) {
if (!_this.lines[index]) {
_this.lines[index] = create$1('line');
_this.g.appendChild(_this.lines[index]);
}
var line = _this.lines[index];
line.setAttribute('x1', 0);
line.setAttribute('x2', width - (_margins.left + _margins.right));
line.setAttribute('y1', position);
line.setAttribute('y2', position);
line.setAttribute('stroke', stroke);
line.setAttribute('stroke-width', strokeWidth);
line.setAttribute('stroke-opacity', strokeOpacity);
if (!isNull$1(_this._strokeStyle)) {
line.setAttribute('stroke-dasharray', _this._strokeStyle);
}
});
return _this.parentNode;
};
}
chrtHorizontalRange.prototype = Object.create(chrtRange.prototype);
chrtHorizontalRange.prototype.constructor = chrtHorizontalRange;
chrtHorizontalRange.parent = chrtRange.prototype;
function chrtHorizontalRange$1 () {
return new chrtHorizontalRange();
}
var isNull = index$3.isNull,
create = index$3.createSVG;
function chrtVerticalRange() {
var _this = this;
chrtRange.call(this);
this.class(['chrt-range', 'chrt-vertical-range']);
this.draw = function () {
var _this$g$classList, _this$g$classList2, _this$parentNode$name, _this$parentNode2;
// console.log('chrtVerticalRange draw', this, this.parentNode.type);
if (!['chrt'].includes(_this.parentNode.type)) {
return _this.parentNode;
}
if (!_this.g) {
_this.g = create('g'); // this.g.setAttribute('data-id', this._id);
_this.g.setAttribute('data-name', "".concat(_this.parentNode.type, "-range"));
}
cssDisplay$3.call(_this, _this.attr('display')());
_this.g.setAttribute('id', "".concat(_this.parentNode.type, "Range-").concat(_this.id()));
(_this$g$classList = _this.g.classList).remove.apply(_this$g$classList, _toConsumableArray(_this.g.classList));
(_this$g$classList2 = _this.g.classList).add.apply(_this$g$classList2, _toConsumableArray(_this._classNames));
var fill = _this.attr('fill')();
var fillOpacity = _this.attr('fillOpacity')();
var stroke = _this.attr('stroke')();
var strokeOpacity = _this.attr('strokeOpacity')();
var strokeWidth = _this.attr('strokeWidth')();
var _this$parentNode = _this.parentNode,
scales = _this$parentNode.scales,
height = _this$parentNode.height,
_margins = _this$parentNode._margins;
var from = null;
var to = null;
if (scales && scales.x[(_this$parentNode$name = _this === null || _this === void 0 ? void 0 : (_this$parentNode2 = _this.parentNode) === null || _this$parentNode2 === void 0 ? void 0 : _this$parentNode2.name) !== null && _this$parentNode$name !== void 0 ? _this$parentNode$name : 'x']) {
var _this$parentNode$name2, _this$parentNode3;
var _scale = scales.x[(_this$parentNode$name2 = _this === null || _this === void 0 ? void 0 : (_this$parentNode3 = _this.parentNode) === null || _this$parentNode3 === void 0 ? void 0 : _this$parentNode3.name) !== null && _this$parentNode$name2 !== void 0 ? _this$parentNode$name2 : 'x'];
from = isNull(_this._range.from) ? from : _scale(_this._range.from);
to = isNull(_this._range.to) ? to : _scale(_this._range.to);
}
if (isNaN(from) || isNaN(to)) {
return;
}
if (!_this.path) {
_this.path = create('path');
_this.g.appendChild(_this.path);
} // console.log('FROM', from, 'TO', to)
if (isNull(from) && isNull(to)) {
return;
}
_this.g.setAttribute('transform', "translate(0, ".concat(height - _margins.bottom - 1, ")")); // the range should be at least 1px thick
from = isNull(from) ? to : from;
to = isNull(to) ? from : to;
if (from === to) {
_this.path.remove();
_this.path = null;
} else {
var d = [[from, 0], [to, 0], [to, -(height - (_margins.top + _margins.bottom))], [from, -(height - (_margins.top + _margins.bottom))]];
_this.path.setAttribute('d', "M".concat(d.join('L'), "z"));
_this.path.setAttribute('fill', fill);
_this.path.setAttribute('fill-opacity', fillOpacity);
}
var strokeStyle = _this.attr('lineStyle')();
if (!isNull(strokeStyle)) {
switch (strokeStyle) {
case 'dashed':
_this._strokeStyle = "".concat(strokeWidth * 4, " ").concat(strokeWidth * 4);
break;
case 'dotted':
_this._strokeStyle = "".concat(strokeWidth, " ").concat(strokeWidth);
break;
case 'solid':
default:
_this._strokeStyle = null;
}
}
var lines = _toConsumableArray(new Set([from, to]));
if (isNull(_this.lines)) {
_this.lines = [];
}
lines.forEach(function (position, index) {
if (!_this.lines[index]) {
_this.lines[index] = create('line');
_this.g.appendChild(_this.lines[index]);
}
var line = _this.lines[index];
line.setAttribute('x1', position);
line.setAttribute('x2', position);
line.setAttribute('y1', 0);
line.setAttribute('y2', -(height - (_margins.top + _margins.bottom)));
line.setAttribute('stroke', stroke);
line.setAttribute('stroke-width', strokeWidth);
line.setAttribute('stroke-opacity', strokeOpacity);
if (!isNull(_this._strokeStyle)) {
line.setAttribute('stroke-dasharray', _this._strokeStyle);
}
});
return _this.parentNode;
};
}
chrtVerticalRange.prototype = Object.create(chrtRange.prototype);
chrtVerticalRange.prototype.constructor = chrtVerticalRange;
chrtVerticalRange.parent = chrtRange.prototype;
function chrtVerticalRange$1 () {
return new chrtVerticalRange();
}
exports.Chrt = chrt$6;
exports.annotation = chrtAnnotation$1;
exports.axisTitle = index$5;
exports.bars = chrtBars$1;
exports.chrtAnnotation = chrtAnnotation$1;
exports.chrtAxisTitle = index$5;
exports.chrtBars = chrtBars$1;
exports.chrtColumns = chrtColumns$1;
exports.chrtDotPlot = chrtDotPlot$1;
exports.chrtGroup = chrtGroup$1;
exports.chrtHistograms = chrtHistograms$1;
exports.chrtHorizontalRange = chrtHorizontalRange$1;
exports.chrtLabel = chrtLabel$1;
exports.chrtLabels = chrtLabels$1;
exports.chrtLine = chrtLine$1;
exports.chrtMarkers = chrtMarkers$1;
exports.chrtPoints = chrtPoints$1;
exports.chrtStack = chrtStack$1;
exports.chrtVerticalRange = chrtVerticalRange$1;
exports.columns = chrtColumns$1;
exports.dotPlot = chrtDotPlot$1;
exports.group = chrtGroup$1;
exports.histograms = chrtHistograms$1;
exports.horizontalGrid = horizontalGrid;
exports.horizontalRange = chrtHorizontalRange$1;
exports.interpolations = chrtInterpolations_esm;
exports.label = chrtLabel$1;
exports.labels = chrtLabels$1;
exports.line = chrtLine$1;
exports.markers = chrtMarkers$1;
exports.points = chrtPoints$1;
exports.stack = chrtStack$1;
exports.version = version;
exports.verticalGrid = verticalGrid;
exports.verticalRange = chrtVerticalRange$1;
exports.xAxis = xAxis$1;
exports.yAxis = yAxis$1;
}));