Skip to content

Commit

Permalink
fix(legend): pass legend.style (#5084)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored May 24, 2023
1 parent 106b807 commit f915d02
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions __tests__/plots/static/athletes-rect-bin-legend-style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { G2Spec } from '../../../src';

export function athletesRectBinLegendStyle(): G2Spec {
return {
type: 'rect',
data: {
type: 'fetch',
value: 'data/athletes.csv',
},
transform: [
{ type: 'binX', y: 'count' },
{ type: 'stackY', orderBy: 'series' },
],
encode: {
x: 'weight',
color: 'sex',
},
legend: {
color: {
style: {
itemMarkerFill: 'red',
itemValueFill: 'black',
itemLabelFontSize: 30,
},
},
},
style: {
inset: 0.5,
},
};
}
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,4 @@ export { tranLineMultiAxesAutoPaddingTickMethod } from './train-line-multi-axes-
export { vaccinesCellScaleRelationAutoPaddingTickFilter } from './vaccines-cell-scale-relation-auto-padding-tick-filter';
export { marketIntervalMarimekkoAutoPaddingFlex } from './market-interval-marimekko-auto-padding-flex';
export { aaplIntervalDateEncodeX } from './aapl-interval-date-encode-x';
export { athletesRectBinLegendStyle } from './athletes-rect-bin-legend-style';
13 changes: 9 additions & 4 deletions src/component/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,16 @@ export function adaptor<T>(style: T) {
'title',
'trunc',
];
// @ts-ignore
const { style: styles, ...rest } = style;
const finalStyle = {};
Object.entries(style).forEach(([key, value]) => {
if (reservedKeys.includes(key))
Object.entries(rest).forEach(([key, value]) => {
if (reservedKeys.includes(key)) {
finalStyle[`show${upperFirst(key)}`] = value;
else finalStyle[key] = value;
} else finalStyle[key] = value;
});
return finalStyle as T;
return {
...finalStyle,
...styles,
};
}

0 comments on commit f915d02

Please sign in to comment.