UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

1,063 lines (1,030 loc) • 46.3 kB
/** * DevExtreme (cjs/__internal/viz/range_selector/range_selector.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _component_registrator = require("../../core/component_registrator"); var _format_helper = _interopRequireDefault(require("../../core/format_helper")); var _m_date = require("../../core/utils/m_date"); var _m_extend = require("../../core/utils/m_extend"); var _m_iterator = require("../../core/utils/m_iterator"); var _m_math = require("../../core/utils/m_math"); var _m_type = require("../../core/utils/m_type"); var _axes_constants = _interopRequireDefault(require("../../viz/axes/axes_constants")); var _base_axis = require("../../viz/axes/base_axis"); var _tick_generator = require("../../viz/axes/tick_generator"); var _parse_utils = require("../../viz/components/parse_utils"); var _base_widget = _interopRequireDefault(require("../../viz/core/base_widget")); var _data_source = require("../../viz/core/data_source"); var _export = require("../../viz/core/export"); var _helpers = require("../../viz/core/helpers"); var _loading_indicator = require("../../viz/core/loading_indicator"); var _title = require("../../viz/core/title"); var _utils = require("../../viz/core/utils"); var _common = require("../../viz/range_selector/common"); var _range_view = require("../../viz/range_selector/range_view"); var _series_data_source = require("../../viz/range_selector/series_data_source"); var _sliders_controller = require("../../viz/range_selector/sliders_controller"); var _tracker = require("../../viz/range_selector/tracker"); var _range = require("../../viz/translators/range"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const START_VALUE = "startValue"; const END_VALUE = "endValue"; const DATETIME = "datetime"; const VALUE = "value"; const DISCRETE = "discrete"; const SEMIDISCRETE = "semidiscrete"; const STRING = "string"; const VALUE_CHANGED = `${VALUE}Changed`; const CONTAINER_BACKGROUND_COLOR = "containerBackgroundColor"; const SLIDER_MARKER = "sliderMarker"; const OPTION_BACKGROUND = "background"; const LOGARITHMIC = "logarithmic"; const KEEP = "keep"; const SHIFT = "shift"; const RESET = "reset"; const INVISIBLE_POS = -1e3; const SEMIDISCRETE_GRID_SPACING_FACTOR = 50; const DEFAULT_AXIS_DIVISION_FACTOR = 30; const DEFAULT_MINOR_AXIS_DIVISION_FACTOR = 15; const DEFAULT_LOGARITHM_BASE = 10; function getTextBBox(renderer, text, fontOptions) { const textElement = renderer.text(text, -1e3, -1e3).css((0, _utils.patchFontOptions)(fontOptions)).append(renderer.root); const textBBox = textElement.getBBox(); textElement.remove(); return textBBox } function calculateMarkerHeight(renderer, value, sliderMarkerOptions) { const formattedText = void 0 === value ? _common.consts.emptySliderMarkerText : (0, _common.formatValue)(value, sliderMarkerOptions); const textBBox = getTextBBox(renderer, formattedText, sliderMarkerOptions.font); return Math.ceil(textBBox.height) + 2 * sliderMarkerOptions.paddingTopBottom + _common.consts.pointerSize } function calculateScaleLabelHalfWidth(renderer, value, scaleOptions, tickIntervalsInfo) { const formattedText = (0, _common.formatValue)(value, scaleOptions.label, tickIntervalsInfo, scaleOptions.valueType, scaleOptions.type, scaleOptions.logarithmBase); const textBBox = getTextBBox(renderer, formattedText, scaleOptions.label.font); return Math.ceil(textBBox.width / 2) } function calculateIndents(renderer, scale, sliderMarkerOptions, indentOptions, tickIntervalsInfo) { let leftScaleLabelWidth = 0; let rightScaleLabelWidth = 0; const ticks = "semidiscrete" === scale.type ? scale.customTicks : tickIntervalsInfo.ticks; const indents = indentOptions || {}; const placeholderWidthLeftOption = indents.left; const placeholderWidthRightOption = indents.right; let { placeholderHeight: placeholderHeight } = sliderMarkerOptions; if (sliderMarkerOptions.visible) { const leftMarkerHeight = calculateMarkerHeight(renderer, scale.startValue, sliderMarkerOptions); const rightMarkerHeight = calculateMarkerHeight(renderer, scale.endValue, sliderMarkerOptions); if (void 0 === placeholderHeight) { placeholderHeight = Math.max(leftMarkerHeight, rightMarkerHeight) } } if (scale.label.visible) { const startTickValue = (0, _m_type.isDefined)(scale.startValue) ? ticks[0] : void 0; const endTickValue = (0, _m_type.isDefined)(scale.endValue) ? ticks[ticks.length - 1] : void 0; leftScaleLabelWidth = calculateScaleLabelHalfWidth(renderer, startTickValue, scale, tickIntervalsInfo); rightScaleLabelWidth = calculateScaleLabelHalfWidth(renderer, endTickValue, scale, tickIntervalsInfo) } const placeholderWidthLeft = void 0 !== placeholderWidthLeftOption ? placeholderWidthLeftOption : leftScaleLabelWidth; const placeholderWidthRight = (void 0 !== placeholderWidthRightOption ? placeholderWidthRightOption : rightScaleLabelWidth) || 1; return { left: placeholderWidthLeft, right: placeholderWidthRight, top: placeholderHeight || 0, bottom: 0 } } function calculateValueType(firstValue, secondValue) { const typeFirstValue = (0, _m_type.type)(firstValue); const typeSecondValue = (0, _m_type.type)(secondValue); const validType = type => typeFirstValue === type || typeSecondValue === type; if (validType("date")) { return DATETIME } if (validType("number")) { return "numeric" } return validType(STRING) ? STRING : "" } function showScaleMarkers(scaleOptions) { return Boolean(scaleOptions.valueType === DATETIME && scaleOptions.marker.visible) } function updateTranslatorRangeInterval(translatorRange, scaleOptions) { let intervalX = scaleOptions.minorTickInterval || scaleOptions.tickInterval; if ("datetime" === scaleOptions.valueType) { intervalX = _m_date.dateUtils.dateToMilliseconds(intervalX) } translatorRange.addRange({ interval: intervalX }) } function checkLogarithmicOptions(options, defaultLogarithmBase, incidentOccurred) { if (!options) { return } const base = options.logarithmBase; if (options.type === LOGARITHMIC && base <= 0 || base && !(0, _m_type.isNumeric)(base)) { options.logarithmBase = defaultLogarithmBase; incidentOccurred("E2104") } else if (options.type !== LOGARITHMIC) { options.logarithmBase = void 0 } } function calculateScaleAreaHeight(renderer, scaleOptions, visibleMarkers, tickIntervalsInfo) { const labelScaleOptions = scaleOptions.label; const markerScaleOptions = scaleOptions.marker; const { placeholderHeight: placeholderHeight } = scaleOptions; const ticks = "semidiscrete" === scaleOptions.type ? scaleOptions.customTicks : tickIntervalsInfo.ticks; const text = (0, _common.formatValue)(ticks[0], labelScaleOptions); if (placeholderHeight) { return Number(placeholderHeight) } const labelHeight = labelScaleOptions.visible ? labelScaleOptions.topIndent + getTextBBox(renderer, text, labelScaleOptions.font).height : 0; const markerHeight = visibleMarkers ? markerScaleOptions.topIndent + markerScaleOptions.separatorHeight : 0; return labelHeight + markerHeight } function getMinorTickIntervalUnit(tickInterval, minorTickInterval, withCorrection) { let interval = _m_date.dateUtils.getDateUnitInterval(minorTickInterval); const majorUnit = _m_date.dateUtils.getDateUnitInterval(tickInterval); const idx = _m_date.dateUtils.dateUnitIntervals.indexOf(interval); if (withCorrection && interval === majorUnit && idx > 0) { interval = _m_date.dateUtils.dateUnitIntervals[idx - 1] } return interval } function getNextTickInterval(tickInterval, minorTickInterval, isDateType) { if (!tickInterval) { return minorTickInterval } if (isDateType) { return _m_date.dateUtils.getNextDateUnit(tickInterval, void 0) } return tickInterval + minorTickInterval } function calculateTickIntervalsForSemidiscreteScale(scaleOptions, min, max, screenDelta) { const { minorTickInterval: minorTickInterval } = scaleOptions; let { tickInterval: tickInterval } = scaleOptions; const isDateType = "datetime" === scaleOptions.valueType; const gridSpacingFactor = scaleOptions.axisDivisionFactor || {}; if (!tickInterval) { let interval = getNextTickInterval(tickInterval, minorTickInterval, isDateType); do { if (tickInterval !== interval) { tickInterval = interval } else { break } if (isDateType) { interval = _m_date.dateUtils.dateToMilliseconds(tickInterval) } const tickCountByInterval = Math.ceil((max - min) / interval); const factor = gridSpacingFactor[tickInterval] || 50; const tickCountByScreen = Math.floor(screenDelta / factor) || 1; if (!(tickCountByInterval > tickCountByScreen)) { break } interval = getNextTickInterval(tickInterval, minorTickInterval, isDateType) } while (interval) } return { tickInterval: tickInterval, minorTickInterval: minorTickInterval, bounds: { minVisible: min, maxVisible: max }, ticks: [] } } function updateTickIntervals(scaleOptions, screenDelta, incidentOccurred, range) { const min = (0, _m_type.isDefined)(range.minVisible) ? range.minVisible : range.min; const max = (0, _m_type.isDefined)(range.maxVisible) ? range.maxVisible : range.max; const categoriesInfo = scaleOptions._categoriesInfo; if (scaleOptions.type === SEMIDISCRETE) { return calculateTickIntervalsForSemidiscreteScale(scaleOptions, min, max, screenDelta) } const ticksInfo = (0, _tick_generator.tickGenerator)({ axisType: scaleOptions.type, dataType: scaleOptions.valueType, logBase: scaleOptions.logarithmBase, allowNegatives: true, linearThreshold: Math.abs(scaleOptions.linearThreshold || 0), axisDivisionFactor: scaleOptions.axisDivisionFactor, minorAxisDivisionFactor: scaleOptions.minorAxisDivisionFactor, calculateMinors: true, allowDecimals: scaleOptions.allowDecimals, endOnTick: scaleOptions.endOnTick, incidentOccurred: incidentOccurred, rangeIsEmpty: range.isEmpty() })({ min: min, max: max, categories: (0, _m_type.isDefined)(categoriesInfo) ? categoriesInfo.categories : [] }, screenDelta, scaleOptions.tickInterval, scaleOptions.forceUserTickInterval, void 0, scaleOptions.minorTickInterval, scaleOptions.minorTickCount); const { length: length } = ticksInfo.ticks; const bounds = { minVisible: ticksInfo.ticks[0] < min ? ticksInfo.ticks[0] : min, maxVisible: ticksInfo.ticks[length - 1] > max ? ticksInfo.ticks[length - 1] : max }; return { tickInterval: ticksInfo.tickInterval, minorTickInterval: 0 === scaleOptions.minorTickInterval ? 0 : ticksInfo.minorTickInterval, bounds: bounds, ticks: ticksInfo.ticks } } function getFirstDayOfWeek(options) { var _options$workWeek; return null === (_options$workWeek = options.workWeek) || void 0 === _options$workWeek ? void 0 : _options$workWeek[0] } function correctValueByInterval(value, isDateValue, interval, firstDayOfWeek) { if (!(0, _m_type.isDefined)(value)) { return value } return isDateValue ? _m_date.dateUtils.correctDateWithUnitBeginning(new Date(value), interval, null, firstDayOfWeek) : (0, _m_math.adjust)(Math.floor((0, _m_math.adjust)(value / interval)) * interval) } function buildDiscreteRange(translatorRange, seriesDataSource, scaleOptions, startValue, endValue) { const rangeForCategories = new _range.Range({ minVisible: startValue, maxVisible: endValue }); rangeForCategories.addRange(translatorRange); const ownCategories = seriesDataSource ? seriesDataSource.argCategories : scaleOptions.categories || startValue && endValue && [startValue, endValue]; const categories = ownCategories || []; return { range: rangeForCategories, categories: categories, categoriesInfo: (0, _utils.getCategoriesInfo)(categories, startValue, endValue) } } function calculateRangeBounds(startValue, endValue, categoriesInfo) { if ((0, _m_type.isDefined)(startValue) && (0, _m_type.isDefined)(endValue)) { const inverted = categoriesInfo ? categoriesInfo.inverted : startValue > endValue; if (categoriesInfo) { return { inverted: inverted, minValue: categoriesInfo.start, maxValue: categoriesInfo.end } } return { inverted: inverted, minValue: inverted ? endValue : startValue, maxValue: inverted ? startValue : endValue } } if ((0, _m_type.isDefined)(startValue) || (0, _m_type.isDefined)(endValue)) { return { inverted: false, minValue: startValue, maxValue: endValue } } if (categoriesInfo) { return { inverted: false, minValue: categoriesInfo.start, maxValue: categoriesInfo.end } } return { inverted: false, minValue: void 0, maxValue: void 0 } } function calculateTranslatorRange(seriesDataSource, scaleOptions) { let { startValue: startValue, endValue: endValue } = scaleOptions; let translatorRange = seriesDataSource ? seriesDataSource.getBoundRange().arg : new _range.Range; const isDateValue = "datetime" === scaleOptions.valueType; const firstDayOfWeek = getFirstDayOfWeek(scaleOptions); const { minRange: minRange } = scaleOptions; const discreteRange = scaleOptions.type === DISCRETE ? buildDiscreteRange(translatorRange, seriesDataSource, scaleOptions, startValue, endValue) : void 0; const categories = null === discreteRange || void 0 === discreteRange ? void 0 : discreteRange.categories; const categoriesInfo = null === discreteRange || void 0 === discreteRange ? void 0 : discreteRange.categoriesInfo; if (discreteRange) { translatorRange = discreteRange.range; scaleOptions._categoriesInfo = categoriesInfo } if (scaleOptions.type === SEMIDISCRETE) { startValue = correctValueByInterval(scaleOptions.startValue, isDateValue, minRange, firstDayOfWeek); scaleOptions.startValue = startValue; endValue = correctValueByInterval(scaleOptions.endValue, isDateValue, minRange, firstDayOfWeek); scaleOptions.endValue = endValue; translatorRange.minVisible = correctValueByInterval(translatorRange.minVisible, isDateValue, minRange, firstDayOfWeek); translatorRange.maxVisible = correctValueByInterval(translatorRange.maxVisible, isDateValue, minRange, firstDayOfWeek); translatorRange.min = correctValueByInterval(translatorRange.min, isDateValue, minRange, firstDayOfWeek); translatorRange.max = correctValueByInterval(translatorRange.max, isDateValue, minRange, firstDayOfWeek) } const { inverted: inverted, minValue: minValue, maxValue: maxValue } = calculateRangeBounds(startValue, endValue, categoriesInfo); translatorRange.addRange({ invert: inverted, min: minValue, max: maxValue, minVisible: minValue, maxVisible: maxValue, dataType: scaleOptions.valueType }); translatorRange.addRange({ categories: !seriesDataSource ? categories : void 0, base: scaleOptions.logarithmBase, axisType: scaleOptions.type, dataType: scaleOptions.valueType }); if (seriesDataSource) { translatorRange.sortCategories(categories) } return translatorRange } function startEndNotDefined(start, end) { return !(0, _m_type.isDefined)(start) || !(0, _m_type.isDefined)(end) } function getDateMarkerVisibilityChecker(screenDelta) { return function(isDateScale, isMarkerVisible, min, max, tickInterval) { if (isMarkerVisible && isDateScale) { const yearsCount = Math.ceil((max - min) / _m_date.dateUtils.dateToMilliseconds("year")) + 1; if (!(0, _m_type.isDefined)(tickInterval) || tickInterval.years || tickInterval.months >= 6 || screenDelta / 50 < yearsCount) { return false } } return isMarkerVisible } } function getIntervalCustomTicks(options) { let min = options.startValue; let max = options.endValue; const isDateValue = "datetime" === options.valueType; const firstDayOfWeek = getFirstDayOfWeek(options); const { tickInterval: tickInterval } = options; const res = { intervals: [] }; if (!(0, _m_type.isDefined)(min) || !(0, _m_type.isDefined)(max)) { return res } res.intervals = _m_date.dateUtils.getSequenceByInterval(min, max, options.minorTickInterval); if (tickInterval !== options.minorTickInterval) { res.altIntervals = res.intervals; min = correctValueByInterval(min, isDateValue, tickInterval, firstDayOfWeek); max = correctValueByInterval(max, isDateValue, tickInterval, firstDayOfWeek); res.intervals = _m_date.dateUtils.getSequenceByInterval(min, max, tickInterval); const [firstAltInterval] = res.altIntervals; res.intervals[0] = firstAltInterval } return res } function updateScaleOptions(scaleOptions, seriesDataSource, translatorRange, tickIntervalsInfo, checkDateMarkerVisibility) { let isEmptyInterval = false; const categoriesInfo = scaleOptions._categoriesInfo; const isDateTime = scaleOptions.valueType === DATETIME; if (seriesDataSource && !seriesDataSource.isEmpty() && !translatorRange.isEmpty()) { const { bounds: bounds } = tickIntervalsInfo; translatorRange.addRange(bounds); scaleOptions.startValue = translatorRange.invert ? bounds.maxVisible : bounds.minVisible; scaleOptions.endValue = translatorRange.invert ? bounds.minVisible : bounds.maxVisible } scaleOptions.marker.visible = checkDateMarkerVisibility(isDateTime && -1 === scaleOptions.type.indexOf(DISCRETE), scaleOptions.marker.visible, scaleOptions.startValue, scaleOptions.endValue, tickIntervalsInfo.tickInterval); if (categoriesInfo) { scaleOptions.startValue = categoriesInfo.start; scaleOptions.endValue = categoriesInfo.end } if (-1 === scaleOptions.type.indexOf(DISCRETE)) { isEmptyInterval = (0, _m_type.isDate)(scaleOptions.startValue) && (0, _m_type.isDate)(scaleOptions.endValue) && scaleOptions.startValue.getTime() === scaleOptions.endValue.getTime() || scaleOptions.startValue === scaleOptions.endValue } scaleOptions.isEmpty = startEndNotDefined(scaleOptions.startValue, scaleOptions.endValue) || isEmptyInterval; if (scaleOptions.isEmpty) { scaleOptions.startValue = void 0; scaleOptions.endValue = void 0 } else { scaleOptions.minorTickInterval = tickIntervalsInfo.minorTickInterval; scaleOptions.tickInterval = tickIntervalsInfo.tickInterval; const needsFormat = !(0, _m_type.isDefined)(scaleOptions.label.format) || scaleOptions.type === SEMIDISCRETE && scaleOptions.minorTickInterval !== scaleOptions.tickInterval; if (isDateTime && needsFormat) { if (scaleOptions.type === DISCRETE) { scaleOptions.label.format = _format_helper.default.getDateFormatByTicks(tickIntervalsInfo.ticks) } else if (!scaleOptions.marker.visible) { scaleOptions.label.format = _format_helper.default.getDateFormatByTickInterval(scaleOptions.startValue, scaleOptions.endValue, scaleOptions.tickInterval) } else { scaleOptions.label.format = _m_date.dateUtils.getDateFormatByTickInterval(scaleOptions.tickInterval) } } } if (scaleOptions.type === SEMIDISCRETE) { const intervals = getIntervalCustomTicks(scaleOptions); scaleOptions.customMinorTicks = intervals.altIntervals; scaleOptions.customTicks = intervals.intervals; scaleOptions.customBoundTicks = [scaleOptions.customTicks[0]] } } function prepareScaleOptions(scaleOption, calculatedValueType, incidentOccurred, containerColor) { let valueType = (0, _parse_utils.correctValueType)((0, _utils.normalizeEnum)(scaleOption.valueType)); const validateStartEndValues = (field, parser) => { const messageToIncidentOccurred = field === START_VALUE ? "start" : "end"; if ((0, _m_type.isDefined)(scaleOption[field])) { const parsedValue = parser(scaleOption[field]); if ((0, _m_type.isDefined)(parsedValue)) { scaleOption[field] = parsedValue } else { scaleOption[field] = void 0; incidentOccurred("E2202", [messageToIncidentOccurred]) } } }; valueType = calculatedValueType || valueType; if (!valueType) { valueType = calculateValueType(scaleOption.startValue, scaleOption.endValue) || "numeric" } if (valueType === STRING || scaleOption.categories) { scaleOption.type = DISCRETE; valueType = STRING } scaleOption.containerColor = containerColor; scaleOption.valueType = valueType; scaleOption.dataType = valueType; const parser = (0, _parse_utils.getParser)(valueType); validateStartEndValues(START_VALUE, parser); validateStartEndValues(END_VALUE, parser); checkLogarithmicOptions(scaleOption, 10, incidentOccurred); if (!scaleOption.type) { scaleOption.type = "continuous" } scaleOption.parser = parser; if (scaleOption.type === SEMIDISCRETE) { scaleOption.minorTick.visible = false; scaleOption.minorTickInterval = scaleOption.minRange; scaleOption.marker.visible = false; scaleOption.maxRange = void 0 } scaleOption.forceUserTickInterval |= Number((0, _m_type.isDefined)(scaleOption.tickInterval) && !(0, _m_type.isDefined)(scaleOption.axisDivisionFactor)); scaleOption.axisDivisionFactor = (0, _m_type.isDefined)(scaleOption.axisDivisionFactor) ? scaleOption.axisDivisionFactor : 30; scaleOption.minorAxisDivisionFactor = (0, _m_type.isDefined)(scaleOption.minorAxisDivisionFactor) ? scaleOption.minorAxisDivisionFactor : 15; return scaleOption } function getSliderMarkerDateFormat(markerVisible, startValue, endValue, interval) { if (markerVisible) { return _m_date.dateUtils.getDateFormatByTickInterval(interval) } if ((0, _m_type.isDefined)(startValue) && (0, _m_type.isDefined)(endValue)) { return _format_helper.default.getDateFormatByTickInterval(startValue, endValue, interval) } return } function getPrecisionForSlider(startValue, endValue, screenDelta) { const d = Math.abs(endValue - startValue) / screenDelta; const tail = d - Math.floor(d); return tail > 0 ? Math.ceil(Math.abs((0, _m_math.adjust)((0, _utils.getLog)(tail, 10)))) : 0 } function prepareAxisOptions(scaleOptions, isCompactMode, height, axisPosition) { scaleOptions.marker.label.font = scaleOptions.label.font; scaleOptions.color = scaleOptions.tick.color; scaleOptions.marker.color = scaleOptions.tick.color; scaleOptions.opacity = scaleOptions.tick.opacity; scaleOptions.marker.opacity = scaleOptions.tick.opacity; scaleOptions.width = scaleOptions.tick.width; scaleOptions.marker.width = scaleOptions.tick.width; scaleOptions.placeholderSize = (scaleOptions.placeholderHeight || 0) + axisPosition; scaleOptions.argumentType = scaleOptions.valueType; scaleOptions.visible = isCompactMode; scaleOptions.isHorizontal = true; scaleOptions.calculateMinors = true; scaleOptions.semiDiscreteInterval = scaleOptions.minRange; if (!isCompactMode) { scaleOptions.minorTick.length = height; scaleOptions.tick.length = height } scaleOptions.label.indentFromAxis = scaleOptions.label.topIndent + axisPosition; return scaleOptions } function createDateMarkersEvent(scaleOptions, markerTrackers, setSelectedRange) { function onPointerDown(e) { const { range: range } = e.target; const minRange = scaleOptions.minRange ? _m_date.dateUtils.addInterval(range.startValue, scaleOptions.minRange) : void 0; const maxRange = scaleOptions.maxRange ? _m_date.dateUtils.addInterval(range.startValue, scaleOptions.maxRange) : void 0; if (!(minRange && minRange > range.endValue || maxRange && maxRange < range.endValue)) { setSelectedRange(range, e) } }(0, _m_iterator.each)(markerTrackers, (_, value) => { value.on("dxpointerdown", onPointerDown) }) } function getSharpDirection() { return 1 } function getTickStartPositionShift(length) { return length % 2 === 1 ? -Math.floor(length / 2) : -length / 2 } function checkShiftedLabels(majorTicks, boxes, minSpacing, alignment) { function checkLabelsOverlapping(nearestLabelsIndexes) { if (2 === nearestLabelsIndexes.length && _axes_constants.default.areLabelsOverlap(boxes[nearestLabelsIndexes[0]], boxes[nearestLabelsIndexes[1]], minSpacing, alignment)) { majorTicks[nearestLabelsIndexes[0]].removeLabel() } } function getTwoVisibleLabels(startIndex) { const labels = []; for (let i = startIndex; labels.length < 2 && i < majorTicks.length; i += 1) { if (majorTicks[i].label) { labels.push(i) } } return labels } if (majorTicks.length < 3) { return } checkLabelsOverlapping(getTwoVisibleLabels(0)); checkLabelsOverlapping(getTwoVisibleLabels(majorTicks.length - 2).reverse()) } class AxisWrapper { constructor(params) { this._axis = new _base_axis.Axis({ renderer: params.renderer, axesContainerGroup: params.root, scaleBreaksGroup: params.scaleBreaksGroup, labelsAxesGroup: params.labelsAxesGroup, incidentOccurred: params.incidentOccurred, axisType: "xyAxes", drawingType: "linear", widgetClass: "dxrs", axisClass: "range-selector", isArgumentAxis: true, getTemplate() {} }); this._updateSelectedRangeCallback = params.updateSelectedRange; this._axis.getAxisSharpDirection = getSharpDirection; this._axis.getSharpDirectionByCoords = getSharpDirection; this._axis.getTickStartPositionShift = getTickStartPositionShift; this._axis._checkShiftedLabels = checkShiftedLabels } update(options, isCompactMode, canvas, businessRange, seriesDataSource) { const axis = this._axis; axis.updateOptions(prepareAxisOptions(options, isCompactMode, canvas.height, canvas.height / 2 - Math.ceil(options.width / 2))); axis.validate(); axis.setBusinessRange(businessRange, true); if (void 0 !== seriesDataSource && seriesDataSource.isShowChart()) { axis.setMarginOptions(seriesDataSource.getMarginOptions(canvas)) } axis.draw(canvas); axis.shift({ left: 0, bottom: -canvas.height / 2 + canvas.top }); if (axis.getMarkerTrackers()) { createDateMarkersEvent(options, axis.getMarkerTrackers(), this._updateSelectedRangeCallback) } axis.drawScaleBreaks({ start: canvas.top, end: canvas.top + canvas.height }) } visualRange() {} getViewport() { return {} } allScaleSelected(value) { const { startValue: startValue, endValue: endValue } = this._axis.visualRange(); return { startValue: value[0].valueOf() === startValue.valueOf(), endValue: value[1].valueOf() === endValue.valueOf() } } getOptions() { return this._axis.getOptions() || {} } } Object.getOwnPropertyNames(_base_axis.Axis.prototype).forEach(field => { if ("constructor" !== field && !field.startsWith("_") && (0, _m_type.isFunction)(_base_axis.Axis.prototype[field]) && !(field in AxisWrapper.prototype)) { AxisWrapper.prototype[field] = function() { const axis = this._axis; return axis[field](...arguments) } } }); class RangeSelector extends _base_widget.default { _toggleParentsScrollSubscription() {} _dataIsReady() { return this._dataIsLoaded() } _getDefaultSize() { return { width: 400, height: 160 } } _initCore() { const renderer = this._renderer; const { root: root } = renderer; root.css({ "touch-action": "pan-y" }); this._clipRect = renderer.clipRect(); const rangeViewGroup = renderer.g().attr({ class: "dxrs-view" }).append(root); const slidersGroup = renderer.g().attr({ class: "dxrs-slidersContainer", "clip-path": this._clipRect.id }).append(root); const scaleGroup = renderer.g().attr({ class: "dxrs-scale", "clip-path": this._clipRect.id }).append(root); const labelsAxesGroup = renderer.g().attr({ class: "dxrs-scale-elements", "clip-path": this._clipRect.id }).append(root); const scaleBreaksGroup = renderer.g().attr({ class: "dxrs-scale-breaks" }).append(root); const trackersGroup = renderer.g().attr({ class: "dxrs-trackers" }).append(root); this._axis = new AxisWrapper({ renderer: renderer, root: scaleGroup, scaleBreaksGroup: scaleBreaksGroup, labelsAxesGroup: labelsAxesGroup, updateSelectedRange: (range, e) => { this.setValue((0, _utils.convertVisualRangeObject)(range), e) }, incidentOccurred: this._incidentOccurred }); this._rangeView = new _range_view.RangeView({ renderer: renderer, root: rangeViewGroup }); this._slidersController = new _sliders_controller.SlidersController({ renderer: renderer, root: slidersGroup, trackersGroup: trackersGroup, updateSelectedRange: (range, lastSelectedRange, e) => { if (!this._rangeOption) { this.option(VALUE, (0, _utils.convertVisualRangeObject)(range, (0, _m_type.isPlainObject)(this._options.silent(VALUE)))) } this._eventTrigger(VALUE_CHANGED, { value: (0, _utils.convertVisualRangeObject)(range), previousValue: (0, _utils.convertVisualRangeObject)(lastSelectedRange), event: e }) }, axis: this._axis, translator: this._axis.getTranslator() }); this._tracker = new _tracker.Tracker({ renderer: renderer, controller: this._slidersController }) } _disposeCore() { this._axis.dispose(); this._slidersController.dispose(); this._tracker.dispose() } _applySize(rect) { this._clientRect = rect.slice(); this._change(["MOSTLY_TOTAL"]) } _change_SCALE() { this._change(["MOSTLY_TOTAL"]) } _setValueByDataSource() { const options = this._options.silent(); const axis = this._axis; if (options.dataSource) { let selectedRangeUpdateMode = this.option("selectedRangeUpdateMode"); const value = this.getValue(); const valueIsReady = (0, _m_type.isDefined)(value[0]) && (0, _m_type.isDefined)(value[1]); if ((0, _m_type.isDefined)(selectedRangeUpdateMode)) { selectedRangeUpdateMode = (0, _utils.normalizeEnum)(selectedRangeUpdateMode); this.__skipAnimation = true } else if (valueIsReady && !this._dataSourceIsAsync) { selectedRangeUpdateMode = RESET } if ("auto" === selectedRangeUpdateMode && valueIsReady) { const rangesInfo = axis.allScaleSelected(value); if (rangesInfo.startValue && rangesInfo.endValue) { selectedRangeUpdateMode = RESET } else if (rangesInfo.endValue) { selectedRangeUpdateMode = SHIFT } else { selectedRangeUpdateMode = KEEP } } if (selectedRangeUpdateMode === RESET) { options[VALUE] = null } else if (selectedRangeUpdateMode === SHIFT && valueIsReady) { const currentValue = this.getValue(); this.__skipAnimation = true; options[VALUE] = { length: axis.getVisualRangeLength({ minVisible: currentValue[0], maxVisible: currentValue[1] }) } } else if (selectedRangeUpdateMode === KEEP) { this.__skipAnimation = true } } this._dataSourceIsAsync = void 0 } _change_DATA_SOURCE() { if (this._options.silent("dataSource")) { this._updateDataSource() } } _change_MOSTLY_TOTAL() { this._applyMostlyTotalChange() } _change_SLIDER_SELECTION() { const value = this._options.silent(VALUE); this._slidersController.setSelectedRange(value && (0, _utils.getVizRangeObject)(value)) } _change_VALUE() { const option = this._rangeOption; this._dataSourceIsAsync = !this._dataIsReady(); if (option) { this._options.silent(VALUE, option); this.setValue(option) } } _validateRange(start, end) { const ensureValueInvalid = value => (0, _m_type.isDefined)(value) && !this._axis.getTranslator().isValid(value); if (this._dataIsReady() && (ensureValueInvalid(start) || ensureValueInvalid(end))) { this._incidentOccurred("E2203") } } _applyChanges() { const value = this._options.silent(VALUE); if (this._changes.has("VALUE") && value) { this._rangeOption = value } super._applyChanges(); this._rangeOption = null; this.__isResizing = false; this.__skipAnimation = false } _applyMostlyTotalChange() { const renderer = this._renderer; const rect = this._clientRect; const skipAnimation = Boolean(this.__isResizing || this.__skipAnimation); const currentAnimationEnabled = skipAnimation ? renderer.animationEnabled() : void 0; const canvas = { left: rect[0], top: rect[1], width: rect[2] - rect[0], height: rect[3] - rect[1] }; if (skipAnimation) { renderer.updateAnimationOptions({ enabled: false }) } this._clipRect.attr({ x: rect[0], y: rect[1], width: rect[2] - rect[0], height: rect[3] - rect[1] }); this._axis.getTranslator().update(new _range.Range, canvas, { isHorizontal: true }); this._updateContent({ left: rect[0], top: rect[1], width: rect[2] - rect[0], height: rect[3] - rect[1] }); if (skipAnimation) { renderer.updateAnimationOptions({ enabled: currentAnimationEnabled }) } this._drawn() } _dataSourceChangedHandler() { this._setValueByDataSource(); this._requestChange(["MOSTLY_TOTAL"]) } _completeSeriesDataSourceCreation(scaleOptions, seriesDataSource) { const rect = this._clientRect; const canvas = { left: rect[0], top: rect[1], width: rect[2] - rect[0], height: rect[3] - rect[1] }; this._axis.updateOptions((0, _m_extend.extend)({}, scaleOptions, { isHorizontal: true, label: {} })); if (seriesDataSource.isShowChart()) { this._axis.setMarginOptions(seriesDataSource.getMarginOptions(canvas)) } this._axis.updateCanvas(canvas); seriesDataSource.createPoints() } _updateContent(canvas) { const chartOptions = this.option("chart"); const seriesDataSource = this._createSeriesDataSource(chartOptions); const isCompactMode = !(seriesDataSource && seriesDataSource.isShowChart() || this.option("background.image.url")); const scaleOptions = prepareScaleOptions(this._getOption("scale"), seriesDataSource && seriesDataSource.getCalculatedValueType(), this._incidentOccurred, this._getOption("containerBackgroundColor", true)); if (seriesDataSource) { this._completeSeriesDataSourceCreation(scaleOptions, seriesDataSource) } const argTranslatorRange = calculateTranslatorRange(seriesDataSource, scaleOptions); const tickIntervalsInfo = updateTickIntervals(scaleOptions, canvas.width, this._incidentOccurred, argTranslatorRange); const chartThemeManager = seriesDataSource && seriesDataSource.isShowChart() && seriesDataSource.getThemeManager(); if (chartThemeManager) { checkLogarithmicOptions(chartOptions && chartOptions.valueAxis, chartThemeManager.getOptions("valueAxis").logarithmBase, this._incidentOccurred) } updateScaleOptions(scaleOptions, seriesDataSource, argTranslatorRange, tickIntervalsInfo, getDateMarkerVisibilityChecker(canvas.width)); updateTranslatorRangeInterval(argTranslatorRange, scaleOptions); const sliderMarkerOptions = this._prepareSliderMarkersOptions(scaleOptions, canvas.width, tickIntervalsInfo, argTranslatorRange); const indents = calculateIndents(this._renderer, scaleOptions, sliderMarkerOptions, this.option("indent"), tickIntervalsInfo); const scaleAreaHeight = calculateScaleAreaHeight(this._renderer, scaleOptions, showScaleMarkers(scaleOptions), tickIntervalsInfo); const rangeContainerCanvas = { left: canvas.left + indents.left, top: canvas.top + indents.top, width: canvas.left + indents.left + Math.max(canvas.width - indents.left - indents.right, 1), height: Math.max(!isCompactMode ? canvas.height - indents.top - indents.bottom - scaleAreaHeight : _common.HEIGHT_COMPACT_MODE, 0), right: 0, bottom: 0 }; this._axis.update(scaleOptions, isCompactMode, rangeContainerCanvas, argTranslatorRange, seriesDataSource); scaleOptions.minorTickInterval = scaleOptions.isEmpty ? 0 : scaleOptions.minorTickInterval; this._updateElements(scaleOptions, sliderMarkerOptions, isCompactMode, rangeContainerCanvas, seriesDataSource); if (chartThemeManager) { chartThemeManager.dispose() } } _updateElements(scaleOptions, sliderMarkerOptions, isCompactMode, canvas, seriesDataSource) { const behavior = this._getOption("behavior"); const shutterOptions = this._getOption("shutter"); const isNotSemiDiscrete = scaleOptions.type !== SEMIDISCRETE; shutterOptions.color = shutterOptions.color || this._getOption(CONTAINER_BACKGROUND_COLOR, true); this._rangeView.update(this.option("background"), this._themeManager.theme("background"), canvas, isCompactMode, behavior.animationEnabled && this._renderer.animationEnabled(), seriesDataSource); this._isUpdating = true; this._slidersController.update([canvas.top, canvas.top + canvas.height], behavior, isCompactMode, this._getOption("sliderHandle"), sliderMarkerOptions, shutterOptions, { minRange: isNotSemiDiscrete ? this.option("scale.minRange") : void 0, maxRange: isNotSemiDiscrete ? this.option("scale.maxRange") : void 0 }, this._axis.getFullTicks(), this._getOption("selectedRangeColor", true)); this._requestChange(["SLIDER_SELECTION"]); this._isUpdating = false; this._tracker.update(!this._axis.getTranslator().getBusinessRange().isEmpty(), behavior) } _createSeriesDataSource(chartOptions) { const dataSource = this._dataSourceItems(); const scaleOptions = this._getOption("scale"); const valueType = scaleOptions.valueType || calculateValueType(scaleOptions.startValue, scaleOptions.endValue); const valueAxis = new _base_axis.Axis({ renderer: this._renderer, axisType: "xyAxes", drawingType: "linear" }); valueAxis.updateOptions({ isHorizontal: false, label: {}, categoriesSortingMethod: this._getOption("chart").valueAxis.categoriesSortingMethod }); if (!dataSource && !(chartOptions && chartOptions.series)) { return } const options = (0, _m_extend.extend)({}, chartOptions, { theme: this.option("theme") }); return new _series_data_source.SeriesDataSource({ renderer: this._renderer, dataSource: dataSource, valueType: (0, _utils.normalizeEnum)(valueType), axisType: scaleOptions.type, chart: options, dataSourceField: this.option("dataSourceField"), incidentOccurred: this._incidentOccurred, categories: scaleOptions.categories, argumentAxis: this._axis, valueAxis: valueAxis }) } _prepareSliderMarkersOptions(scaleOptions, screenDelta, tickIntervalsInfo, argRange) { const { minorTickInterval: minorTickInterval, tickInterval: tickInterval } = tickIntervalsInfo; let interval = tickInterval; const { endValue: endValue, startValue: startValue } = scaleOptions; const sliderMarkerOptions = this._getOption(SLIDER_MARKER); const doNotSnap = !this._getOption("behavior").snapToTicks; const isTypeDiscrete = scaleOptions.type === DISCRETE; const isValueTypeDatetime = scaleOptions.valueType === DATETIME; sliderMarkerOptions.borderColor = this._getOption(CONTAINER_BACKGROUND_COLOR, true); if (!sliderMarkerOptions.format && !argRange.isEmpty()) { if (doNotSnap && (0, _m_type.isNumeric)(scaleOptions.startValue)) { sliderMarkerOptions.format = { type: "fixedPoint", precision: getPrecisionForSlider(startValue, endValue, screenDelta) } } if (isValueTypeDatetime && !isTypeDiscrete) { if ((0, _m_type.isDefined)(minorTickInterval) && 0 !== minorTickInterval) { interval = getMinorTickIntervalUnit(tickInterval, minorTickInterval, doNotSnap) } const dateFormat = getSliderMarkerDateFormat(scaleOptions.marker.visible, startValue, endValue, interval); if (void 0 !== dateFormat) { sliderMarkerOptions.format = dateFormat } } if (isValueTypeDatetime && isTypeDiscrete && tickIntervalsInfo.ticks.length) { sliderMarkerOptions.format = _format_helper.default.getDateFormatByTicks(tickIntervalsInfo.ticks) } } return sliderMarkerOptions } getValue() { return (0, _utils.convertVisualRangeObject)(this._slidersController.getSelectedRange()) } setValue(value, e) { const visualRange = (0, _utils.getVizRangeObject)(value); if (!this._isUpdating && value) { this._validateRange(visualRange.startValue, visualRange.endValue); if (!(0, _utils.rangesAreEqual)(visualRange, this._slidersController.getSelectedRange())) { this._slidersController.setSelectedRange(visualRange, e) } } } _setContentSize() { this.__isResizing = 2 === this._changes.count(); super._setContentSize() } }(0, _helpers.setupWidgetPrototype)(RangeSelector, { _eventsMap: { onValueChanged: { name: VALUE_CHANGED } }, _rootClassPrefix: "dxrs", _rootClass: "dxrs-range-selector", _initialChanges: ["DATA_SOURCE", "VALUE"], _themeDependentChanges: ["MOSTLY_TOTAL"], _themeSection: "rangeSelector", _fontFields: ["scale.label.font", "sliderMarker.font"], _optionChangesMap: { scale: "SCALE", value: "VALUE", dataSource: "DATA_SOURCE" }, _optionChangesOrder: ["SCALE", "DATA_SOURCE"], _customChangesOrder: ["MOSTLY_TOTAL", "VALUE", "SLIDER_SELECTION"] }); ["selectedRangeColor", CONTAINER_BACKGROUND_COLOR, SLIDER_MARKER, "sliderHandle", "shutter", OPTION_BACKGROUND, "behavior", "chart", "indent"].forEach(name => { RangeSelector.prototype._optionChangesMap[name] = "MOSTLY_TOTAL" }); (0, _component_registrator.registerComponent)("dxRangeSelector", RangeSelector); RangeSelector.addPlugin(_export.plugin); RangeSelector.addPlugin(_title.plugin); RangeSelector.addPlugin(_loading_indicator.plugin); RangeSelector.addPlugin(_data_source.plugin); var _default = exports.default = RangeSelector;