"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TIME_MULTIPLIER = exports.TOOLTIP_DEFAULT_MAX_LINES = exports.TOOLTIP_X_OFFSET = exports.TOOLTIP_Y_OFFSET = exports.MIN_SELECTION_WIDTH = exports.CURSOR_STYLE = exports.MARKER_DIAMETER = exports.SERIE_AREA_BORDER_WIDTH = exports.SERIE_AREA_BORDER_COLOR = exports.SERIE_LINE_WIDTH = exports.SERIE_COLOR = exports.PADDING_BOTH = exports.PADDING_RIGHT = exports.PADDING_LEFT = exports.BARS_DRAW_MAX = exports.BARS_DRAW_FACTOR = exports.TYPES_ORDER = exports.X_AXIS_INCRS = exports.X_AXIS_SPACE = exports.X_AXIS_SIZE = exports.X_AXIS_TICK_GAP = exports.DECADE = exports.YEAR = exports.DAY = exports.HOUR = exports.MINUTE = exports.SECOND = exports.Y_AXIS_LABEL_SIZE = exports.Y_AXIS_SIZE = exports.DEFAULT_Y_AXIS_LABEL_PADDING = exports.DEFAULT_Y_AXIS_PADDING = exports.DEFAULT_Y_AXIS_SIZE = exports.Y_AXIS_TICK_GAP = exports.AXIS_VALUES_FONT = exports.AXIS_LABEL_FONT = exports.DEFAULT_AXIS_FONT_SIZE = exports.DARK_DEFAULT_LINE_COLOR = exports.LIGHT_DEFAULT_LINE_COLOR = exports.DEFAULT_TITLE_FONT_SIZE = exports.DEFAULT_SYNC_KEY = exports.DEFAULT_POINT_SIZE = exports.DEFAULT_LOGARITHMIC_MIN_SCALE_VALUE = exports.DEFAULT_SCALE_MIN_RANGE = exports.DEFAULT_Y_AXIS_OFFSET = exports.DEFAULT_MAX_TICKS = exports.DEFAULT_CANVAS_PIXEL_RATIO = exports.DEFAULT_FOCUS_ALPHA = exports.DEFAULT_Y_SCALE = exports.DEFAULT_X_SCALE = exports.DEFAULT_X_SERIE_NAME = void 0;
exports.DEFAULT_X_SERIE_NAME = 'date';
exports.DEFAULT_X_SCALE = 'x';
exports.DEFAULT_Y_SCALE = 'y';
exports.DEFAULT_FOCUS_ALPHA = 0.3;
exports.DEFAULT_CANVAS_PIXEL_RATIO = typeof window === 'undefined' ? 1 : window.devicePixelRatio;
exports.DEFAULT_MAX_TICKS = 5;
exports.DEFAULT_Y_AXIS_OFFSET = 0.05;
exports.DEFAULT_SCALE_MIN_RANGE = 0.01;
exports.DEFAULT_LOGARITHMIC_MIN_SCALE_VALUE = 0.001;
exports.DEFAULT_POINT_SIZE = exports.DEFAULT_CANVAS_PIXEL_RATIO >= 2 ? 4 : 2;
exports.DEFAULT_SYNC_KEY = 'sync';
exports.DEFAULT_TITLE_FONT_SIZE = 14;
exports.LIGHT_DEFAULT_LINE_COLOR = '#222222';
exports.DARK_DEFAULT_LINE_COLOR = '#eeeeee';
exports.DEFAULT_AXIS_FONT_SIZE = 11;
exports.AXIS_LABEL_FONT = 'normal 11px Lucida Grande, Arial, Helvetica, sans-serif';
exports.AXIS_VALUES_FONT = '11px Lucida Grande, Arial, Helvetica, sans-serif';
exports.Y_AXIS_TICK_GAP = 6;
exports.DEFAULT_Y_AXIS_SIZE = 12;
exports.DEFAULT_Y_AXIS_PADDING = 12;
exports.DEFAULT_Y_AXIS_LABEL_PADDING = 2;
const Y_AXIS_SIZE = (self, values, axisIdx) => {
    if (!values) {
        return exports.DEFAULT_Y_AXIS_SIZE;
    }
    const longesValue = values.reduce((l, c) => (l.length > c.length ? l : c));
    const { ctx } = self;
    ctx.save();
    const axis = self.axes[axisIdx];
    ctx.font = axis.font ? axis.font[0] : exports.AXIS_VALUES_FONT;
    const { width: textSize } = ctx.measureText(longesValue);
    ctx.restore();
    let labelSize = 0;
    if (axis.label) {
        labelSize = axis.labelSize || exports.DEFAULT_AXIS_FONT_SIZE;
        ctx.font = axis.labelFont ? axis.labelFont[0] : exports.AXIS_LABEL_FONT;
        let labelText;
        if (typeof axis.label === 'function') {
            labelText = axis.label(self, axisIdx, 0, 0);
        }
        else {
            labelText = axis.label;
        }
        const { fontBoundingBoxAscent: size } = ctx.measureText(labelText);
        labelSize = size;
        ctx.restore();
    }
    return labelSize
        ? textSize / exports.DEFAULT_CANVAS_PIXEL_RATIO + labelSize / exports.DEFAULT_CANVAS_PIXEL_RATIO + exports.DEFAULT_Y_AXIS_LABEL_PADDING
        : textSize / exports.DEFAULT_CANVAS_PIXEL_RATIO + exports.DEFAULT_Y_AXIS_PADDING;
};
exports.Y_AXIS_SIZE = Y_AXIS_SIZE;
exports.Y_AXIS_LABEL_SIZE = 11;
exports.SECOND = 1000;
exports.MINUTE = exports.SECOND * 60;
exports.HOUR = exports.MINUTE * 60;
exports.DAY = exports.HOUR * 24;
exports.YEAR = exports.DAY * 365;
exports.DECADE = exports.YEAR * 10;
exports.X_AXIS_TICK_GAP = 6;
exports.X_AXIS_SIZE = 32;
exports.X_AXIS_SPACE = 80;
exports.X_AXIS_INCRS = [
    // seconds divisors (# os ms)
    1,
    10,
    50,
    100,
    200,
    500,
    // minute divisors
    exports.SECOND,
    exports.SECOND * 2,
    exports.SECOND * 5,
    exports.SECOND * 10,
    exports.SECOND * 15,
    exports.SECOND * 30,
    // hour divisors
    exports.MINUTE,
    exports.MINUTE * 5,
    exports.MINUTE * 10,
    exports.MINUTE * 30,
    // day divisors
    exports.HOUR,
    exports.HOUR * 2,
    exports.HOUR * 3,
    exports.HOUR * 4,
    exports.HOUR * 6,
    exports.HOUR * 12,
    // month divisors
    exports.DAY,
    exports.DAY * 2,
    exports.DAY * 3,
    exports.DAY * 5,
    exports.DAY * 10,
    exports.DAY * 15,
    exports.DAY * 30,
    exports.DAY * 60,
    exports.DAY * 120,
    exports.DAY * 180,
    // year divisors
    exports.YEAR,
    exports.YEAR * 2,
    exports.YEAR * 5,
    exports.YEAR * 10,
];
exports.TYPES_ORDER = ['dots', 'line', 'area', 'column'];
exports.BARS_DRAW_FACTOR = 0.5;
exports.BARS_DRAW_MAX = 100;
exports.PADDING_LEFT = [14, 14, 0, 4];
exports.PADDING_RIGHT = [14, 4, 0, 14];
exports.PADDING_BOTH = [14, 4, 0, 4];
exports.SERIE_COLOR = 'rgba(0, 0, 0, 1)';
exports.SERIE_LINE_WIDTH = 2;
exports.SERIE_AREA_BORDER_COLOR = 'rgba(0, 0, 0, 0.2)';
exports.SERIE_AREA_BORDER_WIDTH = 1;
exports.MARKER_DIAMETER = 8;
exports.CURSOR_STYLE = '1px solid #ffa0a0';
exports.MIN_SELECTION_WIDTH = 15;
const LIGHTEN_COLOR_SHIFT = 0.68;
const DARKEN_COLOR_SHIFT = -0.6;
class ThemedDefaults {
    constructor(colors, theme = 'light') {
        this.setTheme(theme);
        this.colors = colors;
    }
    setTheme(theme) {
        this.theme = theme;
    }
    get GRID() {
        return {
            show: true,
            stroke: () => this.colors.parse('--yagr-grid'),
            width: 1,
        };
    }
    get X_AXIS_TICKS() {
        return { size: 8, ...this.GRID };
    }
    get Y_AXIS_TICKS() {
        return { size: 6, ...this.GRID };
    }
    get AXIS_STROKE() {
        return this.colors.parse('--yagr-axis-stroke');
    }
    get BACKGROUND() {
        return this.colors.parse('--yagr-background');
    }
    get SHIFT() {
        var _a;
        return ((_a = this.theme) === null || _a === void 0 ? void 0 : _a.startsWith('light')) ? LIGHTEN_COLOR_SHIFT : DARKEN_COLOR_SHIFT;
    }
    get DEFAULT_LINE_COLOR() {
        var _a;
        return ((_a = this.theme) === null || _a === void 0 ? void 0 : _a.startsWith('light')) ? exports.LIGHT_DEFAULT_LINE_COLOR : exports.DARK_DEFAULT_LINE_COLOR;
    }
}
exports.default = ThemedDefaults;
exports.TOOLTIP_Y_OFFSET = 24;
exports.TOOLTIP_X_OFFSET = 24;
exports.TOOLTIP_DEFAULT_MAX_LINES = 10;
exports.TIME_MULTIPLIER = 1;
