Skip to content

Commit 90683c5

Browse files
committed
add new custom theme properties for styling
1 parent 22f81ac commit 90683c5

File tree

8 files changed

+687
-498
lines changed

8 files changed

+687
-498
lines changed

src/CentileChart/CentileChart.tsx

+508-464
Large diffs are not rendered by default.

src/RCPCHChart/RCPCHChart.stories.tsx

+105-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default meta;
2323
type Story = StoryObj<typeof RCPCHChart>;
2424

2525
const customChartStyle: ChartStyle = {
26-
backgroundColour: "tomato"
26+
backgroundColour: "tomato",
2727
}
2828

2929
const customStyles = {
@@ -463,4 +463,107 @@ export const MultipleMeasurementSDSChart: Story = {
463463
customThemeStyles: {}
464464
},
465465

466-
}
466+
}
467+
468+
export const CustomThemeStylesChart: Story = {
469+
args: {
470+
title: 'Patient Name - Hospital Number',
471+
measurementMethod: 'height',
472+
reference: 'uk-who',
473+
sex: 'female',
474+
measurements: {
475+
height: twoToEight,
476+
},
477+
midParentalHeightData: {},
478+
enableZoom: true,
479+
chartType: 'centile',
480+
enableExport: false,
481+
exportChartCallback: () => {},
482+
theme: 'custom',
483+
customThemeStyles: {
484+
chartStyle: {
485+
titleStyle: {
486+
weight: 600,
487+
colour: '#706A80',
488+
name: 'sans-serif',
489+
size: 16,
490+
},
491+
subTitleStyle: {
492+
weight: 400,
493+
colour: '#706A80',
494+
name: 'sans-serif',
495+
size: 13,
496+
},
497+
toggleButtonActiveColour: '#B89F81',
498+
toggleButtonInactiveColour: '#e8dbcc',
499+
toggleButtonTextStyle: {
500+
colour: 'white',
501+
name: 'sans-serif',
502+
size: 16,
503+
weight: 400,
504+
},
505+
backgroundColour: '#FAF8F5',
506+
tooltipStroke: '#EBE1D3',
507+
tooltipBackgroundColour: '#FFFDFD',
508+
tooltipTextStyle: {
509+
colour: '#706A80',
510+
name: 'sans-serif',
511+
size: 17,
512+
},
513+
},
514+
axisStyle: {
515+
axisStroke: '#EDE7DD',
516+
tickLabelTextStyle: {
517+
colour: '#706A80',
518+
size: 12,
519+
weight: 400,
520+
name: 'sans-serif',
521+
},
522+
axisLabelTextStyle: {
523+
weight: 500,
524+
colour: '#706A80',
525+
name: 'sans-serif',
526+
size: 14,
527+
},
528+
axisThresholdLabelTextStyle: {
529+
weight: 500,
530+
colour: '#706A80',
531+
name: 'sans-serif',
532+
size: 12.5,
533+
},
534+
axisThresholdLineStyle: {
535+
colour: '#706A80',
536+
},
537+
},
538+
referenceStyle: {
539+
weight: 500,
540+
colour: '#706A80',
541+
name: 'sans-serif',
542+
size: 13,
543+
},
544+
gridlineStyle: {
545+
dashed: true,
546+
stroke: '#EDE7DD',
547+
strokeWidth: 1,
548+
gridlines: true,
549+
},
550+
centileStyle: {
551+
centileStroke: '#B89F81',
552+
midParentalAreaFill: '#B89F81',
553+
midParentalCentileStroke: '#B89F81',
554+
delayedPubertyAreaFill: '#B89F81',
555+
sdsStroke: '#B89F81',
556+
},
557+
measurementStyle: {
558+
eventTextStyle: {
559+
size: 16,
560+
name: 'sans-serif',
561+
weight: 500,
562+
colour: '#706A80',
563+
},
564+
highlightedMeasurementFill: '#B89F81',
565+
measurementFill: '#760050',
566+
},
567+
},
568+
},
569+
};

src/RCPCHChart/RCPCHChart.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const RCPCHChart: React.FC<RCPCHChartProps> = ({
9696

9797

9898
// spread styles into individual objects
99-
const { chartStyle, axisStyle, gridlineStyle, centileStyle, sdsStyle, measurementStyle } = all_styles
99+
const { chartStyle, axisStyle, gridlineStyle, centileStyle, sdsStyle, measurementStyle, referenceStyle } = all_styles
100100

101101
// use height and width if provided to set text size also - text in SVG does not scale with the chart so we need to adjust it
102102
const referenceWidth = 1000;
@@ -111,7 +111,7 @@ const RCPCHChart: React.FC<RCPCHChartProps> = ({
111111
}
112112

113113
// make granular styles to pass into charts
114-
const styles = makeAllStyles(chartStyle, axisStyle, gridlineStyle, centileStyle, sdsStyle, measurementStyle, textScaleFactor);
114+
const styles = makeAllStyles(chartStyle, axisStyle, gridlineStyle, centileStyle, sdsStyle, measurementStyle, textScaleFactor, referenceStyle);
115115

116116

117117
// uncomment in development

src/RCPCHChart/RCPCHChart.types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Measurement } from '../interfaces/RCPCHMeasurementObject';
22
import { MidParentalHeightObject } from '../interfaces/MidParentalHeightObject';
3-
import { AxisStyle, CentileStyle, ChartStyle, GridlineStyle, MeasurementStyle, SDSStyle } from '../interfaces/StyleObjects';
3+
import { AxisStyle, CentileStyle, ChartStyle, GridlineStyle, MeasurementStyle, ReferenceStyle, SDSStyle } from '../interfaces/StyleObjects';
44
import { ClientMeasurementObject } from '../interfaces/ClientMeasurementObject';
55

66
export interface RCPCHChartProps {
@@ -25,5 +25,6 @@ export interface RCPCHChartProps {
2525
measurementStyle?: MeasurementStyle
2626
centileStyle?: CentileStyle
2727
sdsStyle?: SDSStyle
28+
referenceStyle?: ReferenceStyle
2829
} // individual styles to override in each theme. If 'custom' theme is selected, 'monochrome' styles are defaulted and styles passed here override them
2930
}

src/SDSChart/SDSChart.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,11 @@ const SDSChart: React.FC<SDSChartProps> = (
559559
</VictoryChart>
560560

561561
<ChartTitle
562-
fontSize={8}
563-
fontFamily={'Arial'}
564-
color={'#000000'}
565-
fontWeight={'200'}
566-
fontStyle='normal'
562+
fontSize={styles.referenceTextStyle.fontSize}
563+
fontFamily={styles.referenceTextStyle.fontFamily}
564+
color={styles.referenceTextStyle.color}
565+
fontWeight={styles.referenceTextStyle.fontWeight}
566+
fontStyle={styles.referenceTextStyle.fontStyle}
567567
>{referenceText(reference)}</ChartTitle>
568568

569569
</ChartContainer>

src/functions/makeAllStyles.ts

+31-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Most of the properties in each of the interfaces are optionals, as users may not
1414
This function therefore instantiates defaults where user values have not been provided.
1515
This creates a styles object that is passed to the chart.
1616
*/
17-
import { AxisStyle, CentileStyle, SDSStyle, ChartStyle, GridlineStyle, MeasurementStyle } from '../interfaces/StyleObjects';
17+
import { AxisStyle, CentileStyle, SDSStyle, ChartStyle, GridlineStyle, MeasurementStyle, ReferenceStyle } from '../interfaces/StyleObjects';
1818

1919
const black = '#000000';
2020
const white = '#FFFFFF';
@@ -35,7 +35,8 @@ function makeAllStyles(
3535
centileStyle?: CentileStyle,
3636
sdsStyle?: SDSStyle,
3737
measurementStyle?: MeasurementStyle,
38-
textMultiplier?: number // this is used to scale text size based on the aspect ratio of the chart using the height and width. Default is 1
38+
textMultiplier?: number, // this is used to scale text size based on the aspect ratio of the chart using the height and width. Default is 1
39+
referenceStyle?: ReferenceStyle,
3940
) {
4041

4142
let newGridlineStyle = {
@@ -70,17 +71,20 @@ function makeAllStyles(
7071
fontSize: (chartStyle?.tooltipTextStyle?.size ?? 14) * (textMultiplier ?? 1),
7172
fill: chartStyle?.tooltipTextStyle?.colour ?? black,
7273
fontFamily: chartStyle?.tooltipTextStyle?.name ?? 'Montserrat',
74+
fontWeight: chartStyle?.tooltipTextStyle?.weight ?? 400,
7375
fontStyle: chartStyle?.tooltipTextStyle?.style ?? 'normal',
7476
textAnchor: "start"
7577
},
7678
chartTitle: {
77-
fontFamily: chartStyle?.titleStyle?.name ?? 'Arial',
79+
fontFamily: chartStyle?.titleStyle?.name ?? 'Arial',
80+
fontWeight: chartStyle?.subTitleStyle?.weight ?? 700,
7881
color: chartStyle?.titleStyle?.colour ?? black,
7982
fontSize: chartStyle?.titleStyle?.size ?? 14,
8083
fontStyle: chartStyle?.titleStyle?.style === 'italic' ? 'italic' : 'normal',
8184
},
8285
chartSubTitle: {
8386
fontFamily: chartStyle?.subTitleStyle?.name ?? 'Arial',
87+
fontWeight: chartStyle?.subTitleStyle?.weight ?? 700,
8488
color: chartStyle?.subTitleStyle?.colour ?? black,
8589
fontSize: chartStyle?.subTitleStyle?.size ?? 14,
8690
fontStyle: chartStyle?.subTitleStyle?.style === 'italic' ? 'italic' : 'normal',
@@ -96,17 +100,19 @@ function makeAllStyles(
96100
padding: 20,
97101
fill: axisStyle?.axisLabelTextStyle?.colour ?? black,
98102
fontFamily: axisStyle?.axisLabelTextStyle?.name ?? 'Arial',
103+
fontWeight: axisStyle?.axisLabelTextStyle?.weight ?? 400,
99104
fontStyle: axisStyle?.axisLabelTextStyle?.style ?? 'normal',
100105
},
101106
ticks: {
102107
stroke: axisStyle?.tickLabelTextStyle?.colour ?? black,
103108
},
104109
tickLabels: {
105110
fontSize: (axisStyle?.tickLabelTextStyle?.size ?? 8) * (textMultiplier ?? 1),
106-
padding: 5,
111+
padding: axisStyle?.tickLabelTextStyle?.padding ?? 5,
107112
fill: axisStyle?.tickLabelTextStyle?.colour ?? black,
108113
color: axisStyle?.tickLabelTextStyle?.colour ?? black,
109114
fontFamily: axisStyle?.axisLabelTextStyle?.name ?? 'Arial',
115+
fontWeight: axisStyle?.axisLabelTextStyle?.weight ?? 400,
110116
fontStyle: axisStyle?.axisLabelTextStyle?.style ?? 'normal',
111117
},
112118
grid: {
@@ -117,6 +123,7 @@ function makeAllStyles(
117123
fill: axisStyle?.tickLabelTextStyle?.colour ?? black,
118124
fontSize: (axisStyle?.tickLabelTextStyle?.size ?? 8) * (textMultiplier ?? 1),
119125
fontFamily: axisStyle?.tickLabelTextStyle?.name ?? 'Arial',
126+
fontWeight: axisStyle?.tickLabelTextStyle?.weight ?? 400,
120127
fontStyle: axisStyle?.axisLabelTextStyle?.style ?? 'normal',
121128
},
122129
yAxis: {
@@ -129,6 +136,7 @@ function makeAllStyles(
129136
padding: 25,
130137
fill: axisStyle?.axisLabelTextStyle?.colour ?? black,
131138
fontFamily: axisStyle?.axisLabelTextStyle?.name ?? 'Arial',
139+
fontWeight: axisStyle?.axisLabelTextStyle?.weight ?? 400,
132140
fontStyle: axisStyle?.axisLabelTextStyle?.style ?? 'normal',
133141
},
134142
ticks: {
@@ -139,6 +147,7 @@ function makeAllStyles(
139147
padding: 5,
140148
fill: axisStyle?.tickLabelTextStyle?.colour ?? black,
141149
fontFamily: axisStyle?.axisLabelTextStyle?.name ?? 'Arial',
150+
fontWeight: axisStyle?.axisLabelTextStyle?.weight ?? 400,
142151
fontStyle: axisStyle?.axisLabelTextStyle?.style ?? 'normal',
143152
},
144153
grid: {
@@ -154,19 +163,20 @@ function makeAllStyles(
154163
},
155164
delayedPubertyThresholdLine: {
156165
data: {
157-
stroke: charcoal,
166+
stroke: axisStyle.axisThresholdLineStyle?.colour ?? charcoal,
158167
strokeWidth: 1,
159168
},
160169
},
161170
delayedPubertyThresholdLabel: {
162-
fontSize: (9) * (textMultiplier ?? 1),
163-
fill: axisStyle?.axisLabelTextStyle?.colour ?? black,
164-
fontFamily: axisStyle?.axisLabelTextStyle?.name ?? 'Arial',
171+
fontSize: (axisStyle?.axisThresholdLabelTextStyle?.size ?? 9) * (textMultiplier ?? 1),
172+
fill: axisStyle?.axisThresholdLabelTextStyle?.colour ?? black,
173+
fontFamily: axisStyle?.axisThresholdLabelTextStyle?.name ?? 'Arial',
174+
fontWeight: axisStyle?.axisThresholdLabelTextStyle?.weight ?? 400,
165175
textAlign: 'start',
166176
},
167177
nondisjunctionThresholdLine: {
168178
data: {
169-
stroke: charcoal,
179+
stroke: axisStyle.axisThresholdLineStyle?.colour ?? charcoal,
170180
strokeWidth: 1,
171181
},
172182
},
@@ -194,9 +204,10 @@ function makeAllStyles(
194204
},
195205
},
196206
centileLabel: {
197-
fontSize: (6) * (textMultiplier ?? 1),
198-
fontFamily: 'Montserrat',
199-
fill: centileStyle?.centileStroke ?? black
207+
fontSize: (centileStyle.centileTextStyle?.size ?? 6) * (textMultiplier ?? 1),
208+
fontFamily: centileStyle.centileTextStyle?.name ?? 'Montserrat',
209+
fontWeight: centileStyle.centileTextStyle?.weight ?? 400,
210+
fill: centileStyle?.centileStroke ?? black,
200211
},
201212
heightSDS: {
202213
data: {
@@ -275,11 +286,19 @@ function makeAllStyles(
275286
activeColour: chartStyle?.toggleButtonActiveColour ?? black,
276287
inactiveColour: chartStyle?.toggleButtonInactiveColour ?? midGrey,
277288
fontFamily: chartStyle?.toggleButtonTextStyle?.name ?? 'Arial',
289+
fontWeight: chartStyle?.toggleButtonTextStyle?.weight ?? 400,
278290
color: chartStyle?.toggleButtonTextStyle?.colour ?? white,
279291
fontSize: chartStyle?.toggleButtonTextStyle?.size ?? 14,
280292
fontStyle: chartStyle?.toggleButtonTextStyle?.style === 'italic' ? 'italic' : 'normal',
281293
margin: 0
282294
},
295+
referenceTextStyle: {
296+
fontSize: referenceStyle?.size ?? 8,
297+
fontFamily: referenceStyle?.name ?? 'Arial',
298+
color: referenceStyle?.colour ?? black,
299+
fontWeight: referenceStyle?.weight ?? 200,
300+
fontStyle: referenceStyle?.style ?? 'normal',
301+
},
283302
};
284303
}
285304

src/functions/stylesForTheme.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@ import { Tanner2AxisStyles, Tanner2ChartStyles, Tanner2GridlineStyles, Tanner2Ce
44
import { Tanner3AxisStyles, Tanner3ChartStyles, Tanner3GridlineStyles, Tanner3CentileStyles, Tanner3MeasurementStyles, Tanner3SDSStyles } from '../testParameters/styles/tanner3Styles';
55
import { traditionalBoyAxisStyles, traditionalBoyChartStyles, traditionalBoyGridlineStyles, traditionalBoyCentileStyles, traditionalBoyMeasurementStyles, traditionalBoySDSStyles } from '../testParameters/styles/traditionalBoysStyles';
66
import { traditionalGirlAxisStyles, traditionalGirlChartStyles, traditionalGirlGridlineStyles, traditionalGirlCentileStyles, traditionalGirlMeasurementStyles, traditionalGirlSDSStyles } from '../testParameters/styles/traditionalGirlsStyles';
7-
import { ChartStyle, AxisStyle, GridlineStyle, CentileStyle, SDSStyle, MeasurementStyle } from '../interfaces/StyleObjects';
7+
import { ChartStyle, AxisStyle, GridlineStyle, CentileStyle, SDSStyle, MeasurementStyle, ReferenceStyle } from '../interfaces/StyleObjects';
8+
9+
const defaultReferenceStyle: ReferenceStyle = {
10+
colour: '#000000',
11+
name: 'Arial',
12+
size: 8,
13+
style: 'normal',
14+
weight: 200,
15+
};
816

917
export const stylesForTheme = (theme: 'monochrome' | 'traditional' | 'tanner1' | 'tanner2' | 'tanner3' | 'custom', sex: 'male' | 'female')=>{
1018
// Returns the styles objects for a theme. If custom is selected, monochrome is selected to be customized later
11-
let chartStyle:ChartStyle, axisStyle:AxisStyle, gridlineStyle:GridlineStyle, centileStyle:CentileStyle, sdsStyle:SDSStyle, measurementStyle:MeasurementStyle;
19+
let chartStyle:ChartStyle, axisStyle:AxisStyle, gridlineStyle:GridlineStyle, centileStyle:CentileStyle, sdsStyle:SDSStyle, measurementStyle:MeasurementStyle, referenceStyle:ReferenceStyle = defaultReferenceStyle;
1220

1321
switch (theme) {
14-
case 'monochrome' || 'custom':
22+
case 'monochrome':
23+
case 'custom':
1524
chartStyle = monochromeChartStyles
1625
axisStyle = monochromeAxisStyles
1726
gridlineStyle = monochromeGridlineStyle
@@ -65,6 +74,6 @@ export const stylesForTheme = (theme: 'monochrome' | 'traditional' | 'tanner1' |
6574
throw new Error("Please select a valid theme or select custom.");
6675
}
6776

68-
return { chartStyle, axisStyle,gridlineStyle,centileStyle,sdsStyle,measurementStyle };
77+
return { chartStyle, axisStyle,gridlineStyle,centileStyle,sdsStyle,measurementStyle,referenceStyle };
6978

7079
}

0 commit comments

Comments
 (0)