UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

258 lines (254 loc) • 8.29 kB
/** * DevExtreme (cjs/__internal/viz/funnel/funnel.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 _m_common = require("../../core/utils/m_common"); var _base_widget = _interopRequireDefault(require("../../viz/core/base_widget")); var _data_source = require("../../viz/core/data_source"); var _helpers = require("../../viz/core/helpers"); var _item = _interopRequireDefault(require("./item")); var _tiling = require("./tiling"); var _tiling2 = _interopRequireDefault(require("./tiling.funnel")); var _tiling3 = _interopRequireDefault(require("./tiling.pyramid")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const NODES_CREATE_CHANGE = "NODES_CREATE"; (0, _tiling.addAlgorithm)("dynamicslope", _tiling2.default, true); (0, _tiling.addAlgorithm)("dynamicheight", _tiling3.default); function invertFigure(figure) { return figure.map((coord, index) => index % 2 ? 1 - coord : coord) } function getLegendItemState(itemState) { return { fill: itemState.fill, hatching: itemState.hatching } } class Funnel extends _base_widget.default { _getDefaultSize() { return { width: 400, height: 400 } } _initCore() { this._group = this._renderer.g().append(this._renderer.root); this._items = [] } _applySize(rect) { this._rect = rect.slice(); this._change(["TILING"]); return this._rect } _getAlignmentRect() { return this._rect } _change_TILING() { const rect = this._rect; const convertCoord = (coord, index) => { const offset = index % 2; return rect[0 + offset] + (rect[2 + offset] - rect[0 + offset]) * coord }; this._group.clear(); this._items.forEach(item => { const coords = item.figure.map(convertCoord); const element = this._renderer.path([], "area").attr({ points: coords }).append(this._group); item.coords = coords; item.element = element }); this._requestChange(["TILES"]) } _dataSourceChangedHandler() { this._requestChange(["NODES_CREATE"]) } _change_DRAWN() { this._drawn() } _change_DATA_SOURCE() { this._change(["DRAWN"]); this._updateDataSource() } _change_NODES_CREATE() { this._buildNodes() } _change_TILES() { this._applyTilesAppearance() } _suspend() { if (!this._applyingChanges) { this._suspendChanges() } } _resume() { if (!this._applyingChanges) { this._resumeChanges() } } _applyTilesAppearance() { this._items.forEach(item => { const state = item.getState(); item.element.smartAttr(item.states[state]) }) } _hitTestTargets(x, y) { return this._proxyData.reduce((found, callback) => found || callback.call(this, x, y), void 0) } clearHover() { this._suspend(); this._items.forEach(item => { if (item.isHovered()) { item.hover(false) } }); this._resume() } clearSelection() { this._suspend(); this._items.forEach(item => { if (item.isSelected()) { item.select(false) } }); this._resume() } _getData() { const data = this._dataSourceItems() || []; const valueField = this._getOption("valueField", true); const argumentField = this._getOption("argumentField", true); const colorField = this._getOption("colorField", true); const processedData = data.reduce((d, item) => { const value = Number(item[valueField]); if (value >= 0) { d[0].push({ value: value, color: item[colorField], argument: item[argumentField], dataItem: item }); d[1] += value } return d }, [ [], 0 ]); const items = processedData[0]; if (data.length > 0 && 0 === items.length) { this._incidentOccurred("E2005", valueField) } if (!processedData[1]) { return [] } if (this._getOption("sortData", true)) { items.sort((a, b) => b.value - a.value) } return items } _buildNodes() { const data = this._getData(); const algorithm = (0, _tiling.getAlgorithm)(this._getOption("algorithm", true)); const percents = algorithm.normalizeValues(data); const itemOptions = this._getOption("item"); const figures = algorithm.getFigures(percents, this._getOption("neckWidth", true), this._getOption("neckHeight", true)); const palette = this._themeManager.createPalette(this._getOption("palette", true), { useHighlight: true, extensionMode: this._getOption("paletteExtensionMode", true), count: figures.length }); this._items = figures.map((figure, index) => { const curData = data[index]; return new _item.default(this, { figure: figure, data: curData, percent: percents[index], id: index, color: curData.color || palette.getNextColor(), itemOptions: itemOptions }) }); if (this._getOption("inverted", true)) { this._items.forEach(item => { item.figure = invertFigure(item.figure) }) } this._renderer.initDefsElements(); this._change(["TILING", "DRAWN"]) } getAllItems() { return this._items.slice() } _getLegendData() { return this._items.map(item => { const { states: states } = item; return { id: item.id, visible: true, text: item.argument, item: item, states: { normal: getLegendItemState(states.normal), hover: getLegendItemState(states.hover), selection: getLegendItemState(states.selection) } } }) } _getMinSize() { const adaptiveLayout = this._getOption("adaptiveLayout"); return [adaptiveLayout.width, adaptiveLayout.height] } }(0, _helpers.setupWidgetPrototype)(Funnel, { _rootClass: "dxf-funnel", _rootClassPrefix: "dxf", _proxyData: [], _optionChangesMap: { dataSource: "DATA_SOURCE", neckWidth: "NODES_CREATE", neckHeight: "NODES_CREATE", inverted: "NODES_CREATE", algorithm: "NODES_CREATE", item: "NODES_CREATE", valueField: "NODES_CREATE", argumentField: "NODES_CREATE", colorField: "NODES_CREATE", palette: "NODES_CREATE", paletteExtensionMode: "NODES_CREATE", sortData: "NODES_CREATE" }, _themeDependentChanges: ["NODES_CREATE"], _themeSection: "funnel", _fontFields: ["legend.title.font", "legend.title.subtitle.font", "legend.font"], _optionChangesOrder: ["DATA_SOURCE"], _initialChanges: ["DATA_SOURCE"], _eventsMap: { onHoverChanged: { name: "hoverChanged" }, onSelectionChanged: { name: "selectionChanged" } }, _disposeCore: _m_common.noop, _customChangesOrder: ["NODES_CREATE", "LAYOUT", "TILING", "TILES", "DRAWN"], _showTooltip: _m_common.noop, hideTooltip: _m_common.noop }); (0, _component_registrator.registerComponent)("dxFunnel", Funnel); Funnel.addPlugin(_data_source.plugin); var _default = exports.default = Funnel;