From f9cea69c06a3545c066d18db3c6fe186e6d7f116 Mon Sep 17 00:00:00 2001 From: Joel Alan <31396322+lxfu1@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:05:06 +0800 Subject: [PATCH] chore: opt config (#2158) --- packages/plots/src/core/plots/area/index.ts | 3 +++ packages/plots/src/core/plots/bar/index.ts | 3 +++ .../plots/src/core/plots/bullet/adaptor.ts | 21 ++++++++++++------- packages/plots/src/core/plots/bullet/index.ts | 9 +++----- packages/plots/src/core/plots/column/index.ts | 5 +++++ site/package.json | 2 +- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/packages/plots/src/core/plots/area/index.ts b/packages/plots/src/core/plots/area/index.ts index e7c337c7e..07f739a33 100644 --- a/packages/plots/src/core/plots/area/index.ts +++ b/packages/plots/src/core/plots/area/index.ts @@ -17,6 +17,9 @@ export class Area extends Plot { return { type: 'view', children: [{ type: 'area' }], + scale: { + y: { nice: true }, + }, interaction: { tooltip: { shared: true, diff --git a/packages/plots/src/core/plots/bar/index.ts b/packages/plots/src/core/plots/bar/index.ts index 00996f5f3..5aa4936d5 100644 --- a/packages/plots/src/core/plots/bar/index.ts +++ b/packages/plots/src/core/plots/bar/index.ts @@ -18,6 +18,9 @@ export class Bar extends Plot { type: 'view', coordinate: { transform: [{ type: 'transpose' }] }, children: [{ type: 'interval' }], + scale: { + y: { nice: true }, + }, interaction: { tooltip: { shared: true, diff --git a/packages/plots/src/core/plots/bullet/adaptor.ts b/packages/plots/src/core/plots/bullet/adaptor.ts index 3fb4639cb..8dc0715d8 100644 --- a/packages/plots/src/core/plots/bullet/adaptor.ts +++ b/packages/plots/src/core/plots/bullet/adaptor.ts @@ -46,7 +46,7 @@ function getTransformData(data: any[], field: string, xField: string, isSort = t * @returns string[] */ function getFieldColor(maxSize: number, color: string | string[]) { - return new Array(maxSize).fill('').map((d, i) => isArray(color) ? color[i % color.length] : color); + return new Array(maxSize).fill('').map((d, i) => (isArray(color) ? color[i % color.length] : color)); } /** @@ -58,12 +58,20 @@ export function adaptor(params: Params) { * 图表差异化处理 */ const init = (params: Params) => { - const { color, rangeField = 'ranges', measureField = 'measures', targetField = 'targets', xField = 'title', mapField, data } = params.options; + const { + color, + rangeField = 'ranges', + measureField = 'measures', + targetField = 'targets', + xField = 'title', + mapField, + data, + } = params.options; // 数据进行拍平 const [rangesData, rangesMaxSize] = getTransformData(data, rangeField, xField); const [measuresData, measuresMaxSize] = getTransformData(data, measureField, xField, false); - const [targetsData, targetsMaxSize] = getTransformData(data, targetField, xField); + const [targetsData, targetsMaxSize] = getTransformData(data, targetField, xField, false); // 获取颜色 const rangesColor = get(color, [rangeField], DEFAULT_COLORS[0]); @@ -129,13 +137,13 @@ export function adaptor(params: Params) { target.shapeField = 'hyphen'; target.labels[0] = { text: target.labels[0].text, - position: "bottom", + position: 'bottom', dy: -5, }; } return params; - } + }; /** * range、measure、target 配置适配 @@ -146,8 +154,7 @@ export function adaptor(params: Params) { const { range = {}, measure = {}, target = {}, children } = params.options; params.options.children = [range, measure, target].map((c, i) => deepAssign(children[i], c)); return params; - } - + }; return flow(init, layoutAdaptor, cfgAdaptor, coordinateLayout, transformOptions)(params); } diff --git a/packages/plots/src/core/plots/bullet/index.ts b/packages/plots/src/core/plots/bullet/index.ts index edc2f70d0..d300db2e3 100644 --- a/packages/plots/src/core/plots/bullet/index.ts +++ b/packages/plots/src/core/plots/bullet/index.ts @@ -25,7 +25,7 @@ export class Bullet extends Plot { legend: { color: { itemMarker: (d) => { - return d === "target" ? "line" : "square"; + return d === 'target' ? 'line' : 'square'; }, }, }, @@ -39,17 +39,14 @@ export class Bullet extends Plot { type: 'interval', style: { maxWidth: 20 }, transform: [{ type: 'stackY' }], - labels: [{ text: "measures", position: "inside" }], }, { type: 'point', - encode: { size: 8, shape: "line" }, - tooltip: { title: false, items: [{ channel: "y" }] }, - labels: [{ text: "targets", position: "right", textAlign: 'left', dx: 5 }], + encode: { size: 8, shape: 'line' }, }, ], interaction: { tooltip: { shared: true } }, - coordinate: { transform: [{ type: "transpose" }] }, + coordinate: { transform: [{ type: 'transpose' }] }, }; } diff --git a/packages/plots/src/core/plots/column/index.ts b/packages/plots/src/core/plots/column/index.ts index 7196d1b76..6f73e042e 100644 --- a/packages/plots/src/core/plots/column/index.ts +++ b/packages/plots/src/core/plots/column/index.ts @@ -19,6 +19,11 @@ export class Column extends Plot { scale: { y: { nice: true }, }, + interaction: { + tooltip: { + shared: true, + }, + }, children: [ { type: 'interval', diff --git a/site/package.json b/site/package.json index ddf41b5d0..f7150f5da 100644 --- a/site/package.json +++ b/site/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@ant-design/charts-site", - "version": "2.0.0-alpha.0", + "version": "2.0.0-beta.2", "description": "React Visual component library", "keywords": [ "antv",