├── ci.opts
├── src
├── themes
│ └── index.js
├── shared
│ ├── index.js
│ ├── prop.js
│ └── util.js
├── components
│ ├── Axis
│ │ └── index.jsx
│ ├── Coord
│ │ └── index.jsx
│ ├── Tooltip
│ │ └── index.jsx
│ ├── Facet
│ │ └── index.jsx
│ ├── Geom
│ │ └── index.jsx
│ ├── TypedGeom
│ │ ├── Area
│ │ │ └── index.jsx
│ │ ├── Edge
│ │ │ └── index.jsx
│ │ ├── Line
│ │ │ └── index.jsx
│ │ ├── Path
│ │ │ └── index.jsx
│ │ ├── Point
│ │ │ └── index.jsx
│ │ ├── Venn
│ │ │ └── index.jsx
│ │ ├── Schema
│ │ │ └── index.jsx
│ │ ├── Heatmap
│ │ │ └── index.jsx
│ │ ├── Interval
│ │ │ └── index.jsx
│ │ ├── Polygon
│ │ │ └── index.jsx
│ │ ├── index.jsx
│ │ └── generateTypedGeom.jsx
│ ├── index.js
│ ├── ErrorBoundary
│ │ └── index.jsx
│ ├── Legend
│ │ └── index.jsx
│ ├── Guide
│ │ └── index.jsx
│ ├── Chart
│ │ ├── empty.jsx
│ │ ├── index.jsx
│ │ └── purechart.jsx
│ ├── View
│ │ └── index.jsx
│ ├── Label
│ │ └── index.jsx
│ └── Base
│ │ └── index.jsx
├── processor
│ ├── common.js
│ └── g2Delete.js
├── core.jsx
└── index.jsx
├── .eslintignore
├── test
├── readme.md
├── index.js
└── specs
│ └── component
│ ├── View.js
│ ├── Coord.js
│ ├── Guide.js
│ └── Chart.js
├── plugin
└── slider
│ ├── .npmignore
│ ├── demo
│ ├── index.html
│ └── webpack.config.js
│ ├── src
│ ├── error-boundary.jsx
│ └── index.jsx
│ ├── CHANGELOG.md
│ ├── .eslintrc
│ └── webpack.config.js
├── .travis.yml
├── .npmignore
├── .gitignore
├── demo
├── index.html
├── .babelrc
├── component
│ ├── empty
│ │ ├── index.js
│ │ └── empty.js
│ ├── theme
│ │ ├── index.js
│ │ └── black.js
│ ├── relation
│ │ ├── index.js
│ │ └── arc.js
│ ├── slider
│ │ └── index.js
│ ├── facet
│ │ ├── index.js
│ │ ├── list.js
│ │ └── listFunChild.js
│ ├── point
│ │ ├── index.js
│ │ ├── jitter.js
│ │ └── bubble.js
│ ├── funnel
│ │ ├── index.js
│ │ ├── basic.js
│ │ └── symmetric.js
│ ├── map
│ │ ├── index.js
│ │ └── china.js
│ ├── others
│ │ ├── index.js
│ │ ├── htmlTooltip.js
│ │ └── customLegend.js
│ ├── guage
│ │ ├── index.js
│ │ └── basic.js
│ ├── line
│ │ ├── index.js
│ │ ├── basic.js
│ │ ├── step.js
│ │ └── series.js
│ ├── heatmap
│ │ ├── index.js
│ │ ├── image.js
│ │ ├── rectangle.js
│ │ └── heatmap.js
│ ├── guide
│ │ ├── index.js
│ │ ├── dataMarker_dataRegion.js
│ │ └── regionFilter-guide2.js
│ ├── pie
│ │ ├── index.js
│ │ ├── rose.js
│ │ ├── pie.js
│ │ ├── donutRose.js
│ │ └── sunburst.js
│ ├── area
│ │ ├── index.js
│ │ ├── basic.js
│ │ ├── stacked.js
│ │ └── percent.js
│ ├── bar
│ │ ├── index.js
│ │ ├── basic-column.js
│ │ ├── basic.js
│ │ ├── histogramStack.js
│ │ ├── grouped.js
│ │ └── histogram.js
│ ├── index.js
│ └── cloud
│ │ └── index.js
├── index.js
├── webpack.config.js
└── container
│ └── App.js
├── testDemo
├── index.html
├── .babelrc
├── component
│ ├── bugs
│ │ └── index.js
│ ├── guide
│ │ └── index.js
│ ├── axis
│ │ └── index.js
│ ├── geom
│ │ ├── index.js
│ │ └── adddelete.js
│ ├── legend
│ │ ├── index.js
│ │ └── adddelete.js
│ ├── tooltip
│ │ └── index.js
│ ├── com16
│ │ ├── index.js
│ │ ├── listFacet.js
│ │ ├── basic.js
│ │ └── view.js
│ ├── viewUpdate
│ │ └── index.js
│ ├── coord
│ │ ├── index.js
│ │ ├── adddelete.js
│ │ ├── updateRect.js
│ │ ├── updateHelix.js
│ │ ├── updatePolar.js
│ │ └── updateTheta.js
│ ├── index.js
│ └── viewAD
│ │ ├── index.js
│ │ ├── coordAD.js
│ │ ├── axisAD.js
│ │ └── geomAD.js
├── index.js
├── webpack.config.js
└── container
│ └── App.js
├── .babelrc
├── .github
└── issue_template.md
├── scripts
├── build.js
└── release.sh
├── doc
├── tutorial
│ ├── data.md
│ ├── theme.md
│ ├── interaction.md
│ ├── chart.md
│ ├── needload.md
│ └── start.md
├── faq
│ └── faq.md
├── README.md
└── api
│ ├── view.md
│ ├── connector.md
│ ├── bizcharts.md
│ ├── label.md
│ └── graphic.md
├── .editorconfig
├── doc_en
├── tutorial
│ ├── data.md
│ ├── theme.md
│ ├── interaction.md
│ ├── chart.md
│ └── start.md
├── faq
│ └── faq.md
├── README.md
└── api
│ ├── view.md
│ ├── label.md
│ └── bizcharts.md
├── typings
├── tslint.json
└── tsconfig.json
├── .eslintrc
├── LICENSE
└── webpack.config.js
/ci.opts:
--------------------------------------------------------------------------------
1 | --require babel-core/register
2 |
--------------------------------------------------------------------------------
/src/themes/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * themes
3 | */
4 | export default {
5 | };
6 |
--------------------------------------------------------------------------------
/src/shared/index.js:
--------------------------------------------------------------------------------
1 | export Util from './util';
2 | export Prop from './prop';
3 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | build/
2 | demo/
3 | testDemo/
4 | doc/
5 | es6/
6 | node_modules/
7 | lib/
--------------------------------------------------------------------------------
/test/readme.md:
--------------------------------------------------------------------------------
1 | # 由于测试框架的兼容性,内部版本的测试用例正在火速移植中,敬请等待。
2 | # [站点](https://alibaba.github.io/BizCharts/demo.html)上一百多个 demo 都已经顺利正常运行。
--------------------------------------------------------------------------------
/src/components/Axis/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Axis Component
3 | */
4 | import Base from '../Base';
5 |
6 | export default Base.generateBaseTypedComponent('Axis');
7 |
--------------------------------------------------------------------------------
/src/components/Coord/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Coord Component
3 | */
4 | import Base from '../Base';
5 |
6 | export default Base.generateBaseTypedComponent('Coord');
7 |
--------------------------------------------------------------------------------
/plugin/slider/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.log
3 | node_modules
4 | coverage
5 | npm-debug.log
6 | *.orig
7 | .vscode/*
8 | test/*
9 | doc/*
10 | pages/*
11 | demo/*
--------------------------------------------------------------------------------
/src/components/Tooltip/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Tooltip Component
3 | */
4 | import Base from '../Base';
5 |
6 | export default Base.generateBaseTypedComponent('Tooltip');
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | node_js:
4 | - "8"
5 |
6 | install:
7 | - npm install
8 |
9 | script:
10 | - npm run lint
11 | - npm run test:pre
12 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.log
3 | node_modules
4 | coverage
5 | npm-debug.log
6 | *.orig
7 | .vscode/*
8 | test/*
9 | doc/*
10 | pages/*
11 | demo/*
12 | testDemo/*
13 | plugin/*
--------------------------------------------------------------------------------
/src/components/Facet/index.jsx:
--------------------------------------------------------------------------------
1 | import '@antv/g2/lib/facet/index';
2 | import BaseComponent from '../Base';
3 |
4 | export default BaseComponent.generateBaseTypedComponent('Facet');
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.log
3 | node_modules
4 | umd
5 | lib
6 | es6
7 | coverage
8 | npm-debug.log
9 | *.orig
10 | .vscode/*
11 | plugin/slider/node_modules
12 | **/**/coverage/
13 |
--------------------------------------------------------------------------------
/src/components/Geom/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Geom Component
3 | */
4 | import '@antv/g2/lib/geom/index';
5 | import Base from '../Base';
6 |
7 | export default Base.generateBaseTypedComponent('Geom');
8 |
--------------------------------------------------------------------------------
/demo/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | BizCharts Demo
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/testDemo/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | BizCharts Demo
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "stage-0", "react"],
3 | "plugins": [
4 | "transform-object-assign"
5 | ],
6 | "env": {
7 | "test": {
8 | "plugins": [ "istanbul" ]
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/.github/issue_template.md:
--------------------------------------------------------------------------------
1 | - bizcharts Version:
2 | - Platform or react version:
3 | - Mini Showcase(like screenshots):
4 | - CodePen Link:
5 | - you can fork CodePen template form this: https://codepen.io/leslie2014/pen/xjJGER
6 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Area/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/area';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'area');
8 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Edge/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/edge';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'edge');
8 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Line/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/line';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'line');
8 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Path/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/path';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'path');
8 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Point/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/point';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'point');
8 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Venn/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/venn';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'venn');
8 |
--------------------------------------------------------------------------------
/plugin/slider/demo/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | BizCharts-plugin-slider Demo
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Schema/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/schema';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'schema');
8 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Heatmap/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/heatmap';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'heatmap');
8 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Interval/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/interval';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'interval');
8 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/Polygon/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Line geometry Component
3 | */
4 | import '@antv/g2/lib/geom/polygon';
5 | import generateTypedGeom from '../generateTypedGeom';
6 |
7 | export default generateTypedGeom('Geom', 'polygon');
8 |
--------------------------------------------------------------------------------
/src/processor/common.js:
--------------------------------------------------------------------------------
1 | export default {
2 | COORD_FUNC_PROPS: ['rotate', 'scale', 'reflect', 'transpose'],
3 | GEOM_FUNC_PROPS: ['position', 'color', 'size', 'shape',
4 | 'opacity', 'tooltip', 'style', 'animate', 'active', 'select'],
5 | };
6 |
--------------------------------------------------------------------------------
/demo/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | plugins: [
3 | "transform-export-extensions",
4 | "transform-decorators-legacy",
5 | "transform-class-properties",
6 | "transform-object-rest-spread",
7 | "transform-function-bind",
8 | ],
9 | presets: ["es2015", "react"]
10 | }
11 |
--------------------------------------------------------------------------------
/testDemo/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | plugins: [
3 | "transform-export-extensions",
4 | "transform-decorators-legacy",
5 | "transform-class-properties",
6 | "transform-object-rest-spread",
7 | "transform-function-bind",
8 | ],
9 | presets: ["es2015", "react"]
10 | }
11 |
--------------------------------------------------------------------------------
/scripts/build.js:
--------------------------------------------------------------------------------
1 | var execSync = require('child_process').execSync;
2 | var readFileSync = require('fs').readFileSync;
3 |
4 | function exec(command) {
5 | execSync(command, { stdio: [0, 1, 2] });
6 | }
7 |
8 | exec('npm run build');
9 | exec('npm run build-umd');
10 | exec('npm run build-min');
11 |
--------------------------------------------------------------------------------
/test/index.js:
--------------------------------------------------------------------------------
1 | // general component
2 | require('./specs/component/Chart');
3 | require('./specs/component/Coord');
4 | require('./specs/component/View');
5 | require('./specs/component/Guide');
6 | require('./specs/component/Geom');
7 | require('./specs/component/Label');
8 | require('./specs/component/Tooltip');
9 |
--------------------------------------------------------------------------------
/demo/component/empty/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Empty from './empty';
3 |
4 |
5 | export default class LineChart extends Component {
6 | render() {
7 | return (
8 |
9 |
10 |
11 | );
12 | }
13 | }
--------------------------------------------------------------------------------
/doc/tutorial/data.md:
--------------------------------------------------------------------------------
1 |
2 | # 数据
3 |
4 | *文档转自G2*
5 |
6 | ## 数据格式
7 | 图表数据支持两种数据格式:
8 | - JSON数组
9 | - DataView 对象。
10 |
11 | ### JSON 数组
12 | Example:
13 |
14 | ```js
15 | var data = [
16 | {"gender":"男","count":40},
17 | {"gender":"女","count":30}
18 | ];
19 | ```
20 |
21 | ### DataView
22 | 详见 [DataSet 教程](./dataset.md)。
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
15 | [makefile]
16 | indent_style = tab
17 | indent_size = 4
--------------------------------------------------------------------------------
/testDemo/component/bugs/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import DataChange from './datachange';
3 |
4 | // data in render, padding change error
5 | export default class Guide extends Component {
6 | render() {
7 | return (
8 |
9 |
10 |
11 | );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/demo/component/empty/empty.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 |
4 |
5 |
6 | export default class BasicLineChart extends Component {
7 |
8 | render() {
9 | return (
10 |
11 | );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/components/index.js:
--------------------------------------------------------------------------------
1 |
2 | export Chart from './Chart';
3 | export Coord from './Coord';
4 | export Axis from './Axis';
5 | export Legend from './Legend';
6 | export Tooltip from './Tooltip';
7 | export Geom from './Geom';
8 | export View from './View';
9 | export Guide from './Guide';
10 | export Label from './Label';
11 | export Facet from './Facet';
12 |
--------------------------------------------------------------------------------
/testDemo/component/guide/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import AddDelete from './adddelete';
3 | import Update from './update';
4 |
5 |
6 | export default class Guide extends Component {
7 | render() {
8 | return (
9 |
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/testDemo/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import { Router, Route, browserHistory } from 'react-router';
4 | import App from './container/App';
5 |
6 | ReactDOM.render((
7 |
8 |
9 |
10 | ), document.getElementById('root'));
11 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/index.jsx:
--------------------------------------------------------------------------------
1 | export Area from './Area';
2 | export Edge from './Edge';
3 | export Heatmap from './Heatmap';
4 | export Line from './Line';
5 | export Interval from './Interval';
6 | export Path from './Path';
7 | export Point from './Point';
8 | export Polygon from './Polygon';
9 | export Schema from './Schema';
10 | export Venn from './Venn';
11 |
--------------------------------------------------------------------------------
/testDemo/component/axis/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import AddDelete from './adddelete';
3 | import UpdateRect from './updateRect';
4 |
5 |
6 | export default class Guide extends Component {
7 | render() {
8 | return (
9 |
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/testDemo/component/geom/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import AddDelete from './adddelete';
3 | import UpdateRect from './updateRect';
4 |
5 |
6 | export default class Guide extends Component {
7 | render() {
8 | return (
9 |
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/testDemo/component/legend/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import AddDelete from './adddelete';
3 | import UpdateRect from './updateRect';
4 |
5 |
6 | export default class Guide extends Component {
7 | render() {
8 | return (
9 |
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/testDemo/component/tooltip/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import AddDelete from './adddelete';
3 | import UpdateRect from './updateRect';
4 |
5 |
6 | export default class Guide extends Component {
7 | render() {
8 | return (
9 |
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/demo/component/theme/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Black from './black';
3 |
4 |
5 | export default class ThemeChart extends Component {
6 | render() {
7 | return (
8 |
13 | );
14 | }
15 | }
--------------------------------------------------------------------------------
/demo/component/relation/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Arc from './arc';
3 |
4 |
5 | export default class RelationChart extends Component {
6 | render() {
7 | return (
8 |
13 | );
14 | }
15 | }
--------------------------------------------------------------------------------
/demo/component/slider/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Basic from './basic';
3 |
4 |
5 | export default class SliderChart extends Component {
6 | render() {
7 | return (
8 |
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/demo/index.js:
--------------------------------------------------------------------------------
1 | import 'core-js/es6/set';
2 | import 'core-js/es6/map';
3 |
4 | import React from 'react';
5 | import ReactDOM from 'react-dom';
6 | import { Router, Route, browserHistory } from 'react-router';
7 | import App from './container/App';
8 |
9 | ReactDOM.render((
10 |
11 |
12 |
13 | ), document.getElementById('root'));
14 |
--------------------------------------------------------------------------------
/demo/component/facet/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import List from './list';
3 | import ListFuncChild from './listFunChild';
4 |
5 |
6 |
7 | export default class FacetChart extends Component {
8 | render() {
9 | return (
10 |
15 | );
16 | }
17 | }
--------------------------------------------------------------------------------
/doc_en/tutorial/data.md:
--------------------------------------------------------------------------------
1 |
2 | # Source Data
3 |
4 | *Documents are forwarded from G2*
5 |
6 | ## Data Formats
7 | Chart data supports two data formats:
8 | - JSON
9 | - Instance of DataView
10 |
11 | ### JSON (Array)
12 | Example:
13 |
14 | ```js
15 | var data = [
16 | {"gender":"male","count":40},
17 | {"gender":"female","count":30}
18 | ];
19 | ```
20 |
21 | ### DataView
22 | See the detail at [DataSet](./dataset.md).
23 |
--------------------------------------------------------------------------------
/demo/component/point/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Jitter from './jitter';
3 | import Bubble from './bubble';
4 |
5 | export default class PointChart extends Component {
6 | render() {
7 | return (
8 |
14 | );
15 | }
16 | }
--------------------------------------------------------------------------------
/demo/component/funnel/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Basic from './basic';
3 | import Symmetric from './symmetric';
4 |
5 |
6 | export default class FunnelChart extends Component {
7 | render() {
8 | return (
9 |
15 | );
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/demo/component/map/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import China from './china';
3 | import Choropleth from './choropleth';
4 |
5 |
6 | export default class MapChart extends Component {
7 | render() {
8 | return (
9 |
15 | );
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/demo/component/others/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import HtmlTooltip from './htmlTooltip';
3 | import CustomLegend from './customLegend';
4 |
5 |
6 | export default class OtherChart extends Component {
7 | render() {
8 | return (
9 |
15 | );
16 | }
17 | }
--------------------------------------------------------------------------------
/demo/component/guage/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Basic from './basic';
3 | import Color from './color';
4 | import Text from './text';
5 |
6 |
7 | export default class GuageChart extends Component {
8 | render() {
9 | return (
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | );
18 | }
19 | }
--------------------------------------------------------------------------------
/demo/component/line/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Basic from './basic';
3 | import Series from './series';
4 | import Step from './step';
5 |
6 |
7 | export default class LineChart extends Component {
8 | render() {
9 | return (
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | );
18 | }
19 | }
--------------------------------------------------------------------------------
/demo/component/heatmap/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Heatmap from './heatmap';
3 | import Image from './image';
4 | import Reactangle from './rectangle';
5 |
6 |
7 | export default class HeatmapChart extends Component {
8 | render() {
9 | return (
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | );
18 | }
19 | }
--------------------------------------------------------------------------------
/testDemo/component/com16/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Basic from './basic';
3 | import ViewChart from './view';
4 | import ListFacet from './listFacet';
5 |
6 |
7 | export default class LineChart extends Component {
8 | render() {
9 | return (
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | );
18 | }
19 | }
--------------------------------------------------------------------------------
/demo/component/guide/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import RegionFilterGuide2 from './regionFilter-guide2';
3 | import DataMarkerDataRegion from './dataMarker_dataRegion';
4 | import RegionFilterRealtime from './regionFilter-realtime';
5 |
6 | export default class GuageChart extends Component {
7 | render() {
8 | return (
9 |
10 |
11 |
12 |
13 |
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/demo/component/pie/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Pie from './pie';
3 | import Rose from './rose';
4 | import DonutRose from './donutRose';
5 | import Sunburst from './sunburst';
6 |
7 | export default class PieChart extends Component {
8 | render() {
9 | return (
10 |
18 | );
19 | }
20 | }
--------------------------------------------------------------------------------
/testDemo/component/viewUpdate/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import AxisUpdate from './axisUpdate';
3 | import CoordUpdate from './coordUpdate';
4 | import GeomUpdate from './geomUpdate';
5 | import GuideUpdate from './guideUpdate';
6 |
7 |
8 | export default class GuideUpdateChart extends Component {
9 | render() {
10 | return (
11 |
17 | );
18 | }
19 | }
--------------------------------------------------------------------------------
/typings/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "dtslint/dt.json",
3 | "rules": {
4 | // TODOs
5 | "ban-types": false,
6 | "dt-header": false,
7 | "no-any-union": false,
8 | "no-declare-current-package": false,
9 | "no-duplicate-imports": false,
10 | "no-empty-interface": false,
11 | "no-mergeable-namespace": false,
12 | "no-unnecessary-qualifier": false,
13 | "no-unnecessary-type-assertion": false,
14 | "strict-export-declare-modifiers": false,
15 | "use-default-type-parameter": false
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/components/ErrorBoundary/index.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default class ErrorBoundary extends React.Component {
4 | constructor(props) {
5 | super(props);
6 | this.state = { hasError: false };
7 | }
8 |
9 | componentDidCatch() {
10 | this.setState({ hasError: true });
11 | }
12 |
13 | unstable_handleError() {
14 | this.setState({ hasError: true });
15 | }
16 |
17 | render() {
18 | if (this.state.hasError) {
19 | return bizcharts error. ;
20 | }
21 | return this.props.children;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/testDemo/component/coord/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import AddDelete from './adddelete';
3 | import UpdatePolar from './updatePolar';
4 | import UpdateHelix from './updateHelix';
5 | import UpdateRect from './updateRect';
6 | import UpdateTheta from './updateTheta';
7 |
8 |
9 | export default class Guide extends Component {
10 | render() {
11 | return (
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | );
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/testDemo/component/index.js:
--------------------------------------------------------------------------------
1 | import Guide from './guide';
2 | import Coord from './coord';
3 | import Axis from './axis';
4 | import Geom from './geom';
5 | import Legend from './legend';
6 | import Tooltip from './tooltip';
7 | import ViewAD from './viewAD';
8 | import ViewUpdate from './viewUpdate';
9 | import Com16 from './com16';
10 | import Bugs from './bugs';
11 |
12 |
13 | export default {
14 | Demos: {
15 | Guide,
16 | Coord,
17 | Axis,
18 | Geom,
19 | Legend,
20 | Tooltip,
21 | ViewAD,
22 | ViewUpdate,
23 | Com16,
24 | Bugs
25 | },
26 | };
27 |
--------------------------------------------------------------------------------
/plugin/slider/src/error-boundary.jsx:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 |
3 | export default class ErrorBoundary extends React.Component {
4 | constructor(props) {
5 | super(props);
6 | this.state = { hasError: false };
7 | }
8 |
9 | componentDidCatch(error, info) {
10 | this.setState({ hasError: true });
11 | }
12 |
13 | unstable_handleError(error, info) {
14 | this.setState({ hasError: true });
15 | }
16 |
17 | render() {
18 | if (this.state.hasError) {
19 | return Slider error. ;
20 | }
21 | return this.props.children;
22 | }
23 | }
--------------------------------------------------------------------------------
/src/core.jsx:
--------------------------------------------------------------------------------
1 | import G2, { Shape, PathUtil, Animate } from '@antv/g2/lib/core';
2 | import Util from './shared/util';
3 | import Themes from './themes';
4 |
5 | const BizCharts = {
6 | G2,
7 | Util,
8 | Shape,
9 | Animate,
10 | PathUtil,
11 | track(enable = false) {
12 | // for srs
13 | G2.track(enable);
14 | },
15 | setTheme(theme) {
16 | let themeObj = theme;
17 | if (typeof theme === 'string' && Themes[theme]) {
18 | themeObj = Themes[theme];
19 | }
20 |
21 | G2.Global.setTheme(themeObj);
22 | },
23 | };
24 |
25 | exports.default = BizCharts;
26 | module.exports = BizCharts;
27 |
--------------------------------------------------------------------------------
/demo/component/area/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Basic from './basic';
3 | import Percent from './percent';
4 | import Stacked from './stacked';
5 |
6 |
7 | export default class AreaChart extends Component {
8 | render() {
9 | return (
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 | );
22 | }
23 | }
--------------------------------------------------------------------------------
/demo/component/bar/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Basic from './basic';
3 | import BasicColumn from './basic-column';
4 | import Grouped from './grouped';
5 | import Historgram from './histogram';
6 | import HistogramStack from './histogramStack';
7 |
8 | export default class BarChart extends Component {
9 | render() {
10 | return (
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | );
21 | }
22 | }
--------------------------------------------------------------------------------
/typings/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "files": [
3 | "index.d.ts",
4 | "bizcharts-tests.tsx"
5 | ],
6 | "compilerOptions": {
7 | "module": "commonjs",
8 | "lib": [
9 | "es6",
10 | "dom"
11 | ],
12 | "noImplicitAny": false,
13 | "noImplicitThis": true,
14 | "strictNullChecks": false,
15 | "strictFunctionTypes": false,
16 | "baseUrl": "../",
17 | "jsx": "react",
18 | "experimentalDecorators": true,
19 | "typeRoots": [
20 | "../"
21 | ],
22 | "types": [],
23 | "noEmit": true,
24 | "forceConsistentCasingInFileNames": true
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/index.jsx:
--------------------------------------------------------------------------------
1 | import G2, { Shape, PathUtil, Animate } from '@antv/g2/lib/core';
2 | import Util from './shared/util';
3 | import Themes from './themes';
4 | import * as components from './components';
5 |
6 | G2.Global.animate = false;
7 |
8 | const BizCharts = Util.mix(components, {
9 | G2,
10 | Util,
11 | Shape,
12 | Animate,
13 | PathUtil,
14 | track() {
15 | },
16 | setTheme(theme) {
17 | let themeObj = theme;
18 | if (typeof theme === 'string' && Themes[theme]) {
19 | themeObj = Themes[theme];
20 | }
21 |
22 | G2.Global.setTheme(themeObj);
23 | },
24 | });
25 |
26 | exports.default = BizCharts;
27 | module.exports = BizCharts;
28 |
--------------------------------------------------------------------------------
/plugin/slider/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 2.1.1 (09.25, 2018)
2 | - add slider error boundary.
3 |
4 | # 2.1.0 (09.17, 2018)
5 | - update g2 slider to 2.1.10
6 | - bizcharts version must bigger than bizcharts@3.2.3.
7 |
8 | # 2.0.7 (08.28, 2018)
9 | update g2 slider to 2.0.4
10 | fix #477
11 |
12 | //2.0.5, 2.0.6 npm do not have umd files.
13 |
14 | # 2.0.4 (07.31, 2018)
15 | update g2 slider to 2.0.3
16 | fix #386
17 |
18 | # 2.0.3 (04.10, 2018)
19 | fix issue-210
20 |
21 | # 2.0.1 (12.28, 2017)
22 | upgrade g2-plugin-slider version 2.0.1.
23 |
24 | # 2.0.0 (12.18, 2017)
25 | 修复包名,之前是 bizcharts-plugin-slier, 改为 bizcharts-plugin-slider
26 | 包入口之前有误,改为 bizcharts-plugin-slider.min.js
27 |
28 | # 1.0.0 (12.12, 2017)
29 | 1.0.0 版本发布。
30 |
--------------------------------------------------------------------------------
/demo/component/index.js:
--------------------------------------------------------------------------------
1 | import Line from './line';
2 | import Empty from './empty';
3 | import Area from './area';
4 | import Bar from './bar';
5 | import Point from './point';
6 | import Pie from './pie';
7 | import Heatmap from './heatmap';
8 | import Funnel from './funnel';
9 | import Relation from './relation';
10 | import Facet from './facet';
11 | import Theme from './theme';
12 | import Map from './map';
13 | import Guage from './guage';
14 | import Slider from './slider';
15 | import Guide from './guide';
16 |
17 |
18 | export default {
19 | lineChart: {
20 | Line,
21 | Bar,
22 | Area,
23 | Point,
24 | Pie,
25 | Heatmap,
26 | Funnel,
27 | Relation,
28 | Facet,
29 | Theme,
30 | Guage,
31 | Map,
32 | Slider,
33 | Guide
34 | },
35 | };
36 |
--------------------------------------------------------------------------------
/testDemo/component/viewAD/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import ViewAD from './viewAD';
3 | import GeomAD from './geomAD';
4 | import GeomAD2 from './geomAD2';
5 | import LabelAd from './labelAD';
6 | import GuideAD from './guideAD';
7 | import GuideAD2 from './guideAD2';
8 | import AxisAd from './axisAD';
9 | import CoordAd from './coordAD';
10 |
11 |
12 | export default class ViewChart extends Component {
13 | render() {
14 | return (
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | );
28 | }
29 | }
--------------------------------------------------------------------------------
/src/shared/prop.js:
--------------------------------------------------------------------------------
1 | /**
2 | * prop function
3 | */
4 |
5 | import Util from './util';
6 |
7 | export default {
8 | init(keys = {}, props, callback) {
9 | Util.each(keys, (key) => {
10 | let value = props[key];
11 | if (value !== undefined) {
12 | if (!Util.isArray(value)) {
13 | value = [value];
14 | }
15 | callback(value, key);
16 | }
17 | });
18 | },
19 |
20 | update(keys, props, nextProps, callback) {
21 | let value;
22 | let nextValue;
23 | Util.each(keys, (key) => {
24 | value = props[key];
25 | nextValue = nextProps[key];
26 | if (!Util.shallowEqual(nextValue, value)) {
27 | if (!Util.isArray(nextValue)) {
28 | nextValue = [nextValue];
29 | }
30 | callback(nextValue, key);
31 | }
32 | });
33 | },
34 | };
35 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint-config-ali/react",
3 | "parser": "babel-eslint",
4 | "root": true,
5 | "env": {
6 | "jest": true,
7 | "browser": true,
8 | "node": true,
9 | "es6": true
10 | },
11 | "plugins": [
12 | "react",
13 | "jsx-a11y"
14 | ],
15 | "parserOptions": {
16 | "ecmaVersion": 6,
17 | "sourceType": "module",
18 | "ecmaFeatures": {
19 | "jsx": true
20 | }
21 | },
22 | "rules": {
23 | "strict": "off",
24 | "no-console": "off",
25 | "require-yield": "off",
26 | "import/no-dynamic-require": "off",
27 | "react/prefer-stateless-function": "off",
28 | "react/forbid-prop-types": "off",
29 | "class-methods-use-this": "off",
30 | "comma-dangle": "off",
31 | "react/require-default-props": "off",
32 | "import/no-extraneous-dependencies": "off"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/doc_en/tutorial/theme.md:
--------------------------------------------------------------------------------
1 |
2 | # Theme
3 |
4 | **Reference: [G2 Theme](https://antv.alipay.com/zh-cn/g2/3.x/tutorial/theme.html)**
5 |
6 | ## Chart Theme
7 | Bizcharts provides two built-in themes: `default` and `dark`.
8 |
9 |
10 | ## Change Theme
11 |
12 | You can change theme with the `BizCharts.setTheme(themeName)` API.
13 |
14 | Exmaple:
15 |
16 | ```jsx
17 | BizCharts.setTheme('dark');
18 | ```
19 |
20 | ## Customize Theme
21 | Also, by customizing the theme config and then call the `BizCharts.setTheme(themeConfig)` API.
22 |
23 | Example:
24 | ```jsx
25 | const seaTheme = {
26 | animate:false,
27 | colors:{},
28 | shapes:{},
29 | };
30 | BizCharts.setTheme(seaTheme);
31 | ```
32 | More detail about theme customization, reference [Theme API](/doc/api/theme.md)
33 |
--------------------------------------------------------------------------------
/doc/tutorial/theme.md:
--------------------------------------------------------------------------------
1 |
9 |
10 | # 主题
11 |
12 | **引用: [G2 Theme](https://antv.alipay.com/zh-cn/g2/3.x/tutorial/theme.html)**
13 |
14 | ## 图表主题
15 | Bizcharts 提供了两种内建的主题: `default` and `dark`.
16 |
17 |
18 | ## 如何改变主题
19 |
20 | 你可以通过 `BizCharts.setTheme(themeName)` API 来改变主题.
21 |
22 | Exmaple:
23 |
24 | ```jsx
25 | BizCharts.setTheme('dark');
26 | ```
27 |
28 | ## 自定义主题
29 | 当调用 `BizCharts.setTheme()` API 传入的参数是一个对象时,这个时候代表使用你自定义的主题配置。
30 |
31 | Example:
32 | ```jsx
33 | const seaTheme = {
34 | animate:false,
35 | colors:{},
36 | shapes:{},
37 | };
38 | BizCharts.setTheme(seaTheme);
39 | ```
40 |
41 | 更多的自定义配置项, 请参考 [Theme API](/doc/api/theme.md)
42 |
--------------------------------------------------------------------------------
/src/components/Legend/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Legend Component
3 | */
4 | import BaseComponent from '../Base';
5 | import PropTypes from 'prop-types';
6 |
7 | export default class Legend extends BaseComponent {
8 | static contextTypes = {
9 | addElement: PropTypes.func,
10 | updateElement: PropTypes.func,
11 | deleteElement: PropTypes.func,
12 | createId: PropTypes.func,
13 | getParentInfo: PropTypes.func,
14 | getViewId: PropTypes.func,
15 | }
16 |
17 | static childContextTypes = {
18 | addElement: PropTypes.func,
19 | updateElement: PropTypes.func,
20 | deleteElement: PropTypes.func,
21 | createId: PropTypes.func,
22 | getParentInfo: PropTypes.func,
23 | getViewId: PropTypes.func,
24 | }
25 |
26 | static defaultProps = {
27 | visible: true,
28 | }
29 |
30 | constructor(props) {
31 | super(props, 'Legend');
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/demo/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var webpack = require('webpack');
3 |
4 | module.exports = {
5 | context: __dirname,
6 | devtool: '#inline-source-map',
7 | entry: [
8 | './index.js',
9 | ],
10 | output: {
11 | path: path.join(__dirname, 'build'),
12 | filename: 'bundle.js',
13 | },
14 | plugins: [
15 | new webpack.LoaderOptionsPlugin({
16 | debug: true
17 | })
18 | // new webpack.HotModuleReplacementPlugin(),
19 | // new webpack.NoErrorsPlugin()
20 | ],
21 | resolve: {
22 | extensions: ['.js', '.jsx'],
23 | alias: {
24 | 'bizcharts': path.join(__dirname, '..', 'src/index.jsx'),
25 | },
26 | },
27 | module: {
28 | loaders: [{
29 | test: /\.(js|jsx)$/,
30 | loaders: ['babel-loader'],
31 | include: [
32 | __dirname,
33 | path.join(__dirname, '..', 'src'),
34 | ],
35 | }],
36 | },
37 | };
38 |
--------------------------------------------------------------------------------
/plugin/slider/demo/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var webpack = require('webpack');
3 |
4 | module.exports = {
5 | context: __dirname,
6 | devtool: '#inline-source-map',
7 | entry: [
8 | './index.js',
9 | ],
10 | output: {
11 | path: path.join(__dirname, 'build'),
12 | filename: 'bundle.js',
13 | },
14 | plugins: [
15 | new webpack.LoaderOptionsPlugin({
16 | debug: true
17 | })
18 | // new webpack.HotModuleReplacementPlugin(),
19 | // new webpack.NoErrorsPlugin()
20 | ],
21 | resolve: {
22 | extensions: ['.js', '.jsx'],
23 | alias: {
24 | 'bizcharts-slider': path.join(__dirname, '..', 'src/index.jsx'),
25 | },
26 | },
27 | module: {
28 | loaders: [{
29 | test: /\.(js|jsx)$/,
30 | loaders: ['babel-loader'],
31 | include: [
32 | __dirname,
33 | path.join(__dirname, '..', 'src'),
34 | ],
35 | }],
36 | },
37 | };
38 |
--------------------------------------------------------------------------------
/doc/tutorial/interaction.md:
--------------------------------------------------------------------------------
1 |
2 | # 图表交互
3 |
4 | ## 默认交互
5 | 包括:
6 | - active 激活,鼠标hover。
7 | - select 选中,鼠标点击选择、框选。
8 |
9 | ## 激活
10 | 开启以及关闭 shape 对于鼠标 hover 时的响应效果,默认为各个 `` 内置了 active 效果 。可以通过 *active* 属性关闭及开启。
11 | 例如:
12 | ```
13 |
14 |
15 | ```
16 |
17 | ## 选中
18 | 各个几何标记 geom 选中的模式包含如下三种:
19 | 1. 不可选中;
20 | 2. 单选;
21 | 3. 多选;
22 | 4. 选中是否可取消选中。
23 |
24 | 选中模式的设置方式如下:
25 |
26 | ```jsx
27 | ; // 关闭
28 | ; // 打开
29 | ;
35 | ```
36 |
37 | 默认情况下,G2 中只有饼图支持选中交互,其他 geom 的选中模式默认情况下都是关闭的。
38 |
39 | **图表交互控制可以跟[图表事件](../api/chart.md#event)结合用来定制图表的自定义交互,参见demo:[地图省市下钻](https://alibaba.github.io/BizCharts/demo-detail.html?code=demo/map/drill-down)**
40 |
41 |
--------------------------------------------------------------------------------
/testDemo/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var webpack = require('webpack');
3 |
4 | console.log(__dirname);
5 |
6 | module.exports = {
7 | context: __dirname,
8 | devtool: '#inline-source-map',
9 | entry: [
10 | './index.js',
11 | ],
12 | output: {
13 | path: path.join(__dirname, 'build'),
14 | filename: 'bundle.js',
15 | },
16 | plugins: [
17 | new webpack.LoaderOptionsPlugin({
18 | debug: true
19 | })
20 | // new webpack.HotModuleReplacementPlugin(),
21 | // new webpack.NoErrorsPlugin()
22 | ],
23 | resolve: {
24 | extensions: ['.js', '.jsx'],
25 | alias: {
26 | 'bizcharts': path.join(__dirname, '..', 'src/index.jsx'),
27 | },
28 | },
29 | module: {
30 | loaders: [{
31 | test: /\.(js|jsx)$/,
32 | loaders: ['babel-loader'],
33 | include: [
34 | __dirname,
35 | path.join(__dirname, '..', 'src'),
36 | ],
37 | }],
38 | },
39 | };
40 |
--------------------------------------------------------------------------------
/demo/component/heatmap/image.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/heatmap.json'
5 |
6 |
7 | const { DataView } = DataSet;
8 | const { Image } = Guide;
9 |
10 | export default class HeatmapC extends Component {
11 |
12 | render() {
13 | return (
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | );
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/components/Guide/index.jsx:
--------------------------------------------------------------------------------
1 | /*
2 | Components:
3 | Guide
4 | Guide.Line
5 | Guide.Image
6 | Guide.Text
7 | Guide.Region
8 | Guide.Arc
9 | Guide.Html
10 | Guide.RegionFilter
11 | Guide.DataMarker
12 | Guide.DataRegion
13 | */
14 | import Base from '../Base';
15 |
16 | const Guide = Base.generateBaseTypedComponent('Guide');
17 |
18 |
19 | Guide.Line = Base.generateBaseTypedComponent('GuideLine');
20 | Guide.Image = Base.generateBaseTypedComponent('GuideImage');
21 | Guide.Text = Base.generateBaseTypedComponent('GuideText');
22 | Guide.Region = Base.generateBaseTypedComponent('GuideRegion');
23 | Guide.Html = Base.generateBaseTypedComponent('GuideHtml');
24 | Guide.Arc = Base.generateBaseTypedComponent('GuideArc');
25 | Guide.RegionFilter = Base.generateBaseTypedComponent('GuideRegionFilter');
26 | Guide.DataMarker = Base.generateBaseTypedComponent('GuideDataMarker');
27 | Guide.DataRegion = Base.generateBaseTypedComponent('GuideDataRegion');
28 |
29 | export default Guide;
30 |
--------------------------------------------------------------------------------
/demo/component/bar/basic-column.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const data = [
7 | { year: '1951 年', sales: 38 },
8 | { year: '1952 年', sales: 52 },
9 | { year: '1956 年', sales: 61 },
10 | { year: '1957 年', sales: 145 },
11 | { year: '1958 年', sales: 48 },
12 | { year: '1959 年', sales: 38 },
13 | { year: '1960 年', sales: 38 },
14 | { year: '1962 年', sales: 38 },
15 | ];
16 | const cols = {
17 | 'sales': {tickInterval: 20},
18 | };
19 |
20 |
21 | export default class IntervalC extends Component {
22 | render() {
23 | return (
24 |
25 |
26 |
27 |
28 |
29 |
30 | );
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/demo/component/area/basic.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Axis, Geom, Tooltip } from 'bizcharts';
3 |
4 |
5 | const data = [
6 | { year: "1991", value: 3 },
7 | { year: "1992", value: 4 },
8 | { year: "1993", value: 3.5 },
9 | { year: "1994", value: 5 },
10 | { year: "1995", value: 4.9 },
11 | { year: "1996", value: 6 },
12 | { year: "1997", value: 7 },
13 | { year: "1998", value: 9 },
14 | { year: "1999", value: 13 }
15 | ];
16 |
17 | const scale = {
18 | 'value': { min: 0 },
19 | 'year': {range: [ 0 , 1] }
20 | };
21 |
22 | export default class Area extends Component {
23 |
24 | render() {
25 | return (
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/components/Chart/empty.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Empty Component
3 | * 用 g2 创建 chart 一开始没有数据,有数据时对当前 chart 更新数据时,会有问题。
4 | * 因此用了 Empty 作为无数据 chart,PureChart 作为有数据的 chart。
5 | */
6 | import React from 'react';
7 | import PropTypes from 'prop-types';
8 | import warning from 'warning';
9 |
10 | warning(React.PureComponent, '`React.PureComponent` needs React >=15.3.0');
11 |
12 | // react 15.3.0 以下不支持 PureComponent 就做一个兼容
13 | export default class Empty extends (React.PureComponent || React.Component) {
14 | static propTypes = {
15 | width: PropTypes.oneOfType([
16 | PropTypes.string,
17 | PropTypes.number,
18 | ]),
19 | height: PropTypes.oneOfType([
20 | PropTypes.string,
21 | PropTypes.number,
22 | ]),
23 | placeholder: PropTypes.node,
24 | }
25 |
26 | static defaultProps = {
27 | width: '100%',
28 | placeholder: 暂无数据
,
29 | }
30 |
31 | render() {
32 | const { width, height, placeholder } = this.props;
33 |
34 | return {placeholder}
;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Alibaba
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/demo/component/bar/basic.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const data = [
6 | { country: '中国', population: 131744 },
7 | { country: '印度', population: 104970 },
8 | { country: '美国', population: 29034 },
9 | { country: '印尼', population: 23489 },
10 | { country: '巴西', population: 18203 }
11 | ];
12 | const ds = new DataSet();
13 | const dv = ds.createView().source(data);
14 | dv.source(data)
15 | .transform({
16 | type: 'sort',
17 | callback(a, b) { // 排序依据,和原生js的排序callback一致
18 | return a.population - b.population > 0;
19 | }
20 | });
21 |
22 |
23 | export default class IntervalC extends Component {
24 |
25 | render() {
26 | return (
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | );
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/demo/component/line/basic.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 |
4 |
5 | const data = [
6 | { year: "1991", value: 3 },
7 | { year: "1992", value: 4 },
8 | { year: "1993", value: 3.5 },
9 | { year: "1994", value: 5 },
10 | { year: "1995", value: 4.9 },
11 | { year: "1996", value: 6 },
12 | { year: "1997", value: 7 },
13 | { year: "1998", value: 9 },
14 | { year: "1999", value: 13 }
15 | ];
16 |
17 | const scale = {
18 | 'value': { min: 0 },
19 | 'year': {range: [ 0 , 1] }
20 | };
21 |
22 | export default class BasicLineChart extends Component {
23 |
24 | render() {
25 | return (
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/demo/component/line/step.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const data = [
7 | { month: 'Jan', value: 51 },
8 | { month: 'Feb', value: 91 },
9 | { month: 'Mar', value: 34 },
10 | { month: 'Apr', value: 47 },
11 | { month: 'May', value: 63 },
12 | { month: 'June', value: 58 },
13 | { month: 'July', value: 56 },
14 | { month: 'Aug', value: 77 },
15 | { month: 'Sep', value: 99 },
16 | { month: 'Oct', value: 106 },
17 | { month: 'Nov', value: 88 },
18 | { month: 'Dec', value: 56 }
19 | ];
20 | const cols = {
21 | month: {
22 | range: [ 0, 1 ]
23 | }
24 | }
25 |
26 | export default class Step extends Component {
27 | render() {
28 | return (
29 |
30 |
31 |
32 |
33 |
34 |
35 | );
36 | }
37 | }
--------------------------------------------------------------------------------
/demo/component/facet/list.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Facet, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/diamond.json';
5 |
6 | const { DataView } = DataSet;
7 | const { Text } = Guide;
8 |
9 | const scale = {
10 | carat: {
11 | sync: true
12 | },
13 | price: {
14 | sync: true,
15 | tickCount: 3
16 | },
17 | cut: {
18 | sync: true
19 | }
20 | };
21 |
22 |
23 | export default class List extends Component {
24 |
25 | render() {
26 | return (
27 |
28 |
29 |
30 | {
31 | view.point()
32 | .position('carat*price')
33 | .color('cut')
34 | .shape('circle')
35 | .opacity(0.3)
36 | .size(3);
37 | }}>
38 |
39 |
40 | );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/demo/component/bar/histogramStack.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/diamond.json'
5 |
6 | const ds = new DataSet();
7 | const dv = ds.createView().source(data);
8 | dv.transform({
9 | type: 'bin.histogram',
10 | field: 'depth',
11 | binWidth: 1,
12 | // offset: -0.3,
13 | groupBy: [ 'cut' ],
14 | as: [ 'depth', 'count' ]
15 | });
16 |
17 | export default class IntervalC extends Component {
18 |
19 | render() {
20 | return (
21 |
22 |
29 |
30 |
31 |
32 |
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/demo/component/pie/rose.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const data = [
7 | {year: '2001', population: 41.8 },
8 | {year: '2002', population: 38 },
9 | {year: '2003', population: 33.7 },
10 | {year: '2004', population: 30.7 },
11 | {year: '2005', population: 25.8 },
12 | {year: '2006', population: 31.7 },
13 | {year: '2007', population: 33 },
14 | {year: '2008', population: 46 },
15 | {year: '2009', population: 38.3 },
16 | {year: '2010', population: 28 },
17 | {year: '2011', population: 42.5 },
18 | {year: '2012', population: 30.3 }
19 | ];
20 |
21 | export default class PieC extends Component {
22 |
23 | render() {
24 | return (
25 |
26 |
27 |
28 |
33 |
34 |
35 | );
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/demo/component/point/jitter.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/dv-grades.json'
5 |
6 |
7 | export default class PointC extends Component {
8 |
9 | render() {
10 | return (
11 |
12 |
13 |
14 |
28 |
29 |
30 |
31 | );
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/demo/component/facet/listFunChild.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Facet, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/diamond.json';
5 |
6 | const { DataView } = DataSet;
7 | const { Text } = Guide;
8 |
9 | const scale = {
10 | carat: {
11 | sync: true
12 | },
13 | price: {
14 | sync: true,
15 | tickCount: 3
16 | },
17 | cut: {
18 | sync: true
19 | }
20 | };
21 |
22 |
23 | export default class List extends Component {
24 |
25 | render() {
26 | return (
27 |
28 |
29 |
30 |
31 |
32 |
39 |
40 |
41 |
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/scripts/release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 | export RELEASE=1
3 |
4 | if ! [ -e scripts/release.sh ]; then
5 | echo >&2 "Please run scripts/release.sh from the repo root"
6 | exit 1
7 | fi
8 |
9 | update_version() {
10 | echo "$(node -p "p=require('./${1}');p.version='${2}';JSON.stringify(p,null,2)")" > $1
11 | echo "Updated ${1} version to ${2}"
12 | }
13 |
14 | validate_semver() {
15 | if ! [[ $1 =~ ^[0-9]\.[0-9]+\.[0-9](-.+)? ]]; then
16 | echo >&2 "Version $1 is not valid! It must be a valid semver string like 1.0.2 or 2.3.0-beta.1"
17 | exit 1
18 | fi
19 | }
20 |
21 | current_version=$(node -p "require('./package').version")
22 |
23 | printf "Next version (current is $current_version)? "
24 | read next_version
25 |
26 | validate_semver $next_version
27 |
28 | next_ref="v$next_version"
29 |
30 | npm test
31 |
32 | vim CHANGELOG.md
33 |
34 | update_version 'package.json' $next_version
35 |
36 | git commit -am "Version $next_version"
37 |
38 | # push first to make sure we're up-to-date
39 | git push origin master
40 |
41 | git tag $next_ref
42 | #git tag latest -f
43 |
44 | git push origin $next_ref
45 | #git push origin latest -f
46 |
47 | node scripts/build.js
48 |
49 | npm publish
50 |
--------------------------------------------------------------------------------
/test/specs/component/View.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Enzyme, { mount } from 'enzyme';
3 | import Adapter from 'enzyme-adapter-react-16';
4 | import chai, { expect } from 'chai';
5 | import chaiEnzyme from 'chai-enzyme';
6 | // import sinon from 'sinon';
7 | import { Chart, View } from 'bizcharts';
8 |
9 |
10 | chai.use(chaiEnzyme()); // Note the invocation at the end
11 | Enzyme.configure({ adapter: new Adapter() });
12 | let chartInstance = null;
13 |
14 |
15 | const Test = ({ viewProps }) => {
16 | return ( { chartInstance = chart; }}>
17 |
18 |
19 |
20 | );
21 | };
22 |
23 | describe('Context', () => {
24 | const wrapper2 = mount( );
25 | it('viewsHasCreate', () => {
26 | expect(chartInstance.get('views').length).is.eqls(3);
27 | });
28 | it('updateData', () => {
29 | // console.log(chartInstance.get('views')[0]._attrs.data);
30 | wrapper2.setProps({ viewProps: { data: [{ a: 1 }] } });
31 | wrapper2.update();
32 | expect(chartInstance.get('views')[0]._attrs.data.length).is.eqls(1);
33 | });
34 | });
35 |
--------------------------------------------------------------------------------
/src/components/View/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * View Component
3 | */
4 | import BaseComponent from '../Base';
5 | import PropTypes from 'prop-types';
6 |
7 | export default class View extends BaseComponent {
8 | static contextTypes = {
9 | addElement: PropTypes.func,
10 | updateElement: PropTypes.func,
11 | deleteElement: PropTypes.func,
12 | createId: PropTypes.func,
13 | getParentInfo: PropTypes.func,
14 | getViewId: PropTypes.func,
15 | }
16 |
17 | static childContextTypes = {
18 | addElement: PropTypes.func,
19 | updateElement: PropTypes.func,
20 | deleteElement: PropTypes.func,
21 | createId: PropTypes.func,
22 | getParentInfo: PropTypes.func,
23 | getViewId: PropTypes.func,
24 | }
25 |
26 | constructor(props) {
27 | super(props, 'View');
28 | }
29 |
30 | getChildContext() {
31 | return {
32 | addElement: this.context.addElement,
33 | updateElement: this.context.updateElement,
34 | deleteElement: this.context.deleteElement,
35 | createId: this.context.createId,
36 | getParentInfo: this.getParentInfo,
37 | getViewId: this.getViewId,
38 | };
39 | }
40 |
41 | getViewId = () => {
42 | return this.id;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/plugin/slider/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint-config-airbnb",
3 | "parser": "babel-eslint",
4 | "globals": {
5 | "it": true,
6 | "describe": true,
7 | "require": true,
8 | "process": true,
9 | "before": true,
10 | "after" : true,
11 | "sinon": true,
12 | "expect" : true,
13 | "beforeEach": true,
14 | "afterEach": true
15 | },
16 | "env":{
17 | "es6": true,
18 | "node": true,
19 | "browser": true
20 | },
21 | "parserOptions": {
22 | "sourceType": "module"
23 | },
24 | "rules": {
25 | // 低版本 nodejs 需要在 strict 模式下支持 es6 语法
26 | "strict": "off",
27 | // 经常需要打印东西
28 | "no-console" : "off",
29 | // 不希望参数使用解构,低版本 nodejs 不支持
30 | "prefer-spread" : "off",
31 | // 会有很多地方需要直接使用 arguments
32 | "prefer-rest-params": "off",
33 | // 有动态引入的需求
34 | "import/no-dynamic-require": "off",
35 | // 有些函数对外需要暴露 generator 类型函数,但里面确实只有同步代码
36 | "require-yield": "off",
37 | // 一些正则表达式需要用到
38 | "no-useless-escape": "off",
39 | // 感觉这样写简洁一些
40 | "no-mixed-operators" : "warn",
41 | "no-lonely-if" : "off",
42 | "class-methods-use-this" : "off",
43 | "no-restricted-syntax" : "off",
44 | "no-param-reassign" : "off"
45 | }
46 | }
--------------------------------------------------------------------------------
/src/components/Label/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Label Component
3 | */
4 | import invariant from 'invariant';
5 | import BaseComponent from '../Base';
6 | import PropTypes from 'prop-types';
7 |
8 | export default class Label extends BaseComponent {
9 | static contextTypes = {
10 | addElement: PropTypes.func,
11 | updateElement: PropTypes.func,
12 | deleteElement: PropTypes.func,
13 | createId: PropTypes.func,
14 | getParentInfo: PropTypes.func,
15 | getViewId: PropTypes.func,
16 | }
17 |
18 | static childContextTypes = {
19 | addElement: PropTypes.func,
20 | updateElement: PropTypes.func,
21 | deleteElement: PropTypes.func,
22 | createId: PropTypes.func,
23 | getParentInfo: PropTypes.func,
24 | getViewId: PropTypes.func,
25 | }
26 |
27 | constructor(props) {
28 | super(props, 'Label');
29 | }
30 |
31 | componentWillMount() {
32 | const parentInfo = this.context.getParentInfo();
33 | invariant(parentInfo.name === 'Geom', '` ` must be wrapped in ` `');
34 |
35 | this.id = this.context.createId();
36 |
37 | this.context.addElement(
38 | this.name, this.id, this.props,
39 | this.context.getParentInfo(),
40 | this.context.getViewId()
41 | );
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/doc/faq/faq.md:
--------------------------------------------------------------------------------
1 |
2 | # 常见问题
3 |
4 |
5 |
6 | ## 有问题怎么办
7 | 建议将所有问题相关的教程、api文档及相关的 demo 都看一遍,如果还有问题,欢迎提 [issue](https://github.com/alibaba/BizCharts/issues)
8 |
9 | issue 中请务必提供可复现的链接,方便排查问题。链接可以在 Codepen 中 fork [Bizcharts codepen template](https://codepen.io/leslie2014/pen/xjJGER) 后生成。
10 |
11 |
12 |
13 | ## 坐标轴空间不够
14 | 1、通过配置 `` 组件的 [padding属性](../api/chart.md#padding) 调整图表的内边距给非图形区更多空间。
15 | 2、通过配置 `` 组件中 [content属性](../api/axis.md#content) 上的 formatter 或者 rotate 值,让 label 的文字占用更少的空间。
16 |
17 |
18 |
19 | ## 坐标轴label自定义
20 | 通过配置 `` 组件中 [content属性](../api/axis.md#content) 上的 formatter 函数控制。
21 |
22 |
23 |
24 | ## tooltip显示
25 | 1、通过 `` 组件上的 [tooltip 属性](../api/geom.md#tooltip)控制 tooltip 中的显示内容
26 | 2、通过 `` 组件上的 [itemTpl](../api/axis.md#itemtpl) 和 [containerTpl](../api/axis.md#containertpl) 两个属性用通过 HTML 去控制 tooltip 的显示。
27 | 3、特别复杂的场景可以通过 `` 上的 [onTooltipChange](../api/chart.md#onTooltipChange) 事件来格式化 ` ` 显示内容。
28 |
29 |
30 |
31 | ## tooltip自定义
32 | 通过 `` 组件上的 [itemTpl](../api/axis.md#itemTpl) 和 [containerTpl](../api/axis.md#containerTpl) 两个属性用通过 HTML 去控制 tooltip 的显示。
33 |
--------------------------------------------------------------------------------
/demo/component/pie/pie.js:
--------------------------------------------------------------------------------
1 |
2 | import React, { Component } from 'react';
3 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape, G2 } from 'bizcharts';
4 | import { DataView } from '@antv/data-set';
5 |
6 | const data = [
7 | { item: '事例一', count: 40 },
8 | { item: '事例二', count: 21 },
9 | { item: '事例三', count: 17 },
10 | { item: '事例四', count: 13 },
11 | { item: '事例五', count: 9 }
12 | ];
13 | const dv = new DataView();
14 | dv.source(data).transform({
15 | type: 'percent',
16 | field: 'count',
17 | dimension: 'item',
18 | as: 'percent'
19 | });
20 | const cols = {
21 | percent: {
22 | formatter: val => {
23 | val = (val * 100) + '%';
24 | return val;
25 | }
26 | }
27 | }
28 |
29 | console.log(G2.version);
30 |
31 | export default class PieC extends Component {
32 | render() {
33 | return
34 |
35 |
36 |
41 | {
42 | return item.point.item + ': ' + val;}} />
43 |
44 |
45 | }
46 | };
--------------------------------------------------------------------------------
/demo/component/bar/grouped.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const data = [
7 | { label: 'Monday', series1: 2800, series2: 2260 },
8 | { label: 'Tuesday', series1: 1800, series2: 1300 },
9 | { label: 'Wednesday', series1: 950, series2: 900 },
10 | { label: 'Thursday', series1: 500, series2: 390 },
11 | { label: 'Friday', series1: 170, series2: 100 },
12 | ];
13 | const ds = new DataSet();
14 | const dv = ds.createView().source(data);
15 | dv.transform({
16 | type: 'fold',
17 | fields: [ 'series1', 'series2' ], // 展开字段集
18 | key: 'type', // key字段
19 | value: 'value', // value字段
20 | });
21 |
22 | export default class IntervalC extends Component {
23 |
24 | render() {
25 | return (
26 |
27 |
28 |
29 |
30 |
31 |
35 |
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/demo/component/heatmap/rectangle.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/gaussion-distribution.json'
5 |
6 |
7 | const { DataView } = DataSet;
8 | const { Image } = Guide;
9 | const ds = new DataSet({
10 | state: {
11 | sizeEncoding: false
12 | }
13 | });
14 | const dv = ds.createView('diamond').source(data);
15 | dv.transform({
16 | sizeByCount: '$state.sizeEncoding', // calculate bin size by binning count
17 | type: 'bin.rectangle',
18 | fields: [ 'x', 'y' ], // 对应坐标轴上的一个点
19 | bins: [ 20, 10 ]
20 | });
21 |
22 | export default class HeatmapC extends Component {
23 |
24 | render() {
25 | return (
26 |
27 |
34 |
35 |
36 |
37 |
38 | );
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/demo/component/pie/donutRose.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const data = [
7 | {year: '2001', population: 41.8 },
8 | {year: '2002', population: 38 },
9 | {year: '2003', population: 33.7 },
10 | {year: '2004', population: 30.7 },
11 | {year: '2005', population: 25.8 },
12 | {year: '2006', population: 31.7 },
13 | {year: '2007', population: 33 },
14 | {year: '2008', population: 46 },
15 | {year: '2009', population: 38.3 },
16 | {year: '2010', population: 28 },
17 | {year: '2011', population: 42.5 },
18 | {year: '2012', population: 30.3 }
19 | ];
20 |
21 | export default class PieC extends Component {
22 |
23 | render() {
24 | return (
25 |
26 |
27 |
28 |
32 |
38 |
39 |
40 | );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/test/specs/component/Coord.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Enzyme, { mount } from 'enzyme';
3 | import Adapter from 'enzyme-adapter-react-16';
4 | import chai, { expect } from 'chai';
5 | import chaiEnzyme from 'chai-enzyme';
6 | // import sinon from 'sinon';
7 | import { Chart, Coord } from 'bizcharts';
8 |
9 |
10 | chai.use(chaiEnzyme()); // Note the invocation at the end
11 | Enzyme.configure({ adapter: new Adapter() });
12 | let chartInstance = null;
13 |
14 |
15 | const Test1 = ({ viewProps }) => {
16 | return (
17 | { chartInstance = chart; }}>
18 |
19 |
20 | );
21 | };
22 | describe('Helix', () => {
23 | const wrapper1 = mount( );
24 |
25 | it('endAngle', () => {
26 | expect(chartInstance.get('coordController').cfg.startAngle).eqls(-Math.PI / 6);
27 | expect(chartInstance.get('coordController').cfg.endAngle).eqls(7 * Math.PI / 6);
28 | });
29 | it('update data', () => {
30 | wrapper1.setProps({ viewProps: { startAngle: Math.PI / 9 } });
31 | wrapper1.update();
32 | console.log(chartInstance.get('coordController').cfg);
33 | expect(chartInstance.get('coordController').cfg.startAngle).eqls(Math.PI / 9);
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/doc_en/faq/faq.md:
--------------------------------------------------------------------------------
1 |
2 | # FAQ & Common Issues
3 |
4 |
5 |
6 | ## God a problem?
7 | We are willing to help. Do check out the tutorials and search the issue tracker first. If not available, commit an [issue](//github.com/alibaba/BizCharts/issues).
8 |
9 |
10 |
11 | ## No enough space for axis or get a broken axis?
12 | 1. Config component ``'s [padding](/doc/api/chart.md#padding) prop to adjust the padding space for axis.
13 |
14 | 2. Config component ``'s [content](/doc/api/axis.md#content) prop. Customize the `formatter` or `rotate` to make the axis fit in the given space.
15 |
16 |
17 |
18 | ## How to customize the label of axis?
19 | The [content](/doc/api/axis.md#content) prop in ` ` will do the favor by tuning the `formatter` function.
20 |
21 |
22 |
23 | ## How to display and customize tooltips?
24 |
25 | There are three ways to control and customize tooltip.
26 |
27 | 1. Check out ``'s [tooltip](/doc/api/geom.md#tooltip) prop.
28 |
29 | 2. For a more detailed customization, ``'s [itemTpl](/doc/api/axis.md#itemtpl) and [containerTpl](/doc/api/axis.md#containertpl) prop will help.
30 |
31 | 3. In some complicated scenarios, you can use ``'s [onTooltipChange](/doc/api/chart.md#onTooltipChange) event to format ` `.
32 |
33 |
--------------------------------------------------------------------------------
/demo/component/relation/arc.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/relationship-with-weight.json';
5 |
6 | const { DataView } = DataSet;
7 | const { Text } = Guide;
8 |
9 | const ds = new DataSet();
10 | const dv = ds.createView().source(data, {
11 | type: 'graph',
12 | edges: d => d.links
13 | });
14 | dv.transform({
15 | type: 'diagram.arc',
16 | marginRatio: 0.5,
17 | // sortBy: 'frequency' // id, weight, frequency, {function}
18 | });
19 |
20 |
21 | export default class Arc extends Component {
22 |
23 | render() {
24 | return (
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/doc_en/tutorial/interaction.md:
--------------------------------------------------------------------------------
1 |
2 | # Interaction
3 |
4 | **Reference [G2 Interaction](//antv.alipay.com/zh-cn/g2/3.x/tutorial/interaction.html)**
5 | ## Built in interactions
6 | Including:
7 | - active : react to mouse hover event
8 | - select : can or can't be selected by mouse click event
9 |
10 | ## active
11 | Whether or not react to mouse hover event. All ` ` is set to `true` by default. Change it manually if needed.
12 |
13 | ```
14 |
15 |
16 | ```
17 |
18 | ## select
19 | There are three select modes for every geom shape.
20 | 1. can't be selected
21 | 2. single select
22 | 3. multiple select
23 |
24 | Example:
25 |
26 | ```jsx
27 | ; // can't be selected
28 | ; // can be selected
29 | ;
35 | ```
36 |
37 | By default, only the `pie chart` support select mode.
38 |
39 | **Mostly, you can customize chart's interaction by combining built in interaction with chart's [events](/doc/api/chart.md#event). Reference: [Map drill down](//alibaba.github.io/BizCharts/demo-detail.html?code=demo/map/drill-down)**
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/src/components/TypedGeom/generateTypedGeom.jsx:
--------------------------------------------------------------------------------
1 | import PropTypes from 'prop-types';
2 | import BaseComponent from '../Base';
3 |
4 | function generateTypedGeom(name, geomType) {
5 | class TypedGeom extends BaseComponent {
6 | static contextTypes = {
7 | addElement: PropTypes.func,
8 | updateElement: PropTypes.func,
9 | deleteElement: PropTypes.func,
10 | createId: PropTypes.func,
11 | getParentInfo: PropTypes.func,
12 | getViewId: PropTypes.func,
13 | }
14 |
15 | static childContextTypes = {
16 | addElement: PropTypes.func,
17 | updateElement: PropTypes.func,
18 | deleteElement: PropTypes.func,
19 | createId: PropTypes.func,
20 | getParentInfo: PropTypes.func,
21 | getViewId: PropTypes.func,
22 | }
23 |
24 | static propTypes = {
25 | type: PropTypes.string,
26 | }
27 |
28 | static defaultProps = {
29 | type: geomType,
30 | }
31 |
32 | constructor(props) {
33 | super(props, name);
34 | }
35 |
36 | getChildContext() {
37 | return {
38 | addElement: this.context.addElement,
39 | updateElement: this.context.updateElement,
40 | deleteElement: this.context.deleteElement,
41 | createId: this.context.createId,
42 | getParentInfo: this.getParentInfo,
43 | getViewId: this.context.getViewId,
44 | };
45 | }
46 | }
47 |
48 | return TypedGeom;
49 | }
50 |
51 | export default generateTypedGeom;
52 |
--------------------------------------------------------------------------------
/src/shared/util.js:
--------------------------------------------------------------------------------
1 | /**
2 | * util function
3 | */
4 |
5 | import { Util } from '@antv/g2/lib/core';
6 |
7 | /* eslint-disable no-self-compare */
8 |
9 | function is(x, y) {
10 | if (x === y) {
11 | return x !== 0 || y !== 0 || 1 / x === 1 / y;
12 | }
13 | return x !== x && y !== y; // NaN == NaN
14 | }
15 |
16 | function length(obj) {
17 | if (Util.isArray(obj)) {
18 | return obj.length;
19 | } else if (Util.isObject(obj)) {
20 | return Object.keys(obj).length;
21 | }
22 |
23 | return 0;
24 | }
25 |
26 | export default Util.mix({}, Util, {
27 | shallowEqual(objA, objB) {
28 | if (is(objA, objB)) {
29 | return true;
30 | }
31 |
32 | if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
33 | return false;
34 | }
35 |
36 | if (Util.isArray(objA) !== Util.isArray(objB)) {
37 | return false;
38 | }
39 |
40 | if (length(objA) !== length(objB)) {
41 | return false;
42 | }
43 |
44 | let ret = true;
45 |
46 | Util.each(objA, (v, k) => {
47 | if (!is(v, objB[k])) {
48 | ret = false;
49 | return ret;
50 | }
51 | return true;
52 | });
53 |
54 | return ret;
55 | },
56 |
57 | without(objA, keys = []) {
58 | const ret = {};
59 | Util.each(objA, (v, k) => {
60 | if (Util.indexOf(keys, k) === -1) {
61 | ret[k] = v;
62 | }
63 | });
64 | return ret;
65 | },
66 |
67 | length,
68 | });
69 |
--------------------------------------------------------------------------------
/doc/README.md:
--------------------------------------------------------------------------------
1 |
2 | # BizChart 文档
3 |
4 | ## 教程
5 | - [快速入门](/doc/tutorial/start.md)
6 | - [图表介绍](/doc/tutorial/chart.md)
7 | - [图表类型](/doc/tutorial/chartType.md)
8 | - [数据](/doc/tutorial/data.md)
9 | - [DataSet](/doc/tutorial/dataset.md)
10 | - [dataflow](/doc/tutorial/dataflow.md)
11 | - [主题](/doc/tutorial/theme.md)
12 | - [交互](/doc/tutorial/interaction.md)
13 | - [动画](/doc/tutorial/animate.md)
14 | - [按需加载](/doc/tutorial/needload.md)
15 |
16 | ## api 文档
17 | - [BizCharts](/doc/api/bizcharts.md)
18 | - 组件
19 | - [Chart](/doc/api/chart.md)
20 | - [Coord](/doc/api/coord.md)
21 | - [Axis](/doc/api/axis.md)
22 | - [Geom](/doc/api/geom.md)
23 | - [Label](/doc/api/label.md)
24 | - [Legend](/doc/api/legend.md)
25 | - [Tooltip](/doc/api/tooltip.md)
26 | - [Guide](/doc/api/guide.md)
27 | - [Facet](/doc/api/facet.md)
28 | - [View](/doc/api/view.md)
29 | - 插件
30 | - [Slider](//github.com/alibaba/BizCharts/blob/slider/plugin/slider/README.md)
31 | - 其他
32 | - [scale](/doc/api/scale.md)
33 | - [shape](/doc/api/shape.md)
34 | - [dataset](/doc/api/dataset.md)
35 | - [connector](/doc/api/connector.md)
36 | - [transform](/doc/api/transform.md)
37 | - [theme](/doc/api/theme.md)
38 | - [slider](https://github.com/alibaba/BizCharts/tree/slider/plugin/slider)
39 |
40 |
41 | ## 常见问题
42 | - [有问题怎么办](/doc/faq/faq.md#ques)
43 | - [坐标轴空间不够](/doc/faq/faq.md#axisSpace)
44 | - [坐标轴label自定义](/doc/faq/faq.md#customLabel)
45 | - [tooltip显示](/doc/faq/faq.md#tooltipShow)
46 | - [tooltip自定义](/doc/faq/faq.md#customTooltip)
47 |
--------------------------------------------------------------------------------
/demo/component/bar/histogram.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const values = [ 1.2, 3.4, 3.7, 4.3, 5.2, 5.8, 6.1, 6.5, 6.8, 7.1, 7.3, 7.7, 8.3, 8.6, 8.8, 9.1, 9.2, 9.4, 9.5, 9.7, 10.5, 10.7, 10.8, 11.0, 11.0, 11.1, 11.2, 11.3, 11.4, 11.4, 11.7, 12.0, 12.9, 12.9, 13.3, 13.7, 13.8, 13.9, 14.0, 14.2, 14.5, 15, 15.2, 15.6, 16.0, 16.3, 17.3, 17.5, 17.9, 18.0, 18.0, 20.6, 21, 23.4 ];
7 | const data = [];
8 | for (let i = 0; i < values.length; i++) {
9 | const obj = {};
10 | obj.value = values[i];
11 | data.push(obj);
12 | }
13 | const ds = new DataSet();
14 | const dv = ds.createView().source(data);
15 | dv.transform({
16 | type: 'bin.histogram',
17 | field: 'value',
18 | binWidth: 2,
19 | as: ['value', 'count'],
20 | });
21 | const cols = {
22 | value: {
23 | nice: false,
24 | min: 0,
25 | tickInterval: 1
26 | },
27 | count: {
28 | max: 14
29 | }
30 | }
31 |
32 | export default class IntervalC extends Component {
33 |
34 | render() {
35 | return (
36 |
37 | {if ((val %2)) {return val;} return '';}}}/>
38 |
39 |
40 |
41 |
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/testDemo/component/viewAD/coordAD.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import { setTimeout } from 'timers';
5 |
6 |
7 | const data = [
8 | { label: 'Monday', series1: 2800, series2: 2260 },
9 | { label: 'Tuesday', series1: 1800, series2: 1300 },
10 | { label: 'Wednesday', series1: 950, series2: 900 },
11 | { label: 'Thursday', series1: 500, series2: 390 },
12 | { label: 'Friday', series1: 170, series2: 100 },
13 | ];
14 |
15 | export default class IntervalC extends Component {
16 | constructor() {
17 | super();
18 | this.state = {
19 | val: Math.random() * 10,
20 | }
21 | }
22 |
23 | componentDidMount() {
24 | setInterval(() => {
25 | this.setState({
26 | val: Math.random() * 10,
27 | });
28 | }, 1000);
29 | }
30 |
31 | render() {
32 | return (
33 |
34 |
35 | { this.state.val > 5 && }
36 |
37 |
38 |
39 |
40 |
41 | { this.state.val > 3 && }
42 |
43 |
44 |
45 |
46 |
47 | );
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/demo/component/theme/black.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { setTheme, Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/relationship-with-weight.json';
5 |
6 | const { DataView } = DataSet;
7 | const { Text } = Guide;
8 |
9 | const ds = new DataSet();
10 | const dv = ds.createView().source(data, {
11 | type: 'graph',
12 | edges: d => d.links
13 | });
14 | dv.transform({
15 | type: 'diagram.arc',
16 | marginRatio: 0.5,
17 | // sortBy: 'frequency' // id, weight, frequency, {function}
18 | });
19 |
20 |
21 | export default class Arc extends Component {
22 |
23 | render() {
24 | setTheme("dark");
25 | return (
26 |
27 |
bizcharts do not support set chart's separate theme, just support setTheme global.
28 | so when this chart is opened, the all charts's theme is setted to dark.
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/demo/component/line/series.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const data = [
7 | { month: 'Jan', Tokyo: 7.0, London: 3.9 },
8 | { month: 'Feb', Tokyo: 6.9, London: 4.2 },
9 | { month: 'Mar', Tokyo: 9.5, London: 5.7 },
10 | { month: 'Apr', Tokyo: 14.5, London: 8.5 },
11 | { month: 'May', Tokyo: 18.4, London: 11.9 },
12 | { month: 'Jun', Tokyo: 21.5, London: 15.2 },
13 | { month: 'Jul', Tokyo: 25.2, London: 17.0 },
14 | { month: 'Aug', Tokyo: 26.5, London: 16.6 },
15 | { month: 'Sep', Tokyo: 23.3, London: 14.2 },
16 | { month: 'Oct', Tokyo: 18.3, London: 10.3 },
17 | { month: 'Nov', Tokyo: 13.9, London: 6.6 },
18 | { month: 'Dec', Tokyo: 9.6, London: 4.8 }
19 | ];
20 | const ds = new DataSet();
21 | const dv = ds.createView().source(data);
22 | dv.transform({
23 | type: 'fold',
24 | fields: [ 'Tokyo', 'London' ], // 展开字段集
25 | key: 'city', // key字段
26 | value: 'temperature', // value字段
27 | });
28 | const cols = {
29 | month: {
30 | range: [ 0, 1 ]
31 | }
32 | }
33 |
34 | export default class Series extends Component {
35 | render() {
36 | return (
37 |
38 |
39 | `${val}°C`}}/>
40 |
41 |
42 |
43 |
44 | );
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/test/specs/component/Guide.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Enzyme, { mount } from 'enzyme';
3 | import Adapter from 'enzyme-adapter-react-16';
4 | import chai from 'chai';
5 | import chaiEnzyme from 'chai-enzyme';
6 | import { Chart, Guide, Geom } from 'bizcharts';
7 |
8 | // chart无法获取guide实例
9 | const { RegionFilter } = Guide;
10 |
11 | chai.use(chaiEnzyme()); // Note the invocation at the end
12 | Enzyme.configure({ adapter: new Adapter() });
13 | let chartInstance = null;
14 | const data = [{
15 | year: 1700,
16 | exports: 35,
17 | imports: 70,
18 | }, {
19 | year: 1710,
20 | exports: 59,
21 | imports: 81,
22 | }, {
23 | year: 1720,
24 | exports: 76,
25 | imports: 96,
26 | }];
27 | const scale = {
28 | value: {
29 | min: 0,
30 | max: 200,
31 | },
32 | range: {
33 | min: 0,
34 | max: 200,
35 | },
36 | };
37 |
38 | describe('Guide', () => {
39 | const wrapper = mount(
40 | { chartInstance = chart; }}
46 | >
47 |
54 |
55 |
62 |
63 |
64 | );
65 | it('Guide', () => {
66 | // console.log(chartInstance._attrs.geoms[0]._attrs);
67 | // expect(chartInstance.get('guide')).not.to.be.empty;
68 | });
69 | });
70 |
--------------------------------------------------------------------------------
/demo/component/map/china.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import data from '../../data/china-geo.json';
4 | import DataSet from '@antv/data-set';
5 |
6 | const cols = {
7 | x: { sync: true, nice: false },
8 | y: { sync: true, nice: false }
9 | }
10 |
11 | const { features } = data;
12 | const userData = [];
13 | for(let i=0; i
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | );
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/demo/component/point/bubble.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape, G2 } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/bubble.json'
5 |
6 |
7 | const cols={
8 | LifeExpectancy: {
9 | alias: '人均寿命(年)'
10 | },
11 | Population: {
12 | type: 'pow',
13 | alias: '人口总数'
14 | },
15 | GDP: {
16 | alias: '人均国内生产总值($)'
17 | },
18 | Country: {
19 | alias: '国家/地区'
20 | }
21 | };
22 |
23 | const colorMap = {
24 | 'Asia': G2.Global.colors[0],
25 | 'Americas': G2.Global.colors[1],
26 | 'Europe': G2.Global.colors[2],
27 | 'Oceania': G2.Global.colors[3]
28 | };
29 |
30 | export default class PointC extends Component {
31 |
32 | render() {
33 | return (
34 |
35 |
36 | {
38 | return (value / 1000).toFixed(0) + 'k';
39 | } // 格式化坐标轴的显示
40 | }} />
41 |
42 |
43 | {
44 | return colorMap[val];
45 | }]} tooltip='Country*Population*GDP*LifeExpectancy' opacity={0.65} shape="circle" size={['Population', [ 4, 65 ]]} style={['continent', {
46 | lineWidth: 1,
47 | strokeOpacity: 1,
48 | fillOpacity: 0.3,
49 | opacity: 0.65,
50 | stroke: val => {
51 | return colorMap[val];
52 | }
53 | }]}
54 | />
55 |
56 | );
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/doc_en/README.md:
--------------------------------------------------------------------------------
1 |
2 | # BizChart Documentation
3 |
4 | ## Tutorial
5 | - [Getting Started](/doc_en/tutorial/start.md)
6 | - [Chart Basics & Components](/doc_en/tutorial/chart.md)
7 | - [Chart Types](/doc_en/tutorial/chartType.md)
8 | - [Data](/doc_en/tutorial/data.md)
9 | - [DataSet](/doc_en/tutorial/dataset.md)
10 | - [Dataflow](/doc_en/tutorial/dataflow.md)
11 | - [Theme](/doc_en/tutorial/theme.md)
12 | - [Interaction](/doc_en/tutorial/interaction.md)
13 | - [Animation](/doc_en/tutorial/animate.md)
14 |
15 | ## API Documentation
16 | - [BizCharts](/doc_en/api/bizcharts.md)
17 | - Components
18 | - [Chart](/doc_en/api/chart.md)
19 | - [Coord](/doc_en/api/coord.md)
20 | - [Axis](/doc_en/api/axis.md)
21 | - [Geom](/doc_en/api/geom.md)
22 | - [Label](/doc_en/api/label.md)
23 | - [Legend](/doc_en/api/legend.md)
24 | - [Tooltip](/doc_en/api/tooltip.md)
25 | - [Guide](/doc_en/api/guide.md)
26 | - [Facet](/doc_en/api/facet.md)
27 | - [View](/doc_en/api/view.md)
28 | - Plugins
29 | - [Slider](//github.com/alibaba/BizCharts/blob/slider/plugin/slider/README.md)
30 | - Methods & Tools
31 | - [scale](/doc_en/api/scale.md)
32 | - [shape](/doc_en/api/shape.md)
33 | - [dataset](/doc_en/api/dataset.md)
34 | - [connector](/doc_en/api/connector.md)
35 | - [transform](/doc_en/api/transform.md)
36 | - [theme](/doc_en/api/theme.md)
37 | - [slider](https://github.com/alibaba/BizCharts/tree/slider/plugin/slider)
38 |
39 | ## FAQ & Common Issues
40 | - [Got a problem? Check this out first. :point_left:](/doc_en/faq/faq.md#ques)
41 | - [No enough space for axis or get a broken axis?](/doc_en/faq/faq.md#axisSpace)
42 | - [How to customize the label of axis?](/doc_en/faq/faq.md#customLabel)
43 | - [How to display and customize tooltips?](/doc_en/faq/faq.md#tooltipShow)
44 |
--------------------------------------------------------------------------------
/demo/component/guide/dataMarker_dataRegion.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/income.json';
5 |
6 | const { RegionFilter, DataMarker, Text, DataRegion } = Guide;
7 |
8 | const scale = {
9 | time: {
10 | range: [0, 1]
11 | }
12 | };
13 |
14 | export default class RegionFilter2 extends Component {
15 | render() {
16 | return (
17 |
18 |
19 |
20 |
21 |
30 |
38 |
46 |
52 |
53 |
54 | );
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/testDemo/component/com16/listFacet.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Facet, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import data from '../../data/diamond.json';
5 | import { setTimeout } from 'timers';
6 |
7 | const { DataView } = DataSet;
8 | const { Text } = Guide;
9 |
10 | const scale = {
11 | carat: {
12 | sync: true
13 | },
14 | price: {
15 | sync: true,
16 | tickCount: 3
17 | },
18 | cut: {
19 | sync: true
20 | }
21 | };
22 |
23 |
24 | export default class List extends Component {
25 | constructor(props) {
26 | super(props);
27 | this.state = {
28 | type: 'list',
29 | showFacet: true,
30 | height: 400,
31 | };
32 | }
33 |
34 | componentDidMount() {
35 | setInterval(()=>{
36 | this.setState({
37 | type: this.state.type == 'list' ? 'rect' : 'list',
38 | showFacet: true,
39 | height: 800,
40 | });
41 | }, 2000);
42 | }
43 |
44 | render() {
45 | return (
46 |
47 |
48 |
49 | {
50 | this.state.showFacet ?
51 | {
52 | view.point()
53 | .position('carat*price')
54 | .color('cut')
55 | .shape('circle')
56 | .opacity(0.3)
57 | .size(3);
58 | }}>
59 |
60 | :
61 | null
62 | }
63 |
64 |
65 | );
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/doc/tutorial/chart.md:
--------------------------------------------------------------------------------
1 |
2 | # 图表构成
3 |
4 | ## 组件构成
5 | 在 BizCharts 中,图表是由各个组件组合而成的。组件有两种类型,实体组件和抽象组件。
6 | - 实体组件:在图表上有对应的图形、文本显示。
7 | - 抽象组件:没有显示,是一种概念抽象组件。
8 |
9 | 图表组件有:
10 |
11 | | 名称 | 类型 | 说明 |
12 | | :- | :- | :- |
13 | | [Chart](../api/chart.md) | 实体组件 |图表组件,所有的其他组件都必须由 `` 包裹。|
14 | | [Coord](../api/coord.md) | 抽象组件 |坐标系组件。用来描述 ` ` 组件的坐标系,比如笛卡尔坐标系、极坐标系等。|
15 | | [Axis](../api/axis.md) | 实体组件 | 坐标轴组件。通常包含两个坐标轴,在笛卡尔坐标系下,分别为 x 轴和 y 轴,在极坐标轴下,则分别由角度和半径 2 个维度构成。每个坐标轴由坐标轴线(line)、刻度线(tickLine)、刻度文本(label)、标题(title)以及网格线(grid)组成。|
16 | | [Geom](../api/geom.md) | 实体组件|几何标记组件。即我们所说的点、线、面这些几何图形。|
17 | | [Label](../api/label.md) | 实体组件| 几何标记的辅助文本组件。该组件必须作为` ` 的孩子。|
18 | | [Tooltip](../api/tooltip.md) |实体组件| 提示框组件。|
19 | | [Guide](../api/guide.md) |实体组件| 辅助标记组件。|
20 | | [Guide.Line](../api/guide.md#line) |实体组件| 辅助标记线组件。该组件处于 Guide 组件命名空间下,且必须作为 `` `` 的孩子才会生效。|
21 | | [Guide.Image](../api/guide.md#image) |实体组件| 辅助标记图片组件。该组件处于 Guide 组件命名空间下。且必须作为 `` `` 的孩子才会生效|
22 | | [Guide.Text](../api/guide.md#text) |实体组件| 辅助标记文本组件。该组件处于 Guide 组件命名空间下。且必须作为 `` `` 的孩子才会生效|
23 | | [Guide.Region](../api/guide.md#region) |实体组件| 辅助标记举行组件。该组件处于 Guide 组件命名空间下。且必须作为 `` `` 的孩子才会生效|
24 | | [Guide.Arc](../api/guide.md#arc) |实体组件| 辅助标记弧形组件。该组件处于 Guide 组件命名空间下。且必须作为 `` `` 的孩子才会生效|
25 | | [Guide.Html](../api/guide.md#html) |实体组件| 辅助标记html组件。该组件处于 Guide 组件命名空间下。且必须作为 `` `` 的孩子才会生效|
26 | | [Facet](../api/facet.md) |抽象组件| 分面组件。|
27 | | [View](../api/view.md) |抽象组件| 视图组件。|
28 |
29 |
30 | 图表插件有:
31 |
32 | | 名称 | 类型 | 说明 |
33 | | :- | :- | :- |
34 | | [Slider](https://github.com/alibaba/BizCharts/tree/slider/plugin/slider) | 图标插件 |使用前必须确定已经安装了Bizcarts。|
35 |
36 | ## 空间构成
37 | 下图所示为常用图表的各组件的空间构成。
38 |
39 | 
40 |
--------------------------------------------------------------------------------
/src/components/Chart/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Chart Component
3 | */
4 |
5 | import React from 'react';
6 | import PureChart from './purechart';
7 | import Empty from './empty';
8 | import ErrorBoundary from '../ErrorBoundary';
9 |
10 |
11 | function hasSource(source) {
12 | let flag = true;
13 |
14 | if (source == null || source.length === 0) {
15 | flag = false;
16 | }
17 |
18 | return !!flag;
19 | }
20 |
21 | class Chart extends (React.PureComponent || React.Component) {
22 | getG2Instance() {
23 | return this.chart;
24 | }
25 |
26 | _refCallback = (c) => {
27 | if (c) {
28 | this.chart = c.getG2Instance();
29 | }
30 | }
31 |
32 | hasViewSource = () => {
33 | let hasViewSource = false;
34 | React.Children.map(this.props.children, (child) => {
35 | if (!hasViewSource && typeof (child.type) === 'function' && child.type.name === 'View' && child.props.data && hasSource(child.props.data)) {
36 | hasViewSource = true;
37 | }
38 | });
39 | return hasViewSource;
40 | }
41 |
42 | render() {
43 | const { data, width, height, placeholder, className, style } = this.props;
44 | return (
45 |
46 | {
47 | (hasSource(data) || this.hasViewSource() || !placeholder) ?
48 |
:
49 |
54 | }
55 |
56 | );
57 | }
58 | }
59 |
60 |
61 | export default class BChart extends React.Component {
62 | render() {
63 | return (
64 |
65 |
66 |
67 | );
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/testDemo/component/coord/adddelete.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 | const { Text, Html, Arc, Line } = Guide;
7 | const data1 = [
8 | { year: '1951 年', sales: 38 },
9 | { year: '1952 年', sales: 52 },
10 | { year: '1956 年', sales: 61 },
11 | { year: '1957 年', sales: 145 },
12 | { year: '1958 年', sales: 48 },
13 | { year: '1959 年', sales: 38 },
14 | { year: '1960 年', sales: 38 },
15 | { year: '1962 年', sales: 38 },
16 | ];
17 | const data2 = [
18 | { year: '1951 年', sales: 28 },
19 | { year: '1952 年', sales: 62 },
20 | { year: '1956 年', sales: 31 },
21 | { year: '1957 年', sales: 105 },
22 | { year: '1958 年', sales: 148 },
23 | { year: '1959 年', sales: 8 },
24 | { year: '1960 年', sales: 38 },
25 | { year: '1962 年', sales: 98 },
26 | ];
27 | const cols = {
28 | 'sales': {tickInterval: 20},
29 | };
30 | const type = ['rect','helix','polar','theta']
31 | export default class Basic extends Component {
32 | constructor() {
33 | super();
34 | this.state = {
35 | data: data1,
36 | type: 'rect'
37 | }
38 | }
39 |
40 | componentDidMount() {
41 | setInterval(() => {
42 | this.setState({
43 | data: this.state.data == data1 ? data2 : data1,
44 | type: type[Math.floor(Math.random()*5)]
45 | });
46 | }, 1000);
47 | }
48 | render() {
49 | return (
50 |
51 |
54 |
55 |
56 |
57 |
58 |
59 | );
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/plugin/slider/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
3 | var webpack = require('webpack');
4 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5 | var env = process.env.NODE_ENV;
6 |
7 | var config = {
8 | entry: './src/index.jsx',
9 |
10 | output: {
11 | library: 'bizcharts-plugin-slider',
12 | libraryTarget: 'umd',
13 | },
14 |
15 | module: {
16 | loaders: [{
17 | test: /\.(js|jsx)$/,
18 | exclude: /node_modules/,
19 | include: [
20 | path.resolve(__dirname, 'src'),
21 | ],
22 | loader: 'babel-loader',
23 | query: {
24 | plugins: ['lodash'],
25 | },
26 | }],
27 | },
28 |
29 | resolve: {
30 | extensions: ['.js', '.jsx'],
31 | alias: {
32 | react: path.resolve(__dirname, './node_modules/react'),
33 | },
34 | },
35 |
36 | externals: {
37 | react: {
38 | root: 'React',
39 | commonjs2: 'react',
40 | commonjs: 'react',
41 | amd: 'react',
42 | },
43 | },
44 |
45 | plugins: [
46 | new LodashModuleReplacementPlugin({
47 | collections: true,
48 | shorthands: true,
49 | }),
50 | new webpack.DefinePlugin({
51 | 'process.env.NODE_ENV': JSON.stringify(env),
52 | }),
53 | ],
54 | };
55 |
56 | if (env === 'analyse') {
57 | config.plugins.push(
58 | new BundleAnalyzerPlugin()
59 | );
60 | }
61 |
62 | if (env === 'production') {
63 | config.plugins.push(
64 | new webpack.optimize.UglifyJsPlugin({
65 | compressor: {
66 | pure_getters: true,
67 | unsafe: true,
68 | unsafe_comps: true,
69 | warnings: false,
70 | },
71 | output: {
72 | comments: false,
73 | },
74 | sourceMap: false,
75 | })
76 | );
77 | }
78 |
79 | module.exports = config;
80 |
--------------------------------------------------------------------------------
/doc/tutorial/needload.md:
--------------------------------------------------------------------------------
1 | # 按需加载
2 |
3 | 自 bizcharts@3.1.8 版本起,开始支持按需加载资源文件的功能。
4 |
5 | ## 做法
6 | g2 中资源主要是分为 core 和 对应个 geom 资源,g2 用户需要声明使用了哪个 [geom](https://github.com/antvis/g2/issues/364)。
7 | - 在 bizcharts 中也类似,需要用户自己声明需要加载的资源模块,因此加入了各个类别的 geom 组件,参见 ``src/components/TypedGeom`` 目录。
8 |
9 | | 组件 | 说明 |
10 | | :- | :- |
11 | | ```` | 相当于 ```` |
12 | | ```` | 相当于 ```` |
13 | | `` `` | 相当于 ```` |
14 | | ```` | 相当于 ```` |
15 | | ```` | 相当于 ```` |
16 | | ```` | 相当于 ```` |
17 | | ```` | 相当于 ```` |
18 | | ```` | 相当于 ```` |
19 | | ```` | 相当于 ```` |
20 | | ```` | 相当于 ```` |
21 |
22 |
23 | **因此如果想要按需加载 bizcharts 资源,请使用命名后的 geom 组件,例如 `` `` 等,请勿使用之前的 组件,否则会全量加载 geom 资源。 **
24 |
25 | - 需要使用原先 bizcharts 上的工具函数,请加载 ``import Chart from 'bizcharts/lib/core'``
26 |
27 |
28 | ## 使用 demo
29 | 直接加载需要的组件和模块使用即可。
30 |
31 | ```jsx
32 | import * as bizUtil from 'bizcharts/lib/core'
33 | import Chart from 'bizcharts/lib/components/Chart';
34 | import Axis from 'bizcharts/lib/components/Axis';
35 | import Line from 'bizcharts/lib/components/TypedGeom/Line';
36 |
37 | bizUtil.setTheme('dark');
38 |
39 | ReactDOM.render(
40 |
55 |
56 |
57 |
58 | ,
59 | mountNode
60 | );
61 | ```
62 |
--------------------------------------------------------------------------------
/demo/component/others/htmlTooltip.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const data = [
7 | {"month": '一月', "tem":7, "city": "tokyo" },
8 | {"month": '二月', "tem":6.9, "city": "tokyo" },
9 | {"month": '三月', "tem":9.5, "city": "tokyo" },
10 | {"month": '四月', "tem":14.5, "city": "tokyo" },
11 | {"month": '五月', "tem":18.2, "city": "tokyo" },
12 | {"month": '六月', "tem":21.5, "city": "tokyo" },
13 | {"month": '七月', "tem":25.2, "city": "tokyo" },
14 | {"month": '八月', "tem":26.5, "city": "tokyo" },
15 | {"month": '九月' , "tem":23.3, "city": "tokyo" },
16 | {"month": '十月', "tem":18.3, "city": "tokyo" },
17 | {"month": '十一月', "tem":13.9, "city": "tokyo" }
18 | ];
19 |
20 |
21 | export default class IntervalC extends Component {
22 | render() {
23 | return (
24 |
25 |
26 |
27 |
45 |
46 |
47 | );
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/demo/container/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import PropTypes from 'prop-types';
3 | import { Link } from 'react-router';
4 | import components from '../component/index';
5 |
6 | export default class App extends Component {
7 | static propTypes = {
8 | params: PropTypes.object,
9 | location: PropTypes.object,
10 | }
11 |
12 | renderList() {
13 | const items = Object.keys(components).map(key => {
14 | const group = components[key];
15 | const list = Object.keys(group).map(c => {
16 | const entry = group[c];
17 |
18 | return (
19 |
20 | {c}
21 |
22 | );
23 | });
24 |
25 | return (
26 |
32 | );
33 | });
34 |
35 | return (
36 |
37 |
components
38 | {items}
39 |
40 | );
41 | }
42 |
43 | renderPageDetail() {
44 | const { params, location } = this.props;
45 | const { query } = location;
46 | const { group, page } = query;
47 |
48 | return (
49 |
50 |
Back to homepage
51 |
{page}
52 | {components[group] && components[group][page] ? React.createElement(components[group][page]) : null}
53 |
54 | );
55 | }
56 |
57 | render() {
58 | const { location, params } = this.props;
59 |
60 | if (!location.query || !location.query.page) {
61 | return this.renderList();
62 | }
63 |
64 | return this.renderPageDetail();
65 | }
66 | };
67 |
--------------------------------------------------------------------------------
/testDemo/container/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import PropTypes from 'prop-types';
3 | import { Link } from 'react-router';
4 | import components from '../component/index';
5 |
6 | export default class App extends Component {
7 | static propTypes: {
8 | params: PropTypes.object,
9 | location: PropTypes.object,
10 | }
11 |
12 | renderList() {
13 | const items = Object.keys(components).map(key => {
14 | const group = components[key];
15 | const list = Object.keys(group).map(c => {
16 | const entry = group[c];
17 |
18 | return (
19 |
20 | {c}
21 |
22 | );
23 | });
24 |
25 | return (
26 |
32 | );
33 | });
34 |
35 | return (
36 |
37 |
components
38 | {items}
39 |
40 | );
41 | }
42 |
43 | renderPageDetail() {
44 | const { params, location } = this.props;
45 | const { query } = location;
46 | const { group, page } = query;
47 |
48 | return (
49 |
50 |
Back to homepage
51 |
{page}
52 | {components[group] && components[group][page] ? React.createElement(components[group][page]) : null}
53 |
54 | );
55 | }
56 |
57 | render() {
58 | const { location, params } = this.props;
59 |
60 | if (!location.query || !location.query.page) {
61 | return this.renderList();
62 | }
63 |
64 | return this.renderPageDetail();
65 | }
66 | };
67 |
--------------------------------------------------------------------------------
/testDemo/component/coord/updateRect.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 | const { Text, Html, Arc, Line } = Guide;
7 | const data = [
8 | { year: '1951 年', sales: 38 },
9 | { year: '1952 年', sales: 52 },
10 | { year: '1956 年', sales: 61 },
11 | { year: '1957 年', sales: 145 },
12 | { year: '1958 年', sales: 48 },
13 | { year: '1959 年', sales: 38 },
14 | { year: '1960 年', sales: 38 },
15 | { year: '1962 年', sales: 38 },
16 | ];
17 | const cols = {
18 | 'sales': {tickInterval: 20},
19 | };
20 | export default class Basic extends Component {
21 | constructor() {
22 | super();
23 | this.state = {
24 | rotate: Math.random() * 360,
25 | scale: [Math.random() *0.5+0.5,Math.random() *0.5+0.5],
26 | reflect:'x',
27 | innerRadius: Math.random(),
28 | radius: Math.random(),
29 | startAngle:Math.random()-1 * Math.PI,
30 | endAngle:Math.random() * Math.PI
31 | }
32 | }
33 |
34 | componentDidMount() {
35 | setInterval(() => {
36 | this.setState({
37 | rotate: Math.random() * 360,
38 | scale: [Math.random() *0.5+0.5,Math.random() *0.5+0.5],
39 | reflect:this.state.reflect='x'? 'y':'x',
40 | innerRadius: Math.random(),
41 | radius: Math.random(),
42 | startAngle:Math.random()-1 * Math.PI,
43 | endAngle:Math.random() * Math.PI
44 | });
45 | }, 1000);
46 | }
47 | render() {
48 | return (
49 |
50 |
56 |
57 |
58 |
59 |
60 |
61 | );
62 | }
63 | }
--------------------------------------------------------------------------------
/doc/tutorial/start.md:
--------------------------------------------------------------------------------
1 |
2 | # BizCharts
3 |
4 | BizCharts 是一个基于G2封装的React图表库,具有G2、React的全部优点,可以让用户以组件的形式组合出无数种图表;并且集成了大量的统计工具,支持多种坐标系绘制,交互定制,动画定制以及图形定制等等。相信 BizCharts 定能成为您的数据可视化项目的强力助手。
5 |
6 | ## 特性
7 | - 基于 G2、React
8 | - 健壮
9 | - 稳定
10 | - 强大的扩展能力
11 | - 高自定义能力
12 |
13 | ## 安装
14 |
15 | ### 通过 npm 引入
16 |
17 | 我们提供了 BizCharts npm 包,通过下面的命令即可完成安装
18 |
19 | ```bash
20 | npm install bizcharts --save
21 | ```
22 |
23 | 成功安装完成之后,即可使用 import 或 require 进行引用。
24 |
25 | ## 快速开始
26 |
27 | 在 BizCharts 引入页面后,我们就已经做好了创建第一个图表的准备了。
28 |
29 | 下面是以一个基础的柱状图为例开始我们的第一个图表创建。
30 |
31 | 1. 创建容器
32 |
33 | 在页面的 *body* 部分创建一个节点,指定一个 id
34 |
35 | ```html
36 |
37 | ```
38 |
39 | 2. 使用组件生成图表
40 |
41 | - 引入图表需要的组件
42 | - 用组件组装成需要的图表
43 | - 把图表渲染到 mountNode 节点上
44 |
45 | ```jsx
46 | import React from 'react';
47 | import ReactDOM from 'react-dom';
48 | import { Chart, Geom, Axis, Tooltip, Legend, Coord } from 'bizcharts';
49 |
50 | // 数据源
51 | const data = [
52 | { genre: 'Sports', sold: 275, income: 2300 },
53 | { genre: 'Strategy', sold: 115, income: 667 },
54 | { genre: 'Action', sold: 120, income: 982 },
55 | { genre: 'Shooter', sold: 350, income: 5271 },
56 | { genre: 'Other', sold: 150, income: 3710 }
57 | ];
58 |
59 | // 定义度量
60 | const cols = {
61 | sold: { alias: '销售量' },
62 | genre: { alias: '游戏种类' }
63 | };
64 |
65 | // 渲染图表
66 | ReactDOM.render((
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | ), document.getElementById('mountNode'));
75 |
76 | ```
77 |
78 | 一张柱状图就绘制成功了:
79 |
80 | 
81 |
82 |
83 | ## 体验改进计划说明
84 | 为了更好服务用户,G2 会将打点监控,将 URL 等信息发送回 AntV 服务器,BizCharts 没有关闭这个请求:```https://kcart.alipay.com/web/bi.do```
85 |
86 | 除了 URL 与 G2 版本信息外,不会收集任何其他信息,一切为了能对 G2 的运行情况有更多了解,以更好服务于用户。如有担心,可以通过下面的代码关闭:
87 |
88 | ```js
89 | // 关闭 G2 的体验改进计划打点请求(如:服务端渲染)
90 | BizCharts.track(false);
91 | ```
92 |
--------------------------------------------------------------------------------
/testDemo/component/coord/updateHelix.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 | const { Text, Html, Arc, Line } = Guide;
7 | const data = [
8 | { year: '1951 年', sales: 38 },
9 | { year: '1952 年', sales: 52 },
10 | { year: '1956 年', sales: 61 },
11 | { year: '1957 年', sales: 145 },
12 | { year: '1958 年', sales: 48 },
13 | { year: '1959 年', sales: 38 },
14 | { year: '1960 年', sales: 38 },
15 | { year: '1962 年', sales: 38 },
16 | ];
17 | const cols = {
18 | 'sales': {tickInterval: 20},
19 | };
20 | export default class Basic extends Component {
21 | constructor() {
22 | super();
23 | this.state = {
24 | rotate: Math.random() * 360,
25 | scale: [Math.random() *0.5+0.5,Math.random() *0.5+0.5],
26 | reflect:'x',
27 | innerRadius: Math.random(),
28 | radius: Math.random(),
29 | startAngle:Math.random()-1 * Math.PI,
30 | endAngle:Math.random() * Math.PI
31 | }
32 | }
33 |
34 | componentDidMount() {
35 | setInterval(() => {
36 | this.setState({
37 | rotate: Math.random() * 360,
38 | scale: [Math.random() *0.5+0.5,Math.random() *0.5+0.5],
39 | reflect:this.state.reflect='x'? 'y':'x',
40 | innerRadius: Math.random(),
41 | radius: Math.random(),
42 | startAngle:Math.random()-1 * Math.PI,
43 | endAngle:Math.random() * Math.PI
44 | });
45 | }, 1000);
46 | }
47 | render() {
48 | return (
49 |
50 |
60 |
61 |
62 |
63 |
64 |
65 | );
66 | }
67 | }
--------------------------------------------------------------------------------
/testDemo/component/coord/updatePolar.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 | const { Text, Html, Arc, Line } = Guide;
7 | const data = [
8 | { year: '1951 年', sales: 38 },
9 | { year: '1952 年', sales: 52 },
10 | { year: '1956 年', sales: 61 },
11 | { year: '1957 年', sales: 145 },
12 | { year: '1958 年', sales: 48 },
13 | { year: '1959 年', sales: 38 },
14 | { year: '1960 年', sales: 38 },
15 | { year: '1962 年', sales: 38 },
16 | ];
17 | const cols = {
18 | 'sales': {tickInterval: 20},
19 | };
20 | export default class Basic extends Component {
21 | constructor() {
22 | super();
23 | this.state = {
24 | rotate: Math.random() * 360,
25 | scale: [Math.random() *0.5+0.5,Math.random() *0.5+0.5],
26 | reflect:'x',
27 | innerRadius: Math.random(),
28 | radius: Math.random(),
29 | startAngle:Math.random()-1 * Math.PI,
30 | endAngle:Math.random() * Math.PI
31 | }
32 | }
33 |
34 | componentDidMount() {
35 | setInterval(() => {
36 | this.setState({
37 | rotate: Math.random() * 360,
38 | scale: [Math.random() *0.5+0.5,Math.random() *0.5+0.5],
39 | reflect:this.state.reflect='x'? 'y':'x',
40 | innerRadius: Math.random(),
41 | radius: Math.random(),
42 | startAngle:Math.random()-1 * Math.PI,
43 | endAngle:Math.random() * Math.PI
44 | });
45 | }, 1000);
46 | }
47 | render() {
48 | return (
49 |
50 |
60 |
61 |
62 |
63 |
64 |
65 | );
66 | }
67 | }
--------------------------------------------------------------------------------
/testDemo/component/coord/updateTheta.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 | const { Text, Html, Arc, Line } = Guide;
7 | const data = [
8 | { year: '1951 年', sales: 38 },
9 | { year: '1952 年', sales: 52 },
10 | { year: '1956 年', sales: 61 },
11 | { year: '1957 年', sales: 145 },
12 | { year: '1958 年', sales: 48 },
13 | { year: '1959 年', sales: 38 },
14 | { year: '1960 年', sales: 38 },
15 | { year: '1962 年', sales: 38 },
16 | ];
17 | const cols = {
18 | 'sales': {tickInterval: 20},
19 | };
20 | export default class Basic extends Component {
21 | constructor() {
22 | super();
23 | this.state = {
24 | rotate: Math.random() * 360,
25 | scale: [Math.random() *0.5+0.5,Math.random() *0.5+0.5],
26 | reflect:'x',
27 | innerRadius: Math.random(),
28 | radius: Math.random(),
29 | startAngle:Math.random()-1 * Math.PI,
30 | endAngle:Math.random() * Math.PI
31 | }
32 | }
33 |
34 | componentDidMount() {
35 | setInterval(() => {
36 | this.setState({
37 | rotate: Math.random() * 360,
38 | scale: [Math.random() *0.5+0.5,Math.random() *0.5+0.5],
39 | reflect:this.state.reflect='x'? 'y':'x',
40 | innerRadius: Math.random(),
41 | radius: Math.random(),
42 | startAngle:Math.random()-1 * Math.PI,
43 | endAngle:Math.random() * Math.PI
44 | });
45 | }, 1000);
46 | }
47 | render() {
48 | return (
49 |
50 |
60 |
61 |
62 |
63 |
64 |
65 | );
66 | }
67 | }
--------------------------------------------------------------------------------
/doc/api/view.md:
--------------------------------------------------------------------------------
1 | # View
2 |
3 | 视图,由 Chart 生成和管理,拥有自己独立的数据源、坐标系和图层,用于异构数据的可视化以及图表组合,一个 Chart 由一个或者多个视图 View 组成。因此 view 上的 api 同 chart 基本相同。
4 |
5 | ## 使用说明
6 |
7 | ### Parent Components
8 | - ` `
9 | ### Child Components
10 | - [` `](coord.md) 坐标系组件
11 | - [` `](axis.md) 坐标轴组件,特性跟` `一样,默认全部不显示,若配置一个轴显示,则全部轴显示。
12 | - [` `](geom.md) 几何标记组件
13 | - [` `](legend.md) 图例组件
14 | - [` `](tooltip.md) 提示框组件
15 | - [` `](guide.md) 辅助标记组件
16 | - [` `](facet.md) 分面组件
17 | - [` `](view.md) 视图组件
18 |
19 |
20 | **实际开发过程中,很多图表都可以采用View组件来实现,包含但不限于以下几个方面:**
21 |
22 | * 在同一个容器中出现两个或者更多不同坐标系的图表时,可以采用View组件来实现,如下图所示;[Demo](https://alibaba.github.io/BizCharts/demo-detail.html?code=demo/pie/sunburst)
23 | 
24 |
25 | * 同一个容器中的两个图表需要采用不同的数据源时,如下图所示:[Demo](https://alibaba.github.io/BizCharts/demo-detail.html?code=demo/funnel/symmetric)
26 | 
27 |
28 |
29 |
30 | ```html
31 | // 这里只显示部分核心代码
32 |
33 |
34 |
39 |
40 |
41 |
46 |
47 |
48 | ```
49 |
50 | ## 属性
51 | ### 1、id * String *
52 | 视图的 id 标识,用于唯一标定视图,如果用户不指定,G2 会默认提供一套 id 生成机制(‘view’ + views.length,如 view0, view1, …, viewN)。
53 |
54 | ### 2、start * Object *
55 | 绘制区域的起始坐标,x和y的取值范围均为0 -1。
56 | 我们的起始点是从**左上角**开始的。
57 | 参见:
58 | ```jsx
59 |
60 | ```
61 |
62 | ### 3、end * Object *
63 | 绘制区域的结束坐标,x和y的取值范围均为0 -1。
64 |
65 | 参见:
66 | ```jsx
67 |
68 | ```
69 |
70 | ### 4、data * Array | DataSet *
71 | 使用同 `Chart` 的 [data 属性](chart.md#data)。
72 |
73 | ### 5、animate * Boolean *
74 | 视图是否执行动画。
75 | 默认值:true。
76 |
77 | ### 6、scale * Object *
78 | 使用同 `Chart` 的 [scale 属性](chart.md#scale)。
79 |
80 | ### 7、filter * Object *
81 | 使用同 `Chart` 的 [filer 属性](chart.md#filter)。
82 |
83 |
--------------------------------------------------------------------------------
/plugin/slider/src/index.jsx:
--------------------------------------------------------------------------------
1 | import G2Slider from '@antv/g2-plugin-slider';
2 | import React, { Component } from 'react';
3 | import ErrorBoundary from './error-boundary';
4 |
5 | const SliderAttrs = ['width', 'height', 'padding', 'xAis', 'yAxis', 'start', 'end',
6 | 'fillerStyle', 'backgroundStyle', 'scales', 'textStyle', 'handleStyle', 'backgroundChart'];
7 |
8 | function sliderNeedRebuild(props, nextProps) {
9 | if (props.onChange !== nextProps.onChange) { return true; }
10 |
11 | for (let i = 0; i < SliderAttrs.length; i += 1) {
12 | const attr = SliderAttrs[i];
13 | if (!window.G2.Util.isEqual(props[attr], nextProps[attr])) {
14 | return true;
15 | }
16 | }
17 |
18 | return false;
19 | }
20 |
21 | class Slider extends Component {
22 | constructor() {
23 | super();
24 | this.reBuild = false;
25 | }
26 |
27 | componentDidMount() {
28 | const slider = this.createG2Instance();
29 | slider.render();
30 | }
31 |
32 | componentWillReceiveProps(nextProps) {
33 | const { data, ...others } = this.props;
34 | const { data: nextData, ...nextOthers } = nextProps;
35 | // refrence compare
36 | if (data !== nextData) {
37 | this.slider.changeData(nextData);
38 | this.slider.repaint();
39 | }
40 |
41 | if (sliderNeedRebuild(others, nextOthers)) {
42 | this.reBuild = true;
43 | }
44 | }
45 |
46 | componentDidUpdate() {
47 | if (!this.reBuild) { return; }
48 |
49 | this.slider.destroy();
50 | const slider = this.createG2Instance();
51 | slider.render();
52 | this.reBuild = false;
53 | }
54 |
55 | componentWillUnmount() {
56 | this.slider.destroy();
57 | }
58 |
59 | createG2Instance() {
60 | this.slider = new G2Slider({ container: this.container, ...this.props });
61 | return this.slider;
62 | }
63 |
64 | refHandle = (cw) => {
65 | // chart container wrap for reset operation
66 | if (!this.container) {
67 | this.container = cw;
68 | }
69 | }
70 |
71 | render() {
72 | return (
73 |
74 | );
75 | }
76 | }
77 |
78 | class BSlider extends Component {
79 | render() {
80 | return
81 |
82 |
83 | }
84 |
85 | }
86 | exports.default = BSlider;
87 | module.exports = exports['default'];
88 |
--------------------------------------------------------------------------------
/testDemo/component/viewAD/axisAD.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 | import { setTimeout } from 'timers';
5 |
6 |
7 | const data = [
8 | { label: 'Monday', series1: 2800, series2: 2260 },
9 | { label: 'Tuesday', series1: 1800, series2: 1300 },
10 | { label: 'Wednesday', series1: 950, series2: 900 },
11 | { label: 'Thursday', series1: 500, series2: 390 },
12 | { label: 'Friday', series1: 170, series2: 100 },
13 | ];
14 |
15 | export default class IntervalC extends Component {
16 | constructor() {
17 | super();
18 | this.state = {
19 | val: Math.random() * 10,
20 | }
21 | }
22 |
23 | componentDidMount() {
24 | setInterval(() => {
25 | this.setState({
26 | val: Math.random() * 10,
27 | });
28 | }, 1000);
29 | }
30 |
31 | render() {
32 | return (
33 |
34 |
35 |
36 | {
37 | this.state.val < 4 &&
38 | }
39 | {
40 | this.state.val > 2 && this.state.val < 7 &&
41 | }
42 | {
43 | this.state.val > 6 && this.state.val < 11 &&
44 | }
45 |
46 |
47 |
48 |
49 |
50 |
51 | {
52 | this.state.val < 6 &&
53 | }
54 | {
55 | this.state.val > 3 && this.state.val < 8 &&
56 | }
57 | {
58 | this.state.val > 5 && this.state.val < 20 &&
59 | }
60 |
61 |
62 |
63 |
64 |
65 | );
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/demo/component/area/stacked.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 |
7 | const data = [
8 | {country: 'Asia', year: '1750', value: 502},
9 | {country: 'Asia', year: '1800', value: 635},
10 | {country: 'Asia', year: '1850', value: 809},
11 | {country: 'Asia', year: '1900', value: 5268},
12 | {country: 'Asia', year: '1950', value: 4400},
13 | {country: 'Asia', year: '1999', value: 3634},
14 | {country: 'Asia', year: '2050', value: 947},
15 | {country: 'Africa', year: '1750', value: 106},
16 | {country: 'Africa', year: '1800', value: 107},
17 | {country: 'Africa', year: '1850', value: 111},
18 | {country: 'Africa', year: '1900', value: 1766},
19 | {country: 'Africa', year: '1950', value: 221},
20 | {country: 'Africa', year: '1999', value: 767},
21 | {country: 'Africa', year: '2050', value: 133},
22 | {country: 'Europe', year: '1750', value: 163},
23 | {country: 'Europe', year: '1800', value: 203},
24 | {country: 'Europe', year: '1850', value: 276},
25 | {country: 'Europe', year: '1900', value: 628},
26 | {country: 'Europe', year: '1950', value: 547},
27 | {country: 'Europe', year: '1999', value: 729},
28 | {country: 'Europe', year: '2050', value: 408},
29 | {country: 'Oceania', year: '1750', value: 200},
30 | {country: 'Oceania', year: '1800', value: 200},
31 | {country: 'Oceania', year: '1850', value: 200},
32 | {country: 'Oceania', year: '1900', value: 460},
33 | {country: 'Oceania', year: '1950', value: 230},
34 | {country: 'Oceania', year: '1999', value: 300},
35 | {country: 'Oceania', year: '2050', value: 300},
36 | ];
37 | const cols = {
38 | year: {
39 | type: 'linear',
40 | tickInterval: 50
41 | }
42 | }
43 |
44 |
45 | export default class Stacked extends Component {
46 |
47 | render() {
48 | return (
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | );
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/demo/component/area/percent.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 |
7 | const data = [
8 | {country: 'Asia', year: '1750', value: 502},
9 | {country: 'Asia', year: '1800', value: 635},
10 | {country: 'Asia', year: '1850', value: 809},
11 | {country: 'Asia', year: '1900', value: 947},
12 | {country: 'Asia', year: '1950', value: 1402},
13 | {country: 'Asia', year: '1999', value: 3634},
14 | {country: 'Asia', year: '2050', value: 5268},
15 | {country: 'Africa', year: '1750', value: 106},
16 | {country: 'Africa', year: '1800', value: 107},
17 | {country: 'Africa', year: '1850', value: 111},
18 | {country: 'Africa', year: '1900', value: 133},
19 | {country: 'Africa', year: '1950', value: 221},
20 | {country: 'Africa', year: '1999', value: 767},
21 | {country: 'Africa', year: '2050', value: 1766},
22 | {country: 'Europe', year: '1750', value: 163},
23 | {country: 'Europe', year: '1800', value: 203},
24 | {country: 'Europe', year: '1850', value: 276},
25 | {country: 'Europe', year: '1900', value: 408},
26 | {country: 'Europe', year: '1950', value: 547},
27 | {country: 'Europe', year: '1999', value: 729},
28 | {country: 'Europe', year: '2050', value: 628}
29 | ];
30 |
31 | const dv = new DataView().source(data);
32 | dv.transform({
33 | type: 'percent',
34 | field: 'value',
35 | dimension: 'country',
36 | groupBy: [ 'year' ],
37 | as: 'percent'
38 | });
39 | const cols = {
40 | year: {
41 | type: 'linear',
42 | tickInterval: 50
43 | },
44 | 'percent': {
45 | formatter: function(value) {
46 | value = value || 0;
47 | value = value * 100;
48 | return parseInt(value);
49 | },
50 | alias: 'percent(%)'
51 | }
52 | }
53 |
54 | export default class Percent extends Component {
55 |
56 | render() {
57 | return (
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | );
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/demo/component/funnel/basic.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 | const { Text } = Guide;
7 |
8 | let data = [
9 | { action: '浏览网站', pv: 50000 },
10 | { action: '放入购物车', pv: 35000 },
11 | { action: '生成订单', pv: 25000 },
12 | { action: '支付订单', pv: 15000 },
13 | { action: '完成交易', pv: 8000 }
14 | ];
15 | const dv = new DataView().source(data);
16 | dv.transform({
17 | type: 'percent',
18 | field: 'pv',
19 | dimension: 'action',
20 | as: 'percent'
21 | });
22 | data = dv.rows;
23 | const cols = {
24 | percent: {
25 | nice: false
26 | }
27 | }
28 |
29 | export default class Basic extends Component {
30 | render() {
31 | return (
32 |
33 |
34 |
35 |
36 |
37 | {data.map((obj,index) => {
38 | return ( )
51 | })}
52 |
53 | {
55 | return {
56 | name: action,
57 | percent: parseInt(percent * 100) + '%',
58 | pv: pv
59 | };
60 | }]}
61 | >
62 | {
63 | return action + ' ' + pv;
64 | }]}
65 | offset={35}
66 | labeLine={{lineWidth: 1,
67 | stroke: 'rgba(0, 0, 0, 0.15)'}}
68 | />
69 |
70 |
71 | );
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/demo/component/heatmap/heatmap.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 |
7 | const data = [[0, 0, 10], [0, 1, 19], [0, 2, 8], [0, 3, 24], [0, 4, 67], [1, 0, 92], [1, 1, 58], [1, 2, 78], [1, 3, 117], [1, 4, 48], [2, 0, 35], [2, 1, 15], [2, 2, 123], [2, 3, 64], [2, 4, 52], [3, 0, 72], [3, 1, 132], [3, 2, 114], [3, 3, 19], [3, 4, 16], [4, 0, 38], [4, 1, 5], [4, 2, 8], [4, 3, 117], [4, 4, 115], [5, 0, 88], [5, 1, 32], [5, 2, 12], [5, 3, 6], [5, 4, 120], [6, 0, 13], [6, 1, 44], [6, 2, 88], [6, 3, 98], [6, 4, 96], [7, 0, 31], [7, 1, 1], [7, 2, 82], [7, 3, 32], [7, 4, 30], [8, 0, 85], [8, 1, 97], [8, 2, 123], [8, 3, 64], [8, 4, 84], [9, 0, 47], [9, 1, 114], [9, 2, 31], [9, 3, 48], [9, 4, 91]];
8 | const source = [];
9 | for(let i = 0; i < data.length; i ++) {
10 | const item = data[i];
11 | const obj = {};
12 | obj.name = item[0];
13 | obj.day = item[1];
14 | obj.sales = item[2];
15 | source.push(obj);
16 | }
17 |
18 | const cols ={
19 | name: {
20 | type: 'cat',
21 | values: ['Alexander', 'Marie', 'Maximilian', 'Sophia', 'Lukas', 'Maria', 'Leon', 'Anna', 'Tim', 'Laura']
22 | },
23 | day: {
24 | type: 'cat',
25 | values: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
26 | }
27 | }
28 | export default class Headmap extends Component {
29 |
30 | render() {
31 | return (
32 |
33 |
42 |
50 |
51 |
54 |
60 |
61 |
62 | );
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/demo/component/funnel/symmetric.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape, Facet } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 | const { Text } = Guide;
7 |
8 | const data = [
9 | { action: '访问', visitor: 500, site: '站点1' },
10 | { action: '浏览', visitor: 400, site: '站点1' },
11 | { action: '交互', visitor: 300, site: '站点1' },
12 | { action: '下单', visitor: 200, site: '站点1' },
13 | { action: '完成', visitor: 100, site: '站点1' },
14 | { action: '访问', visitor: 550, site: '站点2' },
15 | { action: '浏览', visitor: 420, site: '站点2' },
16 | { action: '交互', visitor: 280, site: '站点2' },
17 | { action: '下单', visitor: 150, site: '站点2' },
18 | { action: '完成', visitor: 80, site: '站点2' }
19 | ];
20 | data.sort(function(obj1, obj2){ // 从小到大
21 | return obj1.visitor - obj2.visitor;
22 | });
23 |
24 |
25 | export default class Basic extends Component {
26 |
27 | render() {
28 | return(
29 |
30 |
31 |
32 |
33 |
34 | {
35 | return {
36 | name: site,
37 | value: action + ': ' + visitor
38 | };
39 | }]}
40 | style={{lineWidth: 1,
41 | stroke: '#fff'}}/>
42 |
43 | {data.map(obj => {
44 | return (
45 |
50 | )
51 | }
52 | )}
53 |
54 |
55 |
56 |
57 | )
58 | }
59 |
60 | }
--------------------------------------------------------------------------------
/doc_en/tutorial/chart.md:
--------------------------------------------------------------------------------
1 |
2 | # Chart Components
3 |
4 | ## Main Components
5 | In BizCharts, charts are made up of the following components. In total, there are 2 kinds of components, concrete and abstract.
6 | - Concrete Component: Components that will be rendered on the chart, such as text
7 | - Abstract Component: Do not show up visually on the chart but will affect how it renders
8 |
9 | The list of components are as follows:
10 |
11 | | Name | Component Type | Description |
12 | | :- | :- | :- |
13 | | [Chart](../api/chart.md) | Concrete |Main chart component. All charts need to be wrapped by the `` component.|
14 | | [Coord](../api/coord.md) | Abstract | Describes the coordinate system of the chart (i.e. Cartesian, Polar) |
15 | | [Axis](../api/axis.md) | Concrete | Charts typically have x and y axes. However in polar coordinates the axes become angle and radius. Each axis is made up of a line, tickline, label, title and grid. |
16 | | [Geom](../api/geom.md) | Concrete| Base component that can be used to represent dots, lines and other shapes |
17 | | [Label](../api/label.md) | Concrete| Component responsible for rendering text associated with the geometry component. Must be the child of a ` ` component. |
18 | | [Tooltip](../api/tooltip.md) |Concrete| Tooltip Component. |
19 | | [Guide](../api/guide.md) |Concrete| Guide Component. Different from labels in that it's not attached to a data point. Can consist of lines, images, text etc |
20 | | [Guide.Line](../api/guide.md#line) |Concrete| Guide Line component. Must be the child of the ` ` component. |
21 | | [Guide.Image](../api/guide.md#image) |Concrete| Image Guide component. Must be the child of the ` ` component. |
22 | | [Guide.Text](../api/guide.md#text) |Concrete| Text Guide component. Must be the child of the ` ` component. |
23 | | [Guide.Region](../api/guide.md#region) |Concrete| Guide Region component. Must be the child of the ` ` component.|
24 | | [Guide.Arc](../api/guide.md#arc) |Concrete| Arc Guide component. Must be the child of the ` ` component.|
25 | | [Guide.Html](../api/guide.md#html) |Concrete| Html Guide component. Must be the child of the ` ` component.|
26 | | [Facet](../api/facet.md) |Abstract| Facet Component |
27 | | [View](../api/view.md) |Abstract| view Component |
28 |
29 | ## Layout
30 | The following image demonstrates how to build a chart using the above components.
31 |
32 | 
33 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
3 | var webpack = require('webpack');
4 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5 | var env = process.env.NODE_ENV;
6 |
7 | var config = {
8 | entry: './src/index.jsx',
9 |
10 | output: {
11 | library: 'BizCharts',
12 | libraryTarget: 'umd',
13 | },
14 |
15 | module: {
16 | loaders: [{
17 | test: /\.(js|jsx)$/,
18 | exclude: /node_modules/,
19 | include: [
20 | path.resolve(__dirname, 'src'),
21 | ],
22 | loader: 'babel-loader',
23 | query: {
24 | plugins: ['lodash'],
25 | },
26 | }],
27 | },
28 |
29 | resolve: {
30 | extensions: ['.js', '.jsx'],
31 | alias: {
32 | react: path.resolve(__dirname, './node_modules/react'),
33 | },
34 | },
35 |
36 | externals: {
37 | react: {
38 | root: 'React',
39 | commonjs2: 'react',
40 | commonjs: 'react',
41 | amd: 'react',
42 | },
43 | 'prop-types': {
44 | commonjs: 'prop-types',
45 | commonjs2: 'prop-types',
46 | amd: 'prop-types',
47 | root: 'prop-types',
48 | },
49 | },
50 |
51 | plugins: [
52 | new LodashModuleReplacementPlugin({
53 | collections: true,
54 | shorthands: true,
55 | }),
56 | new webpack.DefinePlugin({
57 | 'process.env.NODE_ENV': JSON.stringify(env),
58 | }),
59 | ],
60 | };
61 |
62 | if (env === 'analyse') {
63 | config.plugins.push(
64 | new BundleAnalyzerPlugin({
65 | analyzerMode: 'server',
66 | analyzerHost: '127.0.0.1',
67 | analyzerPort: 8889,
68 | reportFilename: 'report.html',
69 | defaultSizes: 'parsed',
70 | openAnalyzer: true,
71 | generateStatsFile: false,
72 | statsFilename: 'stats.json',
73 | statsOptions: null,
74 | logLevel: 'info',
75 | })
76 | );
77 | }
78 |
79 | if (env === 'development' || env === 'production') {
80 | // umd do not use prop-types as external lib.
81 | delete config.externals['prop-types'];
82 | }
83 |
84 | if (env === 'production') {
85 | config.plugins.push(
86 | new webpack.optimize.UglifyJsPlugin({
87 | compressor: {
88 | pure_getters: true,
89 | unsafe: true,
90 | unsafe_comps: true,
91 | warnings: false,
92 | },
93 | output: {
94 | comments: false,
95 | },
96 | sourceMap: false,
97 | })
98 | );
99 | }
100 |
101 | module.exports = config;
102 |
--------------------------------------------------------------------------------
/demo/component/pie/sunburst.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 |
7 | const data = [
8 | { value: 251, type: '大事例一', name: '子事例一' },
9 | { value: 1048, type: '大事例一', name: '子事例二' },
10 | { value: 610, type: '大事例二', name: '子事例三' },
11 | { value: 434, type: '大事例二', name: '子事例四' },
12 | { value: 335, type: '大事例三', name: '子事例五' },
13 | { value: 250, type: '大事例三', name: '子事例六' }
14 | ];
15 | const dv = new DataView();
16 | dv.source(data).transform({
17 | type: 'percent',
18 | field: 'value',
19 | dimension: 'type',
20 | as: 'percent'
21 | });
22 | const cols = {
23 | percent: {
24 | formatter: val => {
25 | val = (val * 100).toFixed(2) + '%';
26 | return val;
27 | }
28 | }
29 | }
30 | const dv1 = new DataView();
31 | dv1.source(data).transform({
32 | type: 'percent',
33 | field: 'value',
34 | dimension: 'name',
35 | as: 'percent'
36 | });
37 |
38 | export default class PieC extends Component {
39 |
40 | render() {
41 | return (
42 |
43 |
44 |
48 | {
53 | percent = (percent * 100).toFixed(2) + '%';
54 | return {
55 | name: item,
56 | value: percent
57 | };
58 | }]}
59 | style={{lineWidth: 1,stroke: '#fff'}}
60 | select={false}
61 | >
62 |
63 |
64 |
65 |
66 | {
71 | percent = (percent * 100).toFixed(2) + '%';
72 | return {
73 | name: item,
74 | value: percent
75 | };
76 | }]}
77 | style={{lineWidth: 1,stroke: '#fff'}}
78 | select={false}
79 | >
80 |
81 |
82 |
83 |
84 | );
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/testDemo/component/legend/adddelete.js:
--------------------------------------------------------------------------------
1 |
2 | import React, { Component } from 'react';
3 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
4 | import DataSet from '@antv/data-set';
5 |
6 | const { DataView } = DataSet;
7 | const { Text, Html, Arc, Line } = Guide;
8 | const data1 = [
9 | { year: '1951 年', sales: 38 },
10 | { year: '1952 年', sales: 52 },
11 | { year: '1956 年', sales: 61 },
12 | { year: '1957 年', sales: 145 },
13 | { year: '1958 年', sales: 48 },
14 | { year: '1959 年', sales: 38 },
15 | { year: '1960 年', sales: 38 },
16 | { year: '1962 年', sales: 38 },
17 | ];
18 | const data2 = [
19 | { year: '1951 年', sales: 28 },
20 | { year: '1952 年', sales: 62 },
21 | { year: '1956 年', sales: 31 },
22 | { year: '1957 年', sales: 105 },
23 | { year: '1958 年', sales: 148 },
24 | { year: '1959 年', sales: 8 },
25 | { year: '1960 年', sales: 38 },
26 | { year: '1962 年', sales: 98 },
27 | ];
28 | const cols = {
29 | 'sales': {tickInterval: 20,'alias':"请显示我!!!"},
30 | };
31 | const typeAry=['point','path','line','area','interval','polygon','edge','schema','heatmap'];
32 | export default class Basic extends Component {
33 | constructor() {
34 | super();
35 | this.state = {
36 | data: data1,
37 | position: 'bottom',
38 | typeAry:'line',
39 | boolean: true
40 | }
41 | }
42 |
43 | componentDidMount() {
44 | setInterval(() => {
45 | this.setState({
46 | data: this.state.data == data1 ? data2 : data1,
47 | typeAry:typeAry[Math.floor(Math.random()*9)]
48 | });
49 | }, 1000);
50 | }
51 | render() {
52 | return (
53 |
54 |
56 |
58 | {this.state.typeAry==='path' && }
59 | {this.state.typeAry==='line' && }
60 | {this.state.typeAry==='area' && }
61 | {this.state.typeAry==='polygon' && }
62 | {this.state.typeAry==='polygon' && }
63 | {this.state.typeAry==='edge' && }
64 | {this.state.typeAry==='schema' && }
65 | {this.state.typeAry==='schema' && }
66 | {this.state.typeAry==='heatmap' && }
67 | {this.state.typeAry==='interval' && }
68 | {this.state.typeAry==='interval' && }
69 |
70 |
71 | );
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/demo/component/cloud/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Axis, Geom, Tooltip, Coord, Legend, Label } from 'bizcharts';
3 | import { DataView } from '@antv/data-set';
4 |
5 |
6 | export default class PieComponent extends React.Component {
7 |
8 | constructor(props) {
9 | super(props);
10 | this.state = {
11 | data: [
12 | {"item":"18岁以下","count":1},
13 | {"item":"18-24岁","count":2},
14 | {"item":"25-29岁","count":1},
15 | {"item":"30-34岁","count":2},
16 | {"item":"40-49岁","count":1}
17 | ]
18 | };
19 | }
20 |
21 | componentWillReceiveProps(nextProps) {
22 | this.setState({
23 | data: nextProps.data
24 | });
25 | }
26 |
27 | render() {
28 | let data = this.state.data;
29 |
30 | const dv = new DataView();
31 | dv.source(data).transform({
32 | type: 'percent',
33 | field: 'count',
34 | dimension: 'item',
35 | as: 'percent',
36 | });
37 |
38 | const cols = {
39 | percent: {
40 | formatter: (val) => {
41 | val = `${val * 100}%`;
42 | return val;
43 | },
44 | },
45 | };
46 |
47 | return (
48 |
49 |
{this.props.title}
50 |
57 |
58 |
59 |
60 |
64 | {
71 | return {
72 | name: item,
73 | value: (percent * 100).toFixed(2) + '%',
74 | };
75 | },
76 | ]}
77 | style={{ lineWidth: 1, stroke: '#fff' }}
78 | >
79 | {
82 | let percent = item.point.percent;
83 | percent = (percent * 100).toFixed(2) + '%';
84 | return `${item.point.item}: ${percent}`;
85 | }}
86 | />
87 |
88 |
89 |
90 | );
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/doc/api/connector.md:
--------------------------------------------------------------------------------
1 | # Connector 数据接入
2 |
3 | 一个数据视图(DataSet.View)实例在接入数据时就会用到 Connector,其语法如下:
4 |
5 | ```js
6 | dv.source(data, {
7 | type: connectorName,
8 | ...otherOptions
9 | });
10 | ```
11 |
12 | 举个例子:
13 |
14 | ```js
15 | const testCSV = `Expt,Run,Speed
16 | 1,1,850
17 | 1,2,740
18 | 1,3,900
19 | 1,4,1070`;
20 |
21 | const dv = new DataSet.View().source(testCSV, {
22 | type: 'csv'
23 | });
24 |
25 | console.log(dv.rows);
26 | /*
27 | * dv.rows:
28 | * [
29 | * {Expt: " 1", Run: "1", Speed: "850"}
30 | * {Expt: " 1", Run: "2", Speed: "740"}
31 | * {Expt: " 1", Run: "3", Speed: "900"}
32 | * {Expt: " 1", Run: "4", Speed: "1070"}
33 | * ]
34 | */
35 | ```
36 |
37 | 上述代码中,数据视图实例 `dv` 使用 `csv` 类型的 Connector 载入了一段 CSV 文本。
38 |
39 | 目前 DataSet 支持以下几种常用的 Connector:
40 |
41 | ## default 默认
42 |
43 | 直接调用 `dv.source(data)`,不通过配置项指定使用的 Connector 时,则有以下两种默认的情形:
44 |
45 | 第一种,data 传入的是具体数组数据,那么
46 |
47 | ```js
48 | dv.rows = deepClone(data);
49 | ```
50 |
51 | 第二种,data 传入的是另一个 DataView 的实例或者实例的名称,那么
52 |
53 | ```js
54 | dv.rows = deepClone(ds.getView(otherDv).rows);
55 | ```
56 |
57 | ## dsv
58 |
59 | 具体用法见示例:
60 |
61 | ```js
62 | dv.source(dsvStr, {
63 | type: 'dsv', // 指定使用dsv connector
64 | delimiter: '|' // 指定分隔符
65 | })
66 | ```
67 |
68 | ## csv
69 |
70 | 具体用法见示例:
71 |
72 | ```js
73 | dv.source(csvStr, {
74 | type: 'csv', // 指定使用dsv connector
75 | delimiter: ',' // 指定分隔符
76 | })
77 | ```
78 |
79 | ## tsv
80 |
81 | 具体用法见示例:
82 |
83 | ```js
84 | dv.source(tsvStr, {
85 | type: 'tsv' // 指定使用tsv connector
86 | })
87 | ```
88 |
89 | ## GeoJSON
90 |
91 | 具体用法见示例:
92 |
93 | ```js
94 | dv.source(geojsonData, {
95 | type: 'GeoJSON', // 别名 geo / geojson
96 | })
97 | ```
98 |
99 | > dv.dataType 会被更改为 'geo',从而 dv 可以执行一些 Geo 相关的实例方法。
100 |
101 | ## TopoJSON
102 |
103 | 具体用法见示例:
104 |
105 | ```js
106 | dv.source(topojsonData, {
107 | type: 'TopoJSON', // 别名 topojson
108 | object: 'xxx' // TopoJSON 相当于多个 GeoJSON 合并起来做了压缩,其中每一个 object 都相当于一份 GeoJSON 数据,指定 object 就是从中提取一份 Geo 数据
109 | })
110 | ```
111 |
112 | > dv.dataType 会被更改为 'geo',从而 dv 可以执行一些 Geo 相关的实例方法。
113 |
114 | ## hierarchy
115 |
116 | 具体用法见示例:
117 |
118 | ```js
119 | dv.source(tree, {
120 | type: 'hierarchy', // 别名 tree
121 | children: d => d.children // 可选,函数,返回子树
122 | })
123 | ```
124 |
125 | > dv.dataType 会被变更为 'hierarchy' ,从而 dv 可以执行一些树形结构相关的实例方法和 Transform。
126 |
127 | > dv.root 为根节点
128 |
129 | ## graph
130 |
131 | 具体用法见示例:
132 |
133 | ```js
134 | dv.source(graph, {
135 | type: 'graph',
136 | nodes: d => d.nodes, // 节点集对应字段
137 | edges: d => d.edges // 边集对应字段
138 | })
139 | ```
140 |
141 | > dv.dataType 会被变更为 'graph',从而 dv 可以执行图相关的实例方法和 Transform。
142 |
--------------------------------------------------------------------------------
/doc/api/bizcharts.md:
--------------------------------------------------------------------------------
1 |
2 | # BizCharts
3 | 全局命名空间 BizCharts 包含:
4 |
5 | # API
6 | ## 1、Component 组件
7 |
8 | ### Chart
9 | 图表最顶级的组件,控制着图表的创建、绘制、销毁等。
10 | 详细文档见 [Chart api](chart.md)
11 |
12 | ### Coord
13 | 坐标系组件,设置 Chart 或者 View 的坐标系类型。
14 | 详细文档见 [Coord api](coord.md)
15 |
16 | ### Aixs
17 | 坐标轴组件,控制图表中坐标轴的样式等。
18 | 详细文档见 [Axis api](axis.md)
19 |
20 | ### Geom
21 | 几何标记对象,决定创建图表的类型。
22 | 详细文档见 [Geom api](geom.md)。
23 |
24 | ### Label
25 | 几何标记对象上的文本。
26 | 详细文档见 [Label api](label.md)
27 |
28 | ### Legend
29 | 图例。
30 | 详细文档见 [Legend api](legend.md)
31 |
32 | ### Guide
33 | 用于绘制图标的辅助元素等。
34 | 详细文档见 [Guide api](guide.md)
35 |
36 | ### Facet
37 | 控制 Chart 分面。
38 | 详细文档见 [Facet api](facet.md)
39 |
40 | ### View
41 | 视图组件。
42 | 详细文档见 [View api](view.md)
43 |
44 | ## 2、G2
45 | G2 的命名空间,在有需要的情况下用户可以直接拿到该对象去工作。
46 |
47 | ## 3、Animate
48 | 用来注册用户自定义动画。
49 | 详细文档见 [动画教程](../tutorial/animate.md)。
50 |
51 | ## 4、Shape
52 | 构成图表具体的形状类。
53 | 详细文档见 [Shape api](shape.md)。
54 |
55 | ## 5、setTheme
56 | 设置 BizCharts 中使用的主题类型。
57 | 详细文档见 [theme tutorial](../tutorial/theme.md)。
58 |
59 | ## 6、track
60 | 该方法用于 G2 情况的打点监控,默认处于开启状态,如果您不想让我们知道您的版本使用情况,请配置为 false。
61 | ```js
62 | BizCharts.track(false);
63 | ```
64 |
65 | ## 7、PathUtil
66 | 来自 G2,用于操作图形路径的工具类。具体提供的方法如下:
67 |
68 | | 方法 | 参数说明 | 返回结果 |
69 | | ---- | ---- | ---- |
70 | | `getBoundingClientRect(node)` | `node`:HTMLElement,dom 节点 | 返回该节点在页面中的位置,返回结果格式为: `{top: , bottom: , left: , right}` |
71 | | `getStyle(dom, name)` | `dom`:HTMLElement,DOM 节点;`name`:String,样式名 | 返回该节点对应样式名 name 的具体样式。 |
72 | | `modifyCSS(dom, css)` | `dom`:HTMLElement,DOM 节点;`css`:Object,样式属性 | 修改对应节点的 css 样式,返回修改样式后的 dom 对象。 |
73 | | `createDom(str)` | `str`:String,Dom 字符串 | 按照传入的 str 创建 dom 节点,并返回创建的节点。 |
74 | | `getRatio()` | -- | 返回屏幕的像素分辨率。 |
75 | | `getWidth(el)` | `el`:HTMLElement,dom 节点| 返回 dom 节点的宽度,不包含 padding、border |
76 | | `getHeight(el)` | `e`l:HTMLElement,dom 节点| 返回 dom 节点的高度,不包含 padding、border |
77 | | `getOuterWidth(el)` | `el`:HTMLElement,dom 节点| 返回 dom 节点的宽度,包含 padding、border |
78 | | `getOuterHeight(el)` | `el`:HTMLElement,dom 节点| 返回 dom 节点的高度,包含 padding、border |
79 | | `addEventListener(target, eventType, callback)` | `target`:HTMLElement,DOM对象;`eventType`:String,事件名;`callback`:Function,回调函数 | 添加事件监听器 |
80 | | `requestAnimationFrame(fn)` | `fn`:Function,回调函数 | 用于定时循环操作。
81 |
82 | ## 8、Util
83 | 默认提供的常见的工具类,大部分基于 lodash 封装。
84 | 如下:
85 | ```js
86 | const Util = {
87 | each: require('lodash/each'),
88 | map: require('lodash/map'),
89 | isObject: require('lodash/isObject'),
90 | isNumber: require('lodash/isNumber'),
91 | isString: require('lodash/isString'),
92 | isFunction: require('lodash/isFunction'),
93 | ...
94 | };
95 | ```
96 |
97 | ## 9、[绘图属性](./graphic.md)
98 |
99 |
100 |
--------------------------------------------------------------------------------
/doc/api/label.md:
--------------------------------------------------------------------------------
1 |
2 | # Label
3 | [``](geom.md) 几何标记上的标注文本组件。
4 |
5 | ## 使用说明
6 | `` 组件只能够被嵌套在 [` `](geom.md) 组件内,如下所示。
7 | ```jsx
8 |
9 |
10 |
11 | ```
12 |
13 | ## API
14 | ### 1、content * String | Array:[String, Function] *
15 | 指定 label 上显示的文本内容,可以是数据纬度,也可以自定义。
16 | 使用示例:
17 | ```jsx
18 |
19 | // 使用数据
20 |
21 | // 使用回调函数
22 | {
23 | return `${data}:${sales}`;
24 | }]}
25 | />
26 | ```
27 | ### 2、labelLine * Object *
28 | 文本距离几何线的配置,如果值为 false,表示不展示文本线。默认不展示。
29 | 使用示例:
30 | ```jsx
31 |
39 | ```
40 |
41 | ### 3、offset * Number *
42 | 设置文本距离几何图形的的距离
43 |
44 | ### 4、textStyle * Object *
45 | 文本的图形样式。其他样式请参考[绘图属性](./graphic.md)
46 | ```jsx
47 |
58 | ```
59 | 样式值支持回调:
60 | ```jsx
61 | {
64 | let textAlign = 'center', // 文本对齐方向,可取值为: start middle end
65 | let fill = (sales > 1000) ? '#ff0000' : '#00ff00';
66 | return {textAlign: textAlign, fill: fill};
67 | }}
68 | />
69 | ```
70 |
71 | ### 5、autoRotate * Boolean *
72 | 是否需要自动旋转。
73 | 默认值:true
74 |
75 | ### 6、formatter * Function *
76 | 用于格式化坐标轴上显示的文本信息。
77 | ```jsx
78 | {
81 | // text 为每条记录 x 属性的值
82 | // item 为映射后的每条数据记录,是一个对象,可以从里面获取你想要的数据信息
83 | // index 为每条记录的索引
84 | var point = item.point; // 每个弧度对应的点
85 | var percent = point['percent'];
86 | percent = (percent * 100).toFixed(2) + '%';
87 | return name + ' ' + percent;
88 | }}
89 | />
90 | ```
91 |
92 | ### 7、htmlTemplate * Function *
93 | 自定义 html 文本
94 | ```jsx
95 | {
98 | // text 为每条记录 x 属性的值
99 | // item 为映射后的每条数据记录,是一个对象,可以从里面获取你想要的数据信息
100 | // index 为每条记录的索引
101 | var point = item.point; // 每个弧度对应的点
102 | var percent = point['percent'];
103 | percent = (percent * 100).toFixed(2) + '%';
104 | // 自定义 html 模板
105 | return '' + text + ' ' + percent + ' ';
106 | }
107 | />
108 | ```
109 |
--------------------------------------------------------------------------------
/doc_en/api/view.md:
--------------------------------------------------------------------------------
1 | # View
2 |
3 | `View`, generated and managed by `Chart` instances, have their own independent data sources, coordinate systems, and layers for visualizing heterogeneous data and chart combinations. A `Chart` consists of one or more `View`, so the properties on the `View` are basically the same as the `Chart`.
4 |
5 | ## Instruction
6 |
7 | ### Parent Components
8 | ` `
9 | ### Child Components
10 | [` `](coord.md) [` `](axis.md) [` `](geom.md) [` `](legend.md) [` `](tooltip.md) [` `](guide.md) [` `](facet.md) [` `](view.md)
11 |
12 | **In the actual development process, many charts can be used View components to achieve, including but not limited to the following:**
13 |
14 | * `View` in the same container when two or more different coordinate system chart appears, as shown below: [Demo](https://alibaba.github.io/BizCharts/demo-detail.html?code=demo/pie/sunburst)
15 | 
16 |
17 | * When two charts in the same container need different data sources. As shown below: [Demo](https://alibaba.github.io/BizCharts/demo-detail.html?code=demo/funnel/symmetric)
18 | 
19 |
20 |
21 |
22 | ```html
23 | // Here only shows part of the core code
24 |
25 |
26 |
31 |
32 |
33 |
38 |
39 |
40 | ```
41 |
42 | ## Properties
43 | ### 1、id * String *
44 | id, used to uniquely demarcate the view, Bizcharts will provide a set of id generation mechanism ('view' + views.length, such as view0, view1, ..., viewN) by default if the user does not specify.
45 |
46 | ### 2、start * Object *
47 | The starting coordinate of the drawing area, both x and y are in the range of 0 -1.
48 | Example:
49 | ```jsx
50 |
51 | ```
52 | ### 3、end * Object *
53 | The end coordinates of the drawing area, both x and y are in the range of 0 -1.
54 |
55 | Example:
56 | ```jsx
57 |
58 | ```
59 |
60 | ### 4、data * Array | DataSet *
61 | Use the same method as `Chart`'s [`data` property](chart.md#data).
62 |
63 | ### 5、animate * Boolean *
64 | View whether to animate.
65 | Default: true.
66 |
67 | ### 6、scale * Object *
68 | Use the same method as `Chart`'s [scale property](chart.md#scale)。
69 |
70 | ### 7、filter * Object *
71 | Use the same method as`Chart`'s [filer property](chart.md#filter)。
72 |
73 |
--------------------------------------------------------------------------------
/testDemo/component/com16/basic.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 |
4 | const GuideLine = Guide.Line;
5 |
6 | const data = [
7 | { year: "1991", value: 3 },
8 | { year: "1992", value: 4 },
9 | { year: "1993", value: 3.5 },
10 | { year: "1994", value: 5 },
11 | { year: "1995", value: 4.9 },
12 | { year: "1996", value: 6 },
13 | { year: "1997", value: 7 },
14 | { year: "1998", value: 9 },
15 | { year: "1999", value: 13 }
16 | ];
17 |
18 | const scale = {
19 | 'value': { min: 0 },
20 | 'year': {range: [ 0 , 1] }
21 | };
22 |
23 | export default class BasicLineChart extends Component {
24 | constructor(props) {
25 | super(props);
26 | this.state = {
27 | showAxis: true,
28 | tooltipType: 'y',
29 | scale: [1, 1],
30 | type: 'polar',
31 | position: 'top',
32 | name: 'year',
33 | size:30,
34 | color: "#ff0000",
35 | height: 400,
36 | padding: 10,
37 | }
38 | }
39 |
40 | componentDidMount() {
41 | setTimeout((() => {
42 | this.setState({
43 | showAxis: false,
44 | tooltipType: 'cross',
45 | scale: [0.7, 0.7],
46 | type: 'rect',
47 | position: 'bottom',
48 | name: 'value',
49 | size:50,
50 | color: "#00ff00",
51 | height: 800,
52 | padding: 300,
53 | });
54 | }).bind(this), 2000);
55 | }
56 |
57 | render() {
58 | return (
59 |
60 | {
61 | this.state.showAxis ? : null
62 | }
63 |
64 | {/*
65 | this.state.showAxis ? : null
66 | */}
67 |
68 | {
69 | this.state.showAxis ? : null
70 | }
71 |
72 |
73 | {
74 |
75 | }
76 |
77 | {
78 | this.state.showAxis ? null :
79 | }
80 |
81 |
82 | {
83 | !this.state.showAxis ? null :
84 | }
85 |
86 |
87 |
88 | );
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/testDemo/component/geom/adddelete.js:
--------------------------------------------------------------------------------
1 |
2 | import React, { Component } from 'react';
3 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
4 | import DataSet from '@antv/data-set';
5 |
6 | const { DataView } = DataSet;
7 | const { Text, Html, Arc, Line } = Guide;
8 | const data1 = [
9 | { year: '1951 年', sales: 38 },
10 | { year: '1952 年', sales: 52 },
11 | { year: '1956 年', sales: 61 },
12 | { year: '1957 年', sales: 145 },
13 | { year: '1958 年', sales: 48 },
14 | { year: '1959 年', sales: 38 },
15 | { year: '1960 年', sales: 38 },
16 | { year: '1962 年', sales: 38 },
17 | ];
18 | const data2 = [
19 | { year: '1951 年', sales: 28 },
20 | { year: '1952 年', sales: 62 },
21 | { year: '1956 年', sales: 31 },
22 | { year: '1957 年', sales: 105 },
23 | { year: '1958 年', sales: 148 },
24 | { year: '1959 年', sales: 8 },
25 | { year: '1960 年', sales: 38 },
26 | { year: '1962 年', sales: 98 },
27 | ];
28 | const cols = {
29 | 'sales': {tickInterval: 20,'alias':"请显示我!!!"},
30 | };
31 | const typeAry=['point','path','line','area','interval','polygon','edge','schema','heatmap'];
32 | export default class Basic extends Component {
33 | constructor() {
34 | super();
35 | this.state = {
36 | data: data1,
37 | position: 'bottom',
38 | typeAry:'line',
39 | boolean: true
40 | }
41 | }
42 |
43 | componentDidMount() {
44 | setInterval(() => {
45 | this.setState({
46 | data: this.state.data == data1 ? data2 : data1,
47 | typeAry:typeAry[Math.floor(Math.random()*9)]
48 | });
49 | }, 1000);
50 | }
51 | render() {
52 | return (
53 |
54 |
56 |
58 | {this.state.typeAry==='path' && }
59 | {this.state.typeAry==='line' && }
60 | {this.state.typeAry==='area' && }
61 | {this.state.typeAry==='polygon' && }
62 | {this.state.typeAry==='polygon' && }
63 | {this.state.typeAry==='edge' && }
64 | {this.state.typeAry==='schema' && }
65 | {this.state.typeAry==='schema' && }
66 | {this.state.typeAry==='heatmap' && }
67 | {this.state.typeAry==='interval' && }
68 | {this.state.typeAry==='interval' && }
69 | {this.state.typeAry==='point' && }
70 |
71 |
72 |
73 | );
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/test/specs/component/Chart.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Enzyme, { mount } from 'enzyme';
3 | import Adapter from 'enzyme-adapter-react-16';
4 | import chai, { expect } from 'chai';
5 | import chaiEnzyme from 'chai-enzyme';
6 | // import sinon from 'sinon';
7 | import { Chart, Geom } from 'bizcharts';
8 |
9 | chai.use(chaiEnzyme()); // Note the invocation at the end
10 | Enzyme.configure({ adapter: new Adapter() });
11 |
12 | window.devicePixelRatio = 1;
13 | describe('', () => {
14 | it('Render no data Chart', () => {
15 | const wrapper = mount(
16 |
17 | );
18 |
19 | expect(wrapper.find('div').length).to.equal(2);
20 | });
21 | });
22 |
23 | describe(' ', () => {
24 | it('Render have data Chart', () => {
25 | const wrapper = mount(
26 |
27 | );
28 |
29 | expect(wrapper.find('div').length).to.equal(2);
30 | });
31 | });
32 |
33 | const data = [
34 | { year: '1991', value: 3 },
35 | { year: '1992', value: 4 },
36 | { year: '1993', value: 3.5 },
37 | { year: '1994', value: 5 },
38 | { year: '1995', value: 4.9 },
39 | { year: '1996', value: 6 },
40 | { year: '1997', value: 7 },
41 | { year: '1998', value: 9 },
42 | { year: '1999', value: 13 }
43 | ];
44 |
45 | // 因为canvas是Didmount之后加的,所以wrapper搜寻不到对应reactNode
46 | describe(' size props of width and height', () => {
47 | let chartInstance = null;
48 | const wrapper = mount(
49 |
50 | { chartInstance = chart; }} >
51 |
52 |
53 |
54 | );
55 | console.log(wrapper.getDOMNode().getElementsByTagName('canvas')[0]);
56 | it('int', () => {
57 | expect(wrapper.getDOMNode().getElementsByTagName('canvas').length).to.equal(1);
58 | expect(wrapper.getDOMNode().getElementsByTagName('canvas')[0].width).to.equal(800);
59 | expect(chartInstance.get('width')).equal(800);
60 | expect(chartInstance.get('height')).equal(500);
61 | });
62 |
63 | it('plot test', () => {
64 | expect(chartInstance.get('plotRange').tl).eqls({ x: 50, y: 0 });
65 | expect(chartInstance.get('plotRange').br).eqls({ x: 750, y: 480 });
66 | });
67 | });
68 |
69 | // 因为canvas是Didmount之后加的,所以wrapper搜寻不到对应reactNode
70 | describe(' data prop', () => {
71 | let chartInstance = null;
72 | const wrapper = mount(
73 | {
79 | // console.log(chart);
80 | chartInstance = chart;
81 | }}
82 | >
83 |
84 |
85 | );
86 | it('int', () => {
87 | expect(chartInstance.get('data').length).equal(9); // 数据初始化
88 | });
89 |
90 | it('update data', () => {
91 | wrapper.setProps({ data: [{ year: '1991', value: 3 }] });
92 | wrapper.update();
93 | expect(chartInstance.get('data').length).equal(1);
94 | });
95 | });
96 |
--------------------------------------------------------------------------------
/src/processor/g2Delete.js:
--------------------------------------------------------------------------------
1 | const deleteFuncMap = {
2 | Chart: 'deleteChart',
3 | Coord: 'deleteCoord',
4 | Geom: 'deleteGeom',
5 | Axis: 'deleteAxis',
6 | Tooltip: 'deleteTooltip',
7 | Legend: 'deleteLegend',
8 | Label: 'deleteLabel',
9 | View: 'deleteView',
10 | Guide: 'deleteGuide',
11 | GuideLine: 'deleteTypedGuide',
12 | GuideImage: 'deleteTypedGuide',
13 | GuideText: 'deleteTypedGuide',
14 | GuideRegion: 'deleteTypedGuide',
15 | GuideHtml: 'deleteTypedGuide',
16 | GuideArc: 'deleteTypedGuide',
17 | Facet: 'deleteFacet',
18 | };
19 |
20 | const reExecuteDeleteElements = {
21 | Geom: true,
22 | Label: true,
23 | Facet: true,
24 | };
25 |
26 | const iDelete = {
27 | deleteAxis(chart, config, id) {
28 | const axisConfig = config.axises[id].props;
29 | chart.axis(axisConfig.name, false);
30 | },
31 |
32 | deleteTooltip(chart) {
33 | chart.tooltip(false);
34 | },
35 |
36 | deleteCoord(chart) {
37 | chart.coord('rect', {});
38 | },
39 |
40 | deleteLegend(chart, config, id) {
41 | const legendConfig = config.legends[id].props;
42 | chart.legend(...(legendConfig.name ? [legendConfig.name, false] : [false]));
43 | },
44 |
45 | deleteGuide(chart) {
46 | chart.guide().clear();
47 | },
48 |
49 | deleteView(chart, config, id) {
50 | if (!config.views[id].g2Instance) return;
51 | chart.removeView(config.views[id].g2Instance);
52 | delete config.views[id].g2Instance;
53 | },
54 |
55 | deleteViewElement(chart, config, deleteInfos, elementInfos) {
56 | // 次模块只处理元素的删除,将删除同步到 g2。
57 | // 因此此处只需要将view destory 掉,如果需要则重建。
58 | Object.keys(deleteInfos).forEach((id) => {
59 | const elementInfo = elementInfos[id];
60 | const viewId = elementInfo.viewId;
61 | if (viewId) {
62 | if (reExecuteDeleteElements[elementInfo.name]) {
63 | config.views[viewId].needReExecute = true;
64 | } else if (config.views[viewId].g2Instance && this[deleteFuncMap[elementInfo.name]]) {
65 | this[deleteFuncMap[elementInfo.name]](
66 | config.views[viewId].g2Instance,
67 | config.views[viewId],
68 | elementInfo.id,
69 | );
70 | }
71 | }
72 | });
73 | },
74 |
75 | needReExecute(deleteInfos, elementInfos) {
76 | for (const id in deleteInfos) {
77 | if (reExecuteDeleteElements[elementInfos[id].name] && !elementInfos[id].viewId) {
78 | return true;
79 | }
80 | }
81 | return false;
82 | // return Object.keys(deleteInfos).find((id) => {
83 | // return reExecuteDeleteElements[elementInfos[id].name] && !elementInfos[id].viewId;
84 | // });
85 | },
86 |
87 | synchronizeG2Delete(chart, config, deleteInfos, elementInfos) {
88 | Object.keys(deleteInfos).forEach((id) => {
89 | const funName = deleteFuncMap[elementInfos[id].name];
90 | if (this[funName] && !elementInfos[id].viewId) {
91 | this[funName](chart, config, id);
92 | }
93 | });
94 |
95 | this.deleteViewElement(chart, config, deleteInfos, elementInfos);
96 | },
97 | };
98 |
99 | export default iDelete;
100 |
--------------------------------------------------------------------------------
/doc_en/api/label.md:
--------------------------------------------------------------------------------
1 |
2 | # Label
3 | Label is a text component for [``](geom.md) .
4 |
5 | ## Instruction
6 | `` only can be nested in [` `](geom.md) , as below show:
7 | ```jsx
8 |
9 |
10 |
11 | ```
12 |
13 | ## Properties
14 | ### 1、content * String | Array:[String, Function] *
15 | The content of label can be specified by this props, example:
16 | ```jsx
17 | {
23 | return `${data}:${sales}`;
24 | }]}
25 | />
26 | ```
27 | ### 2、labelLine * Object | Boolean *
28 |
29 | DEFAULT: true
30 |
31 | labelLine is the line between label and gemetry, which can be hidden once set false. other properties can be specified as below:
32 | ```jsx
33 |
40 | ```
41 |
42 | ### 3、offset * Number *
43 | Distance from label to geometry.
44 |
45 | ### 4、textStyle * Object *
46 | Style of label text can be specified as below:
47 | ```jsx
48 |
59 | ```
60 | property of fill can support functon as below:
61 | ```jsx
62 | {
65 | const style = {textAlign: 'center'};
66 | if(if(sales > 1000)) {
67 | style.fill = '#ff0000';
68 | } else {
69 | style.fill = '#00ff00';
70 | }
71 | return style;
72 | }}
73 | />
74 | ```
75 |
76 | ### 5、autoRotate * Boolean *
77 |
78 | DEFAULT: true
79 |
80 | Enable label to rotate when there's no enough space to show the entire label text.
81 |
82 | ### 6、formatter * Function *
83 |
84 | Formatter let `` support a function to format the label shown
85 |
86 | ```jsx
87 | {
90 | var point = item.point;
91 | var percent = point['percent'];
92 | percent = (percent * 100).toFixed(2) + '%';
93 | return name + ' ' + percent;
94 | }}
95 | />
96 | ```
97 |
98 | ### 7、htmlTemplate * Function *
99 |
100 | `` support custom html to rendering the label, if set the property of htmlTemplate, the function will be called to render the label content.
101 |
102 | ```jsx
103 | {
106 | var point = item.point;
107 | var percent = point['percent'];
108 | percent = (percent * 100).toFixed(2) + '%';
109 | // custom html template
110 | return '' + text + ' ' + percent + ' ';
111 | }
112 | />
113 | ```
114 |
--------------------------------------------------------------------------------
/testDemo/component/com16/view.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 |
7 | const data = [
8 | { value: 251, type: '大事例一', name: '子事例一' },
9 | { value: 1048, type: '大事例一', name: '子事例二' },
10 | { value: 610, type: '大事例二', name: '子事例三' },
11 | { value: 434, type: '大事例二', name: '子事例四' },
12 | { value: 335, type: '大事例三', name: '子事例五' },
13 | { value: 250, type: '大事例三', name: '子事例六' }
14 | ];
15 | const dv = new DataView();
16 | dv.source(data).transform({
17 | type: 'percent',
18 | field: 'value',
19 | dimension: 'type',
20 | as: 'percent'
21 | });
22 | const cols = {
23 | percent: {
24 | formatter: val => {
25 | val = (val * 100).toFixed(2) + '%';
26 | return val;
27 | }
28 | }
29 | }
30 | const dv1 = new DataView();
31 | dv1.source(data).transform({
32 | type: 'percent',
33 | field: 'value',
34 | dimension: 'name',
35 | as: 'percent'
36 | });
37 |
38 | export default class PieC extends Component {
39 |
40 | constructor(props) {
41 | super(props);
42 | this.state = {
43 | showLabel: true,
44 | lineWidth : 1,
45 | showView: true,
46 | };
47 | }
48 |
49 | componentDidMount() {
50 | setTimeout(() => {
51 | this.setState({
52 | showLabel: false,
53 | lineWidth: 15,
54 | showView: true,
55 | });
56 | }, 2000);
57 | }
58 |
59 | render() {
60 | return (
61 |
62 |
63 |
67 | {
72 | percent = (percent * 100).toFixed(2) + '%';
73 | return {
74 | name: item,
75 | value: percent
76 | };
77 | }]}
78 | style={{lineWidth: 1,stroke: '#fff'}}
79 | select={false}
80 | >
81 | {/* {
82 | this.state.showLabel ? : null
83 | } */}
84 |
85 |
86 | {
87 | this.state.showView ?
88 |
89 |
90 | {
95 | percent = (percent * 100).toFixed(2) + '%';
96 | return {
97 | name: item,
98 | value: percent
99 | };
100 | }]}
101 | style={{lineWidth: this.state.lineWidth, stroke: '#fff'}}
102 | select={false}
103 | >
104 | {
105 | this.state.showLabel ? : null
106 | }
107 |
108 |
109 | : null
110 | }
111 |
112 | );
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/doc_en/tutorial/start.md:
--------------------------------------------------------------------------------
1 | # BizCharts
2 |
3 | BizCharts is a charting library based on G2 that allows users to construct charts using React components instead of the usual G2 syntax. This library is meant to be a comprehensive library supporting charts such as the following
4 |
5 | * Many Base Chart Templates to Choose Form
6 | * Visualization and Aggregation of large data sets
7 | * Multi-axis / Charts on a non linear coordinate system
8 | * Interactivity
9 | * Map Based Charts
10 |
11 | ## Key Library Features
12 |
13 | - Based on G2、React
14 | - Robust
15 | - Stable
16 | - Extensible
17 | - High customizability
18 |
19 | ## Installation
20 |
21 | ### Using npm
22 |
23 | We recommend that you install BizCharts using `npm` using the following command
24 |
25 | ```bash
26 | npm install bizcharts --save
27 | ```
28 |
29 | After installation is complete, you can include it in your application using either the `import` or `require` keywords.
30 |
31 | ## Quick Start
32 |
33 | Once Bizcharts has been imported, we can start building our first chart
34 |
35 | Listed below is the code needed to build a basic bar chart
36 |
37 | 1. Create Wrapper NOde
38 |
39 | In the `` of your html file, create an element if an `id` of your choice
40 |
41 | ```html
42 |
43 | ```
44 |
45 | 2. Write a component to render the chart
46 |
47 | - Pull in the base components needed by the chart component
48 | - Use these base components to construct the chart
49 | - Mount the chart on the element by specifying its id (`mountNode` in this example)
50 |
51 | ```jsx
52 | import React from 'react';
53 | import ReactDOM from 'react-dom';
54 | import { Chart, Geom, Axis, Tooltip, Legend, Coord } from 'bizcharts';
55 |
56 | // Data Source
57 | const data = [
58 | { genre: 'Sports', sold: 275, income: 2300 },
59 | { genre: 'Strategy', sold: 115, income: 667 },
60 | { genre: 'Action', sold: 120, income: 982 },
61 | { genre: 'Shooter', sold: 350, income: 5271 },
62 | { genre: 'Other', sold: 150, income: 3710 }
63 | ];
64 |
65 | // Specify Options
66 | const cols = {
67 | sold: { alias: 'Sales' },
68 | genre: { alias: 'Game Category' }
69 | };
70 |
71 | // Render Chart
72 | ReactDOM.render((
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | ), document.getElementById('mountNode'));
81 |
82 | ```
83 |
84 | The above code will render a bar chart looking something like this:
85 |
86 | 
87 |
88 |
89 | ## Telemetry
90 | To serve its users better, G2 will send diagnostic info and the application URL back to AntV. As BizCharts is based on G2, this will happen as well and there is no explicitly blocking of this behavior. Request is currently being made to:
91 |
92 | ```https://kcart.alipay.com/web/bi.do```
93 |
94 | Note that only the application URL and the G2 version is collected. All this information is used to help the development of G2. If you are concerned about this tracking behavior, you can turn it off by calling the following function
95 |
96 | ```js
97 | // 关闭 G2 的体验改进计划打点请求(如:服务端渲染)
98 | BizCharts.track(false);
99 | ```
100 |
--------------------------------------------------------------------------------
/demo/component/others/customLegend.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 |
6 | const data = [
7 | { country: 'Lithuania', litres: 501.9 },
8 | { country: 'Czech Republic', litres: 301.9 },
9 | { country: 'Ireland', litres: 201.1 },
10 | { country: 'Germany', litres: 165.8 },
11 | { country: 'Australia', litres: 139.9 },
12 | { country: 'Austria', litres: 128.3 },
13 | { country: 'UK', litres: 99 },
14 | { country: 'Belgium', litres: 60 },
15 | { country: 'The Netherlands', litres: 50 }
16 | ];
17 |
18 | const ds = new DataSet();
19 | const dv = ds.createView()
20 | .source(data)
21 | .transform({
22 | type: 'percent',
23 | field: 'litres',
24 | dimension: 'country',
25 | as: 'percent'
26 | });
27 | const scale = {
28 | percent: {
29 | formatter: val => {
30 | val = (val * 100).toFixed(2) + '%';
31 | return val;
32 | }
33 | },
34 | nice: false
35 | }
36 |
37 |
38 | export default class IntervalC extends Component {
39 | render() {
40 | return (
41 | {
42 | return val !== 'UK';
43 | }]]} forceFit >
44 |
45 |
46 | {
52 | const obj = dv.rows[index];
53 | checked = checked ? 'checked' : 'unChecked';
54 | return '' +
57 | ' ' +
58 | '' + value + ' ' +
59 | '' + obj.litres + ' ' +
60 | ' ';
61 | }
62 | }
63 | offsetX={15}
64 | g2-legend={{
65 | marginLeft: '100px',
66 | marginTop: '-107px'
67 | }}
68 | g2-legend-list={{
69 | border: 'none'
70 | }}
71 | />
72 |
75 | {
79 | return item.point.country + ': ' + val;
80 | }
81 | }
82 | />
83 |
84 |
85 | );
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/demo/component/guide/regionFilter-guide2.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { RegionFilter, DataMarker, Text } = Guide;
6 |
7 | const data = [{
8 | year: 1700,
9 | exports: 35,
10 | imports: 70
11 | }, {
12 | year: 1710,
13 | exports: 59,
14 | imports: 81
15 | }, {
16 | year: 1720,
17 | exports: 76,
18 | imports: 96
19 | }, {
20 | year: 1730,
21 | exports: 65,
22 | imports: 97
23 | }, {
24 | year: 1740,
25 | exports: 67,
26 | imports: 93
27 | }, {
28 | year: 1750,
29 | exports: 79,
30 | imports: 90
31 | }, {
32 | year: 1760,
33 | exports: 115,
34 | imports: 79
35 | }, {
36 | year: 1770,
37 | exports: 163,
38 | imports: 85
39 | }, {
40 | year: 1780,
41 | exports: 185,
42 | imports: 93
43 | }];
44 |
45 |
46 | const ds = new DataSet();
47 | const dv = ds.createView().source(data);
48 | dv.transform({
49 | type: 'map',
50 | callback: function callback(row) {
51 | row.range = [row.exports, row.imports];
52 | return row;
53 | }
54 | });
55 | dv.transform({
56 | type: 'fold',
57 | fields: ['exports', 'imports'], // 展开字段集
58 | key: 'type', // key字段
59 | value: 'value' // value字段
60 | });
61 |
62 | const scale = {
63 | value: {
64 | min: 0,
65 | max: 200
66 | },
67 | range: {
68 | min: 0,
69 | max: 200
70 | }
71 | };
72 |
73 | export default class RegionFilter2 extends Component {
74 | render() {
75 | return (
76 |
77 |
78 |
79 |
80 |
85 |
90 |
91 |
95 |
99 |
114 |
121 |
128 |
129 |
130 | );
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/components/Base/index.jsx:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import PropTypes from 'prop-types';
3 |
4 | class BaseComponent extends Component {
5 | static contextTypes = {
6 | addElement: PropTypes.func,
7 | updateElement: PropTypes.func,
8 | deleteElement: PropTypes.func,
9 | createId: PropTypes.func,
10 | getParentInfo: PropTypes.func,
11 | getViewId: PropTypes.func,
12 | }
13 |
14 | static childContextTypes = {
15 | addElement: PropTypes.func,
16 | updateElement: PropTypes.func,
17 | deleteElement: PropTypes.func,
18 | createId: PropTypes.func,
19 | getParentInfo: PropTypes.func,
20 | getViewId: PropTypes.func,
21 | }
22 |
23 | constructor(props, name) {
24 | super(props);
25 | this.name = name;
26 | }
27 |
28 | getChildContext() {
29 | return {
30 | addElement: this.context.addElement,
31 | updateElement: this.context.updateElement,
32 | deleteElement: this.context.deleteElement,
33 | createId: this.context.createId,
34 | getParentInfo: this.getParentInfo,
35 | getViewId: this.context.getViewId,
36 | };
37 | }
38 |
39 | componentWillMount() {
40 | const context = this.context;
41 | this.id = context.createId();
42 | context.addElement(
43 | this.name, this.id, this.props,
44 | context.getParentInfo(),
45 | context.getViewId()
46 | );
47 | }
48 |
49 | componentWillReceiveProps(nextProps) {
50 | this.context.updateElement(
51 | this.name, this.id, nextProps,
52 | this.context.getParentInfo(),
53 | this.context.getViewId()
54 | );
55 | }
56 |
57 | componentWillUnmount() {
58 | this.context.deleteElement(this.name, this.id);
59 | }
60 |
61 | getParentInfo = () => {
62 | return {
63 | id: this.id,
64 | name: this.name,
65 | };
66 | }
67 |
68 | render() {
69 | let children = this.props.children;
70 |
71 | if (children) {
72 | if (children.length) {
73 | children = { children }
;
74 | }
75 | } else {
76 | children = null;
77 | }
78 |
79 | return children;
80 | }
81 | }
82 |
83 | function generateBaseTypedComponent(name) {
84 | class TypedComponent extends BaseComponent {
85 | static contextTypes = {
86 | addElement: PropTypes.func,
87 | updateElement: PropTypes.func,
88 | deleteElement: PropTypes.func,
89 | createId: PropTypes.func,
90 | getParentInfo: PropTypes.func,
91 | getViewId: PropTypes.func,
92 | }
93 |
94 | static childContextTypes = {
95 | addElement: PropTypes.func,
96 | updateElement: PropTypes.func,
97 | deleteElement: PropTypes.func,
98 | createId: PropTypes.func,
99 | getParentInfo: PropTypes.func,
100 | getViewId: PropTypes.func,
101 | }
102 |
103 | constructor(props) {
104 | super(props, name);
105 | }
106 |
107 | getChildContext() {
108 | return {
109 | addElement: this.context.addElement,
110 | updateElement: this.context.updateElement,
111 | deleteElement: this.context.deleteElement,
112 | createId: this.context.createId,
113 | getParentInfo: this.getParentInfo,
114 | getViewId: this.context.getViewId,
115 | };
116 | }
117 | }
118 |
119 | return TypedComponent;
120 | }
121 |
122 | BaseComponent.generateBaseTypedComponent = generateBaseTypedComponent;
123 |
124 | export default BaseComponent;
125 |
--------------------------------------------------------------------------------
/demo/component/guage/basic.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 | const { Text, Html, Arc } = Guide;
7 |
8 | Shape.registerShape('point', 'pointer', {
9 | drawShape(cfg, group) {
10 | let point = cfg.points[0]; // 获取第一个标记点
11 | point = this.parsePoint(point);
12 | const center = this.parsePoint({ // 获取极坐标系下画布中心点
13 | x: 0,
14 | y: 0
15 | });
16 | // 绘制指针
17 | group.addShape('line', {
18 | attrs: {
19 | x1: center.x,
20 | y1: center.y,
21 | x2: point.x,
22 | y2: point.y - 20,
23 | stroke: cfg.color,
24 | lineWidth: 5,
25 | lineCap: 'round'
26 | }
27 | });
28 | return group.addShape('circle', {
29 | attrs: {
30 | x: center.x,
31 | y: center.y,
32 | r: 12,
33 | stroke: cfg.color,
34 | lineWidth: 4.5,
35 | fill: '#fff'
36 | }
37 | });
38 | }
39 | });
40 |
41 | const data = [
42 | { value: 5.6 }
43 | ];
44 | const cols = {
45 | 'value': {
46 | min: 0,
47 | max: 9,
48 | tickInterval: 1,
49 | nice: false
50 | }
51 | }
52 |
53 |
54 | export default class Basic extends Component {
55 |
56 | render() {
57 | return (
58 |
59 |
60 |
83 |
84 |
85 |
91 |
97 | {return ('合格率
'+ data[0].value * 10+'%
')}}
100 | />
101 |
102 |
106 |
107 | );
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/testDemo/component/viewAD/geomAD.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape } from 'bizcharts';
3 | import DataSet from '@antv/data-set';
4 |
5 | const { DataView } = DataSet;
6 |
7 | const data = [
8 | { value: 251, type: '大事例一', name: '子事例一' },
9 | { value: 1048, type: '大事例一', name: '子事例二' },
10 | { value: 610, type: '大事例二', name: '子事例三' },
11 | { value: 434, type: '大事例二', name: '子事例四' },
12 | { value: 335, type: '大事例三', name: '子事例五' },
13 | { value: 250, type: '大事例三', name: '子事例六' }
14 | ];
15 |
16 | const dv = new DataView();
17 | dv.source(data).transform({
18 | type: 'percent',
19 | field: 'value',
20 | dimension: 'type',
21 | as: 'percent'
22 | });
23 | const cols = {
24 | percent: {
25 | formatter: val => {
26 | val = (val * 100).toFixed(2) + '%';
27 | return val;
28 | }
29 | }
30 | }
31 | const dv1 = new DataView();
32 | dv1.source(data).transform({
33 | type: 'percent',
34 | field: 'value',
35 | dimension: 'name',
36 | as: 'percent'
37 | });
38 |
39 | export default class PieC extends Component {
40 |
41 | constructor(props) {
42 | super(props);
43 | this.state = {
44 | showVal: Math.floor(Math.random() * 10),
45 | };
46 | }
47 |
48 | componentDidMount() {
49 | setInterval(() => {
50 | this.setState({
51 | showVal: Math.floor(Math.random() * 10),
52 | });
53 | }, 1000);
54 | }
55 |
56 | render() {
57 | return (
58 |
59 |
60 |
61 |
67 |
68 |
69 |
70 | {
71 | this.state.showVal < 4 &&
72 | {
77 | percent = (percent * 100).toFixed(2) + '%';
78 | return {
79 | name: item,
80 | value: percent
81 | };
82 | }]}
83 | style={{lineWidth: this.state.lineWidth, stroke: '#fff'}}
84 | select={false}
85 | />
86 | }
87 | {
88 | this.state.showVal >= 2 && this.state.showVal <=6 &&
89 | {
94 | percent = (percent * 100).toFixed(2) + '%';
95 | return {
96 | name: item,
97 | value: percent
98 | };
99 | }]}
100 | style={{lineWidth: this.state.lineWidth, stroke: '#fff'}}
101 | select={false}
102 | />
103 | }
104 | {
105 | this.state.showVal > 5 &&
106 |
112 | }
113 |
114 |
115 | );
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/components/Chart/purechart.jsx:
--------------------------------------------------------------------------------
1 | /* eslint react/no-unused-prop-types: "off" */
2 | import React, { Component } from 'react';
3 | import PropTypes from 'prop-types';
4 | import Processor from '../../processor/processor';
5 |
6 | export default class PureChart extends Component {
7 | static propTypes = {
8 | data: PropTypes.oneOfType([
9 | PropTypes.arrayOf(PropTypes.object),
10 | PropTypes.object,
11 | ]),
12 | scale: PropTypes.oneOfType([
13 | PropTypes.object,
14 | PropTypes.array,
15 | ]),
16 | animate: PropTypes.bool,
17 | width: PropTypes.number,
18 | height: PropTypes.number.isRequired,
19 | onGetG2Instance: PropTypes.func,
20 | }
21 |
22 | static childContextTypes = {
23 | addElement: PropTypes.func,
24 | updateElement: PropTypes.func,
25 | deleteElement: PropTypes.func,
26 | createId: PropTypes.func,
27 | getParentInfo: PropTypes.func,
28 | getViewId: PropTypes.func,
29 | };
30 |
31 | constructor(props) {
32 | super(props);
33 | this.name = 'Chart';
34 | this.gId = 0;
35 | this.id = this.createId();
36 | this.g2Processor = new Processor();
37 | }
38 |
39 | getChildContext() {
40 | return {
41 | addElement: this.addElement,
42 | updateElement: this.updateElement,
43 | deleteElement: this.deleteElement,
44 | createId: this.createId,
45 | getParentInfo: this.getParentInfo,
46 | getViewId: this.getViewId,
47 | };
48 | }
49 |
50 | componentDidMount() {
51 | this.addElement(
52 | this.name,
53 | this.id,
54 | {
55 | ...this.props,
56 | container: this.containerWrap,
57 | }
58 | );
59 | this.chart = this.g2Processor.createG2Instance();
60 | this.notifyG2Instance();
61 | }
62 |
63 | componentDidUpdate() {
64 | this.updateElement(
65 | this.name,
66 | this.id,
67 | {
68 | ...this.props,
69 | container: this.containerWrap,
70 | }
71 | );
72 | const newChart = this.g2Processor.batchedUpdate();
73 | if (this.chart !== newChart) {
74 | this.chart = newChart;
75 | this.notifyG2Instance();
76 | }
77 | }
78 |
79 | componentWillUnmount() {
80 | this.g2Processor.destory();
81 | this.chart = null;
82 | this.containerWrap = null;
83 | }
84 |
85 | getG2Instance() {
86 | return this.chart;
87 | }
88 |
89 | getViewId = () => { }
90 |
91 | getParentInfo = () => {
92 | return {
93 | id: this.id,
94 | name: this.name,
95 | };
96 | }
97 |
98 | createId = () => {
99 | this.gId += 1;
100 | return this.gId;
101 | }
102 |
103 | addElement = (name, id, props, parentInfo, viewId) => {
104 | return this.g2Processor.addElement(name, id, props, parentInfo, viewId);
105 | }
106 |
107 | updateElement = (name, id, props, parentInfo, viewId) => {
108 | this.g2Processor.updateElement(name, id, props, parentInfo, viewId);
109 | }
110 |
111 | deleteElement = (name, id, parentInfo) => {
112 | this.g2Processor.deleteElement(name, id, parentInfo);
113 | }
114 |
115 | notifyG2Instance() {
116 | if (this.props.onGetG2Instance) {
117 | this.props.onGetG2Instance(this.chart);
118 | }
119 | }
120 |
121 | refHandle = (cw) => {
122 | // chart container wrap for reset operation
123 | if (!this.containerWrap) {
124 | this.containerWrap = cw;
125 | }
126 | }
127 |
128 | render() {
129 | return {this.props.children}
;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/doc/api/graphic.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | # canvas 属性
7 |
8 | 由于 G2 使用的是 canvas,绘制的所有图形都支持 canvas 的属性,本章列出常用的属性,详细信息参考[ canvas 属性](http://www.w3school.com.cn/tags/html_ref_canvas.asp)。
9 |
10 | ## 通用属性
11 |
12 | * `fill` 设置用于填充绘画的颜色、渐变或模式;
13 | * `stroke` 设置用于笔触的颜色、渐变或模式;
14 | * `shadowColor` 设置用于阴影的颜色;
15 | * `shadowBlur` 设置用于阴影的模糊级别;
16 | * `shadowOffsetX` 设置阴影距形状的水平距离;
17 | * `shadowOffsetY` 设置阴影距形状的垂直距离;
18 | * `opacity` 设置绘图的当前 alpha 或透明值;
19 | * `globalCompositeOperation` 设置新图像如何绘制到已有的图像上。
20 |
21 | > **!注意:**
22 |
23 | G2 对图形属性进行了缩写
24 |
25 | * fillStyle 缩写为 `fill`;
26 | * stokeStyle 缩写为 `stroke`;
27 | * globalAlpha 缩写为 `opacity`。
28 |
29 | ## 线条样式
30 |
31 | * [`lineCap`](http://www.w3school.com.cn/tags/canvas_linecap.asp) 设置线条的结束端点样式;
32 | * [`lineJoin`](http://www.w3school.com.cn/tags/canvas_linejoin.asp) 设置两条线相交时,所创建的拐角形状;
33 | * [`lineWidth`](http://www.w3school.com.cn/tags/canvas_linewidth.asp) 设置当前的线条宽度;
34 | * [`miterLimit`](http://www.w3school.com.cn/tags/canvas_miterlimit.asp) 设置最大斜接长度。
35 |
36 | > **!注意:**
37 |
38 | 1. G2 在现有线的样式基础上增加了虚线的支持:
39 |
40 | * `lineDash`:设置线的虚线样式,可以指定一个数组。一组描述交替绘制线段和间距(坐标空间单位)长度的数字。 如果数组元素的数量是奇数, 数组的元素会被复制并重复。例如, [5, 15, 25] 会变成 [5, 15, 25, 5, 15, 25]。
41 |
42 | 这个属性取决于浏览器是否支持 setLineDash 函数,详情参考[setLineDash](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash)。
43 |
44 | 2. G2 在现有线的基础上增加了首尾箭头的绘制支持:
45 |
46 | - `startArrow`: true|boolean,是否渲染起点箭头
47 | - `endArrow`: true|boolean,是否渲染终点箭头
48 | - `arrowAngle`: number,角度,箭头的夹角大小
49 | - `arrowRadius`: number,箭头长度
50 |
51 | ## 文本属性
52 |
53 | * [`font`](http://www.w3school.com.cn/tags/canvas_font.asp) 设置文本内容的当前字体属性;
54 | * [`textAlign`](http://www.w3school.com.cn/tags/canvas_textalign.asp) 设置文本内容的当前对齐方式, 支持的属性:center|end|left|right|start;
55 | * [`textBaseline`](http://www.w3school.com.cn/tags/canvas_textbaseline.asp) 设置在绘制文本时使用的当前文本基线, 支持的属性:top|middle|bottom。
56 |
57 | **!注意:**
58 |
59 | G2 提供了额外的几个文本属性,便于用户设置字体,具体的含义参考[font 组成](http://www.w3school.com.cn/tags/canvas_font.asp)
60 |
61 | * `fontStyle` 对应 font-style;
62 | * `fontVariant` 对应 font-variant;
63 | * `fontWeight` 对应 font-weight;
64 | * `fontSize` 对应 font-size;
65 | * `fontFamily` 对应 font-family;
66 |
67 | ## 渐变色
68 |
69 | G2 中提供了线性渐变、放射状/环形渐变两种形式,使用方式如下:
70 |
71 | * 线性渐变
72 |
73 |
74 |
75 |
76 | > 说明:`l` 表示使用线性渐变,绿色的字体为可变量,由用户自己填写。
77 |
78 | ```js
79 | // example
80 | // 使用渐变色描边,渐变角度为 0,渐变的起始点颜色 #ffffff,中点的渐变色为 #7ec2f3,结束的渐变色为 #1890ff
81 | stroke: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff'
82 | ```
83 |
84 | * 放射状/环形渐变
85 |
86 |
87 |
88 | > 说明:`r` 表示使用放射状渐变,绿色的字体为可变量,由用户自己填写,开始圆的 x y r 值均为相对值,0 至 1 范围。
89 |
90 | ```js
91 | // example
92 | // 使用渐变色填充,渐变起始圆的圆心坐标为被填充物体的包围盒中心点,半径为(包围盒对角线长度 / 2) 的 0.1 倍,渐变的起始点颜色 #ffffff,中点的渐变色为 #7ec2f3,结束的渐变色为 #1890ff
93 | fill: 'r(0.5, 0.5, 0.1) 0:#ffffff 1:#1890ff'
94 | ```
95 |
96 | ## 纹理
97 |
98 |
99 |
100 | > 说明:`p` 表示使用纹理,绿色的字体为可变量,由用户自己填写。
101 |
102 | * `a`: 该模式在水平和垂直方向重复;
103 | * `x`: 该模式只在水平方向重复;
104 | * `y`: 该模式只在垂直方向重复;
105 | * `n`: 该模式只显示一次(不重复)。
106 |
107 | 纹理的内容可以直接是图片或者 [Data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs)。
108 |
109 | ```js
110 | // example
111 | // 使用纹理填充,在水平和垂直方向重复图片
112 | fill: 'p(a)https://gw.alipayobjects.com/zos/rmsportal/ibtwzHXSxomqbZCPMLqS.png'
113 | ```
114 |
115 |
--------------------------------------------------------------------------------
/doc_en/api/bizcharts.md:
--------------------------------------------------------------------------------
1 |
2 | # BizCharts
3 | The global BizCharts namespace contain:
4 |
5 | ## 1、Component
6 |
7 | ### Chart
8 | All BizCharts components should be added into Chart component, such as ` ...`.
9 | It controls the creation update and destruction of the chart.
10 | Detail: [Chart api](chart.md)
11 |
12 | ### Coord
13 | Coordinate component.
14 | It was used to control Chart or View 's coordinate.
15 | Detail: [Coord api](coord.md)
16 |
17 | ### Axis
18 | Coordinate's axis component.
19 | It was used to control Chart or View 's coordinate axis.
20 | Detail: [Axis api](axis.md)
21 |
22 | ### Geom
23 | Geometry mark, the Geom and Coord are determines the type of chart.
24 | Detail: [Geom api](geom.md).
25 |
26 | ### Label
27 | Geometry mark's Label Component.
28 | Detail: [Label api](label.md)
29 |
30 | ### Legend
31 | Legend Component.
32 | Detail: [Legend api](legend.md)
33 |
34 | ### Guide
35 | A container component to control chart's guids(Guide.Text Guide.Line ...) update.
36 | Detail: [Guide api](guide.md)
37 |
38 | ### Facet
39 | Facet component.
40 | Detail: [Facet api](facet.md)
41 |
42 | ### View
43 | View Component.
44 | Defailt: [View api](view.md)
45 |
46 | ## 2、G2
47 | The G2 namespace.
48 | Detail: [G2](//antv.alipay.com/zh-cn/g2/3.x/index.html)
49 |
50 | ## 3、Animate
51 | It's used to register custom animation.
52 | Detail: [动画教程](../tutorial/animate.md).
53 |
54 | ## 4、Shape
55 | Chart's shapes, it's uesed to register custom shape.
56 | Detail [Shape api](shape.md).
57 |
58 | ## 5、setTheme
59 | It's used to change theme.
60 | Defail [theme tutorial](../tutorial/theme.md).
61 |
62 | ## 6、track
63 | It's used to monitor the usage of G2 version by G2, If you dont's want use to know it please set false.
64 | ```js
65 | BizCharts.track(false);
66 | ```
67 |
68 | ## 7、PathUtil
69 | From G2, it's used to
70 | 来自 G2,some apis to manipulate graphic paths。
71 |
72 | | 方法 | 参数说明 | 返回结果 |
73 | | ---- | ---- | ---- |
74 | | `getBoundingClientRect(node)` | `node`:HTMLElement,dom element | return the element's position in page. Data format: `{top: , bottom: , left: , right}` |
75 | | `getStyle(dom, name)` | `dom`:HTMLElement,DOM element;`name`:String, style name | return the element's name style value. |
76 | | `modifyCSS(dom, css)` | `dom`:HTMLElement,DOM element; `css`:Object,style | change the element's css style, then return the final style after changed. |
77 | | `createDom(str)` | `str`:String,Dom string | Create an dom element and return it. |
78 | | `getRatio()` | -- | returns the screen pixel resolution. |
79 | | `getWidth(el)` | `el`:HTMLElement,dom element| return dom element's width, not contain padding border |
80 | | `getHeight(el)` | `e`l:HTMLElement,dom element| return dom element's height, not contain padding border |
81 | | `getOuterWidth(el)` | `el`:HTMLElement,dom element| return dom element's width, contain padding border |
82 | | `getOuterHeight(el)` | `el`:HTMLElement,dom element| return dom element's height, contain padding border |
83 | | `addEventListener(target, eventType, callback)` | `target`:HTMLElement,DOM element;`eventType`:String, event name;`callback`:Function | Add event listener. |
84 | | `requestAnimationFrame(fn)` | `fn`:Function, callback function | .
85 |
86 | ## 8、Util
87 | Util function, most come from lodash.
88 | ```js
89 | // example
90 | const Util = {
91 | each: require('lodash/each'),
92 | map: require('lodash/map'),
93 | isObject: require('lodash/isObject'),
94 | isNumber: require('lodash/isNumber'),
95 | isString: require('lodash/isString'),
96 | isFunction: require('lodash/isFunction'),
97 | ...
98 | };
99 | ```
100 |
101 |
--------------------------------------------------------------------------------