diff --git a/packages/plots/src/components/tiny/tiny-area/index.tsx b/packages/plots/src/components/tiny/area/index.tsx similarity index 100% rename from packages/plots/src/components/tiny/tiny-area/index.tsx rename to packages/plots/src/components/tiny/area/index.tsx diff --git a/packages/plots/src/components/tiny/tiny-column/index.tsx b/packages/plots/src/components/tiny/column/index.tsx similarity index 100% rename from packages/plots/src/components/tiny/tiny-column/index.tsx rename to packages/plots/src/components/tiny/column/index.tsx diff --git a/packages/plots/src/components/tiny/index.ts b/packages/plots/src/components/tiny/index.ts index 946fd4d47..083c0962f 100644 --- a/packages/plots/src/components/tiny/index.ts +++ b/packages/plots/src/components/tiny/index.ts @@ -1,13 +1,15 @@ -import Line from './tiny-line'; -import Area from './tiny-area'; -import Column from './tiny-column'; -import Progress from './tiny-progress'; +import Line from './line'; +import Area from './area'; +import Column from './column'; +import Progress from './progress'; +import Ring from './ring'; -export type { TinyLineConfig } from './tiny-line'; -export type { TinyAreaConfig } from './tiny-area'; -export type { TinyColumnConfig } from './tiny-column'; -export type { TinyProgressConfig } from './tiny-progress'; +export type { TinyLineConfig } from './line'; +export type { TinyAreaConfig } from './area'; +export type { TinyColumnConfig } from './column'; +export type { TinyProgressConfig } from './progress'; +export type { TinyRingConfig } from './ring'; -type TinyOptions = Record; +type TinyOptions = Record; -export const Tiny: TinyOptions = { Line, Area, Column, Progress }; +export const Tiny: TinyOptions = { Line, Area, Column, Progress, Ring }; diff --git a/packages/plots/src/components/tiny/tiny-line/index.tsx b/packages/plots/src/components/tiny/line/index.tsx similarity index 100% rename from packages/plots/src/components/tiny/tiny-line/index.tsx rename to packages/plots/src/components/tiny/line/index.tsx diff --git a/packages/plots/src/components/tiny/tiny-progress/index.tsx b/packages/plots/src/components/tiny/progress/index.tsx similarity index 100% rename from packages/plots/src/components/tiny/tiny-progress/index.tsx rename to packages/plots/src/components/tiny/progress/index.tsx diff --git a/packages/plots/src/components/tiny/ring/index.tsx b/packages/plots/src/components/tiny/ring/index.tsx new file mode 100644 index 000000000..c716bd5e3 --- /dev/null +++ b/packages/plots/src/components/tiny/ring/index.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { TinyRingOptions } from '../../../core'; +import { CommonConfig } from '../../../interface'; +import { BaseChart } from '../../base'; + +export type TinyRingConfig = CommonConfig; + +const TinyRingChart = (props: TinyRingOptions) => ; + +export default TinyRingChart; diff --git a/packages/plots/src/core/base/index.ts b/packages/plots/src/core/base/index.ts index dfd6dd662..8a0e7a66c 100644 --- a/packages/plots/src/core/base/index.ts +++ b/packages/plots/src/core/base/index.ts @@ -87,7 +87,7 @@ export abstract class Plot extends EE { /** * 获取默认的 options 配置项,每个组件都可以复写 */ - protected getDefaultOptions(): Partial | void { } + protected getDefaultOptions(): Partial | void {} /** * 绘制 diff --git a/packages/plots/src/core/constants/index.ts b/packages/plots/src/core/constants/index.ts index 2311a01e3..d4ad5953c 100644 --- a/packages/plots/src/core/constants/index.ts +++ b/packages/plots/src/core/constants/index.ts @@ -9,11 +9,22 @@ export const CHART_OPTIONS = [ 'canvas', 'theme', 'inset', + 'insetLeft', + 'insetRight', + 'insetTop', + 'insetBottom', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', + 'margin', + 'marginTop', + 'marginRight', + 'marginBottom', + 'marginLeft', + 'depth', + 'title', ]; /** 最终透传给 G2 Spec 的保留字 */ @@ -162,6 +173,8 @@ const EXTEND_KEYS = [ 'keyField', 'positionField', 'meta', + 'tooltip', + 'animate', ]; export const CONFIG_SHAPE = [ { diff --git a/packages/plots/src/core/index.ts b/packages/plots/src/core/index.ts index 4b8593cd6..22dd1b3a9 100644 --- a/packages/plots/src/core/index.ts +++ b/packages/plots/src/core/index.ts @@ -11,6 +11,7 @@ export type { TinyLineOptions } from './plots/tiny-line'; export type { TinyAreaOptions } from './plots/tiny-area'; export type { TinyColumnOptions } from './plots/tiny-column'; export type { TinyProgressOptions } from './plots/tiny-progress'; +export type { TinyRingOptions } from './plots/tiny-ring'; export type { RoseOptions } from './plots/rose'; export type { WaterfallOptions } from './plots/waterfall'; export type { HistogramOptions } from './plots/histogram'; @@ -36,6 +37,7 @@ import { TinyLine } from './plots/tiny-line'; import { TinyArea } from './plots/tiny-area'; import { TinyColumn } from './plots/tiny-column'; import { TinyProgress } from './plots/tiny-progress'; +import { TinyRing } from './plots/tiny-ring'; import { Rose } from './plots/rose'; import { Waterfall } from './plots/waterfall'; import { Histogram } from './plots/histogram'; @@ -62,6 +64,7 @@ export const Plots = { TinyArea, TinyColumn, TinyProgress, + TinyRing, Waterfall, Histogram, Heatmap, diff --git a/packages/plots/src/core/plots/column/index.ts b/packages/plots/src/core/plots/column/index.ts index f5374b26d..20ddd99cb 100644 --- a/packages/plots/src/core/plots/column/index.ts +++ b/packages/plots/src/core/plots/column/index.ts @@ -16,6 +16,9 @@ export class Column extends Plot { static getDefaultOptions(): Partial { return { type: 'view', + scale: { + y: { nice: true }, + }, children: [ { type: 'interval', diff --git a/packages/plots/src/core/plots/gauge/index.ts b/packages/plots/src/core/plots/gauge/index.ts index ee263b61e..b7b7a4e49 100644 --- a/packages/plots/src/core/plots/gauge/index.ts +++ b/packages/plots/src/core/plots/gauge/index.ts @@ -14,7 +14,11 @@ export class Gauge extends Plot { * 供外部使用 */ static getDefaultOptions(): Partial { - return { type: 'view', children: [{ type: 'gauge' }] }; + return { + type: 'view', + legend: false, + children: [{ type: 'gauge' }], + }; } /** diff --git a/packages/plots/src/core/plots/line/index.ts b/packages/plots/src/core/plots/line/index.ts index 6f5b67e4a..112661e21 100644 --- a/packages/plots/src/core/plots/line/index.ts +++ b/packages/plots/src/core/plots/line/index.ts @@ -14,7 +14,16 @@ export class Line extends Plot { * 供外部使用 */ static getDefaultOptions(): Partial { - return { type: 'view', children: [{ type: 'line' }] }; + return { + type: 'view', + scale: { + y: { nice: true }, + }, + animate: { + enter: { type: 'growInX' }, + }, + children: [{ type: 'line' }], + }; } /** diff --git a/packages/plots/src/core/plots/liquid/adaptor.ts b/packages/plots/src/core/plots/liquid/adaptor.ts index 567580243..8997b9935 100644 --- a/packages/plots/src/core/plots/liquid/adaptor.ts +++ b/packages/plots/src/core/plots/liquid/adaptor.ts @@ -1,4 +1,4 @@ -import { flow, transformOptions } from '../../utils'; +import { flow, transformOptions, isNumber, set } from '../../utils'; import { mark } from '../../components'; import type { Adaptor } from '../../types'; import type { LiquidOptions } from './type'; @@ -14,6 +14,13 @@ export function adaptor(params: Params) { * 图表差异化处理 */ const init = (params: Params) => { + const { + options: { percent }, + } = params; + + if (isNumber(percent)) { + set(params, 'options.data', percent); + } return params; }; diff --git a/packages/plots/src/core/plots/radar/index.ts b/packages/plots/src/core/plots/radar/index.ts index 133ad645c..810e4b541 100644 --- a/packages/plots/src/core/plots/radar/index.ts +++ b/packages/plots/src/core/plots/radar/index.ts @@ -16,6 +16,12 @@ export class Radar extends Plot { */ static getDefaultOptions(): Partial { return { + axis: { + x: { grid: true, line: true }, + y: { zIndex: 1, title: false, line: true , nice: true}, + }, + meta: { x: { padding: 0.5, align: 0 } }, + interaction: { tooltip: { style: { crosshairsLineDash: [4, 4] } } }, children: [{ type: 'line' }], // 有 polar 和 radar 两种极坐标形式 coordinateType: 'polar', diff --git a/packages/plots/src/core/plots/tiny-area/index.ts b/packages/plots/src/core/plots/tiny-area/index.ts index f209d848d..9c96a036c 100644 --- a/packages/plots/src/core/plots/tiny-area/index.ts +++ b/packages/plots/src/core/plots/tiny-area/index.ts @@ -16,8 +16,14 @@ export class TinyArea extends Plot { static getDefaultOptions(): Partial { return { type: 'view', + animate: { + enter: { type: 'growInX', duration: 500 }, + }, children: [{ type: 'area', axis: false }], autoFit: false, + padding: 0, + margin: 0, + tooltip: false }; } diff --git a/packages/plots/src/core/plots/tiny-column/index.ts b/packages/plots/src/core/plots/tiny-column/index.ts index 6be444ed7..59d819672 100644 --- a/packages/plots/src/core/plots/tiny-column/index.ts +++ b/packages/plots/src/core/plots/tiny-column/index.ts @@ -18,6 +18,9 @@ export class TinyColumn extends Plot { type: 'view', children: [{ type: 'interval', axis: false }], autoFit: false, + padding: 0, + margin: 0, + tooltip: false, }; } diff --git a/packages/plots/src/core/plots/tiny-line/index.ts b/packages/plots/src/core/plots/tiny-line/index.ts index baee2af4f..f84f3a22b 100644 --- a/packages/plots/src/core/plots/tiny-line/index.ts +++ b/packages/plots/src/core/plots/tiny-line/index.ts @@ -18,6 +18,12 @@ export class TinyLine extends Plot { type: 'view', children: [{ type: 'line', axis: false }], autoFit: false, + animate: { + enter: { type: 'growInX', duration: 500 }, + }, + padding: 0, + margin: 0, + tooltip: false, }; } diff --git a/packages/plots/src/core/plots/tiny-progress/index.ts b/packages/plots/src/core/plots/tiny-progress/index.ts index 1daddace5..42bd89f00 100644 --- a/packages/plots/src/core/plots/tiny-progress/index.ts +++ b/packages/plots/src/core/plots/tiny-progress/index.ts @@ -17,6 +17,10 @@ export class TinyProgress extends Plot { return { type: 'view', data: [], + autoFit: false, + margin: 0, + padding: 0, + tooltip: false, children: [ { interaction: { tooltip: false }, @@ -25,7 +29,7 @@ export class TinyProgress extends Plot { axis: false, legend: false, encode: { y: (d) => d, color: (d, idx) => idx }, - } + }, ], }; } diff --git a/packages/plots/src/core/plots/tiny-ring/adaptor.ts b/packages/plots/src/core/plots/tiny-ring/adaptor.ts new file mode 100644 index 000000000..490db8c37 --- /dev/null +++ b/packages/plots/src/core/plots/tiny-ring/adaptor.ts @@ -0,0 +1,43 @@ +import { flow, transformOptions, set } from '../../utils'; +import { mark } from '../../components'; +import type { Adaptor } from '../../types'; +import type { TinyRingOptions } from './type'; + +type Params = Adaptor; + +/** + * @param chart + * @param options + */ +export function adaptor(params: Params) { + /** + * @description radius + */ + const radius = (params: Params) => { + const { options } = params; + const { radius = 0.8 } = options; + set(params, 'options.coordinate.innerRadius', radius); + return params; + }; + + /** + * @description 数据转换 + */ + const transformData = (params: Params) => { + const { options } = params; + const { percent, color = [] } = options; + if (!percent) return params; + + const transformOption = { + scale: { + color: { range: color.length ? color : [] }, + }, + data: [1, percent], + }; + + Object.assign(options, { ...transformOption }); + return params; + }; + + return flow(radius, transformData, transformOptions, mark)(params); +} diff --git a/packages/plots/src/core/plots/tiny-ring/index.ts b/packages/plots/src/core/plots/tiny-ring/index.ts new file mode 100644 index 000000000..9f19d4a52 --- /dev/null +++ b/packages/plots/src/core/plots/tiny-ring/index.ts @@ -0,0 +1,51 @@ +import { Plot } from '../../base'; +import type { Adaptor } from '../../types'; +import { adaptor } from './adaptor'; +import { TinyRingOptions } from './type'; + +export type { TinyRingOptions }; + +export class TinyRing extends Plot { + /** 图表类型 */ + public type = 'TinyRing'; + + /** + * 获取进度图默认配置项 + * 供外部使用 + */ + static getDefaultOptions(): Partial { + return { + type: 'view', + data: [], + autoFit: false, + margin: 0, + padding: 0, + coordinate: { type: 'theta' }, + animate: { enter: { type: 'waveIn' } }, + interaction: { tooltip: false }, + tooltip: false, + children: [ + { + type: 'interval', + axis: false, + legend: false, + encode: { y: (d) => d, color: (d, idx) => idx }, + }, + ], + }; + } + + /** + * 获取 进度图 默认配置 + */ + protected getDefaultOptions() { + return TinyRing.getDefaultOptions(); + } + + /** + * 迷你折线图适配器 + */ + protected getSchemaAdaptor(): (params: Adaptor) => void { + return adaptor; + } +} diff --git a/packages/plots/src/core/plots/tiny-ring/type.ts b/packages/plots/src/core/plots/tiny-ring/type.ts new file mode 100644 index 000000000..29505e78a --- /dev/null +++ b/packages/plots/src/core/plots/tiny-ring/type.ts @@ -0,0 +1,20 @@ +import type { BaseOptions, Options } from '../../types/common'; + +export type TinyRingOptions = Options & + BaseOptions & { + /** + * @title 进度 + */ + percent: number; + /** + * @title 颜色 + * @description [ backgroundColor, progressColor] + */ + color?: [string, string]; + /** + * @title 内径 + * @description 0 ~ 1 + * @default 0.8 + */ + radius?: number; + }; diff --git a/packages/plots/src/core/plots/wordCloud/index.ts b/packages/plots/src/core/plots/wordCloud/index.ts index 40b1696ad..67c478fe0 100644 --- a/packages/plots/src/core/plots/wordCloud/index.ts +++ b/packages/plots/src/core/plots/wordCloud/index.ts @@ -15,7 +15,7 @@ export class WordCloud extends Plot { * 供外部使用 */ static getDefaultOptions(): Partial { - return { type: 'view', children: [{ type: 'wordCloud' }] }; + return { type: 'view', legend: false, children: [{ type: 'wordCloud' }] }; } /** diff --git a/site/examples/statistics/liquid/demo/liquid-background.js b/site/examples/statistics/liquid/demo/liquid-background.js index d8867a33d..1f2e4e89d 100644 --- a/site/examples/statistics/liquid/demo/liquid-background.js +++ b/site/examples/statistics/liquid/demo/liquid-background.js @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom'; const DemoLiquid = () => { const config = { - data: .3, + percent: .3, style: { backgroundFill: 'pink', }, diff --git a/site/examples/statistics/liquid/demo/liquid-custom-shape.js b/site/examples/statistics/liquid/demo/liquid-custom-shape.js index 2d149bc36..814e99666 100644 --- a/site/examples/statistics/liquid/demo/liquid-custom-shape.js +++ b/site/examples/statistics/liquid/demo/liquid-custom-shape.js @@ -4,12 +4,12 @@ import ReactDOM from 'react-dom'; const DemoLiquid = () => { const config = { - data: .3, + percent: 0.3, style: { shape: (x, y, r) => { const path = []; const w = r * 2; - + for (let i = 0; i < 5; i++) { path.push([ i === 0 ? 'M' : 'L', diff --git a/site/examples/statistics/liquid/demo/liquid-pin.js b/site/examples/statistics/liquid/demo/liquid-pin.js index 738a1697f..084420ae3 100644 --- a/site/examples/statistics/liquid/demo/liquid-pin.js +++ b/site/examples/statistics/liquid/demo/liquid-pin.js @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom'; const DemoLiquid = () => { const config = { - data: .7, + percent: 0.7, style: { shape: 'pin', textFill: '#fff', diff --git a/site/examples/statistics/liquid/demo/liquid.js b/site/examples/statistics/liquid/demo/liquid.js index 4708bae7f..bcf95bcc0 100644 --- a/site/examples/statistics/liquid/demo/liquid.js +++ b/site/examples/statistics/liquid/demo/liquid.js @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom'; const DemoLiquid = () => { const config = { - data: .3, + percent: 0.3, style: { outlineBorder: 4, outlineDistance: 8, diff --git a/site/examples/statistics/tiny/demo/meta.json b/site/examples/statistics/tiny/demo/meta.json index d06fb3364..2462f529b 100644 --- a/site/examples/statistics/tiny/demo/meta.json +++ b/site/examples/statistics/tiny/demo/meta.json @@ -67,6 +67,14 @@ "en": "Tiny progress plot" }, "screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*ZJ6JSL4WFt8AAAAAAAAAAAAADmJ7AQ" + }, + { + "filename": "ring.js", + "title": { + "zh": "迷你进度环图", + "en": "Basic tiny ring progress" + }, + "screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*NaLRSIdTx_YAAAAAAAAAAAAAARQnAQ" } ] } diff --git a/site/examples/statistics/tiny/demo/ring.js b/site/examples/statistics/tiny/demo/ring.js new file mode 100644 index 000000000..7a3a2da54 --- /dev/null +++ b/site/examples/statistics/tiny/demo/ring.js @@ -0,0 +1,27 @@ +import { Tiny } from '@ant-design/plots'; +import React from 'react'; +import ReactDOM from 'react-dom'; + +const DemoRing = () => { + const config = { + percent: 0.7, + color: ['#E8EFF5', '#66AFF4'], + annotations: [ + { + type: 'text', + style: { + text: `${progress * 100}%`, + x: '50%', + y: '50%', + textAlign: 'center', + fontSize: 16, + fontStyle: 'bold', + }, + }, + ], + }; + + return ; +}; + +ReactDOM.render(, document.getElementById('container'));