Skip to content

Commit fd6fd90

Browse files
authored
Merge pull request #106 from rcpch:eatyourpeas/issue105
Eatyourpeas/issue105
2 parents 1ad6670 + 306d971 commit fd6fd90

File tree

4 files changed

+155
-80
lines changed

4 files changed

+155
-80
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.0.10",
3+
"version": "7.0.11",
44
"description": "A React component library for the RCPCH digital growth charts using Rollup, TypeScript and Styled-Components",
55
"main": "dist/index.js",
66
"module": "dist/esm.index.js",

src/CentileChart/CentileChart.tsx

+22-18
Original file line numberDiff line numberDiff line change
@@ -289,33 +289,39 @@ function CentileChart({
289289
allowPan={allowZooming}
290290
onZoomDomainChange={handleZoomChange}
291291
zoomDomain={domains}
292+
labels={({ datum }) => {
293+
// This the tool tip text, and accepts a large number of arguments
294+
// tool tips return contextual information for each datapoint, as well as the centile
295+
// and SDS lines, as well as bone ages, events and midparental heights
296+
const tooltipTextList = tooltipText(
297+
reference,
298+
measurementMethod,
299+
datum,
300+
midParentalHeightData,
301+
clinicianFocus,
302+
sex
303+
)
304+
if (tooltipTextList){
305+
return tooltipTextList.join('\n').replace(/^\s+|\s+$/g, '');
306+
}
307+
}}
292308
labelComponent={
293309
<VictoryTooltip
294310
data-testid='tooltip'
295311
constrainToVisibleArea
296312
backgroundPadding={5}
297313
pointerLength={5}
298314
cornerRadius={0}
315+
flyoutHeight={(datum) => {
316+
const numberOfLines = datum.text.length;
317+
return numberOfLines * 18; // 18 is the line height
318+
}}
299319
flyoutStyle={{
300320
...styles.toolTipFlyout,
301321
}}
302322
style={{...styles.toolTipMain}}
303323
/>
304324
}
305-
labels={({ datum }) => {
306-
// This the tool tip text, and accepts a large number of arguments
307-
// tool tips return contextual information for each datapoint, as well as the centile
308-
// and SDS lines, as well as bone ages, events and midparental heights
309-
return tooltipText(
310-
reference,
311-
measurementMethod,
312-
datum,
313-
midParentalHeightData,
314-
clinicianFocus,
315-
sex
316-
)
317-
}
318-
}
319325
voronoiBlacklist={['linkLine', 'chronologicalboneagelinkline', 'correctedboneagelinkline', 'areaMPH']}
320326
/>
321327
}
@@ -688,7 +694,6 @@ function CentileChart({
688694

689695
showChronologicalAge && !showCorrectedAge ?
690696
// Events against chronological age only if corrected age not showing
691-
<VictoryPortal>
692697
<VictoryScatter
693698
key={"item-"+index}
694699
name="eventcaret"
@@ -700,10 +705,9 @@ function CentileChart({
700705
/>
701706
}
702707
/>
703-
</VictoryPortal>
704708
:
705709
// Events against corrected age
706-
<VictoryPortal>
710+
707711
<VictoryScatter
708712
key={"item-"+index}
709713
name="eventcaret"
@@ -715,7 +719,7 @@ function CentileChart({
715719
/>
716720
}
717721
/>
718-
</VictoryPortal>
722+
719723
)
720724
}
721725

src/functions/getDomainsAndData.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { Domains, IDomainSex } from '../interfaces/Domains';
2121

2222
import { IPlottedCentileMeasurement, Reference, ICentile } from '../interfaces/CentilesObject';
2323
import deepCopy from './deepCopy';
24-
import { ClientMeasurementObject } from '../interfaces/ClientMeasurementObject';
2524
import { trisomy21HeightMaleCentileData } from '../chartdata/trisomy21_height_male_centile_data';
2625
import { trisomy21HeightFemaleCentileData } from '../chartdata/trisomy21_height_female_centile_data';
2726
import { trisomy21BMIFemaleCentileData } from '../chartdata/trisomy21_bmi_female_centile_data';
@@ -31,7 +30,6 @@ import { trisomy21WeightFemaleCentileData } from '../chartdata/trisomy21_weight_
3130
import { trisomy21OFCMaleCentileData } from '../chartdata/trisomy21_ofc_male_centile_data';
3231
import { trisomy21OFCFemaleCentileData } from '../chartdata/trisomy21_ofc_female_centile_data';
3332
import { turnerHeightFemaleCentileData } from '../chartdata/turner_height_female_centile_data';
34-
import { LineSegment } from 'victory';
3533

3634
type CentileLabelValues = {
3735
0.4: { value: number; workingX: number };
@@ -267,11 +265,8 @@ function childMeasurementRanges(
267265
let chronologicalX = measurement.plottable_data.centile_data.chronological_decimal_age_data.x;
268266
let correctedY = measurement.plottable_data.centile_data.corrected_decimal_age_data.y;
269267
let chronologicalY = measurement.plottable_data.centile_data.chronological_decimal_age_data.y;
268+
const boneAgeX = measurement.bone_age.bone_age;
270269
const errorsPresent = false;
271-
// measurement.measurement_calculated_values.corrected_measurement_error ||
272-
// measurement.measurement_calculated_values.chronological_measurement_error
273-
// ? true
274-
// : false;
275270

276271
if (!errorsPresent) {
277272
if (showCorrected && !showChronological) {
@@ -299,6 +294,15 @@ function childMeasurementRanges(
299294
lowestChildY = coord;
300295
}
301296
}
297+
// if bone age is present and value is more extreme than the highest or lowest x, update:
298+
if (boneAgeX) {
299+
if (highestChildX < boneAgeX) {
300+
highestChildX = boneAgeX;
301+
}
302+
if (lowestChildX > boneAgeX) {
303+
lowestChildX = boneAgeX;
304+
}
305+
}
302306
} else {
303307
console.warn('Measurements considered invalid by the API given to the chart. The chart will ignore them.');
304308
}
@@ -596,6 +600,7 @@ function getDomainsAndData(
596600
}
597601
if (errorFree) {
598602
const { lowestChildX, highestChildX, lowestChildY, highestChildY } = childCoordinates;
603+
599604
lowestYFromMeasurements = lowestChildY;
600605
highestYFromMeasurements = highestChildY;
601606
const difference = highestChildX - lowestChildX;

0 commit comments

Comments
 (0)