Skip to content

Commit

Permalink
chore: opt config (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfu1 authored Nov 2, 2023
1 parent d208c94 commit f9cea69
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
3 changes: 3 additions & 0 deletions packages/plots/src/core/plots/area/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export class Area extends Plot<AreaOptions> {
return {
type: 'view',
children: [{ type: 'area' }],
scale: {
y: { nice: true },
},
interaction: {
tooltip: {
shared: true,
Expand Down
3 changes: 3 additions & 0 deletions packages/plots/src/core/plots/bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class Bar extends Plot<BarOptions> {
type: 'view',
coordinate: { transform: [{ type: 'transpose' }] },
children: [{ type: 'interval' }],
scale: {
y: { nice: true },
},
interaction: {
tooltip: {
shared: true,
Expand Down
21 changes: 14 additions & 7 deletions packages/plots/src/core/plots/bullet/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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]);
Expand Down Expand Up @@ -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 配置适配
Expand All @@ -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);
}
9 changes: 3 additions & 6 deletions packages/plots/src/core/plots/bullet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Bullet extends Plot<BulletOptions> {
legend: {
color: {
itemMarker: (d) => {
return d === "target" ? "line" : "square";
return d === 'target' ? 'line' : 'square';
},
},
},
Expand All @@ -39,17 +39,14 @@ export class Bullet extends Plot<BulletOptions> {
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' }] },
};
}

Expand Down
5 changes: 5 additions & 0 deletions packages/plots/src/core/plots/column/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class Column extends Plot<ColumnOptions> {
scale: {
y: { nice: true },
},
interaction: {
tooltip: {
shared: true,
},
},
children: [
{
type: 'interval',
Expand Down
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit f9cea69

Please sign in to comment.