2.0.5-alpha.0 • Published 2 years ago

@antv/chart-advisor v2.0.5-alpha.0

Weekly downloads
63
License
MIT
Repository
github
Last release
2 years ago

English | 简体中文

A js library for empiric-driven chart recommendation based on visualization rules and chart linter of AVA.

Version NPM downloads

✨ Features

ChartAdvisor contains several tool classes exported for users, including ChartAdvisor, Advisor and Linter.

  • Advisor: is the tool classes for recommending charts automatically.

  • Linter: is the tool classes for providing chart optimization suggestions.

Advisor and Linter provide advise() and lint() functions for chart recommendation and optimization, respectively.

  • ChartAdvisor: is a tool class that contains both chart recommendation and chart optimization abilities.

ChartAdvisor contains both an Advisor and a Linter object, and provides advise() function, compared to Advisor, it provides an additional Lint object as output for providing chart suggestions.

Chart Recommendation

A list of chart configurations is recommended by analyzing the given dataset and analysis requirements. The chart configuration with the highest recommendation is at the top of the list.

Chart Optimization

Given an existing chart configuration, find and optimize problems in the chart based on rules and given requirements. The problem with the highest error score is at the top of the list.

📦 Installation

$ npm install @antv/chart-advisor

🔨 Usage

ChartAdvisor Usage

The ChartAdvisor class provides the advise() method, which can provide automatic chart recommendation and optimization abilities. Its input parameter is AdviseParams and its output is the recommended charts and corresponding optimization suggestions, where the required input is the source data data: any[] and detailed input and output parameters are described in the ChartAdvisor.advise() API

import { Advisor, Linter, ChartAdvisor } from '@antv/chart-advisor';

const defaultData = [
  { price: 100, type: 'A' },
  { price: 120, type: 'B' },
  { price: 150, type: 'C' },
];

const myChartAdvisor = new ChartAdvisor();

const results = myChartAdvisor.advise({ data }),
// [{
//     "type": "pie_chart",
//     "spec": {
//         "basis": {
//             "type": "chart"
//         },
//         "data": {...},
//         "layer": [...]
//     },
//     "score": 1.5535986680617797,
//     "lint": [...]
// }]

// recommend charts
const myAdvisor = new Advisor();
const advices = myAdvisor.advise({data, fields: ['price', 'type'], options: { refine: true }});

// find problems in a chart
const myLinter = new Linter();
const errors = myLt.lint(spec);

Advisor Usage

The Advisor class provides the advise() method, which aimed to provide automatic chart recommendation ability. Its input parameter is AdviseParams and its output is the recommended charts, where the required input is the source data data: any[] and detailed input and output parameters are described in the Advisor.advise() API.

import { Advisor } from '@antv/chart-advisor';

const data = [
  { year: '2007', sales: 28 },
  { year: '2008', sales: 55 },
  { year: '2009', sales: 43 },
  { year: '2010', sales: 91 },
  { year: '2011', sales: 81 },
  { year: '2012', sales: 53 },
  { year: '2013', sales: 19 },
  { year: '2014', sales: 87 },
  { year: '2015', sales: 52 },
];

const myAdvisor = new Advisor();

const advices = myAdvisor.advise({ data });
// [{
//     "type": "line_chart",
//     "spec": {
//         "basis": {
//             "type": "chart"
//         },
//         "data": {...},
//         "layer": [...]
//     },
//     "score": 2
// }]

Linter Usage

The Linter class provides the Linter() method, which can provide automatic chart optimization suggestions. Its input parameter is LintParams and its output is the recommended optimization suggestions, where the required input is the input chart schema spec: AntVSpec and detailed input and output parameters are described in the Linter.Linter() API

import { Linter } from '@antv/chart-advisor';

const spec = {
  basis: {
    type: 'chart',
  },
  data: {
    type: 'json-array',
    values: [...],
  },
  layer: [...],
};

const myLinter = new Linter();

const problems = myLinter.lint({ spec })
// [{
//     "type": "SOFT",
//     "id": "diff-pie-sector",
//     "score": 0.3752209678037489,
//     "docs": {
//         "lintText": "Difference should be big enough for pie sectors."
//     }
// }]

📖 Documentation

For more usages, please check the API Reference

Contribution

We welcome all contributions. Please read General Contribution Guide first.

You can submit any ideas as Pull Requests or as GitHub Issues. Let's build a better AVA together.

License

MIT

2.0.4

2 years ago

2.0.5-alpha.0

2 years ago

2.0.4-alpha.0

2 years ago

2.0.4-beta.0

2 years ago

2.0.3

3 years ago

2.1.0-alpha.1

3 years ago

2.1.0-alpha.0

3 years ago

2.0.0-alpha.0

3 years ago

2.0.0-alpha.1

3 years ago

2.0.0-alpha.2

3 years ago

2.0.0

3 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.4-alhpa.2

4 years ago

1.1.4-beta.2

4 years ago

1.1.4-alpha.1

4 years ago

1.1.4-alpha.0

4 years ago

1.1.4-beta.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1-beta.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.1.3-beta.7

4 years ago

0.1.3-beta.6

4 years ago

0.1.3-beta.5

5 years ago

0.1.3-beta.4

5 years ago

0.1.3-beta.2

5 years ago

0.1.3-alpha.31

5 years ago

0.1.3-alpha.30

5 years ago

0.1.3-alpha.28

5 years ago

0.1.3-alpha.27

5 years ago

0.1.3-alpha.26

5 years ago

0.1.3-alpha.22

5 years ago

0.1.3-alpha.24

5 years ago

0.1.3-alpha.23

5 years ago

0.1.3-alpha.25

5 years ago

0.1.3-alpha.21

5 years ago

0.1.3-alpha.20

5 years ago

0.1.3-alpha.19

5 years ago

0.1.3-alpha.18

5 years ago

0.1.3-alpha.17

5 years ago

0.0.2-alpha.17

5 years ago

0.0.2-alpha.16

5 years ago

0.1.2-alpha.19

5 years ago

0.1.2-alpha.18

5 years ago

0.1.2-alpha.17

5 years ago

0.1.2-alpha.16

5 years ago

0.1.2-alpha.15

5 years ago

0.1.2-alpha.14

5 years ago

0.1.2-alpha.13

5 years ago

0.1.2-alpha.12

5 years ago

0.1.2-alpha.11

5 years ago

0.1.2-alpha.10

5 years ago

0.1.2-alpha.9

5 years ago

0.1.2-alpha.7

5 years ago

0.1.2-alpha.6

5 years ago

0.1.2-alpha.5

5 years ago

0.1.2-alpha.4

5 years ago

0.1.2-alpha.3

5 years ago

0.1.2-alpha.2

5 years ago

0.1.2-alpha.1

5 years ago

0.1.2-alpha.0

5 years ago