UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

1,326 lines (1,070 loc) • 73.1 kB
"use strict"; var _smart_formatter = require("./smart_formatter"); var _utils = require("../core/utils"); var _utils2 = _interopRequireDefault(_utils); var _type = require("../../core/utils/type"); var _axes_constants = require("./axes_constants"); var _axes_constants2 = _interopRequireDefault(_axes_constants); var _extend = require("../../core/utils/extend"); var _array = require("../../core/utils/array"); var _format_helper = require("../../format_helper"); var _format_helper2 = _interopRequireDefault(_format_helper); var _parse_utils = require("../components/parse_utils"); var _parse_utils2 = _interopRequireDefault(_parse_utils); var _tick_generator = require("./tick_generator"); var _tick_generator2 = _interopRequireDefault(_tick_generator); var _translator2d = require("../translators/translator2d"); var _translator2d2 = _interopRequireDefault(_translator2d); var _range = require("../translators/range"); var _range2 = _interopRequireDefault(_range); var _tick = require("./tick"); var _math2 = require("../../core/utils/math"); var _date = require("../../core/utils/date"); var _common = require("../../core/utils/common"); var _xy_axes = require("./xy_axes"); var _xy_axes2 = _interopRequireDefault(_xy_axes); var _polar_axes = require("./polar_axes"); var _polar_axes2 = _interopRequireDefault(_polar_axes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var convertTicksToValues = _axes_constants2.default.convertTicksToValues; var patchFontOptions = _utils2.default.patchFontOptions; var _math = Math; var _abs = _math.abs; var _max = _math.max; var _min = _math.min; var DEFAULT_AXIS_LABEL_SPACING = 5; var MAX_GRID_BORDER_ADHENSION = 4; var TOP = _axes_constants2.default.top; var BOTTOM = _axes_constants2.default.bottom; var LEFT = _axes_constants2.default.left; var RIGHT = _axes_constants2.default.right; var CENTER = _axes_constants2.default.center; var DEFAULT_AXIS_DIVISION_FACTOR = 50; var DEFAULT_MINOR_AXIS_DIVISION_FACTOR = 15; function getTickGenerator(options, incidentOccurred, skipTickGeneration) { return _tick_generator2.default.tickGenerator({ axisType: options.type, dataType: options.dataType, logBase: options.logarithmBase, axisDivisionFactor: options.axisDivisionFactor || DEFAULT_AXIS_DIVISION_FACTOR, minorAxisDivisionFactor: options.minorAxisDivisionFactor || DEFAULT_MINOR_AXIS_DIVISION_FACTOR, numberMultipliers: options.numberMultipliers, calculateMinors: options.minorTick.visible || options.minorGrid.visible || options.calculateMinors, allowDecimals: options.allowDecimals, endOnTick: options.endOnTick, incidentOccurred: incidentOccurred, firstDayOfWeek: options.workWeek && options.workWeek[0], skipTickGeneration: skipTickGeneration, skipCalculationLimits: options.skipCalculationLimits, generateExtraTick: options.generateExtraTick, minTickInterval: options.minTickInterval, showCalculatedTicks: options.tick.showCalculatedTicks, // DEPRECATED IN 15_2 showMinorCalculatedTicks: options.minorTick.showCalculatedTicks // DEPRECATED IN 15_2 }); } function createMajorTick(axis, renderer, skippedCategory) { var options = axis.getOptions(); return (0, _tick.tick)(axis, renderer, options.tick, options.grid, skippedCategory, axis._translator.getBusinessRange().stubData); } function createMinorTick(axis, renderer) { var options = axis.getOptions(); return (0, _tick.tick)(axis, renderer, options.minorTick, options.minorGrid); } function createBoundaryTick(axis, renderer, isFirst) { var options = axis.getOptions(); return (0, _tick.tick)(axis, renderer, (0, _extend.extend)({}, options.tick, { visible: options.showCustomBoundaryTicks }), options.grid, undefined, false, isFirst ? -1 : 1); } function callAction(ticks, action, actionArgument) { ticks.forEach(function (tick) { tick[action](actionArgument); }); } function initTickCoords(ticks) { callAction(ticks, "initCoords"); } function drawTickMarks(ticks) { callAction(ticks, "drawMark"); } function drawGrids(ticks, drawLine) { callAction(ticks, "drawGrid", drawLine); } function updateTicksPosition(ticks) { callAction(ticks, "updateTickPosition"); } function updateGridsPosition(ticks) { callAction(ticks, "updateGridPosition"); } function measureLabels(items) { items.forEach(function (item) { item.labelBBox = item.label ? item.label.getBBox() : { x: 0, y: 0, width: 0, height: 0 }; }); } function cleanUpInvalidTicks(ticks) { var i = ticks.length - 1; for (i; i >= 0; i--) { if (!removeInvalidTick(ticks, i)) { break; } } for (i = 0; i < ticks.length; i++) { if (removeInvalidTick(ticks, i)) { i--; } else { break; } } } function removeInvalidTick(ticks, i) { if (ticks[i].coords.x === null || ticks[i].coords.y === null) { ticks.splice(i, 1); return true; } return false; } function getAddFunction(range, correctZeroLevel) { // T170398 if (range.dataType === "datetime") { return function (rangeValue, marginValue) { var sign = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; return new Date(rangeValue.getTime() + sign * marginValue); }; } if (range.axisType === "logarithmic") { return function (rangeValue, marginValue) { var sign = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; var log = _utils2.default.getLog(rangeValue, range.base) + sign * marginValue; return _utils2.default.raiseTo(log, range.base); }; } return function (rangeValue, marginValue) { var sign = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; var newValue = rangeValue + sign * marginValue; return correctZeroLevel && newValue * rangeValue <= 0 ? 0 : newValue; }; } function validateAxisOptions(options) { var labelOptions = options.label, position = options.position, defaultPosition = options.isHorizontal ? BOTTOM : LEFT, secondaryPosition = options.isHorizontal ? TOP : RIGHT; if (position !== defaultPosition && position !== secondaryPosition) { position = defaultPosition; } if (position === RIGHT && !labelOptions.userAlignment) { labelOptions.alignment = LEFT; } options.position = position; options.hoverMode = options.hoverMode ? options.hoverMode.toLowerCase() : "none"; labelOptions.minSpacing = (0, _type.isDefined)(labelOptions.minSpacing) ? labelOptions.minSpacing : DEFAULT_AXIS_LABEL_SPACING; } function getOptimalAngle(boxes, labelOpt) { var angle = _math.asin((boxes[0].height + labelOpt.minSpacing) / (boxes[1].x - boxes[0].x)) * 180 / _math.PI; return angle < 45 ? -45 : -90; } function updateLabels(ticks, step, func) { ticks.forEach(function (tick, index) { if (tick.label) { if (index % step !== 0) { tick.label.remove(); } else if (func) { func(tick, index); } } }); } function valueOf(value) { return value.valueOf(); } function correctMarginExtremum(value, margins, maxMinDistance, roundingMethod) { var dividerPower, distancePower, maxDivider; if (!(0, _type.isNumeric)(value) || value === 0) { return value; } else if (!margins.size && !margins.checkInterval) { return (0, _math2.adjust)(value); } dividerPower = _math.floor(_utils2.default.getAdjustedLog10(_abs(value))); distancePower = _math.floor(_utils2.default.getAdjustedLog10(_abs(maxMinDistance))); dividerPower = (dividerPower >= distancePower ? distancePower : dividerPower) - 2; if (dividerPower === 0) { dividerPower = -1; } maxDivider = _utils2.default.raiseTo(dividerPower, 10); return (0, _math2.adjust)(roundingMethod((0, _math2.adjust)(value / maxDivider)) * maxDivider); } function configureGenerator(options, axisDivisionFactor, viewPort, screenDelta, minTickInterval, breaks) { var tickGeneratorOptions = (0, _extend.extend)({}, options, { endOnTick: true, axisDivisionFactor: axisDivisionFactor, skipCalculationLimits: true, generateExtraTick: true, minTickInterval: minTickInterval }); return function (tickInterval, skipTickGeneration, min, max) { return getTickGenerator(tickGeneratorOptions, _common.noop, skipTickGeneration)({ min: min, max: max, categories: viewPort.categories, isSpacedMargin: viewPort.isSpacedMargin, checkMinDataVisibility: viewPort.checkMinDataVisibility, checkMaxDataVisibility: viewPort.checkMaxDataVisibility }, screenDelta, tickInterval, (0, _type.isDefined)(tickInterval), undefined, undefined, undefined, breaks); }; } var Axis = exports.Axis = function (renderSettings) { var that = this; that._renderer = renderSettings.renderer; that._incidentOccurred = renderSettings.incidentOccurred; that._stripsGroup = renderSettings.stripsGroup; that._labelAxesGroup = renderSettings.labelAxesGroup; that._constantLinesGroup = renderSettings.constantLinesGroup; that._scaleBreaksGroup = renderSettings.scaleBreaksGroup; that._axesContainerGroup = renderSettings.axesContainerGroup; that._gridContainerGroup = renderSettings.gridGroup; that._axisCssPrefix = renderSettings.widgetClass + "-" + (renderSettings.axisClass ? renderSettings.axisClass + "-" : ""); that._setType(renderSettings.axisType, renderSettings.drawingType); that._createAxisGroups(); that._translator = that._createTranslator(); that.isArgumentAxis = renderSettings.isArgumentAxis; }; Axis.prototype = { constructor: Axis, _drawAxis: function _drawAxis() { var options = this._options; if (!options.visible) { return; } this._axisElement = this._createAxisElement(); this._updateAxisElementPosition(); this._axisElement.attr({ "stroke-width": options.width, stroke: options.color, "stroke-opacity": options.opacity }).sharp(this._getSharpParam(true)).append(this._axisLineGroup); }, _createPathElement: function _createPathElement(points, attr) { return this._renderer.path(points, "line").attr(attr).sharp(this._getSharpParam()); }, _getGridLineDrawer: function _getGridLineDrawer(borderOptions) { var that = this, isHorizontal = that._isHorizontal; return function (tick, gridStyle) { that.borderOptions = borderOptions; var canvasStart = isHorizontal ? LEFT : TOP, canvasEnd = isHorizontal ? RIGHT : BOTTOM, axisCanvas = that.getCanvas(), canvas = { left: axisCanvas.left, right: axisCanvas.width - axisCanvas.right, top: axisCanvas.top, bottom: axisCanvas.height - axisCanvas.bottom }, firstBorderLinePosition = borderOptions.visible && borderOptions[canvasStart] ? canvas[canvasStart] : undefined, lastBorderLinePosition = borderOptions.visible && borderOptions[canvasEnd] ? canvas[canvasEnd] : undefined, tickPositionField = isHorizontal ? "x" : "y", minDelta = MAX_GRID_BORDER_ADHENSION + firstBorderLinePosition, maxDelta = lastBorderLinePosition - MAX_GRID_BORDER_ADHENSION, element; if (tick.coords[tickPositionField] === undefined || tick.coords[tickPositionField] < minDelta || tick.coords[tickPositionField] > maxDelta) { return; } var grid = that._getGridPoints(tick.coords); if (grid.points) { element = that._createPathElement(grid.points, gridStyle); } return element; }; }, _getGridPoints: function _getGridPoints(coords) { var isHorizontal = this._isHorizontal, tickPositionField = isHorizontal ? "x" : "y", orthogonalPositions = this._orthogonalPositions, positionFrom = orthogonalPositions.start, positionTo = orthogonalPositions.end; return { points: isHorizontal ? coords[tickPositionField] !== null ? [coords[tickPositionField], positionFrom, coords[tickPositionField], positionTo] : null : coords[tickPositionField] !== null ? [positionFrom, coords[tickPositionField], positionTo, coords[tickPositionField]] : null }; }, _getConstantLinePos: function _getConstantLinePos(lineValue, canvasStart, canvasEnd) { var parsedValue = this._validateUnit(lineValue, "E2105", "constantLine"), value = this._getTranslatedCoord(parsedValue); if (!(0, _type.isDefined)(value) || value < _min(canvasStart, canvasEnd) || value > _max(canvasStart, canvasEnd)) { return {}; } return { value: value, parsedValue: parsedValue }; }, _getConstantLineGraphicAttributes: function _getConstantLineGraphicAttributes(value) { var positionFrom = this._orthogonalPositions.start, positionTo = this._orthogonalPositions.end; return { points: this._isHorizontal ? [value, positionFrom, value, positionTo] : [positionFrom, value, positionTo, value] }; }, _createConstantLine: function _createConstantLine(value, attr) { return this._createPathElement(this._getConstantLineGraphicAttributes(value).points, attr); }, _drawConstantLinesAndLabels: function _drawConstantLinesAndLabels(position, lineOptions, canvasStart, canvasEnd) { if (!(0, _type.isDefined)(lineOptions.value)) { return { line: null, label: null, options: lineOptions }; } var that = this, pos = that._getConstantLinePos(lineOptions.value, canvasStart, canvasEnd), labelOptions = lineOptions.label || {}, value = pos.value, attr = { stroke: lineOptions.color, "stroke-width": lineOptions.width, dashStyle: lineOptions.dashStyle }, group = that._axisConstantLineGroups[position], side; if (!group) { side = that._isHorizontal ? labelOptions.verticalAlignment : labelOptions.horizontalAlignment; group = that._axisConstantLineGroups[side]; } if (!(0, _type.isDefined)(value)) { return { line: null, label: null, options: lineOptions }; } return { line: that._createConstantLine(value, attr).append(that._axisConstantLineGroups.inside), label: labelOptions.visible ? that._drawConstantLineLabels(pos.parsedValue, labelOptions, value, group) : null, options: lineOptions, labelOptions: labelOptions, coord: value }; }, _drawConstantLines: function _drawConstantLines(position) { var that = this, canvas = that._getCanvasStartEnd(); if (that._translator.getBusinessRange().stubData) { return []; } return (that._options.constantLines || []).reduce(function (result, constantLine) { var labelPos = constantLine.label.position; if (labelPos === position || !labelPos && position === "inside") { result.push(that._drawConstantLinesAndLabels(position, constantLine, canvas.start, canvas.end)); } return result; }, []); }, _drawConstantLineLabelText: function _drawConstantLineLabelText(text, x, y, constantLineLabelOptions, group) { var that = this, options = that._options, labelOptions = options.label; return that._renderer.text(text, x, y).css(patchFontOptions((0, _extend.extend)({}, labelOptions.font, constantLineLabelOptions.font))).attr({ align: "center" }).append(group); }, _drawConstantLineLabels: function _drawConstantLineLabels(parsedValue, lineLabelOptions, value, group) { var that = this, text = lineLabelOptions.text, options = that._options, labelOptions = options.label, coords; that._checkAlignmentConstantLineLabels(lineLabelOptions); text = (0, _type.isDefined)(text) ? text : that.formatLabel(parsedValue, labelOptions); coords = that._getConstantLineLabelsCoords(value, lineLabelOptions); return that._drawConstantLineLabelText(text, coords.x, coords.y, lineLabelOptions, group); }, _getStripPos: function _getStripPos(startValue, endValue, canvasStart, canvasEnd, range) { var isContinuous = !!(range.minVisible || range.maxVisible), categories = (range.categories || []).reduce(function (result, cat) { result.push(cat.valueOf()); return result; }, []), start, end, swap, startCategoryIndex, endCategoryIndex, min = range.minVisible; if (!isContinuous) { if ((0, _type.isDefined)(startValue) && (0, _type.isDefined)(endValue)) { startCategoryIndex = (0, _array.inArray)(startValue.valueOf(), categories); endCategoryIndex = (0, _array.inArray)(endValue.valueOf(), categories); if (startCategoryIndex === -1 || endCategoryIndex === -1) { return { from: 0, to: 0 }; } if (startCategoryIndex > endCategoryIndex) { swap = endValue; endValue = startValue; startValue = swap; } } } if ((0, _type.isDefined)(startValue)) { startValue = this._validateUnit(startValue, "E2105", "strip"); start = this._getTranslatedCoord(startValue, -1); if (!(0, _type.isDefined)(start) && isContinuous) { start = startValue < min ? canvasStart : canvasEnd; } } else { start = canvasStart; } if ((0, _type.isDefined)(endValue)) { endValue = this._validateUnit(endValue, "E2105", "strip"); end = this._getTranslatedCoord(endValue, 1); if (!(0, _type.isDefined)(end) && isContinuous) { end = endValue > min ? canvasEnd : canvasStart; } } else { end = canvasEnd; } return start < end ? { from: start, to: end } : { from: end, to: start }; }, _getStripGraphicAttributes: function _getStripGraphicAttributes(fromPoint, toPoint) { var x, y, width, height, orthogonalPositions = this._orthogonalPositions, positionFrom = orthogonalPositions.start, positionTo = orthogonalPositions.end; if (this._isHorizontal) { x = fromPoint; y = _min(positionFrom, positionTo); width = toPoint - fromPoint; height = _abs(positionFrom - positionTo); } else { x = _min(positionFrom, positionTo); y = fromPoint; width = _abs(positionFrom - positionTo); height = _abs(fromPoint - toPoint); } return { x: x, y: y, width: width, height: height }; }, _createStrip: function _createStrip(fromPoint, toPoint, attr) { var attrs = this._getStripGraphicAttributes(fromPoint, toPoint); return this._renderer.rect(attrs.x, attrs.y, attrs.width, attrs.height).attr(attr); }, _drawStrips: function _drawStrips() { var that = this, options = that._options, stripData = options.strips, canvas = this._getCanvasStartEnd(), i, stripOptions, stripPos, stripLabelOptions, attr, range = that._translator.getBusinessRange(), labelCoords, strips = []; if (!stripData || range.stubData) { return []; } for (i = 0; i < stripData.length; i++) { stripOptions = stripData[i]; stripLabelOptions = stripOptions.label || {}; attr = { fill: stripOptions.color }; if (((0, _type.isDefined)(stripOptions.startValue) || (0, _type.isDefined)(stripOptions.endValue)) && (0, _type.isDefined)(stripOptions.color)) { stripPos = that._getStripPos(stripOptions.startValue, stripOptions.endValue, canvas.start, canvas.end, range); labelCoords = stripLabelOptions.text ? that._getStripLabelCoords(stripPos.from, stripPos.to, stripLabelOptions) : null; if (stripPos.to - stripPos.from === 0 || !(0, _type.isDefined)(stripPos.to) || !(0, _type.isDefined)(stripPos.from)) { continue; } strips.push({ rect: that._createStrip(stripPos.from, stripPos.to, attr).append(that._axisStripGroup), options: stripOptions, label: stripLabelOptions.text ? that._drawStripLabel(stripLabelOptions, labelCoords) : null, labelCoords: labelCoords }); } } return strips; }, _drawStripLabel: function _drawStripLabel(stripLabelOptions, coords) { return this._renderer.text(stripLabelOptions.text, coords.x, coords.y).css(patchFontOptions((0, _extend.extend)({}, this._options.label.font, stripLabelOptions.font))).attr({ align: "center" }).append(this._axisStripLabelGroup); }, _adjustStripLabels: function _adjustStripLabels() { var that = this; this._strips.forEach(function (strip) { if (strip.label) { strip.label.attr(that._getAdjustedStripLabelCoords(strip)); } }); }, _adjustLabels: function _adjustLabels(offset) { var that = this, maxSize = that._majorTicks.reduce(function (size, tick) { var bBox = tick.labelRotationAngle ? _utils2.default.rotateBBox(tick.labelBBox, [tick.labelCoords.x, tick.labelCoords.y], -tick.labelRotationAngle) : tick.labelBBox; return { width: _max(size.width || 0, bBox.width), height: _max(size.height || 0, bBox.height), offset: _max(size.offset || 0, tick.labelOffset || 0) }; }, {}), additionalOffset = that._isHorizontal ? maxSize.height : maxSize.width; that._majorTicks.forEach(function (tick) { if (tick.label) { tick.label.attr(that._getLabelAdjustedCoord(tick, offset + (tick.labelOffset || 0), maxSize.width)); } }); return offset + additionalOffset + (additionalOffset && that._options.label.indentFromAxis) + maxSize.offset; }, _getLabelAdjustedCoord: function _getLabelAdjustedCoord(tick, offset, maxWidth) { offset = offset || 0; var that = this, options = that._options, box = _utils2.default.rotateBBox(tick.labelBBox, [tick.labelCoords.x, tick.labelCoords.y], -tick.labelRotationAngle || 0), position = options.position, textAlign = tick.labelAlignment || options.label.alignment, indentFromAxis = options.label.indentFromAxis, axisPosition = that._axisPosition, labelCoords = tick.labelCoords, labelX = labelCoords.x, translateX, translateY; if (that._isHorizontal) { if (position === BOTTOM) { translateY = axisPosition + indentFromAxis - box.y + offset; } else { translateY = axisPosition - indentFromAxis - (box.y + box.height) - offset; } if (textAlign === RIGHT) { translateX = labelX - box.x - box.width; } else if (textAlign === LEFT) { translateX = labelX - box.x; } else { translateX = labelX - box.x - box.width / 2; } } else { translateY = labelCoords.y - box.y - box.height / 2; if (position === LEFT) { if (textAlign === LEFT) { translateX = axisPosition - indentFromAxis - maxWidth - box.x; } else if (textAlign === CENTER) { translateX = axisPosition - indentFromAxis - maxWidth / 2 - box.x - box.width / 2; } else { translateX = axisPosition - indentFromAxis - box.x - box.width; } translateX -= offset; } else { if (textAlign === RIGHT) { translateX = axisPosition + indentFromAxis + maxWidth - box.x - box.width; } else if (textAlign === CENTER) { translateX = axisPosition + indentFromAxis + maxWidth / 2 - box.x - box.width / 2; } else { translateX = axisPosition + indentFromAxis - box.x; } translateX += offset; } } return { translateX: translateX, translateY: translateY }; }, _createAxisGroups: function _createAxisGroups() { var that = this, renderer = that._renderer, classSelector = that._axisCssPrefix, constantLinesClass = classSelector + "constant-lines", insideGroup, outsideGroup1, outsideGroup2; that._axisGroup = renderer.g().attr({ "class": classSelector + "axis" }); that._axisStripGroup = renderer.g().attr({ "class": classSelector + "strips" }); that._axisGridGroup = renderer.g().attr({ "class": classSelector + "grid" }); that._axisElementsGroup = renderer.g().attr({ "class": classSelector + "elements" }).append(that._axisGroup); that._axisLineGroup = renderer.g().attr({ "class": classSelector + "line" }).append(that._axisGroup); that._axisTitleGroup = renderer.g().attr({ "class": classSelector + "title" }).append(that._axisGroup); insideGroup = renderer.g().attr({ "class": constantLinesClass }); outsideGroup1 = renderer.g().attr({ "class": constantLinesClass }); outsideGroup2 = renderer.g().attr({ "class": constantLinesClass }); that._axisConstantLineGroups = { inside: insideGroup, outside1: outsideGroup1, left: outsideGroup1, top: outsideGroup1, outside2: outsideGroup2, right: outsideGroup2, bottom: outsideGroup2 }; that._axisStripLabelGroup = renderer.g().attr({ "class": classSelector + "axis-labels" }); }, _clearAxisGroups: function _clearAxisGroups() { var that = this; that._axisGroup.remove(); that._axisStripGroup.remove(); that._axisStripLabelGroup.remove(); that._axisConstantLineGroups.inside.remove(); that._axisConstantLineGroups.outside1.remove(); that._axisConstantLineGroups.outside2.remove(); that._axisGridGroup.remove(); that._axisTitleGroup.clear(); that._axisElementsGroup.clear(); that._axisLineGroup && that._axisLineGroup.clear(); that._axisStripGroup && that._axisStripGroup.clear(); that._axisGridGroup && that._axisGridGroup.clear(); that._axisConstantLineGroups.inside.clear(); that._axisConstantLineGroups.outside1.clear(); that._axisConstantLineGroups.outside2.clear(); that._axisStripLabelGroup && that._axisStripLabelGroup.clear(); }, _getLabelFormatObject: function _getLabelFormatObject(value, labelOptions, range, point, tickInterval, ticks) { range = range || this._getViewportRange(); var formatObject = { value: value, valueText: (0, _smart_formatter.smartFormatter)(value, { labelOptions: labelOptions, ticks: ticks || convertTicksToValues(this._majorTicks), tickInterval: (0, _type.isDefined)(tickInterval) ? tickInterval : this._tickInterval, dataType: this._options.dataType, logarithmBase: this._options.logarithmBase, type: this._options.type, showTransition: !this._options.marker.visible, point: point }) || "", // B252346 min: range.minVisible, max: range.maxVisible }; // for crosshair's customizeText if (point) { formatObject.point = point; } return formatObject; }, formatLabel: function formatLabel(value, labelOptions, range, point, tickInterval, ticks) { var formatObject = this._getLabelFormatObject(value, labelOptions, range, point, tickInterval, ticks); return (0, _type.isFunction)(labelOptions.customizeText) ? labelOptions.customizeText.call(formatObject, formatObject) : formatObject.valueText; }, formatHint: function formatHint(value, labelOptions, range) { var formatObject = this._getLabelFormatObject(value, labelOptions, range); return (0, _type.isFunction)(labelOptions.customizeHint) ? labelOptions.customizeHint.call(formatObject, formatObject) : undefined; }, formatRange: function formatRange(startValue, endValue, interval) { return (0, _smart_formatter.formatRange)(startValue, endValue, interval, this.getOptions()); }, _setTickOffset: function _setTickOffset() { var options = this._options, discreteAxisDivisionMode = options.discreteAxisDivisionMode; this._tickOffset = +(discreteAxisDivisionMode !== "crossLabels" || !discreteAxisDivisionMode); }, getMargins: function getMargins() { var that = this, options = that._options, position = options.position, placeholderSize = options.placeholderSize, canvas = that.getCanvas(), cLeft = canvas.left, cTop = canvas.top, cRight = canvas.width - canvas.right, cBottom = canvas.height - canvas.bottom, edgeMarginCorrection = _max(options.grid.visible && options.grid.width || 0, options.tick.visible && options.tick.width || 0), boxes = [that._axisElementsGroup, that._axisConstantLineGroups.outside1, that._axisConstantLineGroups.outside2].map(function (group) { return group && group.getBBox(); }).concat(function (group) { var box = group && group.getBBox(); if (!box || box.isEmpty) { return box; } if (that._isHorizontal) { box.x = cLeft; box.width = cRight - cLeft; } else { box.y = cTop; box.height = cBottom - cTop; } return box; }(that._axisTitleGroup)), margins = boxes.reduce(function (margins, bBox) { if (!bBox || bBox.isEmpty) { return margins; } return { left: _max(margins.left, cLeft - bBox.x), top: _max(margins.top, cTop - bBox.y), right: _max(margins.right, bBox.x + bBox.width - cRight), bottom: _max(margins.bottom, bBox.y + bBox.height - cBottom) }; }, { left: 0, right: 0, top: 0, bottom: 0 }); margins[position] += options.crosshairMargin; if (placeholderSize) { margins[position] = placeholderSize; } if (edgeMarginCorrection) { if (that._isHorizontal && canvas.right < edgeMarginCorrection && margins.right < edgeMarginCorrection) { margins.right = edgeMarginCorrection; } if (!that._isHorizontal && canvas.bottom < edgeMarginCorrection && margins.bottom < edgeMarginCorrection) { margins.bottom = edgeMarginCorrection; } } return margins; }, _validateUnit: function _validateUnit(unit, idError, parameters) { var that = this; unit = that.parser(unit); if (unit === undefined && idError) { that._incidentOccurred(idError, [parameters]); } return unit; }, _setType: function _setType(axisType, drawingType) { var that = this, axisTypeMethods; switch (axisType) { case "xyAxes": axisTypeMethods = _xy_axes2.default; break; case "polarAxes": axisTypeMethods = _polar_axes2.default; break; } (0, _extend.extend)(that, axisTypeMethods[drawingType]); }, _getSharpParam: function _getSharpParam() { return true; }, _disposeBreaksGroup: _common.noop, // public dispose: function dispose() { var that = this; [that._axisElementsGroup, that._axisStripGroup, that._axisGroup].forEach(function (g) { g.dispose(); }); that._strips = that._title = null; that._axisStripGroup = that._axisConstantLineGroups = that._axisStripLabelGroup = that._axisBreaksGroup = null; that._axisLineGroup = that._axisElementsGroup = that._axisGridGroup = null; that._axisGroup = that._axisTitleGroup = null; that._axesContainerGroup = that._stripsGroup = that._constantLinesGroup = null; that._renderer = that._options = that._textOptions = that._textFontStyles = null; that._translator = null; that._majorTicks = that._minorTicks = null; that._disposeBreaksGroup(); }, getOptions: function getOptions() { return this._options; }, setPane: function setPane(pane) { this.pane = pane; this._options.pane = pane; }, setTypes: function setTypes(type, axisType, typeSelector) { this._options.type = type || this._options.type; this._options[typeSelector] = axisType || this._options[typeSelector]; this._updateTranslator(); }, resetTypes: function resetTypes(typeSelector) { this._options.type = this._initTypes.type; this._options[typeSelector] = this._initTypes[typeSelector]; }, getTranslator: function getTranslator() { return this._translator; }, updateOptions: function updateOptions(options) { var that = this, labelOpt = options.label; that._options = options; options.tick = options.tick || {}; options.minorTick = options.minorTick || {}; options.grid = options.grid || {}; options.minorGrid = options.minorGrid || {}; options.title = options.title || {}; options.marker = options.marker || {}; that._initTypes = { type: options.type, argumentType: options.argumentType, valueType: options.valueType }; validateAxisOptions(options); that._setTickOffset(); that._isHorizontal = options.isHorizontal; that.pane = options.pane; that.name = options.name; that.priority = options.priority; that._hasLabelFormat = labelOpt.format !== "" && (0, _type.isDefined)(labelOpt.format); that._textOptions = { opacity: labelOpt.opacity, align: "center" }; that._textFontStyles = _utils2.default.patchFontOptions(labelOpt.font); if (options.type === _axes_constants2.default.logarithmic) { if (options.logarithmBaseError) { that._incidentOccurred("E2104"); delete options.logarithmBaseError; } } that._updateTranslator(); }, calculateInterval: function calculateInterval(value, prevValue) { var options = this._options; return !options || options.type !== _axes_constants2.default.logarithmic ? _abs(value - prevValue) : _utils2.default.getLog(value / prevValue, options.logarithmBase); }, _processCanvas: function _processCanvas(canvas) { return canvas; }, updateCanvas: function updateCanvas(canvas) { var positions = this._orthogonalPositions = { start: !this._isHorizontal ? canvas.left : canvas.top, end: !this._isHorizontal ? canvas.width - canvas.right : canvas.height - canvas.bottom }; this._canvas = canvas; positions.center = positions.start + (positions.end - positions.start) / 2; this._translator.updateCanvas(this._processCanvas(canvas)); this._initAxisPositions(); }, getCanvas: function getCanvas() { return this._canvas; }, hideTitle: function hideTitle() { var that = this; if (that._options.title.text) { that._incidentOccurred("W2105", [that._isHorizontal ? "horizontal" : "vertical"]); that._axisTitleGroup.clear(); } }, hideOuterElements: function hideOuterElements() { var that = this, options = that._options, constantLineLabels = that._outsideConstantLines.map(function (line) { return line.label; }); if ((options.label.visible || constantLineLabels.length) && !that._translator.getBusinessRange().stubData) { that._incidentOccurred("W2106", [that._isHorizontal ? "horizontal" : "vertical"]); that._axisElementsGroup.clear(); constantLineLabels.forEach(function (label) { label && label.remove(); }); } }, setBusinessRange: function setBusinessRange(range) { var that = this, validateBusinessRange = function validateBusinessRange(range, min, max) { function validate(valueSelector, baseValueSelector, optionValue) { range[valueSelector] = (0, _type.isDefined)(optionValue) ? optionValue : (0, _type.isDefined)(range[valueSelector]) ? range[valueSelector] : range[baseValueSelector]; } validate("minVisible", "min", min); validate("maxVisible", "max", max); return range; }, options = that._options; that._seriesData = new _range2.default.Range(validateBusinessRange(range, options.min, options.max)); that._breaks = that._getScaleBreaks(options, that._seriesData, that._series, that.isArgumentAxis); that._translator.updateBusinessRange(that._seriesData); }, setGroupSeries: function setGroupSeries(series) { this._series = series; }, getLabelsPosition: function getLabelsPosition() { var that = this, options = that._options, position = options.position, labelShift = options.label.indentFromAxis + (that._axisShift || 0) + that._constantLabelOffset, axisPosition = that._axisPosition; return position === TOP || position === LEFT ? axisPosition - labelShift : axisPosition + labelShift; }, getFormattedValue: function getFormattedValue(value, options, point) { var labelOptions = this._options.label; return (0, _type.isDefined)(value) ? this.formatLabel(value, (0, _extend.extend)(true, {}, labelOptions, options), undefined, point) : null; }, _getBoundaryTicks: function _getBoundaryTicks(majors, viewPort) { var that = this, length = majors.length, options = that._options, customBounds = options.customBoundTicks, min = viewPort.minVisible, max = viewPort.maxVisible, addMinMax = options.showCustomBoundaryTicks ? that._boundaryTicksVisibility : {}, boundaryTicks = []; if (options.type === _axes_constants2.default.discrete) { if (that._tickOffset && majors.length !== 0) { boundaryTicks = [majors[0], majors[majors.length - 1]]; } } else { if (customBounds) { if (addMinMax.min && (0, _type.isDefined)(customBounds[0])) { boundaryTicks.push(customBounds[0]); } if (addMinMax.max && (0, _type.isDefined)(customBounds[1])) { boundaryTicks.push(customBounds[1]); } } else { if (addMinMax.min && (length === 0 || majors[0] > min)) { boundaryTicks.push(min); } if (addMinMax.max && (length === 0 || majors[length - 1] < max)) { boundaryTicks.push(max); } } } return boundaryTicks; }, setPercentLabelFormat: function setPercentLabelFormat() { if (!this._hasLabelFormat) { this._options.label.format = "percent"; } }, resetAutoLabelFormat: function resetAutoLabelFormat() { if (!this._hasLabelFormat) { delete this._options.label.format; } }, getMultipleAxesSpacing: function getMultipleAxesSpacing() { return this._options.multipleAxesSpacing || 0; }, getTicksValues: function getTicksValues() { return { majorTicksValues: convertTicksToValues(this._majorTicks), minorTicksValues: convertTicksToValues(this._minorTicks) }; }, setTicks: function setTicks(ticks) { var majors = ticks.majorTicks || []; this._majorTicks = majors.map(createMajorTick(this, this._renderer, this._getSkippedCategory(majors))); this._minorTicks = (ticks.minorTicks || []).map(createMinorTick(this, this._renderer)); this._isSynchronized = true; }, _getTicks: function _getTicks(viewPort, incidentOccurred, skipTickGeneration) { var that = this, options = that._options, customTicks = options.customTicks, customMinorTicks = options.customMinorTicks; return getTickGenerator(options, incidentOccurred || that._incidentOccurred, skipTickGeneration)({ min: viewPort.minVisible, max: viewPort.maxVisible, categories: viewPort.categories, isSpacedMargin: viewPort.isSpacedMargin, checkMinDataVisibility: viewPort.checkMinDataVisibility, checkMaxDataVisibility: viewPort.checkMaxDataVisibility }, that._getScreenDelta(), that._translator.getBusinessRange().stubData ? null : options.tickInterval, options.label.overlappingBehavior.mode === "ignore" ? true : options.forceUserTickInterval, { majors: customTicks, minors: customMinorTicks }, options.minorTickInterval, options.minorTickCount, that._breaks); }, _createTicksAndLabelFormat: function _createTicksAndLabelFormat(range, incidentOccurred) { var options = this._options, ticks; ticks = this._getTicks(range, incidentOccurred, false); if (options.type === _axes_constants2.default.discrete && options.dataType === "datetime" && !this._hasLabelFormat && ticks.ticks.length) { options.label.format = _format_helper2.default.getDateFormatByTicks(ticks.ticks); } return ticks; }, getAggregationInfo: function getAggregationInfo(useAllAggregatedPoints, range) { var that = this, options = that._options, marginOptions = that._marginOptions, viewPort = new _range2.default.Range(that.getTranslator().getBusinessRange()).addRange(range), zoomArgs = that._zoomArgs, minVisible = zoomArgs && zoomArgs.min || viewPort.minVisible, maxVisible = zoomArgs && zoomArgs.max || viewPort.maxVisible, ticks = []; var aggregationInterval = options.aggregationInterval; var aggregationGroupWidth = options.aggregationGroupWidth; if (!aggregationGroupWidth && marginOptions) { if (marginOptions.checkInterval) { aggregationGroupWidth = options.axisDivisionFactor; } if (marginOptions.sizePointNormalState) { aggregationGroupWidth = Math.min(marginOptions.sizePointNormalState, options.axisDivisionFactor); } } var minInterval = !options.aggregationGroupWidth && !aggregationInterval && range.interval; var generateTicks = configureGenerator(options, aggregationGroupWidth, viewPort, that._getScreenDelta(), minInterval, that._breaks); var tickInterval = generateTicks(aggregationInterval, true, minVisible, maxVisible).tickInterval; if (options.type !== _axes_constants2.default.discrete) { var min = useAllAggregatedPoints ? viewPort.min : minVisible; var max = useAllAggregatedPoints ? viewPort.max : maxVisible; if ((0, _type.isDefined)(min) && (0, _type.isDefined)(max)) { var add = getAddFunction({ base: options.logarithmBase, axisType: options.type, dataType: options.dataType }, false); var start = min; var end = max; if (!useAllAggregatedPoints) { var maxMinDistance = Math.max(that.calculateInterval(max, min), options.dataType === "datetime" ? (0, _date.dateToMilliseconds)(tickInterval) : tickInterval); start = add(min, maxMinDistance, -1); end = add(max, maxMinDistance); } start = start < viewPort.min ? viewPort.min : start; end = end > viewPort.max ? viewPort.max : end; ticks = generateTicks(tickInterval, false, start, end).ticks; } } that._aggregationInterval = tickInterval; return { interval: tickInterval, ticks: ticks }; }, createTicks: function createTicks(canvas) { var that = this, renderer = that._renderer, options = that._options, ticks, boundaryTicks, range; if (!canvas) { return; } that._isSynchronized = false; that.updateCanvas(canvas); that._estimatedTickInterval = that._getTicks(new _range2.default.Range(this._seriesData), _common.noop, true).tickInterval; // tickInterval calculation range = that._getViewportRange(); ticks = that._createTicksAndLabelFormat(range); boundaryTicks = that._getBoundaryTicks(ticks.ticks, range); if (options.showCustomBoundaryTicks && boundaryTicks.length) { that._boundaryTicks = [boundaryTicks[0]].map(createBoundaryTick(that, renderer, true)); if (boundaryTicks.length > 1) { that._boundaryTicks = that._boundaryTicks.concat([boundaryTicks[1]].map(createBoundaryTick(that, renderer, false))); } } else { that._boundaryTicks = []; } var minors = (ticks.minorTicks || []).filter(function (minor) { return !boundaryTicks.some(function (boundary) { return valueOf(boundary) === valueOf(minor); }); }); that._tickInterval = ticks.tickInterval; that._minorTickInterval = ticks.minorTickInterval; that._majorTicks = ticks.ticks.map(createMajorTick(that, renderer, that._getSkippedCategory(ticks.ticks))); that._minorTicks = minors.map(createMinorTick(that, renderer)); that._correctedBreaks = ticks.breaks; that.correctTicksOnDeprecated(); that._reinitTranslator(range); }, _reinitTranslator: function _reinitTranslator(range) { var that = this, min = range.min, max = range.max, minVisible = range.minVisible, maxVisible = range.maxVisible, interval = range.interval, ticks = that._majorTicks, length = ticks.length, translator = that._translator; if (that._isSynchronized) { return; } if (that._options.type !== _axes_constants2.default.discrete) { if (length && !that._options.skipViewportExtending && (!(0, _type.isDefined)(that._zoomArgs) || !that.isArgumentAxis)) { if (ticks[0].value < range.minVisible) { minVisible = ticks[0].value; } if (length > 1 && ticks[length - 1].value > range.maxVisible) { maxVisible = ticks[length - 1].value; } } interval = that._calculateRangeInterval(that.calculateInterval(maxVisible, minVisible), interval); range.addRange({ minVisible: minVisible, maxVisible: maxVisible, interval: interval }); if ((0, _type.isDefined)(min) && (0, _type.isDefined)(max) && min.valueOf() === max.valueOf()) { range.min = range.max = min; } } range.breaks = that._correctedBreaks; translator.updateBusinessRange(range); }, _getViewportRange: function _getViewportRange() { var range = new _range2.default.Range(this._seriesData), zoom = this._zoomArgs; range = this._applyMargins(range); if ((0, _type.isDefined)(zoom) && ((0, _type.isDefined)(zoom.min) || (0, _type.isD