Skip to content

Commit

Permalink
feat: add auto mark (#5585)
Browse files Browse the repository at this point in the history
* feat: add auto mark

* fix: update auto mark

* fix: ci

* feat: remove autolib from stdlib

* fix(ci): build

---------

Co-authored-by: xuxinyue.xxy <xuxinyue.xxy@antgroup.com>
Co-authored-by: MiniPear <pearminipro@gmail.com>
  • Loading branch information
3 people committed Sep 28, 2023
1 parent dbbedfe commit 01c52a6
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 11 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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';
import { Auto } from '../../../src/mark/auto';

export function AutoMark(): G2Spec {
return {
type: Auto,
data: {
type: 'fetch',
value: 'data/alphabet.csv',
},
};
}
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
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/mark';

describe('autolib', () => {
it('autolib() should returns expected autolib components.', () => {
expect(autolib()).toEqual({
'mark.auto': Auto,
});
});
});
1 change: 1 addition & 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
9 changes: 1 addition & 8 deletions bundle/g2.std.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
corelib,
plotlib,
graphlib,
geolib,
stdlib,
threedlib,
} from '../src/lib';
import { corelib, plotlib, graphlib, geolib, stdlib } from '../src/lib';
import { extend, Runtime } from '../src/api';
import { API, CompositionAPI } from '../src/api/extend';
import { G2Spec } from '../src/spec';
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test:unit": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/unit/ --coverage -i --logHeapUsage",
"test:integration": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/integration/ --coverage -i --logHeapUsage",
"preview": "vite preview",
"build:umd": "rimraf ./dist && rollup -c && npm run size",
"build:umd": "rimraf ./dist && node --expose-gc --max-old-space-size=4096 node_modules/rollup/dist/bin/rollup -c && npm run size",
"build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
"build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm",
"build": "run-p build:*",
Expand All @@ -56,6 +56,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 Down Expand Up @@ -90,7 +91,9 @@
"@antv/g-webgl": "^1.9.8",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^17.4.4",
"@optimize-lodash/rollup-plugin": "^4.0.3",
"@rollup/plugin-commonjs": "^21.0.2",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-terser": "^0.4.3",
"@types/d3-array": "3.0.5",
Expand Down
9 changes: 7 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import terser from '@rollup/plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';

const isBundleVis = !!process.env.BUNDLE_VIS;

Expand All @@ -21,7 +23,8 @@ export default [
treeshake: {
preset: 'smallest',
// Set `src/exports` as a sideEffects file.
moduleSideEffects: (id, external) => id.includes('src/exports.ts') ? true : false,
moduleSideEffects: (id, external) =>
id.includes('src/exports.ts') ? true : false,
},
output: [
{
Expand All @@ -39,8 +42,10 @@ export default [
typescript({
useTsconfigDeclarationDir: true,
}),
optimizeLodashImports(),
json(),
terser(),
],
context: 'window', // Disable 'THIS_IS_UNDEFINED' warnings
}))
})),
];
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;
}
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';
22 changes: 22 additions & 0 deletions src/mark/auto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Advisor } from '@antv/ava';
import { deepMix } from '@antv/util';

export const Auto = (options) => {
const chartAdvisor = new Advisor();
const {
data,
dataProps,
fields,
options: o,
colorOptions,
...rest
} = options;
const results = chartAdvisor.advise({
data,
dataProps,
fields,
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
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 @@ -391,3 +394,4 @@ export type HeatmapMark = BaseMark<'heatmap'>;
export type LiquidMark = BaseMark<'liquid'>;

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

0 comments on commit 01c52a6

Please sign in to comment.