diff --git a/src/chart/funnel/FunnelView.ts b/src/chart/funnel/FunnelView.ts index f2ba72efb4e4bddca14ffda99df8f4bd07423e52..fa351e147ae13354fcc09ae0fcfd3afae180419a 100644 --- a/src/chart/funnel/FunnelView.ts +++ b/src/chart/funnel/FunnelView.ts @@ -29,7 +29,7 @@ import Displayable from 'zrender/src/graphic/Displayable'; const opacityAccessPath = ['itemStyle', 'opacity'] as const; -type ExtendedDisplayable = Displayable & { +type FunnelLabelEl = Displayable & { hoverIgnore?: boolean normalIgnore?: boolean } @@ -57,12 +57,12 @@ class FunnelPiece extends graphic.Group { var text = this.childAt(2) as graphic.Text; if (toState === 'emphasis') { - labelLine.ignore = (labelLine as ExtendedDisplayable).hoverIgnore; - text.ignore = (text as ExtendedDisplayable).hoverIgnore; + labelLine.ignore = (labelLine as FunnelLabelEl).hoverIgnore; + text.ignore = (text as FunnelLabelEl).hoverIgnore; } else { - labelLine.ignore = (labelLine as ExtendedDisplayable).normalIgnore; - text.ignore = (text as ExtendedDisplayable).normalIgnore; + labelLine.ignore = (labelLine as FunnelLabelEl).normalIgnore; + text.ignore = (text as FunnelLabelEl).normalIgnore; } } @@ -171,11 +171,11 @@ class FunnelPiece extends graphic.Group { } ); - labelText.ignore = (labelText as ExtendedDisplayable).normalIgnore = !labelModel.get('show'); - (labelText as ExtendedDisplayable).hoverIgnore = !labelHoverModel.get('show'); + labelText.ignore = (labelText as FunnelLabelEl).normalIgnore = !labelModel.get('show'); + (labelText as FunnelLabelEl).hoverIgnore = !labelHoverModel.get('show'); - labelLine.ignore = (labelLine as ExtendedDisplayable).normalIgnore = !labelLineModel.get('show'); - (labelLine as ExtendedDisplayable).hoverIgnore = !labelLineHoverModel.get('show'); + labelLine.ignore = (labelLine as FunnelLabelEl).normalIgnore = !labelLineModel.get('show'); + (labelLine as FunnelLabelEl).hoverIgnore = !labelLineHoverModel.get('show'); // Default use item visual color labelLine.setStyle({ diff --git a/src/chart/heatmap/HeatmapView.ts b/src/chart/heatmap/HeatmapView.ts index f023eaadea44fa9f8c74fc903ae7849f802aaed3..52ae3aa4924963bd3d91700dda8e02abd1e34b00 100644 --- a/src/chart/heatmap/HeatmapView.ts +++ b/src/chart/heatmap/HeatmapView.ts @@ -30,7 +30,7 @@ import type PiecewiseModel from '../../component/visualMap/PiecewiseModel'; import type ContinuousModel from '../../component/visualMap/ContinuousModel'; import type Cartesian2D from '../../coord/cartesian/Cartesian2D'; import { CoordinateSystem } from '../../coord/CoordinateSystem'; -import { StageHandlerProgressParams, Dictionary } from '../../util/types'; +import { StageHandlerProgressParams, Dictionary, OptionDataValue } from '../../util/types'; // Coord can be 'geo' 'bmap' 'amap' 'leaflet'... interface GeoLikeCoordSys extends CoordinateSystem { @@ -255,10 +255,10 @@ class HeatmapView extends ChartView { hoverLabelModel = itemModel.getModel(['emphasis', 'label']); } - var rawValue = seriesModel.getRawValue(idx); + var rawValue = seriesModel.getRawValue(idx) as OptionDataValue[]; var defaultText = '-'; if (rawValue && rawValue[2] != null) { - defaultText = rawValue[2]; + defaultText = rawValue[2] + ''; } graphic.setLabelStyle( diff --git a/src/chart/helper/Line.ts b/src/chart/helper/Line.ts index 84edda9a981156e7fba162ec20ee338f08a6bc56..0be21a742c84cafe4e7b6027967ea0c654ca87af 100644 --- a/src/chart/helper/Line.ts +++ b/src/chart/helper/Line.ts @@ -240,7 +240,7 @@ class Line extends graphic.Group { baseText = seriesModel.getFormattedLabel(idx, 'normal', lineData.dataType); if (baseText == null) { - var rawVal = seriesModel.getRawValue(idx); + var rawVal = seriesModel.getRawValue(idx) as number; baseText = rawVal == null ? lineData.getName(idx) : isFinite(rawVal) @@ -262,7 +262,7 @@ class Line extends graphic.Group { // values have to be set on `normalStyle`. if (normalText != null || emphasisText != null) { graphic.setTextStyle(label.style, labelModel, { - text: normalText + text: normalText + '' }, { autoColor: defaultLabelColor }); @@ -282,7 +282,7 @@ class Line extends graphic.Group { if (emphasisText != null) { // Only these properties supported in this emphasis style here. label.hoverStyle = { - text: emphasisText, + text: emphasisText + '', textFill: hoverLabelModel.getTextColor(true), // For merging hover style to normal style, do not use // `hoverLabelModel.getFont()` here. diff --git a/src/chart/helper/treeHelper.ts b/src/chart/helper/treeHelper.ts index 86f6a411c53813dc6bf3430f65ff6d4ca9434564..b1d7d62cc677ce0af3e9aad39ded2b1d7d6bc121 100644 --- a/src/chart/helper/treeHelper.ts +++ b/src/chart/helper/treeHelper.ts @@ -36,12 +36,16 @@ export function retrieveTargetInfo( } if (targetNode && root.contains(targetNode)) { - return {node: targetNode}; + return { + node: targetNode + }; } var targetNodeId = payload.targetNodeId; if (targetNodeId != null && (targetNode = root.getNodeById(targetNodeId))) { - return {node: targetNode}; + return { + node: targetNode + }; } } } @@ -62,7 +66,7 @@ export function aboveViewRoot(viewRoot: TreeNode, node: TreeNode) { } // From root to the input node (the input node will be included). -export function wrapTreePathInfo(node: TreeNode, seriesModel: SeriesModel) { +export function wrapTreePathInfo(node: TreeNode, seriesModel: SeriesModel) { var treePathInfo = []; while (node) { @@ -70,7 +74,7 @@ export function wrapTreePathInfo(node: TreeNode, seriesModel: SeriesModel) { treePathInfo.push({ name: node.name, dataIndex: nodeDataIndex, - value: seriesModel.getRawValue(nodeDataIndex) + value: seriesModel.getRawValue(nodeDataIndex) as T }); node = node.parentNode; } diff --git a/src/chart/pie/PieView.ts b/src/chart/pie/PieView.ts index fc1168f1f75901dcdf1fd50c115b1044393380d0..955134b4c7cbc88339f42cc5f15be01cc7723a33 100644 --- a/src/chart/pie/PieView.ts +++ b/src/chart/pie/PieView.ts @@ -29,6 +29,7 @@ import List from '../../data/List'; import PieSeriesModel, {PieDataItemOption} from './PieSeries'; import { Dictionary } from 'zrender/src/core/types'; import Element from 'zrender/src/Element'; +import Displayable from 'zrender/src/graphic/Displayable'; function updateDataSelected( this: PiePiece, @@ -85,10 +86,9 @@ function toggleItemSelected( : el.attr('position', position); } -type PieceElementExtension = { - hoverIgnore?: boolean, - normalIgnore?: boolean, - ignore?: boolean +interface PieceElementExtension extends Displayable { + hoverIgnore?: boolean + normalIgnore?: boolean }; /** @@ -179,7 +179,7 @@ class PiePiece extends graphic.Group { itemModel.getModel('itemStyle').getItemStyle() ) ); - sector.hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle(); + sector.hoverStyle = itemModel.getModel(['emphasis', 'itemStyle']).getItemStyle(); var cursorStyle = itemModel.getShallow('cursor'); cursorStyle && sector.attr('cursor', cursorStyle); diff --git a/src/chart/sunburst/SunburstPiece.ts b/src/chart/sunburst/SunburstPiece.ts index e2f0b0a019c5a5cea1cbaf6157a154b90e9c21df..1033a0a44ee2b02faea62dca934501542f61b16f 100644 --- a/src/chart/sunburst/SunburstPiece.ts +++ b/src/chart/sunburst/SunburstPiece.ts @@ -17,346 +17,361 @@ * under the License. */ -// @ts-nocheck - import * as zrUtil from 'zrender/src/core/util'; import * as graphic from '../../util/graphic'; +import { ECElement, ZRColor, ColorString } from '../../util/types'; +import { TreeNode } from '../../data/Tree'; +import SunburstSeriesModel, { SunburstSeriesNodeOption, SunburstSeriesOption } from './SunburstSeries'; +import GlobalModel from '../../model/Global'; +import { AllPropTypes } from 'zrender/src/core/types'; var NodeHighlightPolicy = { NONE: 'none', // not downplay others DESCENDANT: 'descendant', ANCESTOR: 'ancestor', SELF: 'self' -}; +} as const; var DEFAULT_SECTOR_Z = 2; var DEFAULT_TEXT_Z = 4; +interface DrawTreeNode extends TreeNode { + piece: SunburstPiece +} /** * Sunburstce of Sunburst including Sector, Label, LabelLine - * @constructor - * @extends {module:zrender/graphic/Group} */ -function SunburstPiece(node, seriesModel, ecModel) { - - graphic.Group.call(this); - - var sector = new graphic.Sector({ - z2: DEFAULT_SECTOR_Z - }); - sector.seriesIndex = seriesModel.seriesIndex; - - var text = new graphic.Text({ - z2: DEFAULT_TEXT_Z, - silent: node.getModel('label').get('silent') - }); - this.add(sector); - this.add(text); - - this.updateData(true, node, 'normal', seriesModel, ecModel); - - // Hover to change label and labelLine - function onEmphasis() { - text.ignore = text.hoverIgnore; - } - function onNormal() { - text.ignore = text.normalIgnore; +class SunburstPiece extends graphic.Group { + + node: TreeNode + + private _seriesModel: SunburstSeriesModel + private _ecModel: GlobalModel + + constructor(node: TreeNode, seriesModel: SunburstSeriesModel, ecModel: GlobalModel) { + super(); + + var sector = new graphic.Sector({ + z2: DEFAULT_SECTOR_Z + }); + (sector as ECElement).seriesIndex = seriesModel.seriesIndex; + + var text = new graphic.Text({ + z2: DEFAULT_TEXT_Z, + silent: node.getModel().get(['label', 'silent']) + }); + this.add(sector); + this.add(text); + + this.updateData(true, node, 'normal', seriesModel, ecModel); + + // Hover to change label and labelLine + // FIXME + // function onEmphasis() { + // text.ignore = text.hoverIgnore; + // } + // function onNormal() { + // text.ignore = text.normalIgnore; + // } + // this.on('emphasis', onEmphasis) + // .on('normal', onNormal) + // .on('mouseover', onEmphasis) + // .on('mouseout', onNormal); } - this.on('emphasis', onEmphasis) - .on('normal', onNormal) - .on('mouseover', onEmphasis) - .on('mouseout', onNormal); -} - -var SunburstPieceProto = SunburstPiece.prototype; -SunburstPieceProto.updateData = function ( - firstCreate, - node, - state, - seriesModel, - ecModel -) { - this.node = node; - node.piece = this; + updateData( + firstCreate: boolean, + node: TreeNode, + state: 'emphasis' | 'normal' | 'highlight' | 'downplay', + seriesModel?: SunburstSeriesModel, + ecModel?: GlobalModel + ) { + this.node = node; + (node as DrawTreeNode).piece = this; - seriesModel = seriesModel || this._seriesModel; - ecModel = ecModel || this._ecModel; + seriesModel = seriesModel || this._seriesModel; + ecModel = ecModel || this._ecModel; - var sector = this.childAt(0); - sector.dataIndex = node.dataIndex; + var sector = this.childAt(0) as graphic.Sector; + (sector as ECElement).dataIndex = node.dataIndex; - var itemModel = node.getModel(); - var layout = node.getLayout(); - // if (!layout) { - // console.log(node.getLayout()); - // } - var sectorShape = zrUtil.extend({}, layout); - sectorShape.label = null; + var itemModel = node.getModel(); + var layout = node.getLayout(); + // if (!layout) { + // console.log(node.getLayout()); + // } + var sectorShape = zrUtil.extend({}, layout); + sectorShape.label = null; - var visualColor = getNodeColor(node, seriesModel, ecModel); + var visualColor = getNodeColor(node, seriesModel, ecModel); - fillDefaultColor(node, seriesModel, visualColor); + fillDefaultColor(node, seriesModel, visualColor); - var normalStyle = itemModel.getModel('itemStyle').getItemStyle(); - var style; - if (state === 'normal') { - style = normalStyle; - } - else { - var stateStyle = itemModel.getModel(state + '.itemStyle') - .getItemStyle(); - style = zrUtil.merge(stateStyle, normalStyle); - } - style = zrUtil.defaults( - { - lineJoin: 'bevel', - fill: style.fill || visualColor - }, - style - ); - - if (firstCreate) { - sector.setShape(sectorShape); - sector.shape.r = layout.r0; - graphic.updateProps( - sector, + var normalStyle = itemModel.getModel('itemStyle').getItemStyle(); + var style; + if (state === 'normal') { + style = normalStyle; + } + else { + var stateStyle = itemModel.getModel([state, 'itemStyle']) + .getItemStyle(); + style = zrUtil.merge(stateStyle, normalStyle); + } + style = zrUtil.defaults( { - shape: { - r: layout.r - } + lineJoin: 'bevel', + fill: style.fill || visualColor }, - seriesModel, - node.dataIndex + style ); - sector.useStyle(style); - } - else if (typeof style.fill === 'object' && style.fill.type - || typeof sector.style.fill === 'object' && sector.style.fill.type - ) { - // Disable animation for gradient since no interpolation method - // is supported for gradient - graphic.updateProps(sector, { - shape: sectorShape - }, seriesModel); - sector.useStyle(style); - } - else { - graphic.updateProps(sector, { - shape: sectorShape, - style: style - }, seriesModel); - } - this._updateLabel(seriesModel, visualColor, state); + if (firstCreate) { + sector.setShape(sectorShape); + sector.shape.r = layout.r0; + graphic.updateProps( + sector, + { + shape: { + r: layout.r + } + }, + seriesModel, + node.dataIndex + ); + sector.useStyle(style); + } + else if (typeof style.fill === 'object' && style.fill.type + || typeof sector.style.fill === 'object' && sector.style.fill.type + ) { + // Disable animation for gradient since no interpolation method + // is supported for gradient + graphic.updateProps(sector, { + shape: sectorShape + }, seriesModel); + sector.useStyle(style); + } + else { + graphic.updateProps(sector, { + shape: sectorShape, + style: style + }, seriesModel); + } - var cursorStyle = itemModel.getShallow('cursor'); - cursorStyle && sector.attr('cursor', cursorStyle); + this._updateLabel(seriesModel, visualColor, state); - if (firstCreate) { - var highlightPolicy = seriesModel.getShallow('highlightPolicy'); - this._initEvents(sector, node, seriesModel, highlightPolicy); - } + var cursorStyle = itemModel.getShallow('cursor'); + cursorStyle && sector.attr('cursor', cursorStyle); - this._seriesModel = seriesModel || this._seriesModel; - this._ecModel = ecModel || this._ecModel; -}; + if (firstCreate) { + var highlightPolicy = seriesModel.getShallow('highlightPolicy'); + this._initEvents(sector, node, seriesModel, highlightPolicy); + } -SunburstPieceProto.onEmphasis = function (highlightPolicy) { - var that = this; - this.node.hostTree.root.eachNode(function (n) { - if (n.piece) { - if (that.node === n) { - n.piece.updateData(false, n, 'emphasis'); - } - else if (isNodeHighlighted(n, that.node, highlightPolicy)) { - n.piece.childAt(0).trigger('highlight'); - } - else if (highlightPolicy !== NodeHighlightPolicy.NONE) { - n.piece.childAt(0).trigger('downplay'); + this._seriesModel = seriesModel || this._seriesModel; + this._ecModel = ecModel || this._ecModel; + } + + onEmphasis(highlightPolicy: AllPropTypes) { + var that = this; + this.node.hostTree.root.eachNode(function (n: DrawTreeNode) { + if (n.piece) { + if (that.node === n) { + n.piece.updateData(false, n, 'emphasis'); + } + else if (isNodeHighlighted(n, that.node, highlightPolicy)) { + n.piece.childAt(0).trigger('highlight'); + } + else if (highlightPolicy !== NodeHighlightPolicy.NONE) { + n.piece.childAt(0).trigger('downplay'); + } } - } - }); -}; + }); + } -SunburstPieceProto.onNormal = function () { - this.node.hostTree.root.eachNode(function (n) { - if (n.piece) { - n.piece.updateData(false, n, 'normal'); - } - }); -}; - -SunburstPieceProto.onHighlight = function () { - this.updateData(false, this.node, 'highlight'); -}; - -SunburstPieceProto.onDownplay = function () { - this.updateData(false, this.node, 'downplay'); -}; - -SunburstPieceProto._updateLabel = function (seriesModel, visualColor, state) { - var itemModel = this.node.getModel(); - var normalModel = itemModel.getModel('label'); - var labelModel = state === 'normal' || state === 'emphasis' - ? normalModel - : itemModel.getModel(state + '.label'); - var labelHoverModel = itemModel.getModel('emphasis.label'); - - var text = zrUtil.retrieve( - seriesModel.getFormattedLabel( - this.node.dataIndex, state, null, null, 'label' - ), - this.node.name - ); - if (getLabelAttr('show') === false) { - text = ''; + onNormal() { + this.node.hostTree.root.eachNode(function (n: DrawTreeNode) { + if (n.piece) { + n.piece.updateData(false, n, 'normal'); + } + }); } - var layout = this.node.getLayout(); - var labelMinAngle = labelModel.get('minAngle'); - if (labelMinAngle == null) { - labelMinAngle = normalModel.get('minAngle'); + onHighlight() { + this.updateData(false, this.node, 'highlight'); } - labelMinAngle = labelMinAngle / 180 * Math.PI; - var angle = layout.endAngle - layout.startAngle; - if (labelMinAngle != null && Math.abs(angle) < labelMinAngle) { - // Not displaying text when angle is too small - text = ''; + + onDownplay() { + this.updateData(false, this.node, 'downplay'); } - var label = this.childAt(1); + _updateLabel( + seriesModel: SunburstSeriesModel, + visualColor: ColorString, + state: 'emphasis' | 'normal' | 'highlight' | 'downplay' + ) { + var itemModel = this.node.getModel(); + var normalModel = itemModel.getModel('label'); + var labelModel = state === 'normal' || state === 'emphasis' + ? normalModel + : itemModel.getModel([state, 'label']); + var labelHoverModel = itemModel.getModel(['emphasis', 'label']); + + var text = zrUtil.retrieve( + seriesModel.getFormattedLabel( + this.node.dataIndex, state, null, null, 'label' + ), + this.node.name + ); + if (getLabelAttr('show') === false) { + text = ''; + } - graphic.setLabelStyle( - label.style, label.hoverStyle || {}, normalModel, labelHoverModel, - { - defaultText: labelModel.getShallow('show') ? text : null, - autoColor: visualColor, - useInsideStyle: true + var layout = this.node.getLayout(); + var labelMinAngle = labelModel.get('minAngle'); + if (labelMinAngle == null) { + labelMinAngle = normalModel.get('minAngle'); } - ); - - var midAngle = (layout.startAngle + layout.endAngle) / 2; - var dx = Math.cos(midAngle); - var dy = Math.sin(midAngle); - - var r; - var labelPosition = getLabelAttr('position'); - var labelPadding = getLabelAttr('distance') || 0; - var textAlign = getLabelAttr('align'); - if (labelPosition === 'outside') { - r = layout.r + labelPadding; - textAlign = midAngle > Math.PI / 2 ? 'right' : 'left'; - } - else { - if (!textAlign || textAlign === 'center') { - r = (layout.r + layout.r0) / 2; - textAlign = 'center'; + labelMinAngle = labelMinAngle / 180 * Math.PI; + var angle = layout.endAngle - layout.startAngle; + if (labelMinAngle != null && Math.abs(angle) < labelMinAngle) { + // Not displaying text when angle is too small + text = ''; } - else if (textAlign === 'left') { - r = layout.r0 + labelPadding; - if (midAngle > Math.PI / 2) { - textAlign = 'right'; + + var label = this.childAt(1) as graphic.Text; + + graphic.setLabelStyle( + label.style, label.hoverStyle || {}, normalModel, labelHoverModel, + { + defaultText: labelModel.getShallow('show') ? text : null, + autoColor: visualColor, + useInsideStyle: true } + ); + + var midAngle = (layout.startAngle + layout.endAngle) / 2; + var dx = Math.cos(midAngle); + var dy = Math.sin(midAngle); + + var r; + var labelPosition = getLabelAttr('position'); + var labelPadding = getLabelAttr('distance') || 0; + var textAlign = getLabelAttr('align'); + if (labelPosition === 'outside') { + r = layout.r + labelPadding; + textAlign = midAngle > Math.PI / 2 ? 'right' : 'left'; } - else if (textAlign === 'right') { - r = layout.r - labelPadding; - if (midAngle > Math.PI / 2) { - textAlign = 'left'; + else { + if (!textAlign || textAlign === 'center') { + r = (layout.r + layout.r0) / 2; + textAlign = 'center'; + } + else if (textAlign === 'left') { + r = layout.r0 + labelPadding; + if (midAngle > Math.PI / 2) { + textAlign = 'right'; + } + } + else if (textAlign === 'right') { + r = layout.r - labelPadding; + if (midAngle > Math.PI / 2) { + textAlign = 'left'; + } } } - } - label.attr('style', { - text: text, - textAlign: textAlign, - textVerticalAlign: getLabelAttr('verticalAlign') || 'middle', - opacity: getLabelAttr('opacity') - }); - - var textX = r * dx + layout.cx; - var textY = r * dy + layout.cy; - label.attr('position', [textX, textY]); - - var rotateType = getLabelAttr('rotate'); - var rotate = 0; - if (rotateType === 'radial') { - rotate = -midAngle; - if (rotate < -Math.PI / 2) { - rotate += Math.PI; + label.attr('style', { + text: text, + textAlign: textAlign, + textVerticalAlign: getLabelAttr('verticalAlign') || 'middle', + opacity: getLabelAttr('opacity') + }); + + var textX = r * dx + layout.cx; + var textY = r * dy + layout.cy; + label.attr('position', [textX, textY]); + + var rotateType = getLabelAttr('rotate'); + var rotate = 0; + if (rotateType === 'radial') { + rotate = -midAngle; + if (rotate < -Math.PI / 2) { + rotate += Math.PI; + } } - } - else if (rotateType === 'tangential') { - rotate = Math.PI / 2 - midAngle; - if (rotate > Math.PI / 2) { - rotate -= Math.PI; + else if (rotateType === 'tangential') { + rotate = Math.PI / 2 - midAngle; + if (rotate > Math.PI / 2) { + rotate -= Math.PI; + } + else if (rotate < -Math.PI / 2) { + rotate += Math.PI; + } } - else if (rotate < -Math.PI / 2) { - rotate += Math.PI; + else if (typeof rotateType === 'number') { + rotate = rotateType * Math.PI / 180; } - } - else if (typeof rotateType === 'number') { - rotate = rotateType * Math.PI / 180; - } - label.attr('rotation', rotate); + label.attr('rotation', rotate); - function getLabelAttr(name) { - var stateAttr = labelModel.get(name); - if (stateAttr == null) { - return normalModel.get(name); - } - else { - return stateAttr; + type LabelOption = SunburstSeriesNodeOption['label'] + function getLabelAttr(name: T): LabelOption[T] { + var stateAttr = labelModel.get(name); + if (stateAttr == null) { + return normalModel.get(name); + } + else { + return stateAttr; + } } } -}; -SunburstPieceProto._initEvents = function ( - sector, - node, - seriesModel, - highlightPolicy -) { - sector.off('mouseover').off('mouseout').off('emphasis').off('normal'); - - var that = this; - var onEmphasis = function () { - that.onEmphasis(highlightPolicy); - }; - var onNormal = function () { - that.onNormal(); - }; - var onDownplay = function () { - that.onDownplay(); - }; - var onHighlight = function () { - that.onHighlight(); - }; - - if (seriesModel.isAnimationEnabled()) { - sector - .on('mouseover', onEmphasis) - .on('mouseout', onNormal) - .on('emphasis', onEmphasis) - .on('normal', onNormal) - .on('downplay', onDownplay) - .on('highlight', onHighlight); + _initEvents( + sector: graphic.Sector, + node: TreeNode, + seriesModel: SunburstSeriesModel, + highlightPolicy: SunburstSeriesOption['highlightPolicy'] + ) { + sector.off('mouseover').off('mouseout').off('emphasis').off('normal'); + + var that = this; + var onEmphasis = function () { + that.onEmphasis(highlightPolicy); + }; + var onNormal = function () { + that.onNormal(); + }; + var onDownplay = function () { + that.onDownplay(); + }; + var onHighlight = function () { + that.onHighlight(); + }; + + if (seriesModel.isAnimationEnabled()) { + sector + .on('mouseover', onEmphasis) + .on('mouseout', onNormal) + .on('emphasis', onEmphasis) + .on('normal', onNormal) + .on('downplay', onDownplay) + .on('highlight', onHighlight); + } } -}; -zrUtil.inherits(SunburstPiece, graphic.Group); +} + export default SunburstPiece; /** * Get node color - * - * @param {TreeNode} node the node to get color - * @param {module:echarts/model/Series} seriesModel series - * @param {module:echarts/model/Global} ecModel echarts defaults */ -function getNodeColor(node, seriesModel, ecModel) { +function getNodeColor( + node: TreeNode, + seriesModel: SunburstSeriesModel, + ecModel: GlobalModel +) { // Color from visualMap var visualColor = node.getVisual('color'); var visualMetaList = node.getVisual('visualMeta'); @@ -366,7 +381,7 @@ function getNodeColor(node, seriesModel, ecModel) { } // Self color or level color - var color = node.getModel('itemStyle').get('color'); + var color = node.getModel().get(['itemStyle', 'color']); if (color) { return color; } @@ -392,7 +407,7 @@ function getNodeColor(node, seriesModel, ecModel) { * @param {TreeNode} node current node * @return {number} index in root */ -function getRootId(node) { +function getRootId(node: TreeNode) { var ancestor = node; while (ancestor.depth > 1) { ancestor = ancestor.parentNode; @@ -402,7 +417,11 @@ function getRootId(node) { return zrUtil.indexOf(virtualRoot.children, ancestor); } -function isNodeHighlighted(node, activeNode, policy) { +function isNodeHighlighted( + node: TreeNode, + activeNode: TreeNode, + policy: AllPropTypes +) { if (policy === NodeHighlightPolicy.NONE) { return false; } @@ -418,7 +437,7 @@ function isNodeHighlighted(node, activeNode, policy) { } // Fix tooltip callback function params.color incorrect when pick a default color -function fillDefaultColor(node, seriesModel, color) { +function fillDefaultColor(node: TreeNode, seriesModel: SunburstSeriesModel, color: ZRColor) { var data = seriesModel.getData(); data.setItemVisual(node.dataIndex, 'color', color); } diff --git a/src/chart/sunburst/SunburstSeries.ts b/src/chart/sunburst/SunburstSeries.ts index 82a8d69fd35542cd21f1bb20e2f59cc02e1132eb..72e6345cb4ac01f3cb938c8b998c0447c023fbe5 100644 --- a/src/chart/sunburst/SunburstSeries.ts +++ b/src/chart/sunburst/SunburstSeries.ts @@ -17,23 +17,140 @@ * under the License. */ -// @ts-nocheck - import * as zrUtil from 'zrender/src/core/util'; import SeriesModel from '../../model/Series'; -import Tree from '../../data/Tree'; +import Tree, { TreeNode } from '../../data/Tree'; import {wrapTreePathInfo} from '../helper/treeHelper'; +import { + SeriesOption, + CircleLayoutOptionMixin, + LabelOption, + ItemStyleOption, + OptionDataValue, + CallbackDataParams +} from '../../util/types'; +import GlobalModel from '../../model/Global'; + +interface SunburstLabelOption extends Omit { + rotate?: 'radial' | 'tangential' | number + minAngle?: number + silent?: boolean +} + +interface SunburstDataParams extends CallbackDataParams { + treePathInfo: { + name: string, + dataIndex: number + value: SunburstSeriesNodeOption['value'] + }[] +} -export default SeriesModel.extend({ +export interface SunburstSeriesNodeOption { + name?: string - type: 'series.sunburst', + nodeClick?: 'rootToNode' | 'link' + // Available when nodeClick is link + link?: string + target?: string + + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + emphasis?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } + highlight?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } + downplay?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } + + value?: OptionDataValue | OptionDataValue[] + + children?: SunburstSeriesNodeOption[] + + collapsed?: boolean + + cursor?: string +} +export interface SunburstSeriesLevelOption { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + emphasis?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } + highlight?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } + downplay?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } +} +export interface SunburstSeriesOption extends SeriesOption, CircleLayoutOptionMixin { + clockwise?: boolean + startAngle?: number + minAngle?: number /** - * @type {module:echarts/data/Tree~Node} + * If still show when all data zero. */ - _viewRoot: null, + stillShowZeroSum?: boolean + /** + * Policy of highlighting pieces when hover on one + * Valid values: 'none' (for not downplay others), 'descendant', + * 'ancestor', 'self' + */ + highlightPolicy?: 'descendant' | 'ancestor' | 'self' + + nodeClick?: 'rootToNode' | 'link' + + renderLabelForZeroData?: boolean + + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + emphasis?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } + highlight?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } + downplay?: { + itemStyle?: ItemStyleOption + label?: SunburstLabelOption + } + + levels?: SunburstSeriesLevelOption[] - getInitialData: function (option, ecModel) { + animationType?: 'expansion' | 'scale' + + sort?: 'desc' | 'asc' | ((a: TreeNode, b: TreeNode) => number) +} + +interface SunburstSeriesModel { + getFormattedLabel( + dataIndex: number, + state?: 'emphasis' | 'normal' | 'highlight' | 'downplay', + dataType?: string, + dimIndex?: number, + labelProp?: string + ): string +} +class SunburstSeriesModel extends SeriesModel { + + static readonly type = 'series.sunburst' + readonly type = SunburstSeriesModel.type + + private _viewRoot: TreeNode + + getInitialData(option: SunburstSeriesOption, ecModel: GlobalModel) { // Create a virtual root. var root = { name: option.name, children: option.data }; @@ -43,33 +160,33 @@ export default SeriesModel.extend({ // levels = option.levels = setDefault(levels, ecModel); - var treeOption = {}; - - treeOption.levels = levels; + var treeOption = { + levels: levels + }; // Make sure always a new tree is created when setOption, // in TreemapView, we check whether oldTree === newTree // to choose mappings approach among old shapes and new shapes. return Tree.createTree(root, this, treeOption).data; - }, + } - optionUpdated: function () { + optionUpdated() { this.resetViewRoot(); - }, + } /* * @override */ - getDataParams: function (dataIndex) { - var params = SeriesModel.prototype.getDataParams.apply(this, arguments); + getDataParams(dataIndex: number) { + var params = super.getDataParams.apply(this, arguments as any) as SunburstDataParams; var node = this.getData().tree.getNodeByDataIndex(dataIndex); - params.treePathInfo = wrapTreePathInfo(node, this); + params.treePathInfo = wrapTreePathInfo(node, this); return params; - }, + } - defaultOption: { + defaultOption: SunburstSeriesOption = { zlevel: 0, z: 2, @@ -82,8 +199,6 @@ export default SeriesModel.extend({ // 最小角度改为0 minAngle: 0, - percentPrecision: 2, - // If still show when all data zero. stillShowZeroSum: true, @@ -107,8 +222,7 @@ export default SeriesModel.extend({ align: 'center', position: 'inside', distance: 5, - silent: true, - emphasis: {} + silent: true }, itemStyle: { borderWidth: 1, @@ -118,12 +232,15 @@ export default SeriesModel.extend({ shadowColor: 'rgba(0, 0, 0, 0.2)', shadowOffsetX: 0, shadowOffsetY: 0, - opacity: 1, - emphasis: {}, - highlight: { + opacity: 1 + }, + highlight: { + itemStyle: { opacity: 1 - }, - downplay: { + } + }, + downplay: { + itemStyle: { opacity: 0.9 } }, @@ -150,16 +267,13 @@ export default SeriesModel.extend({ * } */ sort: 'desc' - }, + } - getViewRoot: function () { + getViewRoot() { return this._viewRoot; - }, + } - /** - * @param {module:echarts/data/Tree~Node} [viewRoot] - */ - resetViewRoot: function (viewRoot) { + resetViewRoot(viewRoot?: TreeNode) { viewRoot ? (this._viewRoot = viewRoot) : (viewRoot = this._viewRoot); @@ -172,14 +286,11 @@ export default SeriesModel.extend({ this._viewRoot = root; } } -}); +} -/** - * @param {Object} dataNode - */ -function completeTreeValue(dataNode) { +function completeTreeValue(dataNode: SunburstSeriesNodeOption) { // Postorder travel tree. // If value of none-leaf node is not set, // calculate it by suming up the value of all children. @@ -190,12 +301,12 @@ function completeTreeValue(dataNode) { completeTreeValue(child); var childValue = child.value; + // TODO First value of array must be a number zrUtil.isArray(childValue) && (childValue = childValue[0]); - - sum += childValue; + sum += childValue as number; }); - var thisValue = dataNode.value; + var thisValue = dataNode.value as number; if (zrUtil.isArray(thisValue)) { thisValue = thisValue[0]; } @@ -212,3 +323,8 @@ function completeTreeValue(dataNode) { ? (dataNode.value[0] = thisValue) : (dataNode.value = thisValue); } + + +SeriesModel.registerClass(SunburstSeriesModel); + +export default SunburstSeriesModel; \ No newline at end of file diff --git a/src/chart/sunburst/SunburstView.ts b/src/chart/sunburst/SunburstView.ts index fc37018e18ce0f4584a2b468045aec7c8a5691ad..48249f00b2a52d0c8dfbcec98b2a6dcbc9adb96f 100644 --- a/src/chart/sunburst/SunburstView.ts +++ b/src/chart/sunburst/SunburstView.ts @@ -17,40 +17,59 @@ * under the License. */ -// @ts-nocheck - import * as zrUtil from 'zrender/src/core/util'; import ChartView from '../../view/Chart'; import SunburstPiece from './SunburstPiece'; import DataDiffer from '../../data/DataDiffer'; +import SunburstSeriesModel, { SunburstSeriesNodeOption } from './SunburstSeries'; +import GlobalModel from '../../model/Global'; +import ExtensionAPI from '../../ExtensionAPI'; +import { TreeNode } from '../../data/Tree'; + +const ROOT_TO_NODE_ACTION = 'sunburstRootToNode'; -var ROOT_TO_NODE_ACTION = 'sunburstRootToNode'; +interface DrawTreeNode extends TreeNode { + parentNode: DrawTreeNode + piece: SunburstPiece + children: DrawTreeNode[] +} +class SunburstView extends ChartView { -var SunburstView = ChartView.extend({ + static readonly type = 'sunburst' + readonly type = SunburstView.type - type: 'sunburst', + seriesModel: SunburstSeriesModel + api: ExtensionAPI + ecModel: GlobalModel - init: function () { - }, + virtualPiece: SunburstPiece - render: function (seriesModel, ecModel, api, payload) { - var that = this; + private _oldChildren: DrawTreeNode[] + + render( + seriesModel: SunburstSeriesModel, + ecModel: GlobalModel, + api: ExtensionAPI, + // @ts-ignore + payload + ) { + var self = this; this.seriesModel = seriesModel; this.api = api; this.ecModel = ecModel; var data = seriesModel.getData(); - var virtualRoot = data.tree.root; + var virtualRoot = data.tree.root as DrawTreeNode; - var newRoot = seriesModel.getViewRoot(); + var newRoot = seriesModel.getViewRoot() as DrawTreeNode; var group = this.group; var renderLabelForZeroData = seriesModel.get('renderLabelForZeroData'); - var newChildren = []; - newRoot.eachNode(function (node) { + var newChildren: DrawTreeNode[] = []; + newRoot.eachNode(function (node: DrawTreeNode) { newChildren.push(node); }); var oldChildren = this._oldChildren || []; @@ -77,7 +96,7 @@ var SunburstView = ChartView.extend({ this._oldChildren = newChildren; - function dualTravel(newChildren, oldChildren) { + function dualTravel(newChildren: DrawTreeNode[], oldChildren: DrawTreeNode[]) { if (newChildren.length === 0 && oldChildren.length === 0) { return; } @@ -88,19 +107,19 @@ var SunburstView = ChartView.extend({ .remove(zrUtil.curry(processNode, null)) .execute(); - function getKey(node) { + function getKey(node: DrawTreeNode) { return node.getId(); } - function processNode(newId, oldId) { - var newNode = newId == null ? null : newChildren[newId]; - var oldNode = oldId == null ? null : oldChildren[oldId]; + function processNode(newIdx: number, oldIdx?: number) { + var newNode = newIdx == null ? null : newChildren[newIdx]; + var oldNode = oldIdx == null ? null : oldChildren[oldIdx]; doRenderNode(newNode, oldNode); } } - function doRenderNode(newNode, oldNode) { + function doRenderNode(newNode: DrawTreeNode, oldNode: DrawTreeNode) { if (!renderLabelForZeroData && newNode && !newNode.getValue()) { // Not render data with value 0 newNode = null; @@ -136,7 +155,7 @@ var SunburstView = ChartView.extend({ } } - function removeNode(node) { + function removeNode(node: DrawTreeNode) { if (!node) { return; } @@ -147,63 +166,55 @@ var SunburstView = ChartView.extend({ } } - function renderRollUp(virtualRoot, viewRoot) { + function renderRollUp(virtualRoot: DrawTreeNode, viewRoot: DrawTreeNode) { if (viewRoot.depth > 0) { // Render - if (that.virtualPiece) { + if (self.virtualPiece) { // Update - that.virtualPiece.updateData( + self.virtualPiece.updateData( false, virtualRoot, 'normal', seriesModel, ecModel); } else { // Add - that.virtualPiece = new SunburstPiece( + self.virtualPiece = new SunburstPiece( virtualRoot, seriesModel, ecModel ); - group.add(that.virtualPiece); + group.add(self.virtualPiece); } - if (viewRoot.piece._onclickEvent) { - viewRoot.piece.off('click', viewRoot.piece._onclickEvent); - } - var event = function (e) { - that._rootToNode(viewRoot.parentNode); - }; - viewRoot.piece._onclickEvent = event; - that.virtualPiece.on('click', event); + viewRoot.piece.off('click'); + self.virtualPiece.on('click', function (e) { + self._rootToNode(viewRoot.parentNode); + }); } - else if (that.virtualPiece) { + else if (self.virtualPiece) { // Remove - group.remove(that.virtualPiece); - that.virtualPiece = null; + group.remove(self.virtualPiece); + self.virtualPiece = null; } } - }, - - dispose: function () { - }, + } /** * @private */ - _initEvents: function () { - var that = this; - - var event = function (e) { + _initEvents() { + this.group.off('click'); + this.group.on('click', (e) => { var targetFound = false; - var viewRoot = that.seriesModel.getViewRoot(); - viewRoot.eachNode(function (node) { + var viewRoot = this.seriesModel.getViewRoot(); + viewRoot.eachNode((node: DrawTreeNode) => { if (!targetFound && node.piece && node.piece.childAt(0) === e.target ) { - var nodeClick = node.getModel().get('nodeClick'); + var nodeClick = node.getModel().get('nodeClick'); if (nodeClick === 'rootToNode') { - that._rootToNode(node); + this._rootToNode(node); } else if (nodeClick === 'link') { - var itemModel = node.getModel(); + var itemModel = node.getModel(); var link = itemModel.get('link'); if (link) { var linkTarget = itemModel.get('target', true) @@ -214,19 +225,13 @@ var SunburstView = ChartView.extend({ targetFound = true; } }); - }; - - if (this.group._onclickEvent) { - this.group.off('click', this.group._onclickEvent); - } - this.group.on('click', event); - this.group._onclickEvent = event; - }, + }); + } /** * @private */ - _rootToNode: function (node) { + _rootToNode(node: DrawTreeNode) { if (node !== this.seriesModel.getViewRoot()) { this.api.dispatchAction({ type: ROOT_TO_NODE_ACTION, @@ -235,12 +240,12 @@ var SunburstView = ChartView.extend({ targetNode: node }); } - }, + } /** * @implement */ - containPoint: function (point, seriesModel) { + containPoint(point: number[], seriesModel: SunburstSeriesModel) { var treeRoot = seriesModel.getData(); var itemLayout = treeRoot.getItemLayout(0); if (itemLayout) { @@ -251,6 +256,9 @@ var SunburstView = ChartView.extend({ } } -}); +} + + +ChartView.registerClass(SunburstView); export default SunburstView; diff --git a/src/chart/sunburst/sunburstAction.ts b/src/chart/sunburst/sunburstAction.ts index 9b4cb2ff3d77d804f2db610cda42bbf417523293..c24c22bf2ef958b6df0ba0e66c163f7aeb689934 100644 --- a/src/chart/sunburst/sunburstAction.ts +++ b/src/chart/sunburst/sunburstAction.ts @@ -17,27 +17,30 @@ * under the License. */ -// @ts-nocheck - /** * @file Sunburst action */ import * as echarts from '../../echarts'; import * as helper from '../helper/treeHelper'; +import SunburstSeriesModel from './SunburstSeries'; +import { Payload } from '../../util/types'; +import GlobalModel from '../../model/Global'; var ROOT_TO_NODE_ACTION = 'sunburstRootToNode'; +interface SunburstRootToNodePayload extends Payload {} + echarts.registerAction( {type: ROOT_TO_NODE_ACTION, update: 'updateView'}, - function (payload, ecModel) { + function (payload: SunburstRootToNodePayload, ecModel: GlobalModel) { ecModel.eachComponent( {mainType: 'series', subType: 'sunburst', query: payload}, handleRootToNode ); - function handleRootToNode(model, index) { + function handleRootToNode(model: SunburstSeriesModel, index: number) { var targetInfo = helper .retrieveTargetInfo(payload, [ROOT_TO_NODE_ACTION], model); @@ -53,19 +56,20 @@ echarts.registerAction( } ); - var HIGHLIGHT_ACTION = 'sunburstHighlight'; +interface SunburstHighlightPayload extends Payload {} + echarts.registerAction( {type: HIGHLIGHT_ACTION, update: 'updateView'}, - function (payload, ecModel) { + function (payload: SunburstHighlightPayload, ecModel: GlobalModel) { ecModel.eachComponent( {mainType: 'series', subType: 'sunburst', query: payload}, handleHighlight ); - function handleHighlight(model, index) { + function handleHighlight(model: SunburstSeriesModel, index: number) { var targetInfo = helper .retrieveTargetInfo(payload, [HIGHLIGHT_ACTION], model); @@ -79,16 +83,18 @@ echarts.registerAction( var UNHIGHLIGHT_ACTION = 'sunburstUnhighlight'; +interface SunburstUnhighlightPayload extends Payload {} + echarts.registerAction( {type: UNHIGHLIGHT_ACTION, update: 'updateView'}, - function (payload, ecModel) { + function (payload: SunburstUnhighlightPayload, ecModel: GlobalModel) { ecModel.eachComponent( {mainType: 'series', subType: 'sunburst', query: payload}, handleUnhighlight ); - function handleUnhighlight(model, index) { + function handleUnhighlight(model: SunburstSeriesModel, index: number) { payload.unhighlight = true; } } diff --git a/src/chart/sunburst/sunburstLayout.ts b/src/chart/sunburst/sunburstLayout.ts index cdbe94f228b29d5db6b73e81e461fd95ec311af9..a3a723a0aed57e2d7563321879db033e52a6e359 100644 --- a/src/chart/sunburst/sunburstLayout.ts +++ b/src/chart/sunburst/sunburstLayout.ts @@ -17,16 +17,22 @@ * under the License. */ -// @ts-nocheck - import { parsePercent } from '../../util/number'; import * as zrUtil from 'zrender/src/core/util'; +import GlobalModel from '../../model/Global'; +import ExtensionAPI from '../../ExtensionAPI'; +import SunburstSeriesModel, { SunburstSeriesNodeOption, SunburstSeriesOption } from './SunburstSeries'; +import { TreeNode } from '../../data/Tree'; // var PI2 = Math.PI * 2; var RADIAN = Math.PI / 180; -export default function (seriesType, ecModel, api, payload) { - ecModel.eachSeriesByType(seriesType, function (seriesModel) { +export default function ( + seriesType: 'sunburst', + ecModel: GlobalModel, + api: ExtensionAPI +) { + ecModel.eachSeriesByType(seriesType, function (seriesModel: SunburstSeriesModel) { var center = seriesModel.get('center'); var radius = seriesModel.get('radius'); @@ -59,10 +65,10 @@ export default function (seriesType, ecModel, api, payload) { var validDataCount = 0; zrUtil.each(treeRoot.children, function (child) { - !isNaN(child.getValue()) && validDataCount++; + !isNaN(child.getValue() as number) && validDataCount++; }); - var sum = treeRoot.getValue(); + var sum = treeRoot.getValue() as number; // Sum may be 0 var unitRadian = Math.PI / (sum || validDataCount) * 2; @@ -84,7 +90,7 @@ export default function (seriesType, ecModel, api, payload) { * Render a tree * @return increased angle */ - var renderNode = function (node, startAngle) { + var renderNode = function (node: TreeNode, startAngle: number) { if (!node) { return; } @@ -94,7 +100,7 @@ export default function (seriesType, ecModel, api, payload) { // Render self if (node !== virtualRoot) { // Tree node is virtual, so it doesn't need to be drawn - var value = node.getValue(); + var value = node.getValue() as number; var angle = (sum === 0 && stillShowZeroSum) ? unitRadian : (value * unitRadian); @@ -113,11 +119,15 @@ export default function (seriesType, ecModel, api, payload) { var rStart = r0 + rPerLevel * depth; var rEnd = r0 + rPerLevel * (depth + 1); - var itemModel = node.getModel(); + var itemModel = node.getModel(); + // @ts-ignore. TODO this is not provided to developer yet. Rename it. if (itemModel.get('r0') != null) { + // @ts-ignore rStart = parsePercent(itemModel.get('r0'), size / 2); } + // @ts-ignore if (itemModel.get('r') != null) { + // @ts-ignore rEnd = parsePercent(itemModel.get('r'), size / 2); } @@ -169,19 +179,16 @@ export default function (seriesType, ecModel, api, payload) { /** * Init node children by order and update visual - * - * @param {TreeNode} node root node - * @param {boolean} isAsc if is in ascendant order */ -function initChildren(node, isAsc) { +function initChildren(node: TreeNode, sortOrder?: SunburstSeriesOption['sort']) { var children = node.children || []; - node.children = sort(children, isAsc); + node.children = sort(children, sortOrder); // Init children recursively if (children.length) { zrUtil.each(node.children, function (child) { - initChildren(child, isAsc); + initChildren(child, sortOrder); }); } } @@ -193,14 +200,14 @@ function initChildren(node, isAsc) { * @param {string | function | null} sort sort method * See SunburstSeries.js for details. */ -function sort(children, sortOrder) { +function sort(children: TreeNode[], sortOrder: SunburstSeriesOption['sort']) { if (typeof sortOrder === 'function') { return children.sort(sortOrder); } else { var isAsc = sortOrder === 'asc'; return children.sort(function (a, b) { - var diff = (a.getValue() - b.getValue()) * (isAsc ? 1 : -1); + var diff = ((a.getValue() as number) - (b.getValue() as number)) * (isAsc ? 1 : -1); return diff === 0 ? (a.dataIndex - b.dataIndex) * (isAsc ? -1 : 1) : diff; diff --git a/src/chart/tree/TreeSeries.ts b/src/chart/tree/TreeSeries.ts index 29df9f9e59775a89b0164c21530f172f76ca3089..2fc938396e3f98a616222122ca87130dc4d8eab1 100644 --- a/src/chart/tree/TreeSeries.ts +++ b/src/chart/tree/TreeSeries.ts @@ -41,9 +41,6 @@ interface CurveLineStyleOption extends LineStyleOption{ export interface TreeSeriesNodeOption extends SymbolOptionMixin { name?: string - /** - * Item style of leave nodes - */ itemStyle?: ItemStyleOption /** * Line style of the edge between node and it's parent. diff --git a/src/chart/treemap/helper.ts b/src/chart/treemap/helper.ts index 346a03fbbe4cf9fabcfadc331360b9e99fd73b13..bd3b334f63894846273965cb478241051ab92b51 100644 --- a/src/chart/treemap/helper.ts +++ b/src/chart/treemap/helper.ts @@ -19,8 +19,6 @@ // @ts-nocheck -import * as zrUtil from 'zrender/src/core/util'; - export function retrieveTargetInfo(payload, seriesModel) { if (payload && ( @@ -39,38 +37,4 @@ export function retrieveTargetInfo(payload, seriesModel) { return {node: targetNode}; } } -} - -// Not includes the given node at the last item. -export function getPathToRoot(node) { - var path = []; - while (node) { - node = node.parentNode; - node && path.push(node); - } - return path.reverse(); -} - -export function aboveViewRoot(viewRoot, node) { - var viewPath = getPathToRoot(viewRoot); - return zrUtil.indexOf(viewPath, node) >= 0; -} - -// From root to the input node (the input node will be included). -export function wrapTreePathInfo(node, seriesModel) { - var treePathInfo = []; - - while (node) { - var nodeDataIndex = node.dataIndex; - treePathInfo.push({ - name: node.name, - dataIndex: nodeDataIndex, - value: seriesModel.getRawValue(nodeDataIndex) - }); - node = node.parentNode; - } - - treePathInfo.reverse(); - - return treePathInfo; -} +} \ No newline at end of file diff --git a/src/data/Tree.ts b/src/data/Tree.ts index 77619592e57dcfb3d1ad0ab2750d162af6142a29..b583cb52b95da70dbc4e93caee664c7bd2b4ca0a 100644 --- a/src/data/Tree.ts +++ b/src/data/Tree.ts @@ -204,9 +204,9 @@ export class TreeNode { return this.hostTree.data.getItemLayout(this.dataIndex); } - // TODO: TYPE Same type with Model#getModel getModel(): Model - getModel(path: S): Model + // @depcrecated + // getModel(path: S): Model getModel(path?: string): Model { if (this.dataIndex < 0) { return; diff --git a/src/model/Series.ts b/src/model/Series.ts index 27f2de6644d637bff667ba243532db3f5f046fc7..ba16bc7696be6beccd45b6980c679a96d99cdb2b 100644 --- a/src/model/Series.ts +++ b/src/model/Series.ts @@ -424,7 +424,7 @@ class SeriesModel extends ComponentMode var data = this.getData(); var tooltipDims = data.mapDimension('defaultedTooltip', true); var tooltipDimLen = tooltipDims.length; - var value = this.getRawValue(dataIndex); + var value = this.getRawValue(dataIndex) as any; var isValueArr = zrUtil.isArray(value); var color = data.getItemVisual(dataIndex, 'color') as ZRColor; diff --git a/src/model/mixin/dataFormat.ts b/src/model/mixin/dataFormat.ts index 3ccaa2ff80b95b397a82d494a8ef7471dbe7d3c3..4ead1a7022ea62c7bcf8aeab35fadcfa9badd557 100644 --- a/src/model/mixin/dataFormat.ts +++ b/src/model/mixin/dataFormat.ts @@ -147,7 +147,7 @@ class DataFormatMixin { getRawValue( idx: number, dataType?: string - ) { + ): unknown { return retrieveRawValue(this.getData(dataType), idx); } diff --git a/src/util/types.ts b/src/util/types.ts index a8b38d79babcfb271b5755d7e09f1dd991359a02..75a34af7aef91c876871e22b8bf2eab4962db587 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -715,6 +715,8 @@ export interface TextCommonOption extends ShadowOptionMixin { // @deprecated baseline?: VerticalAlign + opacity?: number + lineHeight?: number backgroundColor?: ColorString | { image: ImageLike