Skip to content

Commit

Permalink
[fix] 修改多要素数据颜色显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
shallowdream218 committed Nov 21, 2023
1 parent 47eb8f6 commit f850ae8
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/common/chart/ChartMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export default {
isShow: {
type: Boolean,
default: true
},
filterCategoryValue: {
type: String,
default: undefined
}
},
data() {
Expand Down Expand Up @@ -555,6 +559,25 @@ export default {
this.datasetChange = false;
// 设置echartOptions
this.echartOptions = this._optionsHandler(echartOptions, options);
this.setSeriesColor();
});
},
setSeriesColor() {
const colorGroup = getMultiColorGroup(this.colorGroupsData, this.colorNumber);
const firstSeriesName = this.echartOptions.series[0].name;
let SeserieNameTag = firstSeriesName.includes('-') ? firstSeriesName.split('-')[1] : firstSeriesName;
let colorIndex = 0;
this.echartOptions.series.forEach(serie => {
const serieName = serie.name.includes('-') ? serie.name.split('-')[1] : serie.name;
if (SeserieNameTag !== serieName) {
SeserieNameTag = serieName;
colorIndex += 1;
}
serie.itemStyle = serie.itemStyle || {};
serie.itemStyle.color = colorGroup[colorIndex];
if (!this.filterCategoryValue) {
serie.name = serieName;
}
});
},
_optionsHandler(options, dataOptions, dataZoomChanged) {
Expand Down
60 changes: 60 additions & 0 deletions src/common/chart/__tests__/ChartMixin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,64 @@ describe('Chart Mixin Component', () => {
expect(wrapper.emitted().click.length).toBe(1);
expect(wrapper.emitted().click[0]).toEqual([params]);
});

it('setSeriesColor', async done => {
const serieItem = {
name: 'sale',
emphasis: {
itemStyle: {}
},
itemStyle: {
barBorderRadius: [0, 15, 15, 0]
},
stack: 0,
type: 'bar',
barWidth: 10,
data: [22, 65, 86, 48, 43, 53, 34, 33, 24]
};
const series = [serieItem];
const options = {
xAxis: yAxis,
yAxis: xAxis,
legend,
series
};
wrapper = factory({
options
});
expect(wrapper.vm.xBar).toBeTruthy();
await wrapper.setProps({
options: {
...options,
series: [
{
...serieItem,
label: {
normal: {
show: true,
position: 'center',
smart: true
}
}
}
]
}
});
expect(wrapper.vm.echartOptions).toStrictEqual(wrapper.vm.parseOptions);
wrapper.vm.setSeriesColor();
expect(wrapper.vm.echartOptions.series[0].itemStyle.color).toEqual('#d53e4f');
done();
});

it('trigger echarts events', () => {
wrapper = factory({
options: optionFactory(),
datasetOptions: datasetOptionsFactory(['bar']),
dataset: geoJSONDataset,
associatedMap: true
}, { localVue });
const chartInstance = wrapper.vm._getEchart();
expect(chartInstance).not.toBeUndefined();
console.log('chartInstance', chartInstance);
});
});

0 comments on commit f850ae8

Please sign in to comment.