function _array_like_to_array(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 _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _assert_this_initialized(self) {
    if (self === void 0) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    }
    return self;
}
function _call_super(_this, derived, args) {
    derived = _get_prototype_of(derived);
    return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
}
function _class_call_check(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}
function _defineProperties(target, props) {
    for(var i = 0; i < props.length; i++){
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) descriptor.writable = true;
        Object.defineProperty(target, descriptor.key, descriptor);
    }
}
function _create_class(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
}
function _define_property(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 _get_prototype_of(o) {
    _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
        return o.__proto__ || Object.getPrototypeOf(o);
    };
    return _get_prototype_of(o);
}
function _inherits(subClass, superClass) {
    if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function");
    }
    subClass.prototype = Object.create(superClass && superClass.prototype, {
        constructor: {
            value: subClass,
            writable: true,
            configurable: true
        }
    });
    if (superClass) _set_prototype_of(subClass, superClass);
}
function _instanceof(left, right) {
    "@swc/helpers - instanceof";
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
function _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    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 _non_iterable_spread() {
    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 _possible_constructor_return(self, call) {
    if (call && (_type_of(call) === "object" || typeof call === "function")) {
        return call;
    }
    return _assert_this_initialized(self);
}
function _set_prototype_of(o, p) {
    _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
        o.__proto__ = p;
        return o;
    };
    return _set_prototype_of(o, p);
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(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(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function _is_native_reflect_construct() {
    try {
        var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
    } catch (_) {}
    return (_is_native_reflect_construct = function() {
        return !!result;
    })();
}
import { extent, max, min, range as d3Range, sum } from "d3-array";
import { timeFormat, timeFormatDefaultLocale } from "d3-time-format";
import * as scales from "d3-scale";
import { select } from "d3-selection";
import { transition } from "d3-transition";
// @ts-ignore
import pkg from "open-color/open-color.js";
var openColor = pkg.theme;
import { colorContrast, colorDefaults } from "@d3plus/color";
import { assign, attrize, backgroundColor, date, elem, rtl as detectRTL } from "@d3plus/dom";
import { formatAbbreviate, formatDate } from "@d3plus/format";
import { formatLocale, locale } from "@d3plus/locales";
import { closest } from "@d3plus/math";
import { fontFamily as d3plusFontFamily, textWrap } from "@d3plus/text";
import { TextBox } from "../components/index.js";
import * as shapes from "../shapes/index.js";
import { configPrep, BaseClass, constant } from "../utils/index.js";
/* catches for -0 and less*/ var isNegative = function isNegative(d) {
    return d < 0 || Object.is(d, -0);
};
var floorPow = function floorPow(d) {
    return Math.pow(10, Math.floor(Math.log10(Math.abs(d)))) * Math.pow(-1, isNegative(d) ? 1 : 0);
};
var ceilPow = function ceilPow(d) {
    return Math.pow(10, Math.ceil(Math.log10(Math.abs(d)))) * Math.pow(-1, isNegative(d) ? 1 : 0);
};
var fixFloat = function fixFloat(d) {
    var str = "".concat(d);
    if (str.includes("e-") || str === "0") return 0;
    var nineMatch = str.match(/(-*[0-9]+\.[0]*)([0-8]+)9{3,}[0-9]+$/);
    if (nineMatch) return +"".concat(nineMatch[1]).concat(+nineMatch[2] + 1);
    var zeroMatch = str.match(/(-*[0-9]+\.[0]*)([1-9]+)0*[0-9]*0{3,}[0-9]+$/);
    if (zeroMatch) return +"".concat(zeroMatch[1]).concat(+zeroMatch[2]);
    return d;
};
var maxTimezoneOffset = 1000 * 60 * 60 * 26;
/**
 * Calculates ticks from a given scale (negative and/or positive)
 * @param {scale} scale A d3-scale object
 * @private
*/ function calculateStep(// eslint-disable-next-line @typescript-eslint/no-explicit-any
scale) {
    var minorTicks = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    var stepScale = scales.scaleLinear().domain([
        200,
        1200
    ]).range([
        8,
        28
    ]);
    var scaleRange = scale.range();
    var size = Math.abs(scaleRange[1] - scaleRange[0]);
    var step = Math.floor(stepScale(size));
    if (this._scale === "time") {
        if (this._data && this._data.length) {
            var dataExtent = extent(this._data);
            var distance = this._data.reduce(function(n, d, i, arr) {
                if (i) {
                    var dist = Math.abs(d - arr[i - 1]);
                    if (dist < n) n = dist;
                }
                return n;
            }, Infinity);
            var newStep = Math.round((dataExtent[1] - dataExtent[0]) / distance);
            step = min([
                step * (minorTicks ? 2 : 0.5),
                newStep
            ]);
        } else {
            step = minorTicks ? step * 2 : step / 2;
        }
    }
    return Math.floor(step);
}
/**
 * Calculates ticks from a given scale (negative and/or positive)
 * @param {scale} scale A d3-scale object
 * @private
*/ function calculateTicks(// eslint-disable-next-line @typescript-eslint/no-explicit-any
scale) {
    var minorTicks = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
    var ticks = [];
    var scaleClone = scale.copy();
    if (this._scale === "time" && this._data.length) {
        var newDomain = extent(this._data);
        var range = newDomain.map(scale);
        scaleClone.domain(newDomain).range(range);
    }
    var domain = scaleClone.domain();
    var inverted = domain[1] < domain[0];
    var step = calculateStep.bind(this)(scaleClone, minorTicks);
    if (!minorTicks && this._scale === "log") {
        var roundDomain = domain.map(function(d) {
            return Math.log10(d) % 1 === 0 ? d : (inverted ? ceilPow : floorPow)(d);
        });
        var invertedRound = roundDomain[1] < roundDomain[0];
        var powers = roundDomain.map(function(d) {
            return (isNegative(d) ? -1 : 1) * ([
                -1,
                1
            ].includes(d) || Math.abs(d) < 1 ? 1 : Math.log10(Math.abs(d)));
        });
        var powMod = Math.ceil((Math.abs(powers[1] - powers[0]) + 1) / (step * 0.65));
        ticks = powMod <= 1 && powers[0] === powers[1] || invertedRound !== inverted ? scaleClone.ticks(step).filter(function(d) {
            return +"".concat(d).replace("0.", "") % 2 === 0;
        }) : d3Range(powers[0], powers[1], powers[1] < powers[0] ? -1 : 1).concat([
            powers[1]
        ]).filter(function(d) {
            return Math.abs(d) % powMod === 0;
        }).map(function(d) {
            return +"".concat((isNegative(d) ? -1 : 1) * (d ? Math.pow(10, Math.abs(d)) : Math.sign(1 / d) > 0 ? 1 : -1)).replace(/9+/g, "1");
        });
    } else {
        ticks = scaleClone.ticks(step);
        if (!minorTicks && ![
            "log",
            "time"
        ].includes(this._scale) && ticks.length > 1) {
            var majorDiff = Math.abs(fixFloat(ticks[1] - ticks[0]) * 2);
            ticks = ticks.filter(function(d) {
                var mod = Math.abs(d) % majorDiff;
                var modFloat = fixFloat(mod);
                if (modFloat !== mod) {
                    return !modFloat || modFloat === majorDiff;
                }
                return mod === 0;
            });
        }
    }
    // for time scale, if data array has been provided, filter out ticks that are not in the array
    if (this._scale === "time" && this._data.length) {
        var dataNumbers = this._data.map(Number);
        ticks = ticks.filter(function(t) {
            var tn = +t;
            return dataNumbers.find(function(n) {
                return n >= tn - maxTimezoneOffset && n <= tn + maxTimezoneOffset;
            });
        });
    }
    // forces min/max into ticks, if not present
    if (!this._d3ScaleNegative || isNegative(domain[inverted ? 1 : 0]) === ticks.some(function(d) {
        return isNegative(d);
    })) {
        if (!ticks.map(Number).includes(+domain[0])) {
            ticks.unshift(domain[0]);
        }
    }
    if (!this._d3ScaleNegative || isNegative(domain[inverted ? 0 : 1]) === ticks.some(function(d) {
        return isNegative(d);
    })) {
        if (!ticks.map(Number).includes(+domain[1])) {
            ticks.push(domain[1]);
        }
    }
    return ticks;
}
var Axis = /*#__PURE__*/ function(BaseClass) {
    "use strict";
    _inherits(Axis, BaseClass);
    function Axis() {
        _class_call_check(this, Axis);
        var _this;
        _this = _call_super(this, Axis), _define_property(_this, "_select", void 0), _define_property(_this, "_align", void 0), _define_property(_this, "_barConfig", void 0), // eslint-disable-next-line @typescript-eslint/no-explicit-any
        _define_property(_this, "_data", void 0), // eslint-disable-next-line @typescript-eslint/no-explicit-any
        _define_property(_this, "_domain", void 0), _define_property(_this, "_duration", void 0), _define_property(_this, "_gridConfig", void 0), _define_property(_this, "_gridLog", void 0), _define_property(_this, "_gridSize", void 0), _define_property(_this, "_grid", void 0), _define_property(_this, "_height", void 0), _define_property(_this, "_labelOffset", void 0), _define_property(_this, "_labelRotation", void 0), _define_property(_this, "_labels", void 0), _define_property(_this, "_margin", void 0), _define_property(_this, "_maxSize", void 0), _define_property(_this, "_minSize", void 0), _define_property(_this, "_orient", void 0), _define_property(_this, "_outerBounds", void 0), _define_property(_this, "_padding", void 0), _define_property(_this, "_paddingInner", void 0), _define_property(_this, "_paddingOuter", void 0), _define_property(_this, "_position", void 0), _define_property(_this, "_range", void 0), _define_property(_this, "_rounding", void 0), _define_property(_this, "_roundingInsideMinPrefix", void 0), _define_property(_this, "_roundingInsideMinSuffix", void 0), _define_property(_this, "_roundingInsideMaxPrefix", void 0), _define_property(_this, "_roundingInsideMaxSuffix", void 0), _define_property(_this, "_scale", void 0), _define_property(_this, "_scalePadding", void 0), _define_property(_this, "_shape", void 0), // eslint-disable-next-line @typescript-eslint/no-explicit-any
        _define_property(_this, "_shapeConfig", void 0), // eslint-disable-next-line @typescript-eslint/no-explicit-any
        _define_property(_this, "_tickFormat", void 0), _define_property(_this, "_ticks", void 0), _define_property(_this, "_tickSize", void 0), _define_property(_this, "_tickSuffix", void 0), _define_property(_this, "_tickUnit", void 0), _define_property(_this, "_timeLocale", void 0), _define_property(_this, "_title", void 0), _define_property(_this, "_titleClass", void 0), // eslint-disable-next-line @typescript-eslint/no-explicit-any
        _define_property(_this, "_titleConfig", void 0), _define_property(_this, "_width", void 0), // D3 scales have complex polymorphic types that vary at runtime
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        _define_property(_this, "_d3Scale", void 0), // eslint-disable-next-line @typescript-eslint/no-explicit-any
        _define_property(_this, "_d3ScaleNegative", void 0), _define_property(_this, "_group", void 0), _define_property(_this, "_lastScale", void 0), _define_property(_this, "_availableTicks", void 0), _define_property(_this, "_visibleTicks", void 0), _define_property(_this, "_transition", void 0), _define_property(_this, "_userFormat", void 0);
        _this._align = "middle";
        _this._barConfig = {
            stroke: function stroke() {
                var bg = _this._select ? backgroundColor(_this._select.node()) : "rgb(255, 255, 255)";
                return colorContrast(bg);
            },
            "stroke-width": 1
        };
        _this._data = [];
        _this._domain = [
            0,
            10
        ];
        _this._duration = 600;
        _this._gridConfig = {
            stroke: function stroke() {
                var bg = _this._select ? backgroundColor(_this._select.node()) : "rgb(255, 255, 255)";
                var contrast = colorContrast(bg);
                return contrast === colorDefaults.dark ? openColor.colors.gray[200] : openColor.colors.gray[600];
            },
            "stroke-width": 1
        };
        _this._gridLog = false;
        _this._height = 400;
        _this._labelOffset = false;
        _this._labelRotation = false;
        _this.orient("bottom");
        _this._outerBounds = {
            width: 0,
            height: 0,
            x: 0,
            y: 0
        };
        _this._padding = 5;
        _this._paddingInner = 0.1;
        _this._paddingOuter = 0.1;
        _this._rounding = "none";
        _this._roundingInsideMinPrefix = "< ";
        _this._roundingInsideMinSuffix = "";
        _this._roundingInsideMaxPrefix = "";
        _this._roundingInsideMaxSuffix = "+";
        _this._scale = "linear";
        _this._scalePadding = 0.5;
        _this._shape = "Line";
        _this._shapeConfig = {
            fill: function fill() {
                var bg = _this._select ? backgroundColor(_this._select.node()) : "rgb(255, 255, 255)";
                return colorContrast(bg);
            },
            height: function height(d) {
                return d.tick ? 8 : 0;
            },
            label: function label(d) {
                return d.text;
            },
            labelBounds: function labelBounds(d) {
                return d.labelBounds;
            },
            labelConfig: {
                fontColor: function fontColor() {
                    var bg = _this._select ? backgroundColor(_this._select.node()) : "rgb(255, 255, 255)";
                    return colorContrast(bg);
                },
                fontResize: false,
                fontSize: constant(12),
                padding: 5,
                textAnchor: function textAnchor() {
                    var rtl = detectRTL();
                    return _this._orient === "left" ? rtl ? "start" : "end" : _this._orient === "right" ? rtl ? "end" : "start" : _this._labelRotation ? _this._orient === "bottom" ? "end" : "start" : "middle";
                },
                verticalAlign: function verticalAlign() {
                    return _this._orient === "bottom" ? "top" : _this._orient === "top" ? "bottom" : "middle";
                }
            },
            r: function r(d) {
                return d.tick ? 4 : 0;
            },
            stroke: function stroke() {
                var bg = _this._select ? backgroundColor(_this._select.node()) : "rgb(255, 255, 255)";
                return colorContrast(bg);
            },
            strokeWidth: 1,
            width: function width(d) {
                return d.tick ? 8 : 0;
            }
        };
        _this._tickSize = 8;
        _this._tickSuffix = "normal";
        _this._tickUnit = 0;
        _this._timeLocale = undefined;
        _this._titleClass = new TextBox();
        _this._titleConfig = {
            fontColor: function fontColor() {
                var bg = _this._select ? backgroundColor(_this._select.node()) : "rgb(255, 255, 255)";
                return colorContrast(bg);
            },
            fontSize: 12,
            textAnchor: "middle"
        };
        _this._width = 400;
        _this._margin = {
            top: 0,
            right: 0,
            bottom: 0,
            left: 0
        };
        _this._availableTicks = [];
        _this._visibleTicks = [];
        return _this;
    }
    _create_class(Axis, [
        {
            /**
      Sets positioning for the axis bar.
      @param bar @private
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
            key: "_barPosition",
            value: function _barPosition(bar) {
                var _this__position = this._position, height = _this__position.height, x = _this__position.x, y = _this__position.y, opposite = _this__position.opposite, offset = this._margin[opposite], position = [
                    "top",
                    "left"
                ].includes(this._orient) ? this._outerBounds[y] + this._outerBounds[height] - offset : this._outerBounds[y] + offset;
                var x1mod = this._scale === "band" ? this._d3Scale.step() - this._d3Scale.bandwidth() : this._scale === "point" ? this._d3Scale.step() * this._d3Scale.padding() : 0;
                var x2mod = this._scale === "band" ? this._d3Scale.step() : this._scale === "point" ? this._d3Scale.step() * this._d3Scale.padding() : 0;
                var sortedDomain = (this._d3ScaleNegative ? this._d3ScaleNegative.domain() : []).concat(this._d3Scale ? this._d3Scale.domain() : []).sort(function(a, b) {
                    return a - b;
                });
                bar.call(attrize, this._barConfig).attr("".concat(x, "1"), this._getPosition(sortedDomain[0]) - x1mod).attr("".concat(x, "2"), this._getPosition(sortedDomain[sortedDomain.length - 1]) + x2mod).attr("".concat(y, "1"), position).attr("".concat(y, "2"), position);
            }
        },
        {
            /**
      Returns the scale's domain, taking into account negative and positive log scales.
      @private
*/ key: "_getDomain",
            value: function _getDomain() {
                var ticks = [];
                if (this._d3ScaleNegative) ticks = this._d3ScaleNegative.domain();
                if (this._d3Scale) ticks = ticks.concat(this._d3Scale.domain());
                var domain = [
                    "band",
                    "ordinal",
                    "point"
                ].includes(this._scale) ? ticks : extent(ticks);
                return ticks[0] > ticks[1] ? domain.reverse() : domain;
            }
        },
        {
            /**
      Returns a value's scale position, taking into account negative and positive log scales.
      @param d @private
*/ key: "_getPosition",
            value: function _getPosition(d) {
                if (this._scale === "log") {
                    if (d === 0) return (this._d3Scale || this._d3ScaleNegative).range()[this._d3Scale ? 0 : 1];
                    return (isNegative(d) ? this._d3ScaleNegative || function() {
                        return 0;
                    } : this._d3Scale)(d);
                }
                return this._d3Scale(d);
            }
        },
        {
            /**
      Returns the scale's range, taking into account negative and positive log scales.
      @private
*/ key: "_getRange",
            value: function _getRange() {
                var ticks = [];
                if (this._d3ScaleNegative) ticks = this._d3ScaleNegative.range();
                if (this._d3Scale) ticks = ticks.concat(this._d3Scale.range());
                return ticks[0] > ticks[1] ? extent(ticks).reverse() : extent(ticks);
            }
        },
        {
            /**
      Returns the scale's labels, taking into account negative and positive log scales.
      @private
*/ key: "_getLabels",
            value: function _getLabels() {
                var labels = [];
                if (this._d3ScaleNegative) labels = labels.concat(calculateTicks.bind(this)(this._d3ScaleNegative, false));
                if (this._d3Scale) labels = labels.concat(calculateTicks.bind(this)(this._d3Scale, false));
                if (this._scale === "log") {
                    var diverging = labels.some(function(d) {
                        return isNegative(d);
                    }) && labels.some(function(d) {
                        return d > 0;
                    });
                    if (diverging) {
                        var minValue = min(_to_consumable_array(this._d3ScaleNegative.domain().map(Math.abs)).concat(_to_consumable_array(this._d3Scale.domain())));
                        // add minValue if it does not exist, and should
                        if (!labels.includes(minValue)) {
                            labels.splice(labels.findIndex(function(d) {
                                return d > minValue;
                            }), 0, minValue);
                        }
                        // remove -minValue if minValue also exists
                        if (labels.includes(-minValue) && labels.includes(minValue)) {
                            labels.splice(labels.indexOf(-minValue), 1);
                        }
                    }
                }
                return labels;
            }
        },
        {
            /**
      Returns the scale's ticks, taking into account negative and positive log scales.
      @private
*/ key: "_getTicks",
            value: function _getTicks() {
                if ([
                    "band",
                    "ordinal",
                    "point",
                    "time"
                ].includes(this._scale) && this._data.length && this._data.length < this._width / 4) {
                    return this._scale === "time" ? this._data.map(date) : this._data;
                }
                var ticks = [];
                if (this._d3ScaleNegative) ticks = ticks.concat(calculateTicks.bind(this)(this._d3ScaleNegative, true));
                if (this._d3Scale) ticks = ticks.concat(calculateTicks.bind(this)(this._d3Scale, true));
                if (this._scale === "log" && ticks.includes(-1) && ticks.includes(1)) ticks.splice(ticks.indexOf(-1), 1);
                return ticks;
            }
        },
        {
            /**
      Sets positioning for the grid lines.
      @param lines @private
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
            key: "_gridPosition",
            value: function _gridPosition(lines) {
                var last = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
                var _this__position = this._position, height = _this__position.height, x = _this__position.x, y = _this__position.y, opposite = _this__position.opposite, offset = this._margin[opposite], position = [
                    "top",
                    "left"
                ].includes(this._orient) ? this._outerBounds[y] + this._outerBounds[height] - offset : this._outerBounds[y] + offset, scale = last ? this._lastScale || this._getPosition.bind(this) : this._getPosition.bind(this), size = [
                    "top",
                    "left"
                ].includes(this._orient) ? offset : -offset, xDiff = this._scale === "band" ? this._d3Scale.bandwidth() / 2 : 0, xPos = function xPos(d) {
                    return scale(d.id) + xDiff;
                };
                lines.call(attrize, this._gridConfig).attr("".concat(x, "1"), xPos).attr("".concat(x, "2"), xPos).attr("".concat(y, "1"), position).attr("".concat(y, "2"), last ? position : position + size);
            }
        },
        {
            /**
      Renders the current Axis to the page.
    @param callback Optional callback invoked after rendering completes.
*/ key: "render",
            value: function render(callback) {
                var _this = this;
                var _this1 = this;
                /**
     * Creates an SVG element to contain the axis if none
     * has been specified using the "select" method.
*/ if (this._select === void 0) {
                    this.select(select("body").append("svg").attr("width", "".concat(this._width, "px")).attr("height", "".concat(this._height, "px")).node());
                }
                var timeLocale = this._timeLocale || locale[this._locale] || locale["en-US"];
                timeFormatDefaultLocale(timeLocale);
                /**
     * Declares some commonly used variables.
*/ var _this__position = this._position, width = _this__position.width, height = _this__position.height, x = _this__position.x, y = _this__position.y, horizontal = _this__position.horizontal, opposite = _this__position.opposite, clipId = "d3plus-Axis-clip-".concat(this._uuid), flip = [
                    "top",
                    "left"
                ].includes(this._orient), p = this._padding, parent = this._select, rangeOuter = [
                    p,
                    this["_".concat(width)] - p
                ], t = transition().duration(this._duration);
                var tickValue = this._shape === "Circle" ? this._shapeConfig.r : this._shape === "Rect" ? this._shapeConfig[width] : this._shapeConfig.strokeWidth;
                var tickGet = typeof tickValue !== "function" ? function() {
                    return tickValue;
                } : tickValue;
                /**
     * Zeros out the margins for re-calculation.
*/ var margin = this._margin = {
                    top: 0,
                    right: 0,
                    bottom: 0,
                    left: 0
                };
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var labels = [], range = [], ticks = [];
                /**
     * Constructs the tick formatter function.
*/ var tickFormat = this._tickFormat ? this._tickFormat : function(d) {
                    if (isNaN(d) || [
                        "band",
                        "ordinal",
                        "point"
                    ].includes(_this._scale)) {
                        return d;
                    } else if (_this._scale === "time") {
                        var refData = (_this._data.length ? _this._data : _this._domain).map(function(v) {
                            return date(v);
                        }).filter(function(d) {
                            return _instanceof(d, Date);
                        }).sort(function(a, b) {
                            return +a - +b;
                        });
                        return formatDate(d, refData, timeFormat).replace(/^Q/g, timeLocale.quarter);
                    } else if (_this._scale === "linear" && _this._tickSuffix === "smallest") {
                        var loc = _type_of(_this._locale) === "object" ? _this._locale : formatLocale[_this._locale];
                        var separator = loc.separator, suffixes = loc.suffixes;
                        var suff = d >= 1000 ? suffixes[_this._tickUnit + 8] : "";
                        var tick = d / Math.pow(10, 3 * _this._tickUnit);
                        var number = formatAbbreviate(tick, loc, ",.".concat(tick.toString().length, "r"));
                        return "".concat(number).concat(separator).concat(suff);
                    } else {
                        var inverted = ticks[1] < ticks[0];
                        var minTick = inverted ? ticks.length - 1 : 0;
                        var maxTick = inverted ? 0 : ticks.length - 1;
                        var prefix = _this._rounding === "inside" ? ticks.indexOf(d) === minTick ? _this._roundingInsideMinPrefix : ticks.indexOf(d) === maxTick ? _this._roundingInsideMaxPrefix : "" : "";
                        var suffix = _this._rounding === "inside" ? ticks.indexOf(d) === minTick ? _this._roundingInsideMinSuffix : ticks.indexOf(d) === maxTick ? _this._roundingInsideMaxSuffix : "" : "";
                        return "".concat(prefix).concat(formatAbbreviate(d, _this._locale)).concat(suffix);
                    }
                };
                /**
     * (Re)calculates the internal d3 scale
     * @param {} newRange
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var setScale = function setScale() {
                    var newRange = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _this1._range;
                    /**
       * Calculates the internal "range" array to use, including
       * fallbacks if not specified with the "range" method.
*/ range = newRange ? newRange.slice() : [
                        undefined,
                        undefined
                    ];
                    var _rangeOuter = _sliced_to_array(rangeOuter, 2), minRange = _rangeOuter[0], maxRange = _rangeOuter[1];
                    if (_this1._range) {
                        if (_this1._range[0] !== undefined) minRange = _this1._range[0];
                        if (_this1._range[_this1._range.length - 1] !== undefined) maxRange = _this1._range[_this1._range.length - 1];
                    }
                    if (range[0] === undefined || range[0] < minRange) range[0] = minRange;
                    if (range[1] === undefined || range[1] > maxRange) range[1] = maxRange;
                    var sizeInner = maxRange - minRange;
                    if (_this1._scale === "ordinal" && _this1._domain.length > range.length) {
                        if (newRange === _this1._range) {
                            var buckets = _this1._domain.length + 1;
                            range = d3Range(buckets).map(function(d) {
                                return range[0] + sizeInner * (d / (buckets - 1));
                            }).slice(1, buckets);
                            range = range.map(function(d) {
                                return d - range[0] / 2;
                            });
                        } else {
                            var buckets1 = _this1._domain.length;
                            var size = range[1] - range[0];
                            range = d3Range(buckets1).map(function(d) {
                                return range[0] + size * (d / (buckets1 - 1));
                            });
                        }
                    }
                    /**
       * Sets up the initial d3 scale, using this._domain and the
       * previously defined range variable.
*/ var scale = "scale".concat(_this1._scale.charAt(0).toUpperCase()).concat(_this1._scale.slice(1));
                    var initialDomain = _this1._domain.slice();
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    _this1._d3Scale = scales[scale]().domain(_this1._scale === "time" ? initialDomain.map(date) : initialDomain).range(range);
                    if (_this1._rounding !== "none") {
                        var roundDomain = function roundDomain() {
                            var zeroLength = function zeroLength(d) {
                                if (smallScale) {
                                    if (!d) return 0;
                                    var m = "".concat(d).match(/0\.(0*)/);
                                    if (m) return +"0.".concat(Array(m[1].length + 1).fill(0).join(""), "1");
                                }
                                return "".concat(Math.round(Math.abs(d))).length;
                            };
                            var smallScale = initialDomain.every(function(d) {
                                return Math.abs(d) < 1;
                            });
                            var zeroArray = [
                                zeroLength(initialDomain[0]),
                                zeroLength(initialDomain[1])
                            ].filter(Boolean).sort();
                            var diverging = initialDomain.some(function(d) {
                                return isNegative(d);
                            }) && initialDomain.some(function(d) {
                                return d > 0;
                            });
                            var zeros = zeroArray.length === 1 ? zeroArray[0] : zeroArray[0] > 1 && zeroArray[0] === zeroArray[1] ? zeroArray[0] - 1 : _this1._rounding === "outside" || !diverging ? zeroArray[0] + (zeroArray[1] - zeroArray[0]) / 2 : max(zeroArray);
                            var factor = zeros < 1 ? fixFloat(zeros) : +"1".concat(Array(Math.floor(fixFloat(zeros)) - 1).fill(0).join(""));
                            if (factor >= Math.abs(initialDomain[1] - initialDomain[0])) factor /= 2;
                            var inverted = initialDomain[1] < initialDomain[0];
                            var newDomain = [
                                Math[_this1._rounding === "outside" ? inverted ? "ceil" : "floor" : inverted ? "floor" : "ceil"](initialDomain[0] / factor) * factor,
                                Math[_this1._rounding === "outside" ? inverted ? "floor" : "ceil" : inverted ? "ceil" : "floor"](initialDomain[1] / factor) * factor
                            ];
                            if (_this1._scale === "log") {
                                if (newDomain[0] === 0) newDomain[0] = initialDomain[0];
                                if (newDomain[1] === 0) newDomain[1] = initialDomain[1];
                            }
                            _this1._d3Scale.domain(newDomain.map(fixFloat));
                        };
                        if (_this1._scale === "linear") {
                            roundDomain.bind(_this1)();
                        } else if (_this1._scale === "log") {
                            var powDomain = [];
                            var inverted = initialDomain[1] < initialDomain[0];
                            powDomain[0] = (_this1._rounding === "outside" ? isNegative(initialDomain[0]) ? inverted ? floorPow : ceilPow : inverted ? ceilPow : floorPow : isNegative(initialDomain[0]) ? inverted ? ceilPow : floorPow : inverted ? floorPow : ceilPow)(initialDomain[0]);
                            powDomain[1] = (_this1._rounding === "inside" ? isNegative(initialDomain[1]) ? inverted ? floorPow : ceilPow : inverted ? ceilPow : floorPow : isNegative(initialDomain[1]) ? inverted ? ceilPow : floorPow : inverted ? floorPow : ceilPow)(initialDomain[1]);
                            var powInverted = powDomain[1] < powDomain[0];
                            if (powDomain[0] !== powDomain[1] && powDomain.some(function(d) {
                                return Math.abs(d) > 10;
                            }) && powInverted === inverted) {
                                _this1._d3Scale.domain(powDomain);
                            } else {
                                roundDomain.bind(_this1)();
                            }
                        }
                    }
                    if (_this1._d3Scale.padding) _this1._d3Scale.padding(_this1._scalePadding);
                    if (_this1._d3Scale.paddingInner) _this1._d3Scale.paddingInner(_this1._paddingInner);
                    if (_this1._d3Scale.paddingOuter) _this1._d3Scale.paddingOuter(_this1._paddingOuter);
                    /**
       * Constructs a separate "negative only" scale for logarithmic
       * domains, as they cannot pass zero.
*/ _this1._d3ScaleNegative = null;
                    if (_this1._scale === "log") {
                        var domain = _this1._d3Scale.domain();
                        if (domain[0] === 0) {
                            var smallestNumber = min([
                                min(_this1._data),
                                Math.abs(domain[1])
                            ]);
                            domain[0] = smallestNumber === 0 || smallestNumber === 1 ? 1e-6 : smallestNumber <= 1 ? floorPow(smallestNumber) : 1;
                            if (isNegative(domain[1])) domain[0] *= -1;
                        } else if (domain[domain.length - 1] === 0) {
                            var smallestNumber1 = min([
                                min(_this1._data),
                                Math.abs(domain[0])
                            ]);
                            domain[domain.length - 1] = smallestNumber1 === 0 || smallestNumber1 === 1 ? 1e-6 : smallestNumber1 <= 1 ? floorPow(smallestNumber1) : 1;
                            if (isNegative(domain[0])) domain[domain.length - 1] *= -1;
                        }
                        var range1 = _this1._d3Scale.range();
                        // all negatives
                        if (isNegative(domain[0]) && isNegative(domain[domain.length - 1])) {
                            _this1._d3ScaleNegative = _this1._d3Scale.copy().domain(domain).range(range1);
                            _this1._d3Scale = null;
                        } else if (domain[0] > 0 && domain[domain.length - 1] > 0) {
                            _this1._d3Scale.domain(domain).range(range1);
                        } else {
                            var powers = domain.map(function(d) {
                                return Math.log10(Math.abs(d));
                            }).map(function(d) {
                                return d || -1e-6;
                            });
                            var leftPercentage = powers[0] / sum(powers);
                            var zero = leftPercentage * (range1[1] - range1[0]);
                            var minPositive = min([
                                min(_this1._data.filter(function(d) {
                                    return d >= 0;
                                })),
                                Math.abs(domain[1])
                            ]);
                            if (minPositive === 1) minPositive = 1e-6;
                            var minNegative = min([
                                min(_this1._data.filter(isNegative)),
                                Math.abs(domain[0])
                            ]);
                            if (minNegative === 1) minNegative = 1e-6;
                            var minPosPow = minPositive === 0 ? 1e-6 : minPositive <= 1 ? floorPow(minPositive) : 1;
                            var minNegPow = minNegative === 0 ? -1e-6 : minNegative <= 1 ? floorPow(minNegative) : 1;
                            var minValue = min([
                                Math.abs(minPosPow),
                                Math.abs(minNegPow)
                            ]);
                            _this1._d3ScaleNegative = _this1._d3Scale.copy();
                            (isNegative(domain[0]) ? _this1._d3Scale : _this1._d3ScaleNegative).domain([
                                isNegative(domain[0]) ? minValue : -minValue,
                                domain[1]
                            ]).range([
                                range1[0] + zero,
                                range1[1]
                            ]);
                            (isNegative(domain[0]) ? _this1._d3ScaleNegative : _this1._d3Scale).domain([
                                domain[0],
                                isNegative(domain[0]) ? -minValue : minValue
                            ]).range([
                                range1[0],
                                range1[0] + zero
                            ]);
                        }
                    }
                    /**
       * Determines the of values array to use
       * for the "ticks" and the "labels"
*/ ticks = (_this1._ticks ? _this1._scale === "time" ? _this1._ticks.map(date) : _this1._ticks : (_this1._d3Scale ? _this1._d3Scale.ticks : _this1._d3ScaleNegative.ticks) ? _this1._getTicks() : _this1._domain).slice();
                    labels = (_this1._labels ? _this1._scale === "time" ? _this1._labels.map(date) : _this1._labels : (_this1._d3Scale ? _this1._d3Scale.ticks : _this1._d3ScaleNegative.ticks) ? _this1._getLabels() : ticks).slice();
                    if (_this1._scale === "time") {
                        ticks = ticks.map(Number);
                        labels = labels.map(Number);
                    }
                    ticks = ticks.sort(function(a, b) {
                        return _this1._getPosition(a) - _this1._getPosition(b);
                    });
                    labels = labels.sort(function(a, b) {
                        return _this1._getPosition(a) - _this1._getPosition(b);
                    });
                    /**
       * Get the smallest suffix.
*/ if (_this1._scale === "linear" && _this1._tickSuffix === "smallest") {
                        var suffixes = labels.filter(function(d) {
                            return d >= 1000;
                        });
                        if (suffixes.length > 0) {
                            var _Math;
                            var minVal = (_Math = Math).min.apply(_Math, _to_consumable_array(suffixes));
                            var i = 1;
                            while(i && i < 7){
                                var n = Math.pow(10, 3 * i);
                                if (minVal / n >= 1) {
                                    _this1._tickUnit = i;
                                    i += 1;
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                    /**
       * Removes ticks when they overlap other ticks.
*/ var pixels = [];
                    _this1._availableTicks = ticks;
                    ticks.forEach(function(d, i) {
                        var s = tickGet({
                            id: d,
                            tick: true
                        }, i);
                        if (_this1._shape === "Circle") s *= 2;
                        var t = _this1._getPosition(d);
                        if (!pixels.length || Math.abs(closest(t, pixels.filter(function(p) {
                            return p !== false;
                        })) - t) > s * 2) pixels.push(t);
                        else pixels.push(false);
                    });
                    ticks = ticks.filter(function(_d, i) {
                        return pixels[i] !== false;
                    });
                    _this1._visibleTicks = ticks;
                };
                setScale();
                /**
     * Pre-calculates the size of the title, if defined, in order
     * to adjust the internal margins.
*/ if (this._title) {
                    var _this__titleConfig = this._titleConfig, fontFamily = _this__titleConfig.fontFamily, fontSize = _this__titleConfig.fontSize, lineHeight = _this__titleConfig.lineHeight;
                    var titleWrap = textWrap().fontFamily(typeof fontFamily === "function" ? fontFamily() : fontFamily).fontSize(typeof fontSize === "function" ? fontSize() : fontSize).lineHeight(typeof lineHeight === "function" ? lineHeight() : lineHeight).width(range[range.length - 1] - range[0] - p * 2)// eslint-disable-next-line @typescript-eslint/no-explicit-any
                    .height(this["_".concat(height)] - this._tickSize - p * 2);
                    var lines = titleWrap(this._title).lines.length;
                    margin[this._orient] = lines * titleWrap.lineHeight() + p;
                }
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var hBuff = this._shape === "Circle" ? typeof this._shapeConfig.r === "function" ? this._shapeConfig.r({
                    tick: true
                }) : this._shapeConfig.r : this._shape === "Rect" ? typeof this._shapeConfig[height] === "function" ? this._shapeConfig[height]({
                    tick: true
                }) : this._shapeConfig[height] : this._tickSize, // eslint-disable-next-line @typescript-eslint/no-explicit-any
                wBuff = tickGet({
                    tick: true
                });
                if (typeof hBuff === "function") hBuff = max(ticks.map(hBuff));
                if (this._shape === "Rect") hBuff /= 2;
                if (typeof wBuff === "function") wBuff = max(ticks.map(wBuff));
                if (this._shape !== "Circle") wBuff /= 2;
                /**
     * Calculates the text wrapping and size of a given textData object.
     * @param {Object} datum
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var calculateLabelSize = function calculateLabelSize(datum) {
                    var d = datum.d, i = datum.i, fF = datum.fF, fP = datum.fP, fS = datum.fS, rotate = datum.rotate, space = datum.space;
                    var h = rotate ? "width" : "height", w = rotate ? "height" : "width";
                    var wSize = min([
                        _this._maxSize,
                        _this._width
                    ]);
                    var hSize = min([
                        _this._maxSize,
                        _this._height
                    ]);
                    var wrap = textWrap().fontFamily(fF).fontSize(fS).lineHeight(_this._shapeConfig.lineHeight ? _this._shapeConfig.lineHeight(d, i) : undefined);
                    wrap[w](horizontal ? space : wSize - hBuff - p - _this._margin.left - _this._margin.right);
                    wrap[h](horizontal ? hSize - hBuff - p - _this._margin.top - _this._margin.bottom : space);
                    var res = wrap(tickFormat(d));
                    res.lines = res.lines.filter(function(d) {
                        return d !== "";
                    });
                    res.width = res.lines.length ? Math.ceil(max(res.widths)) : 0;
                    res.height = res.lines.length ? Math.ceil(res.lines.length * wrap.lineHeight()) + fP : 0;
                    return res;
                };
                /** Calculates label offsets*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var calculateOffset = function calculateOffset() {
                    var arr = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
                    var offset = 0;
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    arr.forEach(function(datum) {
                        var prev = arr[datum.i - 1];
                        var h = datum.rotate && horizontal || !datum.rotate && !horizontal ? "width" : "height", w = datum.rotate && horizontal || !datum.rotate && !horizontal ? "height" : "width";
                        if (!prev) {
                            offset = 1;
                        } else if (prev.position + prev[w] / 2 > datum.position - datum[w] / 2) {
                            if (offset) {
                                datum.offset = prev[h];
                                offset = 0;
                            } else offset = 1;
                        }
                    });
                };
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var textData = [];
                var createTextData = function createTextData() {
                    var offset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1;
                    var fontSize = _this1._shapeConfig.labelConfig.fontSize;
                    var fontFamily = _this1._shapeConfig.labelConfig.fontFamily || d3plusFontFamily;
                    var fontPadding = _this1._shapeConfig.labelConfig.padding;
                    /**
       * Calculates the space each label would take up, given
       * the provided this._space size.
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    textData = labels.map(function(d, i) {
                        var fF = typeof fontFamily === "function" ? fontFamily(d, i) : fontFamily, fP = typeof fontPadding === "function" ? fontPadding(d, i) : fontPadding, fS = typeof fontSize === "function" ? fontSize(d, i) : fontSize, position = _this1._getPosition(d);
                        var lineHeight = _this1._shapeConfig.lineHeight ? _this1._shapeConfig.lineHeight(d, i) : fS * 1.4;
                        // eslint-disable-next-line @typescript-eslint/no-explicit-any
                        var datum = {
                            d: d,
                            i: i,
                            fF: fF,
                            fP: fP,
                            fS: fS,
                            lineHeight: lineHeight,
                            position: position,
                            rotate: _this1._labelRotation
                        };
                        return datum;
                    });
                    var maxSpace = _this1._scale === "band" ? _this1._d3Scale.bandwidth() : textData.reduce(function(s, d, i) {
                        var position = d.position;
                        var prevPosition = !i ? textData.length === 1 ? rangeOuter[0] : position - (textData[i + 1].position - position) : position - (position - textData[i - 1].position);
                        var prevSpace = Math.abs(position - prevPosition);
                        var nextPosition = i == textData.length - 1 ? textData.length === 1 ? rangeOuter[1] : position + (position - textData[i - 1].position) : position - (position - textData[i + 1].position);
                        var nextSpace = Math.abs(position - nextPosition);
                        var mod = _this1._scale === "point" ? 1 : 2;
                        return max([
                            max([
                                prevSpace,
                                nextSpace
                            ]) * mod,
                            s
                        ]);
                    }, 0);
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    textData = textData.map(function(datum) {
                        datum.space = maxSpace - datum.fP * 2;
                        var res = calculateLabelSize(datum);
                        return Object.assign(res, datum);
                    });
                    var reverseTextData = textData.slice().reverse();
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    textData.forEach(function(datum) {
                        var fP = datum.fP, i = datum.i, position = datum.position;
                        var sizeName = horizontal ? "width" : "height";
                        // eslint-disable-next-line @typescript-eslint/no-explicit-any
                        var prev = i ? reverseTextData.find(function(t) {
                            return t.i < i && !t.truncated;
                        }) : false;
                        if (i === textData.length - 1) {
                            while(prev && position - datum[sizeName] / 2 - fP < prev.position + prev[sizeName] / 2){
                                prev.truncated = true;
                                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                                prev = reverseTextData.find(function(t) {
                                    return t.i < i && !t.truncated;
                                });
                            }
                        }
                        datum.truncated = prev ? position - datum[sizeName] / 2 - fP < prev.position + prev[sizeName] / 2 : false;
                    });
                    if (offset > 1) calculateOffset(textData);
                };
                createTextData();
                var offsetEnabled = // eslint-disable-next-line @typescript-eslint/no-explicit-any
                this._labelOffset && textData.some(function(d) {
                    return d.truncated;
                });
                if (offsetEnabled) createTextData(2);
                /**
     * "spillover" will contain the pixel spillover of the first and last label,
     * and then adjust the scale range accordingly.
*/ var spillovers = [
                    0,
                    1
                ].map(function(index) {
                    var datum = textData[index ? textData.length - 1 : 0];
                    if (!datum) return 0;
                    var dHeight = datum.height, position = datum.position, rotate = datum.rotate, dWidth = datum.width;
                    var compPosition = index ? rangeOuter[1] : rangeOuter[0];
                    var halfSpace = (rotate || !horizontal ? dHeight : dWidth) / 2;
                    if (Math.abs(position - compPosition) >= halfSpace) return 0;
                    var spill = halfSpace - (position - compPosition);
                    return Math.abs(spill);
                });
                var _range = _sliced_to_array(range, 2), first = _range[0], last = _range[1];
                var newRange = [
                    first + spillovers[0],
                    last - spillovers[1]
                ];
                if (this._range) {
                    if (this._range[0] !== undefined) newRange[0] = this._range[0];
                    if (this._range[this._range.length - 1] !== undefined) newRange[1] = this._range[this._range.length - 1];
                }
                if (newRange[0] !== first || newRange[1] !== last) {
                    setScale(newRange);
                    createTextData(offsetEnabled ? 2 : 1);
                }
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var labelHeight = max(textData, function(t) {
                    return t.height;
                }) || 0;
                this._labelRotation = horizontal && this._labelRotation === undefined ? textData.some(function(datum) {
                    var i = datum.i, dH = datum.height, position = datum.position, truncated = datum.truncated;
                    var prev = textData[i - 1];
                    return truncated || i && prev.position + prev.height / 2 > position - dH / 2;
                }) : this._labelRotation;
                var globalOffset = this._labelOffset ? max(textData, function(d) {
                    return d.offset || 0;
                }) : 0;
                textData.forEach(// eslint-disable-next-line @typescript-eslint/no-explicit-any
                function(datum) {
                    return datum.offset = datum.offset ? globalOffset : 0;
                });
                var tBuff = this._shape === "Line" ? 0 : hBuff;
                var _obj;
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var bounds = this._outerBounds = (_obj = {}, _define_property(_obj, height, // eslint-disable-next-line @typescript-eslint/no-explicit-any
                (max(textData, function(t) {
                    return Math.ceil(t[t.rotate || !horizontal ? "width" : "height"] + t.offset);
                }) || 0) + (textData.length ? p : 0)), _define_property(_obj, width, rangeOuter[rangeOuter.length - 1] - rangeOuter[0]), _define_property(_obj, x, rangeOuter[0]), _obj);
                bounds[height] = max([
                    this._minSize,
                    bounds[height]
                ]);
                margin[this._orient] += hBuff;
                margin[opposite] = this._gridSize !== undefined ? max([
                    this._gridSize,
                    tBuff
                ]) : this["_".concat(height)] - margin[this._orient] - bounds[height] - p;
                bounds[height] += margin[opposite] + margin[this._orient];
                bounds[y] = this._align === "start" ? this._padding : this._align === "end" ? this["_".concat(height)] - bounds[height] - this._padding : this["_".concat(height)] / 2 - bounds[height] / 2;
                var group = elem("g#d3plus-Axis-".concat(this._uuid), {
                    parent: parent
                });
                this._group = group;
                var grid = elem("g.grid", {
                    parent: group
                }).selectAll("line").data((this._gridSize !== 0 ? this._grid || this._scale === "log" && !this._gridLog ? labels : ticks : []).map(function(d) {
                    return {
                        id: d
                    };
                }), // eslint-disable-next-line @typescript-eslint/no-explicit-any
                function(d) {
                    return d.id;
                });
                grid.exit().transition(t).attr("opacity", 0).call(this._gridPosition.bind(this)).remove();
                grid.enter().append("line").attr("opacity", 0).attr("clip-path", "url(#".concat(clipId, ")")).call(this._gridPosition.bind(this), true).merge(grid).transition(t).attr("opacity", 1).call(this._gridPosition.bind(this));
                var labelOnly = labels.filter(function(d, i) {
                    return textData[i].lines.length && !ticks.includes(d);
                });
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var rotated = textData.some(function(d) {
                    return d.rotate;
                });
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                var tickData = ticks.concat(labelOnly).map(function(d) {
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    var data = textData.find(function(td) {
                        return td.d === d;
                    });
                    var xPos = _this._getPosition(d);
                    var space = data ? data.space : 0;
                    var lines = data ? data.lines.length : 1;
                    var lineHeight = data ? data.lineHeight : 1;
                    var fP = data ? data.fP : 0;
                    var labelOffset = data && _this._labelOffset ? data.offset : 0;
                    var labelWidth = horizontal ? space : bounds.width - margin[_this._position.opposite] - hBuff - margin[_this._orient] + p;
                    var offset = margin[opposite], size = (hBuff + labelOffset) * (flip ? -1 : 1), yPos = flip ? bounds[y] + bounds[height] - offset : bounds[y] + offset;
                    var _obj;
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    var tickConfig = (_obj = {
                        id: d,
                        labelBounds: rotated && data ? {
                            x: -data.width / 2 + data.fS / 4,
                            y: _this._orient === "bottom" ? size + (data.width - lineHeight * lines) / 2 + fP : size * 2 - (data.width + lineHeight * lines) / 2 + fP,
                            width: data.width,
                            height: data.height
                        } : {
                            x: horizontal ? -space / 2 : _this._orient === "left" ? -labelWidth - p + size : size + p,
                            y: horizontal ? _this._orient === "bottom" ? size + fP : size - labelHeight - fP : -space / 2,
                            width: horizontal ? space : labelWidth,
                            height: horizontal ? labelHeight : space
                        },
                        rotate: data ? data.rotate : false,
                        size: labels.includes(d) || _this._scale === "log" && Math.log10(Math.abs(d)) % 1 === 0 ? size : ticks.includes(d) ? Math.ceil(size / 2) : _this._data.find(function(t) {
                            return +t === d;
                        }) ? Math.ceil(size / 4) : 0,
                        text: // eslint-disable-next-line @typescript-eslint/no-explicit-any
                        !(data || {}).truncated && labels.includes(d) ? tickFormat(d) : false,
                        tick: ticks.includes(d)
                    }, _define_property(_obj, x, xPos + (_this._scale === "band" ? _this._d3Scale.bandwidth() / 2 : 0)), _define_property(_obj, y, yPos), _obj);
                    return tickConfig;
                });
                if (this._shape === "Line") {
                    tickData = tickData.concat(// eslint-disable-next-line @typescript-eslint/no-explicit-any
                    tickData.map(function(d) {
                        var dupe = Object.assign({}, d);
                        dupe[y] += d.size;
                        return dupe;
                    }));
                }
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                new shapes[this._shape]().data(tickData).duration(this._duration).labelConfig({
                    ellipsis: function ellipsis(d) {
                        return d && d.length ? "".concat(d, "...") : "";
                    },
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    rotate: function rotate(d) {
                        return d.rotate ? -90 : 0;
                    }
                }).select(elem("g.ticks", {
                    parent: group
                }).node())// eslint-disable-next-line @typescript-eslint/no-explicit-any
                .config(configPrep.bind(this)(this._shapeConfig)).labelConfig({
                    padding: 0
                }).render();
                var bar = group.selectAll("line.bar").data([
                    null
                ]);
                bar.enter().append("line").attr("class", "bar").attr("opacity", 0).call(this._barPosition.bind(this)).merge(bar).transition(t).attr("opacity", 1).call(this._barPosition.bind(this));
                this._titleClass.data(this._title ? [
                    {
                        text: this._title
                    }
                ] : []).duration(this._duration).height(margin[this._orient]).rotate(this._orient === "left" ? -90 : this._orient === "right" ? 90 : 0).select(elem("g.d3plus-Axis-title", {
                    parent: group
                }).node()).text(function(d) {
                    return d.text;
                }).verticalAlign("middle").width(range[range.length - 1] - range[0]).x(horizontal ? range[0] : this._orient === "left" ? bounds.x + margin.left / 2 - (range[range.length - 1] - range[0]) / 2 : bounds.x + bounds.width - margin.right / 2 - (range[range.length - 1] - range[0]) / 2).y(horizontal ? this._orient === "bottom" ? bounds.y + bounds.height - margin.bottom : bounds.y : range[0] + (range[range.length - 1] - range[0]) / 2 - margin[this._orient] / 2)// eslint-disable-next-line @typescript-eslint/no-explicit-any
                .config(configPrep.bind(this)(this._titleConfig)).render();
                this._lastScale = this._getPosition.bind(this);
                if (callback) setTimeout(callback, this._duration + 100);
                return this;
            }
        },
        {
            key: "align",
            value: function align(_) {
                return arguments.length ? (this._align = _, this) : this._align;
            }
        },
        {
            key: "barConfig",
            value: function barConfig(_) {
                return arguments.length ? (this._barConfig = Object.assign(this._barConfig, _), this) : this._barConfig;
            }
        },
        {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            key: "data",
            value: function data(_) {
                return arguments.length ? (this._data = _, this) : this._data;
            }
        },
        {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            key: "domain",
            value: function domain(_) {
                return arguments.length ? (this._domain = _, this) : this._domain;
            }
        },
        {
            key: "duration",
            value: function duration(_) {
                return arguments.length ? (this._duration = _, this) : this._duration;
            }
        },
        {
            key: "grid",
            value: function grid(_) {
                return arguments.length ? (this._grid = _, this) : this._grid;
            }
        },
        {
            key: "gridConfig",
            value: function gridConfig(_) {
                return arguments.length ? (this._gridConfig = Object.assign(this._gridConfig, _), this) : this._gridConfig;
            }
        },
        {
            key: "gridLog",
            value: function gridLog(_) {
                return arguments.length ? (this._gridLog = _, this) : this._gridLog;
            }
        },
        {
            key: "gridSize",
            value: function gridSize(_) {
                return arguments.length ? (this._gridSize = _, this) : this._gridSize;
            }
        },
        {
            key: "height",
            value: function height(_) {
                return arguments.length ? (this._height = _, this) : this._height;
            }
        },
        {
            key: "labels",
            value: function labels(_) {
                return arguments.length ? (this._labels = _, this) : this._labels;
            }
        },
        {
            key: "labelOffset",
            value: function labelOffset(_) {
                return arguments.length ? (this._labelOffset = _, this) : this._labelOffset;
            }
        },
        {
            key: "labelRotation",
            value: function labelRotation(_) {
                return arguments.length ? (this._labelRotation = _, this) : this._labelRotation;
            }
        },
        {
            key: "maxSize",
            value: function maxSize(_) {
                return arguments.length ? (this._maxSize = _, this) : this._maxSize;
            }
        },
        {
            key: "minSize",
            value: function minSize(_) {
                return arguments.length ? (this._minSize = _, this) : this._minSize;
            }
        },
        {
            key: "orient",
            value: function orient(_) {
                if (arguments.length) {
                    var horizontal = [
                        "top",
                        "bottom"
                    ].includes(_), opps = {
                        top: "bottom",
                        right: "left",
                        bottom: "top",
                        left: "right"
                    };
                    this._position = {
                        horizontal: horizontal,
                        width: horizontal ? "width" : "height",
                        height: horizontal ? "height" : "width",
                        x: horizontal ? "x" : "y",
                        y: horizontal ? "y" : "x",
                        opposite: opps[_]
                    };
                    return this._orient = _, this;
                }
                return this._orient;
            }
        },
        {
            /**
      Returns the outer bounds of the axis content. Must be called after rendering.
      @example
{"width": 180, "height": 24, "x": 10, "y": 20}
*/ key: "outerBounds",
            value: function outerBounds() {
                return this._outerBounds;
            }
        },
        {
            key: "padding",
            value: function padding(_) {
                return arguments.length ? (this._padding = _, this) : this._padding;
            }
        },
        {
            key: "paddingInner",
            value: function paddingInner(_) {
                return arguments.length ? (this._paddingInner = _, this) : this._paddingInner;
            }
        },
        {
            key: "paddingOuter",
            value: function paddingOuter(_) {
                return arguments.length ? (this._paddingOuter = _, this) : this._paddingOuter;
            }
        },
        {
            key: "range",
            value: function range(_) {
                return arguments.length ? (this._range = _, this) : this._range;
            }
        },
        {
            key: "rounding",
            value: function rounding(_) {
                return arguments.length ? (this._rounding = _, this) : this._rounding;
            }
        },
        {
            key: "roundingInsideMinPrefix",
            value: function roundingInsideMinPrefix(_) {
                return arguments.length ? (this._roundingInsideMinPrefix = _, this) : this._roundingInsideMinPrefix;
            }
        },
        {
            key: "roundingInsideMinSuffix",
            value: function roundingInsideMinSuffix(_) {
                return arguments.length ? (this._roundingInsideMinSuffix = _, this) : this._roundingInsideMinSuffix;
            }
        },
        {
            key: "roundingInsideMaxPrefix",
            value: function roundingInsideMaxPrefix(_) {
                return arguments.length ? (this._roundingInsideMaxPrefix = _, this) : this._roundingInsideMaxPrefix;
            }
        },
        {
            key: "roundingInsideMaxSuffix",
            value: function roundingInsideMaxSuffix(_) {
                return arguments.length ? (this._roundingInsideMaxSuffix = _, this) : this._roundingInsideMaxSuffix;
            }
        },
        {
            key: "scale",
            value: function scale(_) {
                return arguments.length ? (this._scale = _, this) : this._scale;
            }
        },
        {
            key: "scalePadding",
            value: function scalePadding(_) {
                return arguments.length ? (this._scalePadding = _, this) : this._scalePadding;
            }
        },
        {
            key: "select",
            value: function select1(_) {
                return arguments.length ? (this._select = select(_), this) : this._select;
            }
        },
        {
            key: "shape",
            value: function shape(_) {
                return arguments.length ? (this._shape = _, this) : this._shape;
            }
        },
        {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            key: "shapeConfig",
            value: function shapeConfig(_) {
                return arguments.length ? (this._shapeConfig = assign(this._shapeConfig, _), this) : this._shapeConfig;
            }
        },
        {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            key: "tickFormat",
            value: function tickFormat(_) {
                return arguments.length ? (this._tickFormat = _, this) : this._tickFormat;
            }
        },
        {
            key: "ticks",
            value: function ticks(_) {
                return arguments.length ? (this._ticks = _, this) : this._ticks;
            }
        },
        {
            key: "tickSize",
            value: function tickSize(_) {
                return arguments.length ? (this._tickSize = _, this) : this._tickSize;
            }
        },
        {
            key: "tickSuffix",
            value: function tickSuffix(_) {
                return arguments.length ? (this._tickSuffix = _, this) : this._tickSuffix;
            }
        },
        {
            key: "timeLocale",
            value: function timeLocale(_) {
                return arguments.length ? (this._timeLocale = _, this) : this._timeLocale;
            }
        },
        {
            key: "title",
            value: function title(_) {
                return arguments.length ? (this._title = _, this) : this._title;
            }
        },
        {
            key: "titleConfig",
            value: function titleConfig(_) {
                return arguments.length ? (this._titleConfig = Object.assign(this._titleConfig, _), this) : this._titleConfig;
            }
        },
        {
            key: "width",
            value: function width(_) {
                return arguments.length ? (this._width = _, this) : this._width;
            }
        }
    ]);
    return Axis;
}(BaseClass);
/**
    Creates an SVG scale based on an array of data.
*/ export { Axis as default };
