Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(histogram): 直方图支持动态 changedata #2199

Merged
merged 2 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/unit/plots/histogram/change-data-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ describe('Histogram: change data', () => {
expect(histogram.chart.options.tooltip.title).toBe('hello wold!');
histogram.changeData(histogramData);
expect(histogram.chart.getData().length).toBe(12);
expect(histogram.options.data).toEqual(histogramData);
expect(histogram.chart.geometries[0].elements.length).toBe(12);

histogram.destroy();
});
Expand Down
8 changes: 8 additions & 0 deletions src/plots/histogram/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Plot } from '../../core/plot';
import { deepAssign } from '../../utils';
import { Adaptor } from '../../core/adaptor';
import { binHistogram } from '../../utils/transform/histogram';
import { HistogramOptions } from './types';
import { adaptor } from './adaptor';

Expand All @@ -10,6 +11,13 @@ export class Histogram extends Plot<HistogramOptions> {
/** 图表类型 */
public type: string = 'histogram';

public changeData(data: HistogramOptions['data']) {
this.updateOption({ data });

const { binField, binNumber, binWidth, stackField } = this.options;
this.chart.changeData(binHistogram(data, binField, binWidth, binNumber, stackField));
}

protected getDefaultOptions() {
return deepAssign({}, super.getDefaultOptions(), {
// @ts-ignore
Expand Down