Skip to content

Commit 842ef69

Browse files
authored
fir(BarChart): add compatibility check (#415)
1 parent fe747bf commit 842ef69

3 files changed

Lines changed: 18 additions & 59 deletions

File tree

src/components/BarChart/index.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,18 @@ class BarChart {
128128
}
129129
});
130130
}
131-
// 如果存在 dataZoom,提前返回
132-
if (this.baseOption.dataZoom[0].show === true) {
133-
return;
134-
};
135-
// 如果用户自定义了 barWidth,提前返回
136-
if (this.iChartOption.itemStyle?.barWidth) {
137-
return;
138-
}
131+
139132
// 处理用户设置的阈值大于y轴,设置y轴max保证阈值显示
140133
if(iChartOption.markLine){
141134
handleMarkLineMax(baseOption, this.chartInstance, this.iChartOption);
142135
}
143136

144-
145-
if (ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
137+
// 如果用户自定义了 barWidth 或 存在 dataZoom,则不主动刷新柱宽
138+
if (!baseOption.dataZoom?.[0]?.show && !this.iChartOption.itemStyle?.barWidth && ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
146139
updateWidth(baseOption, this.chartInstance, this.iChartOption);
147140
}
148141
// 坐标轴二次计算
149-
AdaptiveRectSys(this.baseOption, this.iChartOption, this.chartInstance, this)
142+
AdaptiveRectSys(baseOption, this.iChartOption, this.chartInstance, this)
150143

151144
}
152145

@@ -162,20 +155,13 @@ class BarChart {
162155
// 坐标轴二次计算
163156
AdaptiveRectSys(this.baseOption, this.iChartOption, this.chartInstance, this)
164157
this.baseOption.legend = legend(this.iChartOption, 'BarChart', this.chartInstance);
165-
callback && callback(this.baseOption, { notMerge: false });
166158
}
167-
// 如果存在 dataZoom,提前返回
168-
if (this.baseOption.dataZoom[0].show === true) {
169-
return;
170-
};
171-
// 如果用户自定义了 barWidth,提前返回
172-
if (this.iChartOption.itemStyle?.barWidth) {
173-
return;
174-
}
175-
if (ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
159+
160+
// 如果用户自定义了 barWidth 或 存在 dataZoom,则不主动刷新柱宽
161+
if (!this.baseOption.dataZoom?.[0]?.show && !this.iChartOption.itemStyle?.barWidth && ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
176162
updateWidth(this.baseOption, this.chartInstance, this.iChartOption);
177-
callback && callback(this.baseOption, { notMerge: false });
178163
}
164+
callback && callback(this.baseOption, { notMerge: false });
179165
}
180166
}
181167

src/components/BarLineChart/index.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,10 @@ class BarLineChart {
107107
});
108108
}
109109
baseOption.series = series;
110-
// 如果存在 dataZoom,提前返回
111-
if (this.baseOption.dataZoom[0].show === true) {
112-
return;
113-
};
114-
// 如果用户自定义了 barWidth,提前返回
115-
if (this.iChartOption.itemStyle?.barWidth) {
116-
return;
117-
}
118-
if (ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
119-
updateWidth(this.baseOption, this.chartInstance, this.iChartOption);
110+
111+
// 如果用户自定义了 barWidth 或 存在 dataZoom,则不主动刷新柱宽
112+
if (!baseOption.dataZoom?.[0]?.show && !this.iChartOption.itemStyle?.barWidth && ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
113+
updateWidth(baseOption, this.chartInstance, this.iChartOption);
120114
}
121115

122116
}
@@ -129,15 +123,8 @@ class BarLineChart {
129123

130124
// 自适应柱条宽度
131125
resize(callback) {
132-
// 如果存在 dataZoom,提前返回
133-
if (this.baseOption.dataZoom[0].show === true) {
134-
return;
135-
};
136-
// 如果用户自定义了 barWidth,提前返回
137-
if (this.iChartOption.itemStyle?.barWidth) {
138-
return;
139-
}
140-
if (ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
126+
// 如果用户自定义了 barWidth 或 存在 dataZoom,则不主动刷新柱宽
127+
if (!this.baseOption.dataZoom?.[0]?.show && !this.iChartOption.itemStyle?.barWidth && ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
141128
updateWidth(this.baseOption, this.chartInstance, this.iChartOption);
142129
callback && callback(this.baseOption, { notMerge: false });
143130
}

src/components/BulletChart/index.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,8 @@ class BulletChart {
5858
// 根据渲染出的结果,二次计算option
5959
updateOptionAgain() {
6060
let baseOption = this.baseOption;
61-
// 如果存在 dataZoom,提前返回
62-
if (this.baseOption.dataZoom[0].show === true) {
63-
return;
64-
};
65-
// 如果用户自定义了 barWidth,提前返回
66-
if (this.iChartOption.itemStyle?.barWidth) {
67-
return;
68-
}
69-
if (ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
61+
// 如果用户自定义了 barWidth 或 存在 dataZoom,则不主动刷新柱宽
62+
if (!baseOption.dataZoom?.[0]?.show && !this.iChartOption.itemStyle?.barWidth && ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
7063
updateWidth(baseOption, this.chartInstance, this.iChartOption);
7164
}
7265
}
@@ -78,15 +71,8 @@ class BulletChart {
7871
setOption() { }
7972

8073
resize(callback) {
81-
// 如果存在 dataZoom,提前返回
82-
if (this.baseOption.dataZoom[0].show === true) {
83-
return;
84-
};
85-
// 如果用户自定义了 barWidth,提前返回
86-
if (this.iChartOption.itemStyle?.barWidth) {
87-
return;
88-
}
89-
if (ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
74+
// 如果用户自定义了 barWidth 或 存在 dataZoom,则不主动刷新柱宽
75+
if (!this.baseOption.dataZoom?.[0]?.show && !this.iChartOption.itemStyle?.barWidth && ADAPTIVE_THEME.includes(this.iChartOption.theme)) {
9076
updateWidth(this.baseOption, this.chartInstance, this.iChartOption);
9177
callback && callback(this.baseOption);
9278
}

0 commit comments

Comments
 (0)