Skip to content

Commit

Permalink
feat: add auto mark
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxinyue.xxy committed Sep 22, 2023
1 parent 952f6f9 commit 62733de
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions __tests__/plots/static/auto-mark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { G2Spec } from '../../../src';

export function AutoMark(): G2Spec {
return {
type: 'auto',
data: {
type: 'fetch',
value: 'data/alphabet.csv',
},
smartColor: true,
};
}
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export { aaplIntervalDateEncodeX } from './aapl-interval-date-encode-x';
export { athletesRectBinLegendStyle } from './athletes-rect-bin-legend-style';
export { HeatmapHeatmapBasic } from './heatmap-heatmap-basic';
export { DiamondHeatmapDensity } from './diamond-heatmap-density';
export { AutoMark } from './auto-mark';
export { basicLineNullLabel } from './basic-line-null-label';
export { alphabetIntervalViewStyle } from './alphabet-interval-view-style';
export { vennBasic } from './venn-basic';
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"animation"
],
"dependencies": {
"@antv/ava": "^3.0.7",
"@antv/coord": "^0.4.1",
"@antv/event-emitter": "^0.1.3",
"@antv/g": "^5.18.6",
Expand All @@ -80,6 +81,7 @@
"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
7 changes: 7 additions & 0 deletions src/lib/auto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Auto } from '../mark/auto';

export function autolib() {
return {
'mark.auto': Auto,
} as const;
}
2 changes: 2 additions & 0 deletions src/lib/std.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { corelib } from './core';
import { geolib } from './geo';
import { graphlib } from './graph';
import { plotlib } from './plot';
import { autolib } from './auto';

export function stdlib() {
return {
...geolib(),
...graphlib(),
...plotlib(),
...corelib(),
...autolib(),
} as const;
}
8 changes: 8 additions & 0 deletions src/mark/auto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Advisor } from '@antv/ava';
import { AutoMark } from '../spec';

export const Auto = (options: AutoMark) => {
const chartAdvisor = new Advisor();
const results = chartAdvisor.advise(options);
return results?.[0].spec;
};
4 changes: 4 additions & 0 deletions src/spec/mark.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AdviseParams } from '@antv/ava';
import { MarkComponent } from '../runtime';
import { Encode } from './encode';
import { Transform } from './transform';
Expand All @@ -18,6 +19,7 @@ import {
import { Closeable, Literal2Object, Padding } from './utils';

export type Mark =
| AutoMark
| IntervalMark
| RectMark
| LineMark
Expand Down Expand Up @@ -51,6 +53,7 @@ export type Mark =
| CompositeMark;

export type MarkTypes =
| 'auto'
| 'interval'
| 'rect'
| 'line'
Expand Down Expand Up @@ -389,3 +392,4 @@ export type DensityMark = BaseMark<'density', ChannelTypes | 'series'>;
export type HeatmapMark = BaseMark<'heatmap'>;

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

0 comments on commit 62733de

Please sign in to comment.