UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

226 lines (221 loc) • 9.18 kB
/** * DevExtreme (cjs/__internal/viz/components/chart_theme_manager.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.ThemeManager = void 0; var _m_common = require("../../core/utils/m_common"); var _m_extend = require("../../core/utils/m_extend"); var _m_type = require("../../core/utils/m_type"); var _base_theme_manager = require("../../viz/core/base_theme_manager"); var _utils = require("../../viz/core/utils"); function processTitleOptions(options) { return (0, _m_type.isString)(options) ? { text: options } : options } function processAxisOptions(axisOptions) { if (!axisOptions) { return {} } const processedOptions = (0, _m_extend.extend)(true, {}, axisOptions); processedOptions.title = processTitleOptions(processedOptions.title); if ("logarithmic" === processedOptions.type && processedOptions.logarithmBase <= 0 || processedOptions.logarithmBase && !(0, _m_type.isNumeric)(processedOptions.logarithmBase)) { processedOptions.logarithmBase = void 0; processedOptions.logarithmBaseError = true } if (processedOptions.label) { if (processedOptions.label.alignment) { processedOptions.label.userAlignment = true } } return processedOptions } function getAnimationUserOptions(value) { if ((0, _m_type.isPlainObject)(value)) { return value } return (0, _m_type.isDefined)(value) ? { enabled: !!value } : {} } function parseZoomAndPanOption(option) { const normalizedOption = (0, _utils.normalizeEnum)(option); const pan = "pan" === normalizedOption || "both" === normalizedOption; const zoom = "zoom" === normalizedOption || "both" === normalizedOption; return { pan: pan, zoom: zoom, none: !pan && !zoom } } let ThemeManager = exports.ThemeManager = class extends _base_theme_manager.BaseThemeManager { constructor(params) { super(params); const options = params.options || {}; this._userOptions = options; this._mergeAxisTitleOptions = []; this._multiPieColors = {}; this._callback = _m_common.noop } dispose() { if (this.palette) { this.palette.dispose() } Object.assign(this, { _multiPieColors: null, _mergedSettings: null, _userOptions: null, palette: null }); return super.dispose() } refresh() { this._mergedSettings = {}; return super.refresh() } _initializeTheme() { super._initializeTheme(); this.updatePalette() } getOptions(name) { switch (name) { case "argumentAxis": case "valueAxis": return this._getAxisOptions(name, arguments.length <= 1 ? void 0 : arguments[1], arguments.length <= 2 ? void 0 : arguments[2]); case "valueAxisRangeSelector": return this._mergeOptions("valueAxis"); case "series": return this._getSeriesOptions(arguments.length <= 1 ? void 0 : arguments[1], arguments.length <= 2 ? void 0 : arguments[2]); case "animation": return this._mergeOptions(name, getAnimationUserOptions(this._userOptions[name])); case "seriesTemplate": return this._getSeriesTemplateOptions(); case "zoomAndPan": return this._getZoomAndPanOptions(); default: return this._mergeOptions(name, arguments.length <= 1 ? void 0 : arguments[1]) } } resetOptions(name) { this._mergedSettings[name] = null } update(options) { this._userOptions = options } updatePalette() { this.palette = this.createPalette(this.getOptions("palette"), { useHighlight: true, extensionMode: this.getOptions("paletteExtensionMode") }) } resetPalette() { this.palette.reset(); this._multiPieColors = {} } _mergeOptions(name, userOptions) { const options = userOptions || this._userOptions[name]; const theme = this._theme[name]; let result = this._mergedSettings[name]; if (result) { return result } if ((0, _m_type.isPlainObject)(theme) && (0, _m_type.isPlainObject)(options)) { result = (0, _m_extend.extend)(true, {}, theme, options) } else { result = (0, _m_type.isDefined)(options) ? options : theme } this._mergedSettings[name] = result; return result } _getAxisOptions(name, userOptions, rotated) { const theme = this._theme; const isValueAxis = "valueAxis" === name; const position = Boolean(rotated) === isValueAxis ? "horizontalAxis" : "verticalAxis"; const processedUserOptions = processAxisOptions(userOptions); const commonAxisSettings = processAxisOptions(this._userOptions.commonAxisSettings); const mergeOptions = (0, _m_extend.extend)(true, {}, theme.commonAxisSettings, theme[position], theme[name], commonAxisSettings, processedUserOptions); mergeOptions.workWeek = processedUserOptions.workWeek || theme[name].workWeek; mergeOptions.forceUserTickInterval |= Number((0, _m_type.isDefined)(processedUserOptions.tickInterval) && !(0, _m_type.isDefined)(processedUserOptions.axisDivisionFactor)); return mergeOptions } _getSeriesOptions(userOptions, seriesCount) { const theme = this._theme; let userCommonSettings = this._userOptions.commonSeriesSettings || {}; const themeCommonSettings = theme.commonSeriesSettings; const widgetType = this._themeSection.split(".").slice(-1)[0]; const type = (0, _utils.normalizeEnum)(userOptions.type || userCommonSettings.type || themeCommonSettings.type || "pie" === widgetType && theme.type); const { palette: palette } = this; const isBar = type.includes("bar"); const isLine = type.includes("line"); const isArea = type.includes("area"); const isBubble = "bubble" === type; const resolveLabelsOverlapping = this.getOptions("resolveLabelsOverlapping"); const containerBackgroundColor = this.getOptions("containerBackgroundColor"); const seriesTemplate = this._getSeriesTemplateOptions(); let seriesOptions = userOptions; if (isBar || isBubble) { seriesOptions = (0, _m_extend.extend)(true, {}, userCommonSettings, userCommonSettings[type], seriesOptions); const seriesVisibility = seriesOptions.visible; userCommonSettings = { type: {} }; (0, _m_extend.extend)(true, seriesOptions, seriesOptions.point); seriesOptions.visible = seriesVisibility } const settings = (0, _m_extend.extend)(true, { aggregation: {} }, themeCommonSettings, themeCommonSettings[type], userCommonSettings, userCommonSettings[type], seriesOptions); settings.aggregation.enabled = "chart" === widgetType && !!settings.aggregation.enabled; settings.type = type; settings.widgetType = widgetType; settings.containerBackgroundColor = containerBackgroundColor; settings.mainSeriesColor = "pie" !== widgetType ? (0, _utils.extractColor)(settings.color, true) || palette.getNextColor(seriesCount) : (argument, index, count) => { const cat = `${argument}-${index}`; if (!this._multiPieColors[cat]) { this._multiPieColors[cat] = palette.getNextColor(count) } return this._multiPieColors[cat] }; settings.resolveLabelsOverlapping = resolveLabelsOverlapping; if (settings.label && (isLine || isArea && "rangearea" !== type || "scatter" === type)) { settings.label.position = "outside" } if (seriesTemplate) { settings.nameField = seriesTemplate.nameField } return settings } _getSeriesTemplateOptions() { const value = this._mergeOptions("seriesTemplate"); if (value) { value.nameField = value.nameField || "series" } return value } _getZoomAndPanOptions() { const options = this._mergeOptions("zoomAndPan"); return { valueAxis: parseZoomAndPanOption(options.valueAxis), argumentAxis: parseZoomAndPanOption(options.argumentAxis), dragToZoom: !!options.dragToZoom, dragBoxStyle: { class: "dxc-shutter", fill: options.dragBoxStyle.color, opacity: options.dragBoxStyle.opacity }, panKey: options.panKey, allowMouseWheel: !!options.allowMouseWheel, allowTouchGestures: !!options.allowTouchGestures } } };