-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCentileChart.tsx
1123 lines (1048 loc) · 63.6 KB
/
CentileChart.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as React from 'react';
import { useState, useLayoutEffect, useMemo, MouseEvent, useRef } from 'react';
import {
// libraries
createContainer,
VictoryChart,
VictoryGroup,
VictoryLine,
VictoryScatter,
VictoryTooltip,
VictoryAxis,
VictoryLabel,
VictoryArea,
DomainPropType,
} from 'victory';
// helper functions
import { getDomainsAndData, getVisibleData } from '../functions/getDomainsAndData';
import { yAxisLabel } from '../functions/yAxisLabel';
import xAxisLabel from '../functions/xAxisLabel';
import tailoredXTickValues from '../functions/tailoredXTickValues';
import defaultToggles from '../functions/defaultToggles';
import { tooltipText } from '../functions/tooltips';
import { delayedPubertyThreshold, makePubertyThresholds, lowerPubertyBorder } from '../functions/DelayedPuberty';
import { nondisjunctionThresholds, makeNonDisjunctionThresholds } from '../functions/nondisjunctionLines';
import { getFilteredMidParentalHeightData } from '../functions/getFilteredMidParentalHeightData';
import { isCrowded } from '../functions/isCrowded';
import { labelAngle } from '../functions/labelAngle';
import addOrdinalSuffix from '../functions/addOrdinalSuffix';
import { labelIndexInterval } from '../functions/labelIndexInterval';
import { referenceText } from '../functions/referenceText';
// interfaces & props
import { CentileChartProps } from './CentileChart.types';
import { ICentile } from '../interfaces/CentilesObject';
import { Measurement } from '../interfaces/RCPCHMeasurementObject';
// components/subcomponents
import { XPoint } from '../SubComponents/XPoint';
import CustomGridComponent from '../SubComponents/CustomGridComponent';
import RenderTickLabel from '../SubComponents/RenderTickLabel';
import { TitleContainer } from '../SubComponents/TitleContainer';
import { StyledRadioButtonGroup } from '../SubComponents/StyledRadioButtonGroup';
import { StyledResetZoomButton } from '../SubComponents/StyledResetZoomButton';
import { StyledGradientLabelsButton } from '../SubComponents/StyledGradientLabelsButton';
import { StyledButtonTooltip } from '../SubComponents/StyledButtonTooltip';
import { ButtonContainer } from '../SubComponents/ButtonContainer';
import { ThreeButtonContainer } from '../SubComponents/ThreeButtonContainer';
import { ChartTitle } from '../SubComponents/ChartTitle';
import { LogoContainer } from '../SubComponents/LogoContainer';
import { IndividualLogoContainer } from '../SubComponents/IndividualLogoContainer';
import { MainContainer } from '../SubComponents/MainContainer';
import { TopContainer } from '../SubComponents/TopContainer';
import { VersionLabel } from '../SubComponents/VersionLabel';
import { EventCaret } from '../SubComponents/EventCaret';
import { StyledShareButton } from '../SubComponents/StyledShareButton';
import { StyledFullScreenButton } from '../SubComponents/StyledFullScreenButton';
import { ShareButtonWrapper } from '../SubComponents/ShareButtonWrapper';
import { FullScreenButtonWrapper } from '../SubComponents/FullScreenButtonWrapper';
import { ShareIcon } from '../SubComponents/ShareIcon';
import { CopiedLabel } from '../SubComponents/CopiedLabel';
import { ShowCentileLabelIcon } from '../SubComponents/ShowCentileLabelIcon';
import { HideCentileLabelIcon } from '../SubComponents/HideCentileLabelIcon';
import { ChartContainer } from '../SubComponents/ChartContainer';
import { FullScreenIcon } from '../SubComponents/FullScreenIcon';
import { CloseFullScreenIcon } from '../SubComponents/CloseFullScreenIcon';
import { ResetZoomContainer } from '../SubComponents/ResetZoomContainer';
import { GradientLabelsButtonWrapper } from '../SubComponents/GradientLabelsButtonWrapper';
// RCPCH Icon:
import icon from '../images/icon.png';
import ukca from '../images/ukca.png';
import { BottomContainer } from '../SubComponents/BottomContainer';
import { BottomLogoContainer } from '../SubComponents/BottomLogoContainer';
// allows two top level containers: zoom and voronoi
const VictoryZoomVoronoiContainer: any = createContainer('zoom', 'voronoi');
function CentileChart({
chartsVersion,
reference,
title,
subtitle,
measurementMethod,
sex,
childMeasurements,
midParentalHeightData,
enableZoom,
styles,
height,
width,
textScaleFactor,
enableExport,
exportChartCallback,
clinicianFocus,
logoVariant
}: CentileChartProps) {
const [userDomains, setUserDomains] = useState(null);
const [storedChildMeasurements, setStoredChildMeasurements] = useState(childMeasurements);
const { defaultShowCorrected, defaultShowChronological, showToggle } = defaultToggles(childMeasurements);
const [showChronologicalAge, setShowChronologicalAge] = useState(defaultShowChronological);
const [showCorrectedAge, setShowCorrectedAge] = useState(defaultShowCorrected);
const chartRef = useRef<any>();
const [active, setActive] = useState(false);
const [fullScreen, setFullScreen] = useState(true);
const [centileLabels, setCentileLabels] = useState(false);
// save & destruct domains and data on initial render and when dependencies change
let { bmiSDSData, centileData, computedDomains, chartScaleType } = useMemo(
() =>
getDomainsAndData(
storedChildMeasurements,
sex,
measurementMethod,
reference,
showCorrectedAge,
showChronologicalAge,
),
[storedChildMeasurements, sex, measurementMethod, reference, showCorrectedAge, showChronologicalAge],
);
// get the highest reference index of visible centile data
let maxVisibleReferenceIndex: number = null;
let minimumArrayLength;
centileData.forEach((item, index) => {
switch (index) {
case 0:
minimumArrayLength = 3; // neonates label gap
break;
case 1:
minimumArrayLength = 4; // infants label gap
break;
case 2:
minimumArrayLength = 6; // small child label gap
break;
case 3:
minimumArrayLength = 15; // large child label gap
break;
default:
minimumArrayLength = 6;
break;
}
if (item[0].data !== null && item[0].data.length > minimumArrayLength) {
maxVisibleReferenceIndex = index;
}
});
const allowZooming = storedChildMeasurements.length > 0 && enableZoom ? true : false;
const domains = userDomains || computedDomains;
const isChartCrowded = isCrowded(domains, childMeasurements);
let pubertyThresholds: null | any[] = null;
let nondisjunctionThresholds: null | any[] = null;
if (reference === 'uk-who' && measurementMethod === 'height') {
pubertyThresholds = makePubertyThresholds(domains, sex);
}
if (reference === 'uk-who') {
nondisjunctionThresholds = makeNonDisjunctionThresholds(domains, sex);
}
const filteredMidParentalHeightData = useMemo(
() => getFilteredMidParentalHeightData(reference, childMeasurements, midParentalHeightData, sex),
[reference, childMeasurements, midParentalHeightData, sex],
);
// Create the shaded area at term
let termAreaData: null | any[] = null;
if (
childMeasurements[0]?.birth_data.gestation_weeks >= 37 &&
measurementMethod === 'weight' &&
reference === 'uk-who' &&
domains?.x[0] < 0.038329911019849415 && // 2 weeks postnatal
domains?.x[1] >= -0.057494866529774126 // 37 weeks gest
) {
termAreaData = [
{
x: -0.057494866529774126,
y: domains.y[1],
y0: domains.y[0],
},
{
x: 0.038329911019849415,
y: domains.y[1],
y0: domains.y[0],
},
];
}
// cut and paste action
const exportPressed = () => {
if (enableExport) {
setActive(true);
exportChartCallback(chartRef.current.firstChild); // this passes the raw SVG back to the client for converting
}
};
// label fade on cut
const labelFadeEnd = () => {
setActive(false);
};
// full screen button action
const fullScreenPressed = () => {
setFullScreen(!fullScreen);
fullScreen ? setStoredChildMeasurements([]) : setStoredChildMeasurements(childMeasurements);
};
// toggle between corrected/uncorrected/both
const onSelectRadioButton = (event: MouseEvent<HTMLButtonElement>) => {
switch ((event.target as HTMLInputElement).value) {
case 'unadjusted':
setShowChronologicalAge(true);
setShowCorrectedAge(false);
break;
case 'adjusted':
setShowChronologicalAge(false);
setShowCorrectedAge(true);
break;
case 'both':
setShowChronologicalAge(true);
setShowCorrectedAge(true);
break;
default:
console.warn('Fall through case on toggle adjusted age function');
}
setUserDomains(null);
};
const handleZoomChange = (domain: DomainPropType) => {
setUserDomains(domain);
};
const renderGradientLabels = () => {
setCentileLabels(!centileLabels);
};
// always reset zoom to default when measurements array changes
useLayoutEffect(() => {
setUserDomains(null);
}, [storedChildMeasurements]);
return (
<MainContainer>
{logoVariant === 'top' && (
<TopContainer>
<LogoContainer>
<IndividualLogoContainer>
<img src={icon} width={24} height={24} />
</IndividualLogoContainer>
<VersionLabel
fontFamily={styles.chartTitle.fontFamily}
>{chartsVersion}</VersionLabel>
<IndividualLogoContainer>
<img src={ukca} width={18} height={18}/>
</IndividualLogoContainer>
</LogoContainer>
</TopContainer>
)}
<ChartContainer>
<TitleContainer>
<ChartTitle {...styles.chartTitle}>{title}</ChartTitle>
<ChartTitle {...styles.chartSubTitle}>{subtitle}</ChartTitle>
</TitleContainer>
{/* The VictoryChart is the parent component. It contains a Voronoi container, which groups data sets together for the purposes of tooltips */}
{/* It has an animation object and the domains are the thresholds of ages rendered. This is calculated from the child data supplied by the user. */}
{/* Tooltips are here as it is the parent component. More information of tooltips in centiles below. */}
<VictoryChart
width={width}
height={height}
style={styles.chartMisc}
domain={computedDomains}
containerComponent={
<VictoryZoomVoronoiContainer
data-testid="label-container"
containerRef={(ref) => {
chartRef.current = ref;
}}
allowZoom={allowZooming}
allowPan={allowZooming}
onZoomDomainChange={handleZoomChange}
zoomDomain={domains}
labels={({ datum }) => {
// This the tool tip text, and accepts a large number of arguments
// tool tips return contextual information for each datapoint, as well as the centile
// and SDS lines, as well as bone ages, events and midparental heights
const tooltipTextList = tooltipText(
reference,
measurementMethod,
datum,
midParentalHeightData,
clinicianFocus,
sex,
);
if (tooltipTextList) {
return tooltipTextList.join('\n').replace(/^\s+|\s+$/g, '');
}
}}
labelComponent={
<VictoryTooltip
data-testid="tooltip"
constrainToVisibleArea
backgroundPadding={5}
pointerLength={5}
cornerRadius={styles.toolTipBorderRadius}
flyoutHeight={(datum) => {
const numberOfLines = datum.text.length;
return numberOfLines * 18 * textScaleFactor; // 18 is the line height
}}
flyoutStyle={{
...styles.toolTipFlyout,
}}
style={{ ...styles.toolTipMain }}
/>
}
voronoiBlacklist={[
'linkLine',
'chronologicalboneagelinkline',
'correctedboneagelinkline',
'areaMPH',
]}
/>
}
>
{
/* Term child shaded area: */
termAreaData !== null && reference == 'uk-who' && (
<VictoryArea style={styles.termArea} data={termAreaData} />
)
}
{/* X axis: */}
<VictoryAxis
label={xAxisLabel(chartScaleType, domains)}
style={styles.xAxis}
tickValues={tailoredXTickValues[chartScaleType]}
tickLabelComponent={
<RenderTickLabel
specificStyle={styles.xTicklabel}
chartScaleType={chartScaleType}
domains={domains}
/>
}
gridComponent={<CustomGridComponent chartScaleType={chartScaleType} />}
/>
{
/* render the y axis */
<VictoryAxis
minDomain={0}
label={yAxisLabel(measurementMethod, false)}
style={styles.yAxis}
dependentAxis
/>
}
{/* This is the shaded area below the 0.4th centile in late childhood/early adolescence */}
{/* Any measurements plotting here are likely due to delayed puberty */}
{/* The upper border is the 0.4th centile so this must come before the centiles */}
{reference === 'uk-who' &&
measurementMethod === 'height' &&
// delayed puberty area:
pubertyThresholds !== null && (
<VictoryArea
data={delayedPubertyThreshold(sex)}
y0={(d: any) => lowerPubertyBorder(d, sex)}
style={styles.delayedPubertyArea}
name="delayed"
/>
)}
{/*
midparental height centiles
These are three lines, the MPH centile, a centile 2SD above it, and another 2SD below
There is an area fill between the highest and lowest
*/}
{(reference === 'uk-who' || reference === 'cdc') &&
measurementMethod === 'height' &&
filteredMidParentalHeightData &&
filteredMidParentalHeightData.map((reference, index) => {
// this function filters the midparental height centile data to only those values
// one month either side of the most recent measurement, or 20 y if no measurements
// supplied.
if (index === 0) {
// neonates - remove
return;
}
const lowerData = reference.lowerParentalCentile;
const midData = reference.midParentalCentile;
const upperData = reference.upperParentalCentile;
return (
<VictoryGroup key={'midparentalCentileDataBlock' + index}>
{upperData.map((centile: ICentile, centileIndex: number) => {
// area lower and and upper boundaries
const newData: any = centile.data.map((data, index) => {
let o: any = Object.assign({}, data);
o.y0 = lowerData[centileIndex].data[index].y;
return o;
});
if (newData.length < 1) {
// prevents a css `width` infinity error if no data presented to centile line;
return;
}
return (
<VictoryArea
name="areaMPH"
key={centile.centile + '-area-' + centileIndex}
data={newData}
style={{ ...styles.midParentalArea }}
/>
);
})}
{lowerData.map((lowercentile: ICentile, centileIndex: number) => {
if (lowercentile.data.length < 1) {
// prevents a css `width` infinity error if no data presented to centile line
return;
}
return (
<VictoryLine
name="lowerCentileMPH"
key={lowercentile.centile + '-' + centileIndex}
padding={{ top: 20, bottom: 20 }}
data={lowercentile.data}
style={styles.midParentalCentile}
/>
);
})}
{midData.map((centile: ICentile, centileIndex: number) => {
if (centile.data.length < 1) {
// prevents a css `width` infinity error if no data presented to centile line
return;
}
return (
<VictoryLine
name="centileMPH"
key={centile.centile + '-' + centileIndex}
padding={{ top: 20, bottom: 20 }}
data={centile.data}
style={styles.midParentalCentile}
/>
);
})}
{upperData.map((uppercentile: ICentile, centileIndex: number) => {
if (uppercentile.data.length < 1) {
// prevents a css `width` infinity error if no data presented to centile line
return;
}
return (
<VictoryLine
name="upperCentileMPH"
key={uppercentile.centile + '-' + centileIndex}
padding={{ top: 20, bottom: 20 }}
data={uppercentile.data}
style={styles.midParentalCentile}
/>
);
})}
</VictoryGroup>
);
})}
{/* Render the centiles - loop through the data set, create a line for each centile */}
{/* On the old charts the 50th centile was thicker and darker and this led parents to believe it was therefore */}
{/* the line their children should follow. This was a design mistake, since it does not matter which line the child is on */}
{/* so long as they follow it. The middle line was therefore 'de-emphasised' on the newer charts. */}
{/* For each reference data set, there are 9 centiles. The 0.4th, 9th, 50th, 91st, 99.6th are all dashed. */}
{/* The 2nd, 25th, 75th, 98th are all continuous lines. As there are 4 datasets, this means 36 separate line series to render. */}
{/* It is essential each centile from each reference is plotted as a series to prevent interpolation between centiles of one reference */}
{/* and centiles of another. The discontinuous lines reflect the transition between references and are essential */}
{/* One final line is the VictoryArea, which represents the shaded area at the onset of puberty. Children that plot here */}
{/* will have delayed puberty. */}
{/* Tooltips are found in the parent element (VictoryChart). Tooltips included: */}
{/* 1 for each centile, 1 for the shaded area, 1 at 2years to indicate children are measured standing leading */}
{/* to a step down in height weight and bmi in the data set. There is another tool tip at 4 years to indicate transition from datasets. */}
{centileData &&
centileData.map((referenceData, referenceIndex) => {
if (reference === 'cdc') {
if (referenceIndex === 0 || (measurementMethod === 'ofc' && referenceIndex > 1)) {
// this is a hack that needs fixing in future. It arrises because of the null data in the CDC neonate dataset (Fenton). Once the data is fixed, this can be removed. Only for weight is renders a line in the under ones.
// it also removes the duplicate tooltips in the head circumference chart
return;
}
}
return (
<VictoryGroup key={'centileDataBlock' + referenceIndex} name="centileLineGroup">
{referenceData.map((centile: ICentile, centileIndex: number) => {
// BMI charts also have SDS lines at -5, -4, -3, -2, 2, 3, 4, 5
if (centile.data !== null && centile.data.length < 1) {
// prevents a css `width` infinity error if no data presented to centile line
return;
}
if (centileIndex % 2) {
// even index - centile is dashed
return (
<VictoryLine
data-testid={
'reference-' +
referenceIndex +
'-centile-' +
centile.centile +
'-measurement-' +
measurementMethod
}
name={'centileLine-' + centileIndex}
key={centile.centile + '-' + centileIndex}
padding={{ top: 20, bottom: 20 }}
data={centile.data}
style={{ ...styles.dashedCentile }}
labels={(props: { index: number }) =>
centileLabels &&
labelIndexInterval(chartScaleType, props.index) &&
props.index > 0
? [addOrdinalSuffix(centile.centile)]
: null
}
labelComponent={
<VictoryLabel
angle={({ index }) => {
return labelAngle(
centile.data,
index,
chartScaleType,
measurementMethod,
domains,
);
}}
style={styles.centileLabel}
backgroundStyle={{ fill: 'white' }}
backgroundPadding={{ top: 1, bottom: 1, left: 3, right: 3 }}
textAnchor={'middle'}
verticalAnchor={'middle'}
dy={0}
/>
}
/>
);
} else {
// uneven index - centile is continuous
return (
<VictoryLine
data-testid={
'reference-' +
referenceIndex +
'-centile-' +
centile.centile +
'-measurement-' +
measurementMethod
}
name={'centileLine-' + centileIndex}
key={centile.centile + '-' + centileIndex}
padding={{ top: 20, bottom: 20 }}
data={centile.data}
style={{ ...styles.continuousCentile }}
labels={(props: { index: number }) =>
centileLabels &&
labelIndexInterval(chartScaleType, props.index) &&
props.index > 0
? [addOrdinalSuffix(centile.centile)]
: null
}
labelComponent={
<VictoryLabel
angle={({ index }) => {
return labelAngle(
centile.data,
index,
chartScaleType,
measurementMethod,
domains,
);
}}
style={[
{
fill: styles.centileLabel.fill,
fontFamily: styles.centileLabel.fontFamily,
fontSize: styles.centileLabel.fontSize,
},
]}
backgroundStyle={{ fill: 'white' }}
backgroundPadding={{ top: 0, bottom: 0, left: 3, right: 3 }}
textAnchor={'middle'}
verticalAnchor={'middle'}
dy={0}
/>
}
/>
);
}
})}
</VictoryGroup>
);
})}
{
/* BMI SDS lines */
measurementMethod === 'bmi' &&
bmiSDSData &&
reference === 'uk-who' && // only render for UK-WHO BMI charts since other references do not have SDS lines
bmiSDSData.map((sdsReferenceData, index) => {
return (
<VictoryGroup key={'sdsDataBlock' + index} name="sdsLineGroup">
{sdsReferenceData.map((sdsLine: ICentile, sdsIndex: number) => {
// BMI charts have SDS lines at -5, -4, -3, 3, 3.33, 3.67, 4
if (sdsLine.data.length < 1) {
// prevents a css `width` infinity error if no data presented to sds line
return;
}
// sds line is dashed
return (
<VictoryLine
data-testid={
'reference-' + index + '-centile-' + sdsLine.sds + '-bmisds'
}
name={'sdsLine-' + sdsIndex}
key={sdsLine.sds + '-' + sdsIndex}
padding={{ top: 20, bottom: 20 }}
data={sdsLine.data}
style={styles.sdsLine}
labels={(props: { index: number }) =>
centileLabels &&
labelIndexInterval(chartScaleType, props.index) &&
props.index > 0
? [sdsLine.sds]
: null
}
labelComponent={
<VictoryLabel
angle={({ index }) => {
return labelAngle(
sdsLine.data,
index,
chartScaleType,
measurementMethod,
domains,
);
}}
style={{ fill: styles.sdsLine.data.stroke, fontSize: 10.0 }}
backgroundStyle={{ fill: 'white' }}
textAnchor={'end'}
dy={5}
/>
}
/>
);
})}
</VictoryGroup>
);
})
}
{
// puberty threshold lines uk90:
pubertyThresholds !== null &&
pubertyThresholds.map((dataArray) => {
if (dataArray[0].x > domains.x[0] && dataArray[1].x < domains.x[1]) {
return (
<VictoryLine
key={dataArray[0].x}
name={`puberty-${dataArray[0].x}`}
style={styles.delayedPubertyThresholdLine}
data={dataArray}
labelComponent={
<VictoryLabel
textAnchor="start"
angle={-90}
dx={5}
dy={
// adjust label margins relatively to font size so text doesn't overlap the line
styles.delayedPubertyThresholdLabel?.fontSize
? styles.delayedPubertyThresholdLabel.fontSize * 1.15
: 10
}
style={styles.delayedPubertyThresholdLabel}
/>
}
/>
);
} else {
return null;
}
})
}
{
// nondisjunction lines uk90->uk-who->uk-who
nondisjunctionThresholds !== null &&
nondisjunctionThresholds.map((dataArray) => {
if (dataArray[0].x > domains.x[0] && dataArray[1].x < domains.x[1]) {
return (
<VictoryLine
key={dataArray[0].x}
name={`nondisjunction-${dataArray[0].x}`}
style={styles.nondisjunctionThresholdLine}
data={dataArray}
labelComponent={
<VictoryLabel
textAnchor="start"
angle={-90}
dx={5}
dy={
// adjust label margins relatively to font size so text doesn't overlap the line
styles.nondisjunctionThresholdLabel?.fontSize
? styles.nondisjunctionThresholdLabel.fontSize * 1.15
: 10
}
style={styles.nondisjunctionThresholdLabel}
/>
}
/>
);
} else {
return null;
}
})
}
{/* create a series for each child measurements data point: a circle for chronological age, a cross for corrected */}
{/* If data points are close together, reduce the size of the point */}
{childMeasurements.map((childMeasurement: Measurement, index) => {
const [observationYear, observationMonth, observationDay] = childMeasurement.measurement_dates.observation_date.split('-');
const observationDate = `${observationDay}/${observationMonth}/${observationYear}`;
const chronData: any = {
age_type: 'chronological_age',
age_error: childMeasurement.measurement_dates.chronological_decimal_age_error,
b: childMeasurement.bone_age.bone_age,
bone_age_label: childMeasurement.bone_age.bone_age_text,
bone_age_sds: childMeasurement.bone_age.bone_age_sds,
bone_age_centile: childMeasurement.bone_age.bone_age_centile,
bone_age_type: childMeasurement.bone_age.bone_age_type,
calendar_age: childMeasurement.measurement_dates.chronological_calendar_age,
gestational_age: childMeasurement.measurement_dates.corrected_gestational_age,
centile: childMeasurement.measurement_calculated_values.chronological_centile,
centile_band: childMeasurement.measurement_calculated_values.chronological_centile_band,
clinician_comment:
childMeasurement.measurement_dates.comments.clinician_chronological_decimal_age_comment,
lay_comment:
childMeasurement.measurement_dates.comments.lay_chronological_decimal_age_comment,
observation_date: observationDate,
observation_value_error: childMeasurement.child_observation_value.observation_value_error,
chronological_measurement_error:
childMeasurement.measurement_calculated_values.chronological_measurement_error,
chronological_decimal_age_error:
childMeasurement.measurement_dates.chronological_decimal_age_error,
x: childMeasurement.measurement_dates.chronological_decimal_age,
y: childMeasurement.child_observation_value.observation_value,
sds: childMeasurement.measurement_calculated_values.chronological_sds,
chronological_percentage_median_bmi:
childMeasurement.measurement_calculated_values.chronological_percentage_median_bmi,
};
const correctData: any = {
age_type: 'corrected_age',
age_error: childMeasurement.measurement_dates.corrected_decimal_age_error,
b: childMeasurement.bone_age.bone_age,
bone_age_label: childMeasurement.bone_age.bone_age_text,
bone_age_sds: childMeasurement.bone_age.bone_age_sds,
bone_age_centile: childMeasurement.bone_age.bone_age_centile,
bone_age_type: childMeasurement.bone_age.bone_age_type,
calendar_age:
childMeasurement.measurement_dates.corrected_decimal_age < 0.0383
? childMeasurement.measurement_dates.chronological_calendar_age
: childMeasurement.measurement_dates.corrected_calendar_age, // calendar age not corrected if < EDD
gestational_age: childMeasurement.measurement_dates.corrected_gestational_age,
centile: childMeasurement.measurement_calculated_values.corrected_centile,
centile_band: childMeasurement.measurement_calculated_values.corrected_centile_band,
clinician_comment:
childMeasurement.measurement_dates.comments.clinician_corrected_decimal_age_comment,
lay_comment: childMeasurement.measurement_dates.comments.lay_corrected_decimal_age_comment,
observation_date: observationDate,
observation_value_error: childMeasurement.child_observation_value.observation_value_error,
corrected_measurement_error:
childMeasurement.measurement_calculated_values.corrected_measurement_error,
corrected_decimal_age_error: childMeasurement.measurement_dates.corrected_decimal_age_error,
x: childMeasurement.measurement_dates.corrected_decimal_age,
y: childMeasurement.child_observation_value.observation_value,
sds: childMeasurement.measurement_calculated_values.corrected_sds,
corrected_percentage_median_bmi:
childMeasurement.measurement_calculated_values.corrected_percentage_median_bmi,
};
if (isChartCrowded) {
chronData.size = 3.5;
correctData.size = 3.5;
} else {
chronData.size = 4.5;
correctData.size = 4.5;
}
return (
<VictoryGroup key={'measurement' + index}>
{childMeasurement.events_data.events_text &&
childMeasurement.events_data.events_text.length > 0 &&
(showChronologicalAge && !showCorrectedAge ? (
// Events against chronological age only if corrected age not showing
<VictoryScatter
key={'item-' + index}
name="eventcaret"
data={[
{
x: childMeasurement.measurement_dates.chronological_decimal_age,
y: childMeasurement.child_observation_value.observation_value,
},
]}
dataComponent={
<EventCaret
eventsText={childMeasurement.events_data.events_text}
style={styles.eventTextStyle}
/>
}
/>
) : (
// Events against corrected age
<VictoryScatter
key={'item-' + index}
name="eventcaret"
data={[
{
x: childMeasurement.measurement_dates.corrected_decimal_age,
y: childMeasurement.child_observation_value.observation_value,
},
]}
dataComponent={
<EventCaret
eventsText={childMeasurement.events_data.events_text}
style={styles.eventTextStyle}
/>
}
/>
))}
{showChronologicalAge &&
childMeasurement.bone_age.bone_age &&
(showChronologicalAge || showCorrectedAge) &&
!(showCorrectedAge && showChronologicalAge) && ( // bone age linked to chronological age
<VictoryScatter // bone age
key={'item-' + index}
name="chronologicalboneage"
data={[chronData]}
x={'b'}
y={'y'}
size={15}
dataComponent={
<XPoint isBoneAge={true} colour={styles.measurementPoint.data.fill} />
}
/>
)}
{showCorrectedAge &&
childMeasurement.bone_age.bone_age && ( // bone age linked to corrected age
<VictoryScatter // bone age
key={'item-' + index}
name="correctedboneage"
data={[correctData]}
x={'b'}
y={'y'}
size={15}
dataComponent={
<XPoint isBoneAge={true} colour={styles.measurementPoint.data.fill} />
}
/>
)}
{showChronologicalAge &&
!showCorrectedAge &&
childMeasurement.bone_age.bone_age && ( // bone age line linked to chronological age
<VictoryLine // bone age link line
key={'item-' + index}
name="chronologicalboneagelinkline"
data={[
{ x: chronData.x, y: chronData.y },
{ x: chronData.b, y: chronData.y },
]}
style={{
data: {
strokeWidth: 2,
stroke: '#A9A9A9',
strokeDasharray: '5, 3',
},
}}
/>
)}
{showCorrectedAge &&
childMeasurement.bone_age.bone_age && ( // bone age line linked to corrected age
<VictoryLine // bone age link line
key={'item-' + index}
name="correctedboneagelinkline"
data={[
{ x: correctData.x, y: correctData.y },
{ x: correctData.b, y: correctData.y },
]}
style={{
data: {
strokeWidth: 2,
stroke: '#A9A9A9',
strokeDasharray: '3, 3',
},
}}
/>
)}
{showChronologicalAge && (
<VictoryScatter // chronological age
key={'item-' + index}
data-testid="chronologicalMeasurementPoint"
data={[chronData]}
symbol="circle"
style={styles.measurementPoint}
name="chronological_age"
/>
)}
{showCorrectedAge && (
<VictoryScatter // corrected age - a custom component that renders a cross
key={'item-' + index}
data-testid="correctedMeasurementXPoint"
data={[correctData]}
dataComponent={
<XPoint isBoneAge={false} colour={styles.measurementPoint.data.fill} />
}
style={styles.measurementPoint}
name="corrected_age"
/>
)}
{showChronologicalAge &&
showCorrectedAge && ( // only show the line if both cross and dot are rendered
<VictoryLine
key={'item-' + index}
name="linkLine"
style={styles.measurementLinkLine}
data={[chronData, correctData]}
/>
)}
</VictoryGroup>
);
})}
</VictoryChart>
<ChartTitle
fontSize={styles.referenceTextStyle.fontSize}
fontFamily={styles.referenceTextStyle.fontFamily}
color={styles.referenceTextStyle.color}
fontWeight={styles.referenceTextStyle.fontWeight}
fontStyle={styles.referenceTextStyle.fontStyle}
>{referenceText(reference)}</ChartTitle>
{logoVariant === 'legend' && (
<ChartTitle
fontSize={styles.referenceTextStyle.fontSize}
fontFamily={styles.referenceTextStyle.fontFamily}
color={styles.referenceTextStyle.color}
fontWeight={styles.referenceTextStyle.fontWeight}
fontStyle={styles.referenceTextStyle.fontStyle}
>Powered by RCPCH Digital Growth Charts - {chartsVersion}</ChartTitle>
)}
{logoVariant === 'bottom' && (
<BottomContainer>
<BottomLogoContainer>
<IndividualLogoContainer>
<img src={icon} width={24} height={24} />
</IndividualLogoContainer>
<VersionLabel fontFamily={styles.chartTitle.fontFamily}>{chartsVersion}</VersionLabel>
<IndividualLogoContainer>
<img src={ukca} width={18} height={18}/>
</IndividualLogoContainer>
</BottomLogoContainer>
</BottomContainer>
)}
</ChartContainer>
{(showToggle || allowZooming || enableExport || childMeasurements.length > 0) && (
<ButtonContainer>