Skip to content

Commit

Permalink
fix: update auto mark
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxinyue.xxy committed Sep 22, 2023
1 parent 424f9c6 commit 233a3d9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 deletions.
2 changes: 2 additions & 0 deletions __tests__/plots/static/auto-mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export function AutoMark(): G2Spec {
smartColor: true,
};
}

AutoMark.skip = true;
10 changes: 10 additions & 0 deletions __tests__/unit/lib/auto.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { autolib } from '../../../src/lib';
import { Auto } from '../../../src';

describe('autolib', () => {
it('autolib() should returns expected autolib components.', () => {
expect(autolib()).toEqual({
'mark.auto': Auto,
});
});
});
2 changes: 2 additions & 0 deletions __tests__/unit/lib/std.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
Density as DensityGeometry,
Heatmap,
Liquid,
Auto,
} from '../../../src/mark';
import { Category10, Category20 } from '../../../src/palette';
import {
Expand Down Expand Up @@ -260,6 +261,7 @@ describe('stdlib', () => {
'mark.gauge': Gauge,
'mark.liquid': Liquid,
'mark.heatmap': Heatmap,
'mark.auto': Auto,
'palette.category10': Category10,
'palette.category20': Category20,
'scale.linear': Linear,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"pdfast": "^0.2.0"
},
"devDependencies": {
"@antv/ava": "^3.0.7",
"@antv/data-set": "^0.11.8",
"@antv/g-plugin-3d": "^1.9.5",
"@antv/g-plugin-control": "^1.9.5",
Expand Down
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { plotlib } from './plot';
export { threedlib } from './threed';
export { stdlib } from './std';
export { litelib } from './lite';
export { autolib } from './auto';
24 changes: 20 additions & 4 deletions src/mark/auto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import { Advisor } from '@antv/ava';
import { AutoMark } from '../spec';
import { deepMix } from '@antv/util';

export const Auto = (options: AutoMark) => {
export const Auto = (options) => {
const chartAdvisor = new Advisor();
const results = chartAdvisor.advise(options);
return results?.[0].spec;
const {
data,
dataProps,
fields,
smartColor,
options: o,
colorOptions,
...rest
} = options;
const results = chartAdvisor.advise({
data,
dataProps,
fields,
smartColor,
options: o,
colorOptions,
});
return deepMix({}, rest, results?.[0].spec);
};
1 change: 1 addition & 0 deletions src/mark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export { Gauge } from './gauge';
export { Density } from './density';
export { Heatmap } from './heatmap';
export { Liquid } from './liquid';
export { Auto } from './auto';

export type { IntervalOptions } from './interval';
export type { RectOptions } from './rect';
Expand Down
2 changes: 1 addition & 1 deletion src/spec/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,4 @@ export type HeatmapMark = BaseMark<'heatmap'>;
export type LiquidMark = BaseMark<'liquid'>;

export type CustomMark = BaseMark<MarkComponent, ChannelTypes>;
export type AutoMark = { type: 'auto' } & AdviseParams;
export type AutoMark = BaseMark<'auto'> & AdviseParams;

0 comments on commit 233a3d9

Please sign in to comment.