UNPKG

@syncfusion/ej2-charts

Version:

Feature-rich chart control with built-in support for over 25 chart types, technical indictors, trendline, zooming, tooltip, selection, crosshair and trackball.

177 lines (176 loc) 7.49 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { Double } from '../axis/double-axis'; import { getActualDesiredIntervalsCount, triggerLabelRender } from '../../common/utils/helper'; import { logBase, withIn } from '../../common/utils/helper'; import { extend, getValue, isNullOrUndefined } from '@syncfusion/ej2-base'; /** * The `Logarithmic` module is used to render the logarithmic axis in charts. */ var Logarithmic = /** @class */ (function (_super) { __extends(Logarithmic, _super); /** * Constructor for the logerithmic module. * * @private * @param {Chart} chart - Specifies the chart. */ function Logarithmic(chart) { return _super.call(this, chart) || this; } /** * The method to calculate the range and labels for the axis. * * @returns {void} * @private */ Logarithmic.prototype.calculateRangeAndInterval = function (size, axis) { this.calculateRange(axis); this.getActualRange(axis, size); this.calculateVisibleRange(size, axis); this.calculateVisibleLabels(axis, this.chart); }; /** * Calculates actual range for the axis. * * @private */ Logarithmic.prototype.getActualRange = function (axis, size) { this.initializeDoubleRange(axis); this.min = this.min < 0 ? 0 : this.min; var logStart = logBase(this.min, axis.logBase); logStart = isFinite(logStart) ? logStart : this.min; var logEnd = this.max === 1 ? 1 : logBase(this.max, axis.logBase); logEnd = isFinite(logStart) ? logEnd : this.max; this.min = Math.floor(logStart / 1); var isRectSeries = axis.series && axis.series.some(function (item) { return (item.type.indexOf('Column') !== -1 || item.type.indexOf('Bar') !== -1) && item.type.indexOf('Range') === -1; }); if (isRectSeries) { this.min = (this.min <= 0) ? (+this.min - 1) : this.min; } this.max = Math.ceil(logEnd / 1); this.max = this.max === this.min ? this.max + 1 : this.max; axis.actualRange.interval = axis.interval || this.calculateLogNiceInterval(this.max - this.min, size, axis); axis.actualRange.min = this.min; axis.actualRange.max = this.max; axis.actualRange.delta = this.max - this.min; }; /** * Calculates visible range for the axis. * * @private * @param {Size} size - The size used for calculation. * @param {Axis} axis - The axis for which the visible range is calculated. * @returns {void} */ Logarithmic.prototype.calculateVisibleRange = function (size, axis) { axis.visibleRange = { interval: axis.actualRange.interval, max: axis.actualRange.max, min: axis.actualRange.min, delta: axis.actualRange.delta }; var isLazyLoad = isNullOrUndefined(axis.zoomingScrollBar) ? false : axis.zoomingScrollBar.isLazyLoad; if ((axis.zoomFactor < 1 || axis.zoomPosition > 0) && !isLazyLoad) { axis.calculateVisibleRangeOnZooming(); axis.visibleRange.interval = (axis.enableAutoIntervalOnZooming) ? this.calculateLogNiceInterval(axis.doubleRange.delta, size, axis) : axis.visibleRange.interval; axis.visibleRange.interval = Math.floor(axis.visibleRange.interval) === 0 ? 1 : Math.floor(axis.visibleRange.interval); axis.triggerRangeRender(this.chart, axis.visibleRange.min, axis.visibleRange.max, axis.visibleRange.interval); } }; /** * Calculates log inteval for the axis. * * @private * @param {number} delta - The difference between the axis maximum and minimum values. * @param {Size} size - The size of the axis. * @param {Axis} axis - The axis. * @returns {number} - The calculated logarithmic interval. */ Logarithmic.prototype.calculateLogNiceInterval = function (delta, size, axis) { var actualDesiredIntervalsCount = getActualDesiredIntervalsCount(size, axis); var niceInterval = delta; var minInterval = Math.pow(axis.logBase, Math.floor(logBase(niceInterval, 10))); axis.intervalDivs = niceInterval >= 10 ? [10, 5, 2, 1, 0.5, 0.2] : axis.intervalDivs; for (var j = 0, len = axis.intervalDivs.length; j < len; j++) { var currentInterval = minInterval * axis.intervalDivs[j]; if (actualDesiredIntervalsCount < (delta / currentInterval)) { break; } niceInterval = currentInterval; } return niceInterval; }; /** * Calculates labels for the axis. * * @private * @param {Axis} axis - The axis. * @param {Chart | RangeNavigator} chart - The chart or range navigator control. * @returns {void} */ Logarithmic.prototype.calculateVisibleLabels = function (axis, chart) { /** Generate axis labels */ var tempInterval = axis.visibleRange.min; axis.visibleLabels = []; var labelStyle; var value; if (axis.zoomFactor < 1 || axis.zoomPosition > 0) { tempInterval = axis.visibleRange.min - (axis.visibleRange.min % axis.visibleRange.interval); } var axisFormat = this.getFormat(axis); var isCustomFormat = axisFormat.match('{value}') !== null; var startValue = Math.pow(axis.logBase, axis.visibleRange.min); axis.format = chart.intl.getNumberFormat({ format: isCustomFormat ? '' : axisFormat, useGrouping: chart.useGroupingSeparator, maximumFractionDigits: startValue < 1 ? 20 : 3 }); axis.startLabel = axis.format(startValue < 1 ? +startValue.toPrecision(1) : startValue); axis.endLabel = axis.format(Math.pow(axis.logBase, axis.visibleRange.max)); for (; tempInterval <= axis.visibleRange.max; tempInterval += axis.visibleRange.interval) { labelStyle = (extend({}, getValue('properties', axis.labelStyle), null, true)); if (withIn(tempInterval, axis.visibleRange)) { value = Math.pow(axis.logBase, tempInterval); triggerLabelRender(this.chart, tempInterval, this.formatValue(axis, isCustomFormat, axisFormat, value < 1 ? +value.toPrecision(1) : value), labelStyle, axis); } } if (axis.getMaxLabelWidth) { axis.getMaxLabelWidth(this.chart); } }; /** * Get module name */ Logarithmic.prototype.getModuleName = function () { /** * Returns the module name */ return 'Logarithmic'; }; /** * To destroy the category axis. * * @returns {void} * @private */ Logarithmic.prototype.destroy = function () { /** * Destroy method performed here */ }; return Logarithmic; }(Double)); export { Logarithmic };