Skip to content

Commit 61aed1c

Browse files
authored
Merge pull request #145 from rcpch:label-angles
Label-angles
2 parents 31c5adb + 2b8ba84 commit 61aed1c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rcpch/digital-growth-charts-react-component-library",
3-
"version": "7.3.1",
3+
"version": "7.3.2",
44
"description": "A React component library for the RCPCH digital growth charts using Rollup, TypeScript and Styled-Components",
55
"main": "build/index.js",
66
"module": "build/esm.index.js",

src/CentileChart/CentileChart.tsx

+12-8
Original file line numberDiff line numberDiff line change
@@ -550,18 +550,19 @@ function CentileChart({
550550
angle={({ index }) => {
551551
return labelAngle(
552552
centile.data,
553-
index,
553+
parseInt(index.toString()),
554554
chartScaleType,
555555
measurementMethod,
556556
domains,
557557
);
558558
}}
559559
style={styles.centileLabel}
560560
backgroundStyle={{ fill: 'white' }}
561-
backgroundPadding={{ top: 1, bottom: 1, left: 3, right: 3 }}
561+
backgroundPadding={{ top: 1, bottom: 1, left: 1, right: 1 }}
562562
textAnchor={'middle'}
563563
verticalAnchor={'middle'}
564564
dy={0}
565+
dx={0}
565566
/>
566567
}
567568
/>
@@ -596,7 +597,7 @@ function CentileChart({
596597
angle={({ index }) => {
597598
return labelAngle(
598599
centile.data,
599-
index,
600+
parseInt(index.toString()),
600601
chartScaleType,
601602
measurementMethod,
602603
domains,
@@ -610,9 +611,10 @@ function CentileChart({
610611
},
611612
]}
612613
backgroundStyle={{ fill: 'white' }}
613-
backgroundPadding={{ top: 0, bottom: 0, left: 3, right: 3 }}
614+
backgroundPadding={{ top: 0, bottom: 0, left: 0, right: 0 }}
614615
textAnchor={'middle'}
615616
verticalAnchor={'middle'}
617+
dx={0}
616618
dy={0}
617619
/>
618620
}
@@ -655,24 +657,26 @@ function CentileChart({
655657
centileLabels &&
656658
labelIndexInterval(props.index, props.data, domains) &&
657659
props.index > 0
658-
? [sdsLine.sds]
660+
? [addOrdinalSuffix(sdsLine.sds)]
659661
: null
660662
}
661663
labelComponent={
662664
<VictoryLabel
663665
angle={({ index }) => {
664666
return labelAngle(
665667
sdsLine.data,
666-
index,
668+
parseInt(index.toString()),
667669
chartScaleType,
668670
measurementMethod,
669671
domains,
670672
);
671673
}}
672674
style={{ fill: styles.sdsLine.data.stroke, fontSize: 10.0 }}
673675
backgroundStyle={{ fill: 'white' }}
674-
textAnchor={'end'}
675-
dy={5}
676+
textAnchor={'middle'}
677+
verticalAnchor={'middle'}
678+
dy={0}
679+
dx={0}
676680
/>
677681
}
678682
/>

src/functions/labelIndexInterval.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ export function labelIndexInterval(index: number, data: any[], domains: { x: num
66
if (data == undefined) {
77
return false;
88
}
9+
if (index <= 0 || index >= data.length - 2) {
10+
return undefined; // Cannot calculate angle at the edges.
11+
}
912
const bill = data.filter((d: any) => {
1013
if (d.x > domains.x[0] && d.x < domains.x[1]) {
1114
return d;
1215
}
1316
});
14-
let numberOfItemsBetweenLabels = Math.floor(bill.length / 3); // 3 labels per line - this will serve as an index to split the data into 4 sections
17+
let numberOfItemsBetweenLabels = Math.floor(bill.length / 2); // 2 labels per line - this will serve as an index to split the data into 4 sections
1518

1619
return index % numberOfItemsBetweenLabels == 0;
1720
}

0 commit comments

Comments
 (0)