Skip to content

Commit

Permalink
feat(legend): support config category legend
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed May 31, 2022
1 parent 4e3790c commit a69a471
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions __tests__/unit/runtime/statistic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ describe('statistic', () => {
},
{ type: 'stackY', orderBy: 'series' },
],
paddingTop: 68,
scale: {
x: { field: 'Date', utc: true },
y: { guide: { label: { formatter: (d) => `${+d.text / 1000}k` } } },
color: { guide: { autoWrap: true, size: 68, maxRows: 3, cols: 4 } },
},
encode: {
shape: 'smoothArea',
Expand Down
19 changes: 13 additions & 6 deletions src/component/legendCategory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Category } from '@antv/gui';
import { deepMix } from '@antv/util';
import {
GuideComponentComponent as GCC,
GuideComponentPosition,
Expand All @@ -23,19 +24,23 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
name: formatter(d),
color: scale.map(d),
}));
return new Category({
style: {
const { cols, autoWrap, ...guideCfg } = scale.getOptions().guide || {};
const maxItemWidth = autoWrap && cols ? width / cols : undefined;
const legendStyle = deepMix(
{},
{
items,
x,
y,
maxWidth: width,
maxHeight: height,
autoWrap,
maxItemWidth,
itemWidth: maxItemWidth,
spacing: [8, 0],
itemName: {
style: {
default: {
fontSize: 12,
},
fontSize: 12,
},
},
...(field && {
Expand All @@ -53,7 +58,9 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
symbol: 'circle',
},
},
});
guideCfg,
);
return new Category({ style: legendStyle });
};
};

Expand Down

0 comments on commit a69a471

Please sign in to comment.