Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sunburst): radius in levels #15706

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/chart/sunburst/SunburstSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ export interface SunburstSeriesNodeItemOption extends
}
export interface SunburstSeriesLevelOption
extends SunburstStateOption, StatesOptionMixin<SunburstStateOption, SunburstStatesMixin> {

radius?: (number | string)[]
/**
* @deprecated use radius instead
*/
r?: number | string
/**
* @deprecated use radius instead
*/
r0?: number | string

highlight?: {
itemStyle?: SunburstItemStyleOption
label?: SunburstLabelOption
Expand Down Expand Up @@ -152,16 +163,18 @@ class SunburstSeriesModel extends SeriesModel<SunburstSeriesOption> {
ignoreStyleOnData = true;

private _viewRoot: TreeNode;
private _levelModels: Model<SunburstSeriesLevelOption>[];

getInitialData(option: SunburstSeriesOption, ecModel: GlobalModel) {
// Create a virtual root.
const root = { name: option.name, children: option.data } as SunburstSeriesNodeItemOption;

completeTreeValue(root);

const levelModels = zrUtil.map(option.levels || [], function (levelDefine) {
return new Model(levelDefine, this, ecModel);
}, this);
const levelModels = this._levelModels
= zrUtil.map(option.levels || [], function (levelDefine) {
return new Model(levelDefine, this, ecModel);
}, this);

// Make sure always a new tree is created when setOption,
// in TreemapView, we check whether oldTree === newTree
Expand Down Expand Up @@ -195,6 +208,10 @@ class SunburstSeriesModel extends SeriesModel<SunburstSeriesOption> {
return params;
}

getLevelModel(node: TreeNode) {
return this._levelModels && this._levelModels[node.depth];
}

static defaultOption: SunburstSeriesOption = {
zlevel: 0,
z: 2,
Expand Down
24 changes: 14 additions & 10 deletions src/chart/sunburst/sunburstLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../core/ExtensionAPI';
import SunburstSeriesModel, { SunburstSeriesNodeItemOption, SunburstSeriesOption } from './SunburstSeries';
import { TreeNode } from '../../data/Tree';
import SeriesModel from '../../model/Series';

// let PI2 = Math.PI * 2;
const RADIAN = Math.PI / 180;
Expand Down Expand Up @@ -119,16 +120,19 @@ export default function sunburstLayout(
let rStart = r0 + rPerLevel * depth;
let rEnd = r0 + rPerLevel * (depth + 1);

const itemModel = node.getModel<SunburstSeriesNodeItemOption>();
// @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);
const levelModel = seriesModel.getLevelModel(node);
if (levelModel) {
let r0 = levelModel.get('r0', true);
let r = levelModel.get('r', true);
let radius = levelModel.get('radius', true);

if (radius != null) {
r0 = radius[0];
r = radius[1];
}

(r0 != null) && (rStart = parsePercent(r0, size / 2));
(r != null) && (rEnd = parsePercent(r, size / 2));
}

node.setLayout({
Expand Down