Skip to content

Commit 663496d

Browse files
authored
fix(BulletChart): modify the symbolSize when the orient is horizontal (#264)
1 parent fe04e8c commit 663496d

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

public/option/BulletChart/BulletChart-2.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const option = {
2-
theme: 'light',
3-
padding: [30, 80, 50, 20],
4-
data: [
2+
theme: 'light',
3+
padding: [30, 80, 50, 20],
4+
data: [
55
{ 'Month': '一月', 'Score': 400 },
66
{ 'Month': '二月', 'Score': 500, },
7-
{ 'Month': '三月', 'Score': 900,},
7+
{ 'Month': '三月', 'Score': 900, },
88
{ 'Month': '四月', 'Score': 700 },
99
{ 'Month': '五月', 'Score': 800 },
1010
{ 'Month': '六月', 'Score': 500 },
@@ -25,18 +25,17 @@ const option = {
2525
markLine: {
2626
data: 800,
2727
name: 'info',
28-
symbolSize: [2, 32],
2928
},
3029
background: [{
3130
name: 'error',
3231
data: 100,
33-
},{
32+
}, {
3433
name: 'warning',
3534
data: 200,
36-
},{
35+
}, {
3736
name: 'subwarning',
3837
data: 300,
39-
},{
38+
}, {
4039
name: 'success',
4140
data: 400,
4241
}]

src/components/BulletChart/handleSeries.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { isArray } from '../../util/type';
1616
import Token from '../../feature/token';
1717

1818
// 设置背景色颜色
19-
function handleSetColor(data,opacity) {
19+
function handleSetColor(data, opacity) {
2020
const { colorState } = Token.config
2121
const stateColorGroup = {
2222
info: colorState.colorInfo,
@@ -25,25 +25,25 @@ function handleSetColor(data,opacity) {
2525
subwarning: colorState.colorWarning,
2626
success: colorState.colorSuccess,
2727
};
28-
28+
2929
let backgroundColor;
30-
if(data.color) {
30+
if (data.color) {
3131
backgroundColor = data.color
3232
} else {
33-
backgroundColor = stateColorGroup[data.name] ? codeToRGB(stateColorGroup[data.name],opacity) : ''
33+
backgroundColor = stateColorGroup[data.name] ? codeToRGB(stateColorGroup[data.name], opacity) : ''
3434
}
3535
return backgroundColor;
3636
}
3737

38-
function handleLabel(barData,iChartOpt,baseOpt) {
38+
function handleLabel(barData, iChartOpt, baseOpt) {
3939
const label = iChartOpt.label;
4040
const { colorBoard } = Token.config;
4141
const orange = colorBoard.orange.colorOrange40;
4242
const green = colorBoard.green.colorGreen40;
4343
let labelOption = label;
4444
if (labelOption && labelOption.show) {
4545
let showLabelArr = [];
46-
barData.forEach((item,index) => {
46+
barData.forEach((item, index) => {
4747
let markLineNum = isArray(iChartOpt.markLine.data) ? iChartOpt.markLine.data[index] : iChartOpt.markLine.data;
4848
let showLabel = Math.round((item - markLineNum) / markLineNum * 100);
4949
showLabelArr.push(showLabel);
@@ -54,35 +54,37 @@ function handleLabel(barData,iChartOpt,baseOpt) {
5454
position: 'top',
5555
data: showLabelArr,
5656
axisLabel: {
57-
show:true,
57+
show: true,
5858
fontSize: chartToken.fontSize,
59-
formatter: (value)=>{
59+
formatter: (value) => {
6060
return value + '%'
6161
},
62-
color: (value)=>{
62+
color: (value) => {
6363
return value >= 0 ? green : orange;
6464
}
6565
},
6666
axisLine: {
67-
show:false
67+
show: false
6868
},
6969
axisTick: {
70-
show:false
70+
show: false
7171
},
7272
}
7373
baseOpt.xAxis.push(categoryX);
7474
}
7575
}
7676

77-
export function handleSeries(baseOpt, iChartOpt, legendData ,seriesData) {
77+
export function handleSeries(baseOpt, iChartOpt, legendData, seriesData) {
7878
const series = [];
7979
const barWidth = iChartOpt.itemStyle?.barWidth ? iChartOpt.itemStyle.barWidth : chartToken.barWidth;
8080
const backgroundWidth = iChartOpt.itemStyle?.backgroundWidth ? iChartOpt.itemStyle.backgroundWidth : chartToken.barBgWidth;
8181
const barData = seriesData[legendData[0]];
8282
const radius = chartToken.borderRadius;
8383
let borderRadius = [radius, radius, 0, 0];
84-
if(iChartOpt.direction === 'horizontal') {
84+
let symbolSize = iChartOpt.markLine.symbolSize ? iChartOpt.markLine.symbolSize : [backgroundWidth, 2];
85+
if (iChartOpt.direction === 'horizontal') {
8586
borderRadius = [0, radius, radius, 0];
87+
symbolSize = iChartOpt.markLine.symbolSize ? iChartOpt.markLine.symbolSize : [2, backgroundWidth]
8688
}
8789

8890
const barObj = {
@@ -98,35 +100,35 @@ export function handleSeries(baseOpt, iChartOpt, legendData ,seriesData) {
98100
}
99101
}
100102
// 设置图例
101-
handleLabel(barData,iChartOpt,baseOpt);
103+
handleLabel(barData, iChartOpt, baseOpt);
102104
const markLineData = isArray(iChartOpt.markLine.data) ? iChartOpt.markLine.data : iChartOpt.data.map(() => { return iChartOpt.markLine.data });
103105
// 设置阈值
104106
const scatterObj = {
105107
type: 'scatter',
106108
symbol: 'rect',
107109
silent: true,
108-
symbolSize: iChartOpt.markLine.symbolSize ? iChartOpt.markLine.symbolSize : [backgroundWidth, 2],
110+
symbolSize: symbolSize,
109111
symbolOffset: iChartOpt.markLine.symbolOffset ? iChartOpt.markLine.symbolOffset : [0, 0],
110112
z: 20,
111113
data: markLineData,
112-
color: iChartOpt.markLine.color ? iChartOpt.markLine.color : handleSetColor(iChartOpt.markLine,1),
114+
color: iChartOpt.markLine.color ? iChartOpt.markLine.color : handleSetColor(iChartOpt.markLine, 1),
113115
emphasis: {
114116
scale: false
115117
}
116118
}
117119
// 设置柱子背景
118-
if(iChartOpt.background) {
120+
if (iChartOpt.background) {
119121
iChartOpt.background.forEach(item => {
120122
const rectData = isArray(item.data) ? item.data : iChartOpt.data.map(() => { return item.data });
121123
let totalData = {
122124
type: 'bar',
123125
barWidth: backgroundWidth,
124126
stack: 'total',
125127
data: rectData,
126-
color: iChartOpt.theme.indexOf('dark')!== -1 ? handleSetColor(item,0.3) : handleSetColor(item,0.15),
128+
color: iChartOpt.theme.indexOf('dark') !== -1 ? handleSetColor(item, 0.3) : handleSetColor(item, 0.15),
127129
barGap: 0
128130
}
129-
if(iChartOpt.direction === 'horizontal') {
131+
if (iChartOpt.direction === 'horizontal') {
130132
totalData.yAxisIndex = 1;
131133
} else {
132134
totalData.xAxisIndex = 1;
@@ -136,9 +138,9 @@ export function handleSeries(baseOpt, iChartOpt, legendData ,seriesData) {
136138
let xaxisData = {
137139
type: 'category',
138140
show: false,
139-
axisLine: { show : false },
140-
axisTick: { show : false },
141-
axisLabel: { show : false },
141+
axisLine: { show: false },
142+
axisTick: { show: false },
143+
axisLabel: { show: false },
142144
}
143145
xaxisData.data = baseOpt.xAxis[0].data;
144146
baseOpt.xAxis.push(xaxisData);

0 commit comments

Comments
 (0)