devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
1,141 lines (1,120 loc) • 108 kB
JavaScript
/**
* DevExtreme (viz/axes/base_axis.js)
* Version: 20.1.7
* Build date: Tue Aug 25 2020
*
* Copyright (c) 2012 - 2020 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
"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 _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);
var _constant_line = require("./constant_line");
var _constant_line2 = _interopRequireDefault(_constant_line);
var _strip = require("./strip");
var _strip2 = _interopRequireDefault(_strip);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
"default": obj
}
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
})
} else {
obj[key] = value
}
return obj
}
var convertTicksToValues = _axes_constants2.default.convertTicksToValues;
var patchFontOptions = _utils2.default.patchFontOptions;
var getVizRangeObject = _utils2.default.getVizRangeObject;
var getLog = _utils2.default.getLogExt;
var raiseTo = _utils2.default.raiseToExt;
var valueOf = _utils2.default.valueOf;
var _math = Math;
var _abs = _math.abs;
var _max = _math.max;
var _min = _math.min;
var _isArray = Array.isArray;
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 KEEP = "keep";
var SHIFT = "shift";
var RESET = "reset";
var ROTATE = "rotate";
var DEFAULT_AXIS_DIVISION_FACTOR = 50;
var DEFAULT_MINOR_AXIS_DIVISION_FACTOR = 15;
var SCROLL_THRESHOLD = 5;
var MIN_BAR_MARGIN = 5;
var MAX_MARGIN_VALUE = .8;
var dateIntervals = {
day: 864e5,
week: 6048e5
};
function getTickGenerator(options, incidentOccurred, skipTickGeneration, rangeIsEmpty, adjustDivisionFactor, _ref) {
var _options$workWeek;
var allowNegatives = _ref.allowNegatives,
linearThreshold = _ref.linearThreshold;
return _tick_generator2.default.tickGenerator({
axisType: options.type,
dataType: options.dataType,
logBase: options.logarithmBase,
allowNegatives: allowNegatives,
linearThreshold: linearThreshold,
axisDivisionFactor: adjustDivisionFactor(options.axisDivisionFactor || DEFAULT_AXIS_DIVISION_FACTOR),
minorAxisDivisionFactor: adjustDivisionFactor(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: null === (_options$workWeek = options.workWeek) || void 0 === _options$workWeek ? void 0 : _options$workWeek[0],
skipTickGeneration: skipTickGeneration,
skipCalculationLimits: options.skipCalculationLimits,
generateExtraTick: options.generateExtraTick,
minTickInterval: options.minTickInterval,
rangeIsEmpty: rangeIsEmpty
})
}
function createMajorTick(axis, renderer, skippedCategory) {
var options = axis.getOptions();
return (0, _tick.tick)(axis, renderer, options.tick, options.grid, skippedCategory, false)
}
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, void 0, false, isFirst ? -1 : 1)
}
function callAction(elements, action, actionArgument1, actionArgument2) {
(elements || []).forEach(function(e) {
return e[action](actionArgument1, actionArgument2)
})
}
function initTickCoords(ticks) {
callAction(ticks, "initCoords")
}
function drawTickMarks(ticks, options) {
callAction(ticks, "drawMark", options)
}
function drawGrids(ticks, drawLine) {
callAction(ticks, "drawGrid", drawLine)
}
function updateTicksPosition(ticks, options, animate) {
callAction(ticks, "updateTickPosition", options, animate)
}
function updateGridsPosition(ticks, animate) {
callAction(ticks, "updateGridPosition", animate)
}
var measureLabels = exports.measureLabels = function(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 (null === ticks[i].coords.x || null === ticks[i].coords.y) {
ticks.splice(i, 1);
return true
}
return false
}
function validateAxisOptions(options) {
var _labelOptions$minSpac;
var labelOptions = options.label;
var position = options.position;
var defaultPosition = options.isHorizontal ? BOTTOM : LEFT;
var secondaryPosition = options.isHorizontal ? TOP : RIGHT;
var labelPosition = labelOptions.position;
if (position !== defaultPosition && position !== secondaryPosition) {
position = defaultPosition
}
if (!labelPosition || "outside" === labelPosition) {
labelPosition = position
} else {
if ("inside" === labelPosition) {
var _TOP$BOTTOM$LEFT$RIGH;
labelPosition = (_TOP$BOTTOM$LEFT$RIGH = {}, _defineProperty(_TOP$BOTTOM$LEFT$RIGH, TOP, BOTTOM), _defineProperty(_TOP$BOTTOM$LEFT$RIGH, BOTTOM, TOP), _defineProperty(_TOP$BOTTOM$LEFT$RIGH, LEFT, RIGHT), _defineProperty(_TOP$BOTTOM$LEFT$RIGH, RIGHT, LEFT), _TOP$BOTTOM$LEFT$RIGH)[position]
}
}
if (labelPosition !== defaultPosition && labelPosition !== secondaryPosition) {
labelPosition = position
}
if (labelOptions.alignment !== CENTER && !labelOptions.userAlignment) {
var _TOP$BOTTOM$LEFT$RIGH2;
labelOptions.alignment = (_TOP$BOTTOM$LEFT$RIGH2 = {}, _defineProperty(_TOP$BOTTOM$LEFT$RIGH2, TOP, CENTER), _defineProperty(_TOP$BOTTOM$LEFT$RIGH2, BOTTOM, CENTER), _defineProperty(_TOP$BOTTOM$LEFT$RIGH2, LEFT, RIGHT), _defineProperty(_TOP$BOTTOM$LEFT$RIGH2, RIGHT, LEFT), _TOP$BOTTOM$LEFT$RIGH2)[labelPosition]
}
options.position = position;
labelOptions.position = labelPosition;
options.hoverMode = options.hoverMode ? options.hoverMode.toLowerCase() : "none";
labelOptions.minSpacing = null !== (_labelOptions$minSpac = labelOptions.minSpacing) && void 0 !== _labelOptions$minSpac ? _labelOptions$minSpac : DEFAULT_AXIS_LABEL_SPACING;
options.type && (options.type = options.type.toLowerCase());
options.argumentType && (options.argumentType = options.argumentType.toLowerCase());
options.valueType && (options.valueType = options.valueType.toLowerCase())
}
function getOptimalAngle(boxes, labelOpt) {
var angle = 180 * _math.asin((boxes[0].height + labelOpt.minSpacing) / (boxes[1].x - boxes[0].x)) / _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.removeLabel()
} else {
if (func) {
func(tick, index)
}
}
}
})
}
function getZoomBoundValue(optionValue, dataValue) {
if (void 0 === optionValue) {
return dataValue
} else {
if (null === optionValue) {
return
} else {
return optionValue
}
}
}
function configureGenerator(options, axisDivisionFactor, viewPort, screenDelta, minTickInterval) {
var tickGeneratorOptions = (0, _extend.extend)({}, options, {
endOnTick: true,
axisDivisionFactor: axisDivisionFactor,
skipCalculationLimits: true,
generateExtraTick: true,
minTickInterval: minTickInterval
});
return function(tickInterval, skipTickGeneration, min, max, breaks) {
return getTickGenerator(tickGeneratorOptions, _common.noop, skipTickGeneration, viewPort.isEmpty(), function(v) {
return v
}, viewPort)({
min: min,
max: max,
categories: viewPort.categories,
isSpacedMargin: viewPort.isSpacedMargin
}, screenDelta, tickInterval, (0, _type.isDefined)(tickInterval), void 0, void 0, void 0, breaks)
}
}
function convertVisualRangeObject(visualRange, optionValue) {
return _utils2.default.convertVisualRangeObject(visualRange, !_isArray(optionValue))
}
function getConstantLineSharpDirection(coord, axisCanvas) {
return Math.max(axisCanvas.start, axisCanvas.end) !== coord ? 1 : -1
}
var calculateCanvasMargins = exports.calculateCanvasMargins = function(bBoxes, canvas) {
var cLeft = canvas.left;
var cTop = canvas.top;
var cRight = canvas.width - canvas.right;
var cBottom = canvas.height - canvas.bottom;
return bBoxes.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
})
};
var Axis = exports.Axis = function(renderSettings) {
var that = this;
that._renderer = renderSettings.renderer;
that._incidentOccurred = renderSettings.incidentOccurred;
that._eventTrigger = renderSettings.eventTrigger;
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;
that._viewport = {};
that._firstDrawing = true;
that._initRange = {}
};
Axis.prototype = {
constructor: Axis,
_drawAxis: function() {
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), this.getAxisSharpDirection()).append(this._axisLineGroup)
},
_createPathElement: function(points, attr, sharpDirection) {
return this.sharp(this._renderer.path(points, "line").attr(attr), sharpDirection)
},
sharp: function(svgElement) {
var sharpDirection = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 1;
return svgElement.sharp(this._getSharpParam(), sharpDirection)
},
customPositionIsAvailable: function() {
return false
},
getOrthogonalAxis: _common.noop,
getCustomPosition: _common.noop,
getCustomBoundaryPosition: _common.noop,
resolveOverlappingForCustomPositioning: _common.noop,
hasCustomPosition: function() {
return false
},
customPositionIsBoundaryOrthogonalAxis: function() {
return false
},
getResolvedBoundaryPosition: function() {
return this.getOptions().position
},
getAxisSharpDirection: function() {
var position = this.getResolvedBoundaryPosition();
return this.hasCustomPosition() || position !== BOTTOM && position !== RIGHT ? 1 : -1
},
getSharpDirectionByCoords: function(coords) {
var canvas = this._getCanvasStartEnd();
var maxCoord = Math.max(canvas.start, canvas.end);
return this.getRadius ? 0 : maxCoord !== coords[this._isHorizontal ? "x" : "y"] ? 1 : -1
},
_getGridLineDrawer: function() {
var that = this;
return function(tick, gridStyle) {
var grid = that._getGridPoints(tick.coords);
if (grid.points) {
return that._createPathElement(grid.points, gridStyle, that.getSharpDirectionByCoords(tick.coords))
}
return null
}
},
_getGridPoints: function(coords) {
var that = this;
var isHorizontal = this._isHorizontal;
var tickPositionField = isHorizontal ? "x" : "y";
var orthogonalPositions = this._orthogonalPositions;
var positionFrom = orthogonalPositions.start;
var positionTo = orthogonalPositions.end;
var borderOptions = that.borderOptions;
var canvasStart = isHorizontal ? LEFT : TOP;
var canvasEnd = isHorizontal ? RIGHT : BOTTOM;
var axisCanvas = that.getCanvas();
var canvas = {
left: axisCanvas.left,
right: axisCanvas.width - axisCanvas.right,
top: axisCanvas.top,
bottom: axisCanvas.height - axisCanvas.bottom
};
var firstBorderLinePosition = borderOptions.visible && borderOptions[canvasStart] ? canvas[canvasStart] : void 0;
var lastBorderLinePosition = borderOptions.visible && borderOptions[canvasEnd] ? canvas[canvasEnd] : void 0;
var minDelta = MAX_GRID_BORDER_ADHENSION + firstBorderLinePosition;
var maxDelta = lastBorderLinePosition - MAX_GRID_BORDER_ADHENSION;
if (that.areCoordsOutsideAxis(coords) || void 0 === coords[tickPositionField] || coords[tickPositionField] < minDelta || coords[tickPositionField] > maxDelta) {
return {
points: null
}
}
return {
points: isHorizontal ? null !== coords[tickPositionField] ? [coords[tickPositionField], positionFrom, coords[tickPositionField], positionTo] : null : null !== coords[tickPositionField] ? [positionFrom, coords[tickPositionField], positionTo, coords[tickPositionField]] : null
}
},
_getConstantLinePos: function(parsedValue, canvasStart, canvasEnd) {
var value = this._getTranslatedCoord(parsedValue);
if (!(0, _type.isDefined)(value) || value < _min(canvasStart, canvasEnd) || value > _max(canvasStart, canvasEnd)) {
return
}
return value
},
_getConstantLineGraphicAttributes: function(value) {
var positionFrom = this._orthogonalPositions.start;
var positionTo = this._orthogonalPositions.end;
return {
points: this._isHorizontal ? [value, positionFrom, value, positionTo] : [positionFrom, value, positionTo, value]
}
},
_createConstantLine: function(value, attr) {
return this._createPathElement(this._getConstantLineGraphicAttributes(value).points, attr, getConstantLineSharpDirection(value, this._getCanvasStartEnd()))
},
_drawConstantLineLabelText: function(text, x, y, _ref2, group) {
var font = _ref2.font,
cssClass = _ref2.cssClass;
return this._renderer.text(text, x, y).css(patchFontOptions((0, _extend.extend)({}, this._options.label.font, font))).attr({
align: "center",
"class": cssClass
}).append(group)
},
_drawConstantLineLabels: function(parsedValue, lineLabelOptions, value, group) {
var _text;
var that = this;
var text = lineLabelOptions.text;
var options = that._options;
var labelOptions = options.label;
that._checkAlignmentConstantLineLabels(lineLabelOptions);
text = null !== (_text = text) && void 0 !== _text ? _text : that.formatLabel(parsedValue, labelOptions);
var coords = that._getConstantLineLabelsCoords(value, lineLabelOptions);
return that._drawConstantLineLabelText(text, coords.x, coords.y, lineLabelOptions, group)
},
_getStripPos: function(startValue, endValue, canvasStart, canvasEnd, range) {
var isContinuous = !!(range.minVisible || range.maxVisible);
var categories = (range.categories || []).reduce(function(result, cat) {
result.push(cat.valueOf());
return result
}, []);
var start;
var end;
var swap;
var startCategoryIndex;
var endCategoryIndex;
if (!isContinuous) {
if ((0, _type.isDefined)(startValue) && (0, _type.isDefined)(endValue)) {
var parsedStartValue = this.parser(startValue);
var parsedEndValue = this.parser(endValue);
startCategoryIndex = (0, _array.inArray)((0, _type.isDefined)(parsedStartValue) ? parsedStartValue.valueOf() : void 0, categories);
endCategoryIndex = (0, _array.inArray)((0, _type.isDefined)(parsedEndValue) ? parsedEndValue.valueOf() : void 0, categories);
if (startCategoryIndex === -1 || endCategoryIndex === -1) {
return {
from: 0,
to: 0,
outOfCanvas: true
}
}
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)
} else {
start = canvasStart
}
if ((0, _type.isDefined)(endValue)) {
endValue = this.validateUnit(endValue, "E2105", "strip");
end = this._getTranslatedCoord(endValue, 1)
} else {
end = canvasEnd
}
var stripPosition = start < end ? {
from: start,
to: end
} : {
from: end,
to: start
};
var visibleArea = this.getVisibleArea();
if (stripPosition.from <= visibleArea[0] && stripPosition.to <= visibleArea[0] || stripPosition.from >= visibleArea[1] && stripPosition.to >= visibleArea[1]) {
stripPosition.outOfCanvas = true
}
return stripPosition
},
_getStripGraphicAttributes: function(fromPoint, toPoint) {
var x;
var y;
var width;
var height;
var orthogonalPositions = this._orthogonalPositions;
var positionFrom = orthogonalPositions.start;
var 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(attrs) {
return this._renderer.rect(attrs.x, attrs.y, attrs.width, attrs.height)
},
_adjustStripLabels: function() {
var that = this;
this._strips.forEach(function(strip) {
if (strip.label) {
strip.label.attr(that._getAdjustedStripLabelCoords(strip))
}
})
},
_adjustLabelsCoord: function(offset, maxWidth, checkCanvas) {
var that = this;
that._majorTicks.forEach(function(tick) {
if (tick.label) {
tick.updateMultilineTextAlignment();
tick.label.attr(that._getLabelAdjustedCoord(tick, offset + (tick.labelOffset || 0), maxWidth, checkCanvas))
}
})
},
_adjustLabels: function(offset) {
var that = this;
var options = that.getOptions();
var positionsAreConsistent = options.position === options.label.position;
var maxSize = that._majorTicks.reduce(function(size, tick) {
if (!tick.label) {
return size
}
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)
}
}, {});
var additionalOffset = positionsAreConsistent ? that._isHorizontal ? maxSize.height : maxSize.width : 0;
that._adjustLabelsCoord(offset, maxSize.width);
return offset + additionalOffset + (additionalOffset && that._options.label.indentFromAxis) + (positionsAreConsistent ? maxSize.offset : 0)
},
_getLabelAdjustedCoord: function(tick, offset, maxWidth) {
offset = offset || 0;
var that = this;
var options = that._options;
var box = _utils2.default.rotateBBox(tick.labelBBox, [tick.labelCoords.x, tick.labelCoords.y], -tick.labelRotationAngle || 0);
var textAlign = tick.labelAlignment || options.label.alignment;
var isDiscrete = "discrete" === that._options.type;
var isFlatLabel = tick.labelRotationAngle % 90 === 0;
var indentFromAxis = options.label.indentFromAxis;
var labelPosition = options.label.position;
var axisPosition = that._axisPosition;
var labelCoords = tick.labelCoords;
var labelX = labelCoords.x;
var translateX;
var translateY;
if (that._isHorizontal) {
if (labelPosition === BOTTOM) {
translateY = axisPosition + indentFromAxis - box.y + offset
} else {
translateY = axisPosition - indentFromAxis - (box.y + box.height) - offset
}
if (textAlign === RIGHT) {
translateX = isDiscrete && isFlatLabel ? tick.coords.x - (box.x + box.width) : labelX - box.x - box.width
} else {
if (textAlign === LEFT) {
translateX = isDiscrete && isFlatLabel ? labelX - box.x - (tick.coords.x - labelX) : labelX - box.x
} else {
translateX = labelX - box.x - box.width / 2
}
}
} else {
translateY = labelCoords.y - box.y - box.height / 2;
if (labelPosition === 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
}
},
_createAxisConstantLineGroups: function() {
var that = this;
var renderer = that._renderer;
var classSelector = that._axisCssPrefix;
var constantLinesClass = classSelector + "constant-lines";
var insideGroup = renderer.g().attr({
"class": constantLinesClass
});
var outsideGroup1 = renderer.g().attr({
"class": constantLinesClass
});
var outsideGroup2 = renderer.g().attr({
"class": constantLinesClass
});
return {
inside: insideGroup,
outside1: outsideGroup1,
left: outsideGroup1,
top: outsideGroup1,
outside2: outsideGroup2,
right: outsideGroup2,
bottom: outsideGroup2,
remove: function() {
this.inside.remove();
this.outside1.remove();
this.outside2.remove()
},
clear: function() {
this.inside.clear();
this.outside1.clear();
this.outside2.clear()
}
}
},
_createAxisGroups: function() {
var that = this;
var renderer = that._renderer;
var classSelector = that._axisCssPrefix;
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);
that._axisConstantLineGroups = {
above: that._createAxisConstantLineGroups(),
under: that._createAxisConstantLineGroups()
};
that._axisStripLabelGroup = renderer.g().attr({
"class": classSelector + "axis-labels"
})
},
_clearAxisGroups: function() {
var that = this;
that._axisGroup.remove();
that._axisStripGroup.remove();
that._axisStripLabelGroup.remove();
that._axisConstantLineGroups.above.remove();
that._axisConstantLineGroups.under.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.above.clear();
that._axisConstantLineGroups.under.clear();
that._axisStripLabelGroup && that._axisStripLabelGroup.clear()
},
_getLabelFormatObject: function(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: null !== tickInterval && void 0 !== tickInterval ? tickInterval : this._tickInterval,
dataType: this._options.dataType,
logarithmBase: this._options.logarithmBase,
type: this._options.type,
showTransition: !this._options.marker.visible,
point: point
}) || "",
min: range.minVisible,
max: range.maxVisible
};
if (point) {
formatObject.point = point
}
return formatObject
},
formatLabel: function(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(value, labelOptions, range) {
var formatObject = this._getLabelFormatObject(value, labelOptions, range);
return (0, _type.isFunction)(labelOptions.customizeHint) ? labelOptions.customizeHint.call(formatObject, formatObject) : void 0
},
formatRange: function(startValue, endValue, interval) {
return (0, _smart_formatter.formatRange)(startValue, endValue, interval, this.getOptions())
},
_setTickOffset: function() {
var options = this._options;
var discreteAxisDivisionMode = options.discreteAxisDivisionMode;
this._tickOffset = +("crossLabels" !== discreteAxisDivisionMode || !discreteAxisDivisionMode)
},
resetApplyingAnimation: function(isFirstDrawing) {
this._resetApplyingAnimation = true;
if (isFirstDrawing) {
this._firstDrawing = true
}
},
getMargins: function() {
var that = this;
if (that.hasCustomPosition()) {
return {
left: 0,
right: 0,
top: 0,
bottom: 0
}
}
var options = that._options;
var position = options.position;
var placeholderSize = options.placeholderSize;
var canvas = that.getCanvas();
var cLeft = canvas.left;
var cTop = canvas.top;
var cRight = canvas.width - canvas.right;
var cBottom = canvas.height - canvas.bottom;
var edgeMarginCorrection = _max(options.grid.visible && options.grid.width || 0, options.tick.visible && options.tick.width || 0);
var constantLineAboveSeries = that._axisConstantLineGroups.above;
var constantLineUnderSeries = that._axisConstantLineGroups.under;
var boxes = [that._axisElementsGroup, constantLineAboveSeries.outside1, constantLineAboveSeries.outside2, constantLineUnderSeries.outside1, constantLineUnderSeries.outside2, that._axisLineGroup].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));
var margins = calculateCanvasMargins(boxes, canvas);
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(unit, idError, parameters) {
var that = this;
unit = that.parser(unit);
if (void 0 === unit && idError) {
that._incidentOccurred(idError, [parameters])
}
return unit
},
_setType: function(axisType, drawingType) {
var that = this;
var axisTypeMethods;
switch (axisType) {
case "xyAxes":
axisTypeMethods = _xy_axes2.default;
break;
case "polarAxes":
axisTypeMethods = _polar_axes2.default
}(0, _extend.extend)(that, axisTypeMethods[drawingType])
},
_getSharpParam: function() {
return true
},
_disposeBreaksGroup: _common.noop,
dispose: function() {
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() {
return this._options
},
setPane: function(pane) {
this.pane = pane;
this._options.pane = pane
},
setTypes: function(type, axisType, typeSelector) {
this._options.type = type || this._options.type;
this._options[typeSelector] = axisType || this._options[typeSelector];
this._updateTranslator()
},
resetTypes: function(typeSelector) {
this._options.type = this._initTypes.type;
this._options[typeSelector] = this._initTypes[typeSelector]
},
getTranslator: function() {
return this._translator
},
updateOptions: function(options) {
var that = this;
var labelOpt = options.label;
validateAxisOptions(options);
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
};
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",
"class": labelOpt.cssClass
};
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();
that._createConstantLines();
that._strips = (options.strips || []).map(function(o) {
return (0, _strip2.default)(that, o)
});
that._majorTicks = that._minorTicks = null;
that._firstDrawing = true
},
calculateInterval: function(value, prevValue) {
var options = this._options;
if (!options || options.type !== _axes_constants2.default.logarithmic) {
return _abs(value - prevValue)
}
var _Range = new _range.Range(this.getTranslator().getBusinessRange()),
allowNegatives = _Range.allowNegatives,
linearThreshold = _Range.linearThreshold;
return _abs(getLog(value, options.logarithmBase, allowNegatives, linearThreshold) - getLog(prevValue, options.logarithmBase, allowNegatives, linearThreshold))
},
getCanvasRange: function() {
var translator = this._translator;
return {
startValue: translator.from(translator.translate("canvas_position_start")),
endValue: translator.from(translator.translate("canvas_position_end"))
}
},
_processCanvas: function(canvas) {
return canvas
},
updateCanvas: function(canvas, canvasRedesign) {
if (!canvasRedesign) {
var positions = this._orthogonalPositions = {
start: !this._isHorizontal ? canvas.left : canvas.top,
end: !this._isHorizontal ? canvas.width - canvas.right : canvas.height - canvas.bottom
};
positions.center = positions.start + (positions.end - positions.start) / 2
} else {
this._orthogonalPositions = null
}
this._canvas = canvas;
this._translator.updateCanvas(this._processCanvas(canvas));
this._initAxisPositions()
},
getCanvas: function() {
return this._canvas
},
getAxisShift: function() {
return this._axisShift || 0
},
hideTitle: function() {
var that = this;
if (that._options.title.text) {
that._incidentOccurred("W2105", [that._isHorizontal ? "horizontal" : "vertical"]);
that._axisTitleGroup.clear()
}
},
getTitle: function() {
return this._title
},
hideOuterElements: function() {
var that = this;
var options = that._options;
if ((options.label.visible || that._outsideConstantLines.length) && !that._translator.getBusinessRange().isEmpty()) {
that._incidentOccurred("W2106", [that._isHorizontal ? "horizontal" : "vertical"]);
that._axisElementsGroup.clear();
callAction(that._outsideConstantLines, "removeLabel")
}
},
adjustViewport: function(businessRange) {
var that = this;
var options = that._options;
var isDiscrete = options.type === _axes_constants2.default.discrete;
var categories = that._seriesData && that._seriesData.categories || [];
var wholeRange = that.adjustRange(getVizRangeObject(options.wholeRange));
var visualRange = that.getViewport() || {};
var result = new _range.Range(businessRange);
that._addConstantLinesToRange(result, "minVisible", "maxVisible");
var minDefined = (0, _type.isDefined)(visualRange.startValue);
var maxDefined = (0, _type.isDefined)(visualRange.endValue);
if (!isDiscrete) {
minDefined = minDefined && (!(0, _type.isDefined)(wholeRange.endValue) || visualRange.startValue < wholeRange.endValue);
maxDefined = maxDefined && (!(0, _type.isDefined)(wholeRange.startValue) || visualRange.endValue > wholeRange.startValue)
}
var minVisible = minDefined ? visualRange.startValue : result.minVisible;
var maxVisible = maxDefined ? visualRange.endValue : result.maxVisible;
if (!isDiscrete) {
var _wholeRange$startValu, _wholeRange$endValue;
result.min = null !== (_wholeRange$startValu = wholeRange.startValue) && void 0 !== _wholeRange$startValu ? _wholeRange$startValu : result.min;
result.max = null !== (_wholeRange$endValue = wholeRange.endValue) && void 0 !== _wholeRange$endValue ? _wholeRange$endValue : result.max
} else {
var categoriesInfo = _utils2.default.getCategoriesInfo(categories, wholeRange.startValue, wholeRange.endValue);
categories = categoriesInfo.categories;
result.categories = categories
}
var adjustedVisualRange = _utils2.default.adjustVisualRange({
axisType: options.type,
dataType: options.dataType,
base: options.logarithmBase
}, {
startValue: minDefined ? visualRange.startValue : void 0,
endValue: maxDefined ? visualRange.endValue : void 0,
length: visualRange.length
}, {
categories: categories,
min: wholeRange.startValue,
max: wholeRange.endValue
}, {
categories: categories,
min: minVisible,
max: maxVisible
});
result.minVisible = adjustedVisualRange.startValue;
result.maxVisible = adjustedVisualRange.endValue;
!(0, _type.isDefined)(result.min) && (result.min = result.minVisible);
!(0, _type.isDefined)(result.max) && (result.max = result.maxVisible);
result.addRange({});
return result
},
adjustRange: function(range) {
range = range || {};
var isDiscrete = this._options.type === _axes_constants2.default.discrete;
var isLogarithmic = this._options.type === _axes_constants2.default.logarithmic;
var disabledNegatives = false === this._options.allowNegatives;
if (isLogarithmic) {
range.startValue = disabledNegatives && range.startValue <= 0 ? null : range.startValue;
range.endValue = disabledNegatives && range.endValue <= 0 ? null : range.endValue
}
if (!isDiscrete && (0, _type.isDefined)(range.startValue) && (0, _type.isDefined)(range.endValue) && range.startValue > range.endValue) {
var tmp = range.endValue;
range.endValue = range.startValue;
range.startValue = tmp
}
return range
},
_getVisualRangeUpdateMode: function(viewport, newRange, oppositeValue) {
var value = this._options.visualRangeUpdateMode;
var translator = this._translator;
var range = this._seriesData;
if (this.isArgumentAxis) {
if ([SHIFT, KEEP, RESET].indexOf(value) === -1) {
if (range.axisType === _axes_constants2.default.discrete) {
var categories = range.categories;
var newCategories = newRange.categories;
var visualRange = this.visualRange();
if (categories && newCategories && categories.length && newCategories.map(function(c) {
return c.valueOf()
}).join(",").indexOf(categories.map(function(c) {
return c.valueOf()
}).join(",")) !== -1 && (visualRange.startValue.valueOf() !== categories[0].valueOf() || visualRange.endValue.valueOf() !== categories[categories.length - 1].valueOf())) {
value = KEEP
} else {
value = RESET
}
} else {
var minPoint = translator.translate(range.min);
var minVisiblePoint = translator.translate(viewport.startValue);
var maxPoint = translator.translate(range.max);
var maxVisiblePoint = translator.translate(viewport.endValue);
if (minPoint === minVisiblePoint && maxPoint === maxVisiblePoint) {
value = RESET
} else {
if (minPoint !== minVisiblePoint && maxPoint === maxVisiblePoint) {
value = SHIFT
} else {
value = KEEP
}
}
}
}
} else {
if ([KEEP, RESET].indexOf(value) === -1) {
if (oppositeValue === KEEP) {
value = KEEP
} else {
value = RESET
}
}
}
return value
},
_handleBusinessRangeChanged: function(oppositeVisualRangeUpdateMode, axisReinitialized, newRange) {
var that = this;
var visualRange = this.visualRange();
if (axisReinitialized || that._translator.getBusinessRange().isEmpty()) {
return
}
var visualRangeUpdateMode = that._lastVisualRangeUpdateMode = that._getVisualRangeUpdateMode(visualRange, newRange, oppositeVisualRangeUpdateMode);
if (!that.isArgumentAxis) {
var viewport = that.getViewport();
if (!(0, _type.isDefined)(viewport.startValue) && !(0, _type.isDefined)(viewport.endValue) && !(0, _type.isDefined)(viewport.length)) {
visualRangeUpdateMode = RESET
}
}
that._prevDataWasEmpty && (visualRangeUpdateMode = KEEP);
if (visualRangeUpdateMode === KEEP) {
that._setVisualRange([visualRange.startValue, visualRange.endValue])
}
if (visualRangeUpdateMode === RESET) {
that._setVisualRange([null, null])
}
if (visualRangeUpdateMode === SHIFT) {
that._setVisualRange({
length: that.getVisualRangeLength()
})
}
},
getVisualRangeLength: function(range) {
var currentBusinessRange = range || this._translator.getBusinessRange();
var type = this._options.type;
var length;
if (type === _axes_constants2.default.logarithmic) {
length = (0, _math2.adjust)(this.calculateInterval(currentBusinessRange.maxVisible, currentBusinessRange.minVisible))
} else {
if (type === _axes_constants2.default.discrete) {
var categoriesInfo = _utils2.default.getCategoriesInfo(currentBusinessRange.categories, currentBusinessRange.minVisible, currentBusinessRange.maxVisible);
length = categoriesInfo.categories.length
} else {
length = currentBusinessRange.maxVisible - currentBusinessRange.minVisible
}
}
return length
},
getVisualRangeCenter: function(range) {
var businessRange = this._translator.getBusinessRange();
var currentBusinessRange = range || businessRange;
var _this$_options = this._options,
type = _this$_options.type,
logarithmBase = _this$_options.logarithmBase;
var center;
if (!(0, _type.isDefined)(currentBusinessRange.minVisible) || !(0, _type.isDefined)(currentBusinessRange.maxVisible)) {
return
}
if (type === _axes_constants2.default.logarithmic) {
var allowNegatives = currentBusinessRange.allowNegatives,
linearThreshold = currentBusinessRange.linearThreshold,
minVisible = currentBusinessRange.minVisible,
maxVisible = currentBusinessRange.maxVisible;
center = raiseTo((0, _math2.adjust)(getLog(maxVisible, logarithmBase, allowNegatives, linearThreshold) + getLog(minVisible, logarithmBase, allowNegatives, linearThreshold)) / 2, logarithmBase, allowNegatives, linearThreshold)
} else {
if (type === _axes_constants2.default.discrete) {
var categoriesInfo = _utils2.default.getCategoriesInfo(currentBusinessRange.categories, currentBusinessRange.minVisible, currentBusinessRange.maxVisible);
var index = Math.ceil(categoriesInfo.categories.le