提交 bc012f0f 编写于 作者: P pissang

fix(sunburst): adjust default color strategy

上级 b02066d0
......@@ -118,8 +118,6 @@ class SunburstSeriesModel extends SeriesModel<SunburstSeriesOption> {
private _viewRoot: TreeNode;
useColorPaletteOnData = true;
getInitialData(option: SunburstSeriesOption, ecModel: GlobalModel) {
// Create a virtual root.
const root = { name: option.name, children: option.data };
......
......@@ -20,14 +20,41 @@
import GlobalModel from '../../model/Global';
import SunburstSeriesModel, { SunburstSeriesNodeItemOption } from './SunburstSeries';
import { extend } from 'zrender/src/core/util';
import { Dictionary, ColorString } from '../../util/types';
import { TreeNode } from '../../data/Tree';
import { lift } from 'zrender/src/tool/color';
export default function (ecModel: GlobalModel) {
const paletteScope: Dictionary<ColorString> = {};
// Default color strategy
function pickColor(node: TreeNode, seriesModel: SunburstSeriesModel, treeHeight: number) {
// Choose color from palette based on the first level.
let current = node;
while (current && current.depth > 1) {
current = current.parentNode;
}
let color = seriesModel.getColorFromPalette((current.name || current.dataIndex + ''), paletteScope);
if (node.depth > 1 && typeof color === 'string') {
// Lighter on the deeper level.
color = lift(color, (node.depth - 1) / (treeHeight - 1) * 0.5);
}
return color;
}
ecModel.eachSeriesByType('sunburst', function (seriesModel: SunburstSeriesModel) {
const data = seriesModel.getData();
const tree = data.tree;
tree.eachNode(function (node) {
const model = node.getModel<SunburstSeriesNodeItemOption>();
const style = model.getModel('itemStyle').getItemStyle();
if (!style.fill) {
style.fill = pickColor(node, seriesModel, tree.root.height);
}
const existsStyle = data.ensureUniqueItemVisual(node.dataIndex, 'style');
extend(existsStyle, style);
});
......
......@@ -361,12 +361,6 @@ window.allChartsOptions = [
data: data,
label: {
show: true
},
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}]
};
......@@ -480,10 +474,20 @@ window.allChartsOptions = [
{
series: [{
type: 'sunburst',
label: {
fontSize: 6,
color: '#fff'
},
emphasis: {
label: {
fontSize: 12
}
},
radius: [20, '80%'],
data: [{
name: 'Food',
children: [{
value: 5,
value: 3,
name: 'Fruit',
children: [{
value: 1,
......@@ -494,15 +498,13 @@ window.allChartsOptions = [
children: [{
name: 'Seville Orange',
value: 1
}]
}, {
children: [{
}, {
name: 'Blood Orange',
value: 1
}]
}]
}, {
value: 10,
value: 9,
name: 'Meat',
children: [{
value: 6,
......@@ -528,17 +530,15 @@ window.allChartsOptions = [
value: 1
}]
}, {
children: [{
name: 'Breast',
value: 1
}]
name: 'Breast',
value: 1
}]
}]
}, {
value: 9,
value: 6,
name: 'Drinks',
children: [{
value: 4,
value: 3,
name: 'Wine',
children: [{
name: 'USA',
......@@ -560,12 +560,12 @@ window.allChartsOptions = [
value: 1
}, {
name: 'Orange Juice',
value: 1
value: 2
}]
}]
}]
}, {
value: 7,
value: 6,
name: 'Fashion',
children: [{
name: 'Clothing',
......@@ -598,7 +598,7 @@ window.allChartsOptions = [
name: 'Computers',
children: [{
name: 'Components',
value: 6,
value: 4,
children: [{
name: 'Barebones',
value: 1
......@@ -639,7 +639,7 @@ window.allChartsOptions = [
data: [{
name: 'Food',
children: [{
value: 5,
value: 3,
name: 'Fruit',
children: [{
value: 1,
......@@ -650,15 +650,13 @@ window.allChartsOptions = [
children: [{
name: 'Seville Orange',
value: 1
}]
}, {
children: [{
}, {
name: 'Blood Orange',
value: 1
}]
}]
}, {
value: 10,
value: 8,
name: 'Meat',
children: [{
value: 6,
......@@ -684,17 +682,15 @@ window.allChartsOptions = [
value: 1
}]
}, {
children: [{
name: 'Breast',
value: 1
}]
name: 'Breast',
value: 1
}]
}]
}, {
value: 9,
value: 6,
name: 'Drinks',
children: [{
value: 4,
value: 3,
name: 'Wine',
children: [{
name: 'USA',
......@@ -716,12 +712,12 @@ window.allChartsOptions = [
value: 1
}, {
name: 'Orange Juice',
value: 1
value: 2
}]
}]
}]
}, {
value: 7,
value: 6,
name: 'Fashion',
children: [{
name: 'Clothing',
......@@ -754,7 +750,7 @@ window.allChartsOptions = [
name: 'Computers',
children: [{
name: 'Components',
value: 6,
value: 4,
children: [{
name: 'Barebones',
value: 1
......@@ -909,12 +905,6 @@ window.allChartsOptions = [
series: [
{
type: 'themeRiver',
emphasis: {
itemStyle: {
shadowBlur: 20,
shadowColor: 'rgba(0, 0, 0, 0.8)'
}
},
/* eslint-disable */
data: [['2015/11/08',10,'DQ'],['2015/11/09',15,'DQ'],['2015/11/10',35,'DQ'],
['2015/11/11',38,'DQ'],['2015/11/12',22,'DQ'],['2015/11/13',16,'DQ'],
......@@ -1124,6 +1114,9 @@ window.allChartsOptions = [
series: [{
type: 'custom',
dimensions: ['x', 'y'],
labelLayout: {
hideOverlap: true
},
renderItem: function (params, api) {
var points = [];
for (var i = 0; i < data[params.dataIndex].length;) {
......@@ -1141,6 +1134,21 @@ window.allChartsOptions = [
shape: {
points: points,
},
textContent: {
style: {
text: new Intl.DateTimeFormat('en-US', {
year: '2-digit', month: '2-digit', day: '2-digit',
hour: 'numeric', minute: 'numeric', second: 'numeric'
}).format(new Date(rawData[params.dataIndex].wall_time)),
align: 'left',
verticalAlign: 'bottom'
},
x: points[0][0],
y: points[0][1],
},
textConfig: {
position: null
},
style: api.style({
stroke: '#005',
lineWidth: 1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册