devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
235 lines (230 loc) • 8.87 kB
JavaScript
/**
* DevExtreme (esm/__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/
*/
import {
noop
} from "../../core/utils/m_common";
import {
extend
} from "../../core/utils/m_extend";
import {
isDefined,
isNumeric,
isPlainObject,
isString
} from "../../core/utils/m_type";
import {
BaseThemeManager
} from "../../viz/core/base_theme_manager";
import {
extractColor,
normalizeEnum
} from "../../viz/core/utils";
function processTitleOptions(options) {
return isString(options) ? {
text: options
} : options
}
function processAxisOptions(axisOptions) {
if (!axisOptions) {
return {}
}
const processedOptions = extend(true, {}, axisOptions);
processedOptions.title = processTitleOptions(processedOptions.title);
if ("logarithmic" === processedOptions.type && processedOptions.logarithmBase <= 0 || processedOptions.logarithmBase && !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 (isPlainObject(value)) {
return value
}
return isDefined(value) ? {
enabled: !!value
} : {}
}
function parseZoomAndPanOption(option) {
const normalizedOption = normalizeEnum(option);
const pan = "pan" === normalizedOption || "both" === normalizedOption;
const zoom = "zoom" === normalizedOption || "both" === normalizedOption;
return {
pan: pan,
zoom: zoom,
none: !pan && !zoom
}
}
export let ThemeManager = class extends BaseThemeManager {
constructor(params) {
super(params);
const options = params.options || {};
this._userOptions = options;
this._mergeAxisTitleOptions = [];
this._multiPieColors = {};
this._callback = 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 (isPlainObject(theme) && isPlainObject(options)) {
result = extend(true, {}, theme, options)
} else {
result = 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 = extend(true, {}, theme.commonAxisSettings, theme[position], theme[name], commonAxisSettings, processedUserOptions);
mergeOptions.workWeek = processedUserOptions.workWeek || theme[name].workWeek;
mergeOptions.forceUserTickInterval |= Number(isDefined(processedUserOptions.tickInterval) && !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 = 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 = extend(true, {}, userCommonSettings, userCommonSettings[type], seriesOptions);
const seriesVisibility = seriesOptions.visible;
userCommonSettings = {
type: {}
};
extend(true, seriesOptions, seriesOptions.point);
seriesOptions.visible = seriesVisibility
}
const settings = 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 ? 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
}
}
};