Skip to content

Commit 37b48e8

Browse files
committed
put styles of multiline text into an object instead of an array
1 parent b9c2f41 commit 37b48e8

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victoryLabelParser.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ function parseVictoryLabelNode(tnode: TNode): PartialProcessNodeResult {
1010
x: parseAttribute<number>(tnode.attributes.x) ?? 0,
1111
y: parseAttribute<number>(tnode.attributes.y) ?? 0,
1212
text: parseAttribute<string>(tnode.attributes.text) ?? '',
13-
color: [],
14-
fontSize: [],
15-
fontWeight: [],
13+
color: {},
14+
fontSize: {},
15+
fontWeight: {},
1616
lineHeight: parseAttribute<number[]>(tnode.attributes.lineheight),
1717
textAnchor: parseAttribute<TextAnchor>(tnode.attributes.textanchor),
1818
verticalAnchor: parseAttribute<TextAnchor>(tnode.attributes.verticalanchor),
@@ -21,15 +21,24 @@ function parseVictoryLabelNode(tnode: TNode): PartialProcessNodeResult {
2121
const style = parseAttribute(tnode.attributes.style);
2222
if (style) {
2323
const textStyles = Array.isArray(style) ? (style as RawLabelStyle[]) : [style as RawLabelStyle];
24-
for (const textStyle of textStyles) {
24+
for (const [index, textStyle] of textStyles.entries()) {
2525
if (textStyle.fill) {
26-
labelItem.color?.push(textStyle.fill);
26+
labelItem.color = {
27+
...labelItem.color,
28+
[index]: textStyle.fill,
29+
};
2730
}
2831
if (textStyle.fontSize) {
29-
labelItem.fontSize?.push(Number(textStyle.fontSize));
32+
labelItem.fontSize = {
33+
...labelItem.fontSize,
34+
[index]: Number(textStyle.fontSize),
35+
};
3036
}
3137
if (textStyle.fontWeight) {
32-
labelItem.fontWeight?.push(Number(textStyle.fontWeight) === 700 ? 'bold' : 'normal');
38+
labelItem.fontWeight = {
39+
...labelItem.fontWeight,
40+
[index]: Number(textStyle.fontWeight) === 700 ? 'bold' : 'normal',
41+
};
3342
}
3443
}
3544
}

src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ type LabelItem = {
7373
text: string;
7474

7575
/** The color of the text (per line) */
76-
color?: Color[];
76+
color?: Record<number, Color>;
7777

7878
/** Font size (per line) */
79-
fontSize?: number[];
79+
fontSize?: Record<number, number>;
8080

8181
/** Font weight (per line) */
82-
fontWeight?: Array<'normal' | 'bold'>;
82+
fontWeight?: Record<number, 'normal' | 'bold'>;
8383

8484
/** Line height (per line) */
85-
lineHeight?: number[];
85+
lineHeight?: Record<number, number>;
8686

8787
/** Text horizontal anchor */
8888
textAnchor?: TextAnchor;

0 commit comments

Comments
 (0)