Skip to content

Commit ae3b9af

Browse files
feat: update code comment (#832)
* build: remove unused files * docs: add comment * Update packages/ava/src/advisor/advisor.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update packages/ava/package.json Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 9b8ed53 commit ae3b9af

7 files changed

Lines changed: 119 additions & 63 deletions

File tree

packages/ava/.fatherrc.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import fatherConfig from '../../.fatherrc';
21
import path from 'path';
2+
import { defineConfig } from 'father';
33

4-
export default fatherConfig('ts', 'AVA', {
4+
export default defineConfig({
5+
umd: {
6+
name: 'AVA',
7+
output: 'dist',
8+
},
59
alias: {
610
'@ava': path.resolve(__dirname, 'src'),
11+
'@ava/advisor-deprecated': path.resolve(__dirname, 'src/advisor-deprecated'),
712
'@advisor': path.resolve(__dirname, 'src/advisor'),
13+
'@advisor-deprecated': path.resolve(__dirname, 'src/advisor-deprecated'),
14+
'@ava/insight': path.resolve(__dirname, 'src/insight'),
815
}
916
});

packages/ava/package.json

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
{
22
"name": "@antv/ava",
33
"version": "4.0.0-alpha.0",
4-
"description": "A framework for automated visual analytics.",
5-
"author": {
6-
"name": "AntV",
7-
"url": "https://antv.antgroup.com/"
8-
},
9-
"homepage": "https://ava.antv.antgroup.com",
10-
"repository": {
11-
"type": "git",
12-
"url": "https://github.com/antvis/AVA/tree/master/packages/ava"
13-
},
4+
"description": "A framework for AI driven Visual Analytics.",
145
"sideEffects": false,
156
"keywords": [
7+
"antv",
8+
"ava",
9+
"ai",
10+
"visual-analytics",
1611
"visualization",
1712
"augmented-analytics",
1813
"insight"
1914
],
20-
"license": "MIT",
21-
"publishConfig": {
22-
"access": "public"
23-
},
2415
"main": "lib/index.js",
2516
"types": "lib/index.d.ts",
2617
"unpkg": "dist/ava.min.js",
@@ -31,21 +22,13 @@
3122
"lib"
3223
],
3324
"scripts": {
34-
"lint": "eslint --ext .js,.jsx,.ts,.tsx './'",
35-
"lint-fix": "npm run lint -- --fix",
36-
"prettier": " prettier --check '**/*' --ignore-path=../../.prettierignore",
37-
"prettier-fix": "npm run prettier -- --write",
38-
"format": "npm run prettier-fix && npm run lint-fix",
39-
"lint-staged": "lint-staged",
4025
"clean": "rimraf lib esm dist",
4126
"build:umd": "father build",
42-
"build:cjs": "rimraf ./lib && tsc -p tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json",
43-
"build:esm": "rimraf ./esm && tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
44-
"build:ntv-schema": "mkdir -p build && ts-json-schema-generator -f tsconfig.json -p src/text/index.ts -t NarrativeTextSpec --no-type-check --no-ref-encode > build/ntv-schema.json",
27+
"build:esm": "rimraf esm && tsc --module esnext --target es6 --outDir ./esm",
28+
"build:cjs": "rimraf lib && tsc --module commonjs --target es6 --outDir ./lib",
4529
"build": "run-p build:*",
4630
"test": "jest",
47-
"coverage": "jest --coverage",
48-
"watch": "yarn module && yarn build --w"
31+
"coverage": "jest --coverage"
4932
},
5033
"lint-staged": {
5134
"*.{ts,tsx}": [
@@ -74,6 +57,7 @@
7457
"@stdlib/types": "^0.0.12",
7558
"@testing-library/jest-dom": "^4.2.4",
7659
"@types/d3-array": "^3.0.1",
60+
"@types/d3-dispatch": "3.0.2",
7761
"@types/jest": "^30.0.0",
7862
"@types/lodash": "^4.14.171",
7963
"@types/numeral": "^2.0.2",
@@ -84,9 +68,22 @@
8468
"npm-run-all": "^4.1.5",
8569
"numeral": "^2.0.6",
8670
"prettier": "^2.4.1",
87-
"rimraf": "^3.0.2",
71+
"rimraf": "^6.1.0",
8872
"ts-json-schema-generator": "^1.1.2",
8973
"tsc-alias": "^1.8.10",
9074
"typescript": "^4.9.3"
75+
},
76+
"author": {
77+
"name": "AntV",
78+
"url": "https://antv.antgroup.com/"
79+
},
80+
"homepage": "https://ava.antv.antgroup.com",
81+
"repository": {
82+
"type": "git",
83+
"url": "https://github.com/antvis/AVA"
84+
},
85+
"license": "MIT",
86+
"publishConfig": {
87+
"access": "public"
9188
}
9289
}

packages/ava/src/advisor/advisor.ts

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,98 @@ import {
99
} from '../types';
1010
import { extractData } from '../data';
1111
import { AdviseChartPipeline } from './advise-chart-pipeline/pipeline';
12-
import { AdviseTextPipeline } from './advise-text-pipeline/pipeline';
1312
import { RENDERER, type Spec } from '../bind';
1413

14+
/**
15+
* The 1st level advisor class.
16+
* Used to extract data, recommend charts, and render charts. All functionalities are AI-driven.
17+
*/
1518
export class Advisor {
1619

17-
config!: AdvisorConfig;
20+
/**
21+
* Configuration for the advisor. Includes LLM settings, chart inclusion/exclusion lists.
22+
*/
23+
private config!: AdvisorConfig;
1824

1925
adviseChartPipeline: BasePipeline<AdviseChartParams>;
2026

21-
adviseTextPipeline: BasePipeline<AdviseTextParams>;
22-
2327
constructor(config: AdvisorConfig = {}) {
2428
this.config = config;
29+
30+
// Initialize pipelines.
2531
this.adviseChartPipeline = new AdviseChartPipeline({
2632
config,
2733
});
28-
this.adviseTextPipeline = new AdviseTextPipeline({
29-
config,
30-
});
3134
}
3235

36+
/**
37+
* Extract data shards from raw data or user query.
38+
*
39+
* Case 1 - User provides a text query, extract relevant data shards:
40+
*
41+
advisor.extract('What is the average age of people who work as engineers?');
42+
*
43+
* Case 2 - User provides a query with raw data:
44+
*
45+
advisor.extract(`帮我可视化以下数据:
46+
城市 类别 渠道 销售额 价格
47+
杭州 体育 A 100 80
48+
北京 体育 A 200 90
49+
上海 体育 B 150 85
50+
广州 体育 B 120 70
51+
深圳 体育 C 180 95
52+
`);
53+
*
54+
* Case 3 - User provides raw data, extract data shards directly:
55+
*
56+
advisor.extract({ type: 'A', value: 2 });
57+
*/
3358
async extract(params: AdviseChartParams) {
3459
const { purpose, data } = params;
3560
const input = purpose ?? data;
3661
const dataShards = await extractData(input, { llmConfig: this.config.llm });
3762
return dataShards;
3863
}
3964

40-
// eslint-disable-next-line no-dupe-class-members
65+
/**
66+
* Advise charts based on the data shards, which are extracted from the `advisor.extract` API.
67+
* This is the core function of the Advisor class, which leverages LLMs to recommend suitable chart types and encodings based on the provided data and user purpose.
68+
*
69+
* const advises = advisor.advise(dataShards);
70+
*/
4171
advise(params: AdviseChartParams): Promise<AdviseStageOutput>;
42-
43-
// eslint-disable-next-line no-dupe-class-members
4472
advise(params: AdviseTextParams): Promise<AdviseText>;
45-
46-
// Actual implementation
47-
// eslint-disable-next-line no-dupe-class-members
4873
async advise(params: AdviseChartParams | AdviseTextParams): Promise<AdviseStageOutput | AdviseText> {
4974
const result = await this.adviseChartPipeline.execute(params as AdviseChartParams);
5075
return result;
51-
// recommend text
52-
// TODO: implement text recommendation
53-
// await this.adviseTextPipeline.execute(params as AdviseTextParams);
54-
// return {} as AdviseText;
5576
}
5677

78+
/**
79+
* Render the chart recommendation spec into a chart dom. We can use different renderers by customizing the renderer.
80+
*
81+
* Case 1 - Using default renderer (AVA built-in):
82+
*
83+
advisor.render({
84+
container: '#chart',
85+
spec: chartSpec,
86+
});
87+
*
88+
* Case 2 - Using custom renderer:
89+
*
90+
const customRenderer: Renderer = (container, spec) => { ... };
91+
bindRenderer(customRenderer);
92+
advisor.render({
93+
container: '#chart',
94+
spec: chartSpec,
95+
});
96+
*
97+
*/
5798
render(params: { container: string; spec: Spec }) {
5899
if (RENDERER) {
59100
const { container, spec } = params;
60101
return RENDERER(container, spec);
61102
}
62-
logError('Chart render not configured');
103+
logError('Chart render not configured, please bind a renderer first, GPT-Vis is recommended.');
63104
return null;
64105
}
65106
}

packages/ava/src/advisor/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { Advisor, bindRenderer } from './advisor';
1+
export { Advisor } from './advisor';

packages/ava/tsconfig.cjs.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/ava/tsconfig.esm.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/ava/tsconfig.json

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
{
2-
"extends": "../../tsconfig.json",
3-
"include": ["./src", "./__tests__"]
2+
"compilerOptions": {
3+
"module": "ESNext",
4+
"target": "es6",
5+
"jsx": "preserve",
6+
"importHelpers": true,
7+
"moduleResolution": "node",
8+
"experimentalDecorators": true,
9+
"declaration": true,
10+
"sourceMap": true,
11+
"allowSyntheticDefaultImports": true,
12+
"esModuleInterop": true,
13+
"isolatedModules": true,
14+
"noEmitOnError": false,
15+
"pretty": true,
16+
"lib": ["dom", "esnext"],
17+
"skipLibCheck": true,
18+
"resolveJsonModule": true,
19+
"baseUrl": ".",
20+
"paths": {
21+
"@antv/ava": ["src/index.ts"],
22+
"@ava/*": ["src/*"],
23+
"@advisor/*": ["src/advisor/*"],
24+
"@ava/advisor-deprecated/*": ["src/advisor-deprecated/*"],
25+
"@ava/insight/*": ["src/insight/*"]
26+
}
27+
},
28+
"include": ["src/**/*"]
429
}

0 commit comments

Comments
 (0)