Skip to content

Commit

Permalink
V1 combo bugfix (#1516)
Browse files Browse the repository at this point in the history
  • Loading branch information
lessmost authored Sep 2, 2020
1 parent 16aee80 commit 6a9fbfe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## <small>1.1.26 (2020-09-02)</small>

* fix: 修复双折线中tooltip重复的问题 ([08ec94e](https://github.com/antvis/g2plot/commit/08ec94e))
* fix: 修复双轴图在一侧数据为空时不渲染问题 ([0963377](https://github.com/antvis/g2plot/commit/0963377))

## <small>1.1.25 (2020-08-31)</small>

* docs(waterfall): 修复瀑布图文档, 更新 tooltip 使用方式 (#1492) ([7dbe86a](https://github.com/antvis/g2plot/commit/7dbe86a)), closes [#1492](https://github.com/antvis/g2plot/issues/1492)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g2plot",
"version": "1.1.25",
"version": "1.1.26",
"description": "An interactive and responsive charting library",
"keywords": [
"chart",
Expand Down
15 changes: 14 additions & 1 deletion src/combo/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,16 @@ export default abstract class ComboViewLayer<T extends IComboViewLayer = IComboV
return layer;
}

// 临时修复 v1 双轴图在左侧数据为0的时候右侧scale处理错误的问题
protected getLeftYAxisMax() {
const leftScaleData = this.getScaleData(0);
const rightScaleData = this.getScaleData(1);

return leftScaleData.min == 0 && leftScaleData.max === 0 ? Math.max(rightScaleData.max, 0) : leftScaleData.max;
}

protected yAxis(index: number) {
const leftScaleData = this.getScaleData(0);
const { yAxis } = this.options;
const config = index === 0 ? yAxis.leftConfig : yAxis.rightConfig;
const colorValue = this.colors[index];
Expand Down Expand Up @@ -180,6 +189,10 @@ export default abstract class ComboViewLayer<T extends IComboViewLayer = IComboV
}
const yAxisGlobalConfig = this.getYAxisGlobalConfig();

if (index === 0 && leftScaleData.max === 0 && leftScaleData.min === 0) {
yAxisConfig.max = this.getLeftYAxisMax();
}

return deepMix({}, yAxisGlobalConfig, yAxisConfig);
}

Expand All @@ -193,7 +206,7 @@ export default abstract class ComboViewLayer<T extends IComboViewLayer = IComboV
{},
{
min: 0,
max: leftScaleData.max,
max: this.getLeftYAxisMax(),
nice: true,
values: leftScaleData.values,
},
Expand Down
20 changes: 11 additions & 9 deletions src/combo/dual-line/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { registerPlotType } from '../../base/global';
import ComboViewLayer from '../base';
import { LayerConfig } from '../../base/layer';
import LineLayer from '../../plots/line/layer';
import { clone, deepMix, each } from '@antv/util';
import { clone, deepMix, each, findIndex } from '@antv/util';
import { IValueAxis, ICatAxis, ITimeAxis } from '../../interface/config';
import { ComboViewConfig, LineConfig } from '../util/interface';

Expand Down Expand Up @@ -148,14 +148,16 @@ export default class DualLineLayer<T extends DualLineLayerConfig = DualLineLayer
const originItem = clone(ev.items[0]);
const dataItemsA = this.getDataByXField(ev.title, 0)[0];
if (dataItemsA) {
ev.items.push({
...originItem,
mappingData: deepMix({}, originItem.mappingData, { _origin: dataItemsA }),
data: dataItemsA,
name: yField[0],
value: dataItemsA[yField[0]],
color: this.colors[0],
});
if (findIndex(ev.items, (item: any) => item.name === yField[0]) < 0) {
ev.items.push({
...originItem,
mappingData: deepMix({}, originItem.mappingData, { _origin: dataItemsA }),
data: dataItemsA,
name: yField[0],
value: dataItemsA[yField[0]],
color: this.colors[0],
});
}
}
if (legend.visible) {
each(this.legends, (legend, index) => {
Expand Down

0 comments on commit 6a9fbfe

Please sign in to comment.