Skip to content

Commit

Permalink
feat: support stackInverse for waterfall chart
Browse files Browse the repository at this point in the history
  • Loading branch information
xuefei1313 committed Feb 11, 2025
1 parent 3a09d67 commit 0872295
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/vchart/__tests__/runtime/browser/index.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
*/

// import VChart from '../../../src';
import './index.page.local';
import './index.page.local.ts';
// window['VChart'] = VChart;
3 changes: 2 additions & 1 deletion packages/vchart/src/data/transforms/waterfall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface IWaterfallOpt {
increase: string;
decrease: string;
};
stackInverse: boolean;
groupData: () => DataView;
}

Expand Down Expand Up @@ -77,7 +78,7 @@ export const waterfall = (lastData: Array<Datum>, op: IWaterfallOpt) => {
negative: temp.end
};

const indexData = dimensionData[key];
const indexData = op.stackInverse === true ? dimensionData[key].reverse() : dimensionData[key];
indexData?.forEach((d, i) => {
if (i === indexData.length - 1) {
d[STACK_FIELD_TOTAL_TOP] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const tickAlign = (data: Array<Datum>, op: ITickAlignOpt) => {
// make the tickData of the current axis consistent with the tickData of the target axis
const newTicks: number[] = targetData.map((d: { value: number }) => {
const percent = (d.value - targetDomain[0]) / targetRange;
return currentRange * percent + currentDomain[0];
return Math.round(currentRange * percent + currentDomain[0]);
});
return convertDomainToTickData(newTicks);
};
6 changes: 4 additions & 2 deletions packages/vchart/src/series/waterfall/waterfall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export class WaterfallSeries<T extends IWaterfallSeriesSpec = IWaterfallSeriesSp
valueField: this.getStackValueField(),
seriesField: this.getSeriesField(),
seriesFieldName: this._theme.seriesFieldName,
total: this._spec.total
total: this._spec.total,
stackInverse: this.getRegion().getStackInverse()
}
},
false
Expand All @@ -123,7 +124,8 @@ export class WaterfallSeries<T extends IWaterfallSeriesSpec = IWaterfallSeriesSp
startAs: STACK_FIELD_START,
endAs: STACK_FIELD_END,
total: this._spec.total,
groupData: () => this.getGroups().groupData
groupData: () => this.getGroups().groupData,
stackInverse: this.getRegion().getStackInverse()
}
},
false
Expand Down

0 comments on commit 0872295

Please sign in to comment.