nhsuk-tools-chart-components-react 1.1.16 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,18 +15,6 @@
15
15
  margin-bottom: 3px;
16
16
  }
17
17
 
18
- .nhsuk-bar-slider-graph {
19
- position: relative;
20
- outline: 1px solid black;
21
- margin-top: 20px;
22
- display: flex;
23
- height: 28px;
24
- }
25
- @media (min-width: 320px) and (max-width: 641px) {
26
- .nhsuk-bar-slider-graph {
27
- height: 24px;
28
- }
29
- }
30
18
 
31
19
  .nhsuk-bar-slider-arrow-marker {
32
20
  position: absolute;
@@ -88,19 +76,31 @@
88
76
  background: repeating-linear-gradient(45deg, #da5147, #da5147 4.5px, #d5281b 4.5px, #d5281b 9px);
89
77
  }
90
78
 
91
- .nhsuk-bmi-graph {
79
+ .nhsuk-bmi-legend-key-classification-obese {
80
+ border-bottom: none;
81
+ box-shadow: none;
82
+ }
83
+
84
+ .nhsuk-bmi-legend-key-marker {
85
+ border-bottom: none;
86
+ box-shadow: none;
87
+ }
88
+
89
+
90
+ .nhsuk-bar-slider-graph {
92
91
  position: relative;
93
92
  outline: 1px solid black;
93
+ margin-top: 20px;
94
94
  display: flex;
95
95
  height: 28px;
96
- margin-bottom: nhsuk-spacing(4);
97
96
  }
98
97
  @media (min-width: 320px) and (max-width: 641px) {
99
- .nhsuk-bmi-graph {
98
+ .nhsuk-bar-slider-graph {
100
99
  height: 24px;
101
100
  }
102
101
  }
103
102
 
103
+
104
104
  .nhsuk-bmi-classification-underweight, .nhsuk-bmi-legend-key-classification-underweight {
105
105
  background: #330072;
106
106
  }
@@ -117,16 +117,20 @@
117
117
  background: repeating-linear-gradient(45deg, #da5147, #da5147 4.5px, #d5281b 4.5px, #d5281b 9px);
118
118
  }
119
119
 
120
- .nhsuk-bmi-legend-key-classification-obese {
121
- border-bottom: none;
122
- box-shadow: none;
120
+ .nhsuk-bmi-graph {
121
+ position: relative;
122
+ outline: 1px solid black;
123
+ display: flex;
124
+ height: 28px;
125
+ margin-bottom: nhsuk-spacing(4);
123
126
  }
124
-
125
- .nhsuk-bmi-legend-key-marker {
126
- border-bottom: none;
127
- box-shadow: none;
127
+ @media (min-width: 320px) and (max-width: 641px) {
128
+ .nhsuk-bmi-graph {
129
+ height: 24px;
130
+ }
128
131
  }
129
132
 
133
+
130
134
  .nhsuk-bmi-chart-marker {
131
135
  position: absolute;
132
136
  z-index: 4;
@@ -142,53 +146,6 @@
142
146
  }
143
147
  }
144
148
 
145
- .nhsuk-bmi-classification-underweight, .nhsuk-bmi-legend-key-classification-underweight {
146
- background: #330072;
147
- }
148
-
149
- .nhsuk-bmi-classification-healthy, .nhsuk-bmi-legend-key-classification-healthy {
150
- background: repeating-linear-gradient(-45deg, #30b4ab, #30b4ab 4.5px, #00a499 4.5px, #00a499 9px);
151
- }
152
-
153
- .nhsuk-bmi-classification-overweight, .nhsuk-bmi-legend-key-classification-overweight {
154
- background: #ffb81c;
155
- }
156
-
157
- .nhsuk-bmi-classification-obese, .nhsuk-bmi-legend-key-classification-obese {
158
- background: repeating-linear-gradient(45deg, #da5147, #da5147 4.5px, #d5281b 4.5px, #d5281b 9px);
159
- }
160
-
161
- .nhsuk-bmi-classification-obese, .nhsuk-bmi-classification-overweight, .nhsuk-bmi-classification-healthy, .nhsuk-bmi-classification-underweight {
162
- position: absolute;
163
- bottom: 0%;
164
- outline: 1px solid black;
165
- border-right: 1px solid black;
166
- box-shadow: -1px 0px white inset, 2px 0px white, 0px -2px white;
167
- height: 28px;
168
- }
169
- @media (min-width: 320px) and (max-width: 641px) {
170
- .nhsuk-bmi-classification-obese, .nhsuk-bmi-classification-overweight, .nhsuk-bmi-classification-healthy, .nhsuk-bmi-classification-underweight {
171
- height: 24px;
172
- }
173
- }
174
-
175
- .nhsuk-bmi-classification-underweight {
176
- z-index: 3;
177
- }
178
-
179
- .nhsuk-bmi-classification-healthy {
180
- z-index: 2;
181
- }
182
-
183
- .nhsuk-bmi-classification-overweight {
184
- z-index: 1;
185
- }
186
-
187
- .nhsuk-bmi-classification-obese {
188
- border-right: none;
189
- box-shadow: none;
190
- }
191
-
192
149
  .nhsuk-bp-classification-low, .nhsuk-bp-legend-key-classification-low {
193
150
  background: #330072;
194
151
  }
@@ -231,81 +188,6 @@
231
188
  box-shadow: none;
232
189
  }
233
190
 
234
- .nhsuk-bp-graph-marker {
235
- position: absolute;
236
- z-index: 6;
237
- height: 24px;
238
- width: 24px;
239
- margin: 0 0 -12px -12px;
240
- }
241
- @media (max-width: 320px) {
242
- .nhsuk-bp-graph-marker {
243
- height: 20px;
244
- width: 20px;
245
- margin: 0 0 -10px -10px;
246
- }
247
- }
248
- @media (min-width: 320px) and (max-width: 641px) {
249
- .nhsuk-bp-graph-marker {
250
- height: 22px;
251
- width: 22px;
252
- margin: 0 0 -11px -11px;
253
- }
254
- }
255
-
256
- .nhsuk-bp-graph {
257
- position: relative;
258
- margin-left: 20px;
259
- margin-right: 20px;
260
- outline: 2px solid black;
261
- display: flex;
262
- flex-direction: column;
263
- height: 350px;
264
- }
265
- @media (max-width: 320px) {
266
- .nhsuk-bp-graph {
267
- height: 225px;
268
- }
269
- }
270
- @media (min-width: 320px) and (max-width: 641px) {
271
- .nhsuk-bp-graph {
272
- height: 275px;
273
- }
274
- }
275
-
276
- .nhsuk-bp-graph-row {
277
- flex-grow: 1;
278
- display: flex;
279
- }
280
-
281
- .nhsuk-bp-systolic-legend-wrapper {
282
- display: flex;
283
- align-items: flex-end;
284
- margin-bottom: 10px;
285
- }
286
-
287
- .nhsuk-bp-diastolic-legend-wrapper {
288
- display: flex;
289
- align-items: flex-start;
290
- margin-top: 30px;
291
- padding-left: 18px;
292
- }
293
-
294
- .nhsuk-bp-diastolic-legend-marker, .nhsuk-bp-systolic-legend-marker {
295
- height: 16px;
296
- margin-right: 5px;
297
- border-left: 2px solid black;
298
- }
299
-
300
- .nhsuk-bp-systolic-legend-marker {
301
- width: 40px;
302
- border-top: 2px solid black;
303
- }
304
-
305
- .nhsuk-bp-diastolic-legend-marker {
306
- width: 20px;
307
- border-bottom: 2px solid black;
308
- }
309
191
 
310
192
  .nhsuk-bp-diastolic-axis-marker, .nhsuk-bp-systolic-axis-marker {
311
193
  position: absolute;
@@ -367,20 +249,59 @@
367
249
  text-align: center;
368
250
  }
369
251
 
370
- .nhsuk-bp-graph-cell {
252
+
253
+ .nhsuk-bp-graph {
254
+ position: relative;
255
+ margin-left: 20px;
256
+ margin-right: 20px;
257
+ outline: 2px solid black;
258
+ display: flex;
259
+ flex-direction: column;
260
+ height: 350px;
261
+ }
262
+ @media (max-width: 320px) {
263
+ .nhsuk-bp-graph {
264
+ height: 225px;
265
+ }
266
+ }
267
+ @media (min-width: 320px) and (max-width: 641px) {
268
+ .nhsuk-bp-graph {
269
+ height: 275px;
270
+ }
271
+ }
272
+
273
+ .nhsuk-bp-graph-row {
371
274
  flex-grow: 1;
372
- border-bottom: 1px solid white;
373
- border-left: 1px solid white;
374
- background: transparent;
375
- z-index: 4;
275
+ display: flex;
376
276
  }
377
277
 
378
- .nhsuk-bp-first-in-column {
379
- border-bottom: none;
278
+ .nhsuk-bp-systolic-legend-wrapper {
279
+ display: flex;
280
+ align-items: flex-end;
281
+ margin-bottom: 10px;
380
282
  }
381
283
 
382
- .nhsuk-bp-first-in-row {
383
- border-left: none;
284
+ .nhsuk-bp-diastolic-legend-wrapper {
285
+ display: flex;
286
+ align-items: flex-start;
287
+ margin-top: 30px;
288
+ padding-left: 18px;
289
+ }
290
+
291
+ .nhsuk-bp-diastolic-legend-marker, .nhsuk-bp-systolic-legend-marker {
292
+ height: 16px;
293
+ margin-right: 5px;
294
+ border-left: 2px solid black;
295
+ }
296
+
297
+ .nhsuk-bp-systolic-legend-marker {
298
+ width: 40px;
299
+ border-top: 2px solid black;
300
+ }
301
+
302
+ .nhsuk-bp-diastolic-legend-marker {
303
+ width: 20px;
304
+ border-bottom: 2px solid black;
384
305
  }
385
306
 
386
307
  .nhsuk-bp-classification-low, .nhsuk-bp-legend-key-classification-low {
@@ -434,30 +355,16 @@
434
355
  z-index: 0;
435
356
  }
436
357
 
437
- .nhsuk-bmi-axis-marker {
438
- position: absolute;
439
- outline: 0.5px solid black;
440
- height: 5px;
441
- bottom: -5px;
442
- }
443
-
444
- .nhsuk-bmi-axis-marker-label {
445
- position: absolute;
446
- bottom: -25px;
447
- left: -10px;
448
- width: 20px;
449
- text-align: center;
450
- }
451
358
 
452
- .nhsuk-cbmi-legend-key-classification-healthy, .nhsuk-cbmi-classification-healthy {
359
+ .nhsuk-cbmi-classification-healthy, .nhsuk-cbmi-legend-key-classification-healthy {
453
360
  background: repeating-linear-gradient(-45deg, #30b4ab, #30b4ab 4.5px, #00a499 4.5px, #00a499 9px);
454
361
  }
455
362
 
456
- .nhsuk-cbmi-legend-key-classification-overweight, .nhsuk-cbmi-classification-overweight {
363
+ .nhsuk-cbmi-classification-overweight, .nhsuk-cbmi-legend-key-classification-overweight {
457
364
  background: #ffb81c;
458
365
  }
459
366
 
460
- .nhsuk-cbmi-legend-key-classification-underweight, .nhsuk-cbmi-classification-underweight {
367
+ .nhsuk-cbmi-classification-underweight, .nhsuk-cbmi-legend-key-classification-underweight {
461
368
  background: #330072;
462
369
  }
463
370
 
@@ -474,50 +381,32 @@
474
381
  }
475
382
  }
476
383
 
477
- .nhsuk-cbmi-legend-key-classification-healthy, .nhsuk-cbmi-classification-healthy {
478
- background: repeating-linear-gradient(-45deg, #30b4ab, #30b4ab 4.5px, #00a499 4.5px, #00a499 9px);
479
- }
480
-
481
- .nhsuk-cbmi-legend-key-classification-overweight, .nhsuk-cbmi-classification-overweight {
482
- background: #ffb81c;
384
+ .nhsuk-bp-graph-cell {
385
+ flex-grow: 1;
386
+ border-bottom: 1px solid white;
387
+ border-left: 1px solid white;
388
+ background: transparent;
389
+ z-index: 4;
483
390
  }
484
391
 
485
- .nhsuk-cbmi-legend-key-classification-underweight, .nhsuk-cbmi-classification-underweight {
486
- background: #330072;
392
+ .nhsuk-bp-first-in-column {
393
+ border-bottom: none;
487
394
  }
488
395
 
489
- .nhsuk-cbmi-axis-marker {
490
- border: 1px solid black;
491
- position: absolute;
492
- bottom: -5px;
493
- margin-left: -0.5px;
494
- box-shadow: 0px 0px white inset, 1px 0px white, -1px 0px white;
495
- z-index: 100;
496
- height: 33px;
497
- }
498
- @media (min-width: 320px) and (max-width: 641px) {
499
- .nhsuk-cbmi-axis-marker {
500
- height: 29px;
501
- }
396
+ .nhsuk-bp-first-in-row {
397
+ border-left: none;
502
398
  }
503
399
 
504
- .nhsuk-cbmi-axis-marker-label {
505
- position: absolute;
506
- bottom: -25px;
507
- left: -10px;
508
- width: 20px;
509
- text-align: center;
510
- }
511
400
 
512
- .nhsuk-cbmi-legend-key-classification-healthy, .nhsuk-cbmi-classification-healthy {
401
+ .nhsuk-cbmi-classification-healthy, .nhsuk-cbmi-legend-key-classification-healthy {
513
402
  background: repeating-linear-gradient(-45deg, #30b4ab, #30b4ab 4.5px, #00a499 4.5px, #00a499 9px);
514
403
  }
515
404
 
516
- .nhsuk-cbmi-legend-key-classification-overweight, .nhsuk-cbmi-classification-overweight {
405
+ .nhsuk-cbmi-classification-overweight, .nhsuk-cbmi-legend-key-classification-overweight {
517
406
  background: #ffb81c;
518
407
  }
519
408
 
520
- .nhsuk-cbmi-legend-key-classification-underweight, .nhsuk-cbmi-classification-underweight {
409
+ .nhsuk-cbmi-classification-underweight, .nhsuk-cbmi-legend-key-classification-underweight {
521
410
  background: #330072;
522
411
  }
523
412
 
@@ -580,15 +469,54 @@
580
469
  }
581
470
  }
582
471
 
583
- .nhsuk-cbmi-legend-key-classification-healthy, .nhsuk-cbmi-classification-healthy {
472
+ .nhsuk-cbmi-classification-healthy, .nhsuk-cbmi-legend-key-classification-healthy {
584
473
  background: repeating-linear-gradient(-45deg, #30b4ab, #30b4ab 4.5px, #00a499 4.5px, #00a499 9px);
585
474
  }
586
475
 
587
- .nhsuk-cbmi-legend-key-classification-overweight, .nhsuk-cbmi-classification-overweight {
476
+ .nhsuk-cbmi-classification-overweight, .nhsuk-cbmi-legend-key-classification-overweight {
588
477
  background: #ffb81c;
589
478
  }
590
479
 
591
- .nhsuk-cbmi-legend-key-classification-underweight, .nhsuk-cbmi-classification-underweight {
480
+ .nhsuk-cbmi-classification-underweight, .nhsuk-cbmi-legend-key-classification-underweight {
481
+ background: #330072;
482
+ }
483
+
484
+ .nhsuk-cbmi-legend-key-classification-overweight {
485
+ border-bottom: none;
486
+ box-shadow: none;
487
+ }
488
+
489
+ .nhsuk-cbmi-legend-key, .nhsuk-cbmi-legend-key-classification-underweight, .nhsuk-cbmi-legend-key-classification-healthy, .nhsuk-cbmi-legend-key-classification-overweight {
490
+ border-bottom: 2px solid white;
491
+ margin-bottom: 2px;
492
+ }
493
+
494
+ .nhsuk-cbmi-legend-marker {
495
+ margin-bottom: 2px;
496
+ }
497
+
498
+ .nhsuk-cbmi-classification-underweight-heading {
499
+ border-left: 8px solid #330072;
500
+ }
501
+
502
+ .nhsuk-cbmi-classification-healthy-heading {
503
+ border-left: 8px solid #30b4ab;
504
+ }
505
+
506
+ .nhsuk-cbmi-classification-overweight-heading {
507
+ border-left: 8px solid #ffb81c;
508
+ }
509
+
510
+
511
+ .nhsuk-cbmi-classification-healthy, .nhsuk-cbmi-legend-key-classification-healthy {
512
+ background: repeating-linear-gradient(-45deg, #30b4ab, #30b4ab 4.5px, #00a499 4.5px, #00a499 9px);
513
+ }
514
+
515
+ .nhsuk-cbmi-classification-overweight, .nhsuk-cbmi-legend-key-classification-overweight {
516
+ background: #ffb81c;
517
+ }
518
+
519
+ .nhsuk-cbmi-classification-underweight, .nhsuk-cbmi-legend-key-classification-underweight {
592
520
  background: #330072;
593
521
  }
594
522
 
@@ -616,6 +544,44 @@
616
544
  z-index: 1;
617
545
  }
618
546
 
547
+ .nhsuk-bmi-axis-marker {
548
+ position: absolute;
549
+ outline: 0.5px solid black;
550
+ height: 5px;
551
+ bottom: -5px;
552
+ }
553
+
554
+ .nhsuk-bmi-axis-marker-label {
555
+ position: absolute;
556
+ bottom: -25px;
557
+ left: -10px;
558
+ width: 20px;
559
+ text-align: center;
560
+ }
561
+
562
+
563
+ .nhsuk-bp-graph-marker {
564
+ position: absolute;
565
+ z-index: 6;
566
+ height: 24px;
567
+ width: 24px;
568
+ margin: 0 0 -12px -12px;
569
+ }
570
+ @media (max-width: 320px) {
571
+ .nhsuk-bp-graph-marker {
572
+ height: 20px;
573
+ width: 20px;
574
+ margin: 0 0 -10px -10px;
575
+ }
576
+ }
577
+ @media (min-width: 320px) and (max-width: 641px) {
578
+ .nhsuk-bp-graph-marker {
579
+ height: 22px;
580
+ width: 22px;
581
+ margin: 0 0 -11px -11px;
582
+ }
583
+ }
584
+
619
585
  .nhsuk-cbmi-legend-key-classification-healthy, .nhsuk-cbmi-classification-healthy {
620
586
  background: repeating-linear-gradient(-45deg, #30b4ab, #30b4ab 4.5px, #00a499 4.5px, #00a499 9px);
621
587
  }
@@ -628,28 +594,74 @@
628
594
  background: #330072;
629
595
  }
630
596
 
631
- .nhsuk-cbmi-legend-key-classification-overweight {
632
- border-bottom: none;
633
- box-shadow: none;
597
+
598
+ .nhsuk-cbmi-axis-marker {
599
+ border: 1px solid black;
600
+ position: absolute;
601
+ bottom: -5px;
602
+ margin-left: -0.5px;
603
+ box-shadow: 0px 0px white inset, 1px 0px white, -1px 0px white;
604
+ z-index: 100;
605
+ height: 33px;
606
+ }
607
+ @media (min-width: 320px) and (max-width: 641px) {
608
+ .nhsuk-cbmi-axis-marker {
609
+ height: 29px;
610
+ }
634
611
  }
635
612
 
636
- .nhsuk-cbmi-legend-key, .nhsuk-cbmi-legend-key-classification-underweight, .nhsuk-cbmi-legend-key-classification-healthy, .nhsuk-cbmi-legend-key-classification-overweight {
637
- border-bottom: 2px solid white;
638
- margin-bottom: 2px;
613
+ .nhsuk-cbmi-axis-marker-label {
614
+ position: absolute;
615
+ bottom: -25px;
616
+ left: -10px;
617
+ width: 20px;
618
+ text-align: center;
639
619
  }
640
620
 
641
- .nhsuk-cbmi-legend-marker {
642
- margin-bottom: 2px;
621
+
622
+ .nhsuk-bmi-classification-underweight, .nhsuk-bmi-legend-key-classification-underweight {
623
+ background: #330072;
643
624
  }
644
625
 
645
- .nhsuk-cbmi-classification-underweight-heading {
646
- border-left: 8px solid #330072;
626
+ .nhsuk-bmi-classification-healthy, .nhsuk-bmi-legend-key-classification-healthy {
627
+ background: repeating-linear-gradient(-45deg, #30b4ab, #30b4ab 4.5px, #00a499 4.5px, #00a499 9px);
647
628
  }
648
629
 
649
- .nhsuk-cbmi-classification-healthy-heading {
650
- border-left: 8px solid #30b4ab;
630
+ .nhsuk-bmi-classification-overweight, .nhsuk-bmi-legend-key-classification-overweight {
631
+ background: #ffb81c;
651
632
  }
652
633
 
653
- .nhsuk-cbmi-classification-overweight-heading {
654
- border-left: 8px solid #ffb81c;
634
+ .nhsuk-bmi-classification-obese, .nhsuk-bmi-legend-key-classification-obese {
635
+ background: repeating-linear-gradient(45deg, #da5147, #da5147 4.5px, #d5281b 4.5px, #d5281b 9px);
636
+ }
637
+
638
+ .nhsuk-bmi-classification-obese, .nhsuk-bmi-classification-overweight, .nhsuk-bmi-classification-healthy, .nhsuk-bmi-classification-underweight {
639
+ position: absolute;
640
+ bottom: 0%;
641
+ outline: 1px solid black;
642
+ border-right: 1px solid black;
643
+ box-shadow: -1px 0px white inset, 2px 0px white, 0px -2px white;
644
+ height: 28px;
645
+ }
646
+ @media (min-width: 320px) and (max-width: 641px) {
647
+ .nhsuk-bmi-classification-obese, .nhsuk-bmi-classification-overweight, .nhsuk-bmi-classification-healthy, .nhsuk-bmi-classification-underweight {
648
+ height: 24px;
649
+ }
650
+ }
651
+
652
+ .nhsuk-bmi-classification-underweight {
653
+ z-index: 3;
654
+ }
655
+
656
+ .nhsuk-bmi-classification-healthy {
657
+ z-index: 2;
658
+ }
659
+
660
+ .nhsuk-bmi-classification-overweight {
661
+ z-index: 1;
662
+ }
663
+
664
+ .nhsuk-bmi-classification-obese {
665
+ border-right: none;
666
+ box-shadow: none;
655
667
  }
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react"),t=require("nhsuk-react-components"),a=require("big.js");function n(e){const t=function(e){if(e.axis.ticks.length<=2)throw Error("invalid number of axis ticks");const t=[...e.axis.ticks].sort(((e,t)=>e.value-t.value));return e.segments.map(((e,a)=>{var n,s;const r=null!==(n=e.start)&&void 0!==n?n:t[a].value,l=null!==(s=e.end)&&void 0!==s?s:t[a+1].value;return Object.assign(Object.assign({},e),{start:r,end:l})}))}(e),a=t.reduce(((e,t)=>{var a;return e+(null!==(a=t.weight)&&void 0!==a?a:0)}),0),n=t.filter((e=>void 0===e.weight)).reduce(((e,t)=>e+(t.end-t.start)),0),s=100-a;if(s<0)throw new Error("Invalid segment weight.");return t.map((e=>{if(void 0!==e.weight)return e;const t=(e.end-e.start)/n*s;return Object.assign(Object.assign({},e),{weight:t})}))}class s{constructor(e,t){this.chartWidth=t,this.chartName=e.name,this.axis=e.axis,this.constraints=e.constraints,this.segments=n(e)}get name(){return this.chartName}getAxisTicks(){return Object.values(this.axis.ticks).map((e=>{var t;const a=null===(t=e.isVisible)||void 0===t||t;return{label:e.value.toString(),value:this.calculateRawPosition(e.value),isVisible:a}}))}getChartRegions(){return Object.values(this.axis.ticks).slice(1).map((e=>({value:this.calculateRawPosition(e.value),styleClass:this.segmentstyleSuffix(e.value)})))}segmentstyleSuffix(e){const t=this.getSegmentByTick(e);return(null==t?void 0:t.styleSuffix)?`${this.chartName}-${t.styleSuffix}`:""}getSegmentByTick(e){for(const t of this.segments)if(e>=t.start&&e<=t.end)return t;return null}calculatePosition(e){if(this.constraints){const{value:t,position:a}=this.constraints.max;if(e>=t)return a}return this.calculateRawPosition(e)}calculateRawPosition(e){let t=0;const a=this.clampValue(e),{totalSegmentsWidth:n}=this;for(const e of this.segments){if(a>=e.start&&a<=e.end){return t+(a-e.start)/(e.end-e.start)*(e.weight/n)*this.chartWidth}t+=e.weight/n*this.chartWidth}return 0}clampValue(e){return Math.min(Math.max(e,this.axis.ticks[0].value),this.axis.ticks[this.axis.ticks.length-1].value)}get totalSegmentsWidth(){return this.segments.reduce(((e,t)=>e+t.weight),0)}}const r=(e,t)=>t>0?`${e}-axis-marker-label`:`${e}-start-axis-marker-label`,l=(e,t)=>t>0?`${e}-axis-marker`:`${e}-start-axis-marker`;function i({chartName:t,markerText:a,offsetPercent:n}){return e.createElement("div",{className:`${l(t,n)}`,style:{left:`${n}%`}},e.createElement("div",{className:`nhsuk-font-size-16 nhsuk-u-secondary-text-color ${r(t,n)}`},a))}function c({model:t}){return e.createElement(e.Fragment,null,t.getAxisTicks().map((({label:a,value:n,isVisible:s})=>s&&e.createElement(i,{chartName:t.name,markerText:a,offsetPercent:n,key:a}))))}function o(){return e.createElement("svg",{viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M6 9L0.803849 -9.78799e-07L11.1962 -7.02746e-08L6 9Z",fill:"black"}))}const u=(e,t)=>t<=20?`${e}-label-align-left`:t<=80?`${e}-label-align-center`:`${e}-label-align-right`;function m({chartName:t,value:a,offset:n,markerText:s}){return e.createElement("div",{className:`${t}-label-marker`},e.createElement("div",{className:`nhsuk-font-size-16 ${u(t,n)}`},s,e.createElement("span",{className:`${t}-value-marker`},a)))}function d({value:t,model:a,markerText:n}){const s=a.calculatePosition(t),r=Math.pow(10,1),l=Math.round(s*r)/r;return e.createElement(e.Fragment,null,e.createElement("div",{className:`${a.name}-arrow-marker`,style:{left:`${l}%`}},e.createElement(m,{chartName:a.name,value:t,markerText:n,offset:l}),e.createElement(o,null)),e.createElement("div",{className:`${a.name}-value-axis-marker`,style:{left:`${l}%`}}))}function h({value:t,styleClass:a}){return e.createElement("div",{className:a,style:{width:`${t}%`}})}function g({model:t}){return e.createElement(e.Fragment,null,t.getChartRegions().map((({value:t,styleClass:a})=>e.createElement(h,{value:t,styleClass:a,key:t}))))}const f=100;function p({config:t,value:a,markerText:n}){const r=new s(t,f);return e.createElement("div",{className:`${t.name}-graph nhsuk-u-margin-bottom-9`,"aria-hidden":"true"},e.createElement(c,{model:r}),e.createElement(d,{value:a,markerText:n,model:r}),e.createElement(g,{model:r}))}function b({element:t,text:a,className:n,wrapperClassName:s}){return e.createElement("div",{className:`nhsuk-chart-legend-key-wrapper ${null!=s?s:""}`},e.createElement("div",{className:`nhsuk-chart-legend-key ${null!=n?n:""}`},t),a)}function k({legendKeys:a,className:n}){return e.createElement(t.Card,{className:`${n} nhsuk-u-padding-3 nhsuk-chart-legend-card`},a.map((t=>e.createElement(b,Object.assign({key:t.text},t)))))}function y({legendKeys:t,className:a}){return e.createElement("div",{className:a},t.map((t=>e.createElement(b,Object.assign({key:t.text},t)))))}function v({legendKeys:t,borderWrapper:a=!0}){const n="nhsuk-u-margin-top-6 nhsuk-u-margin-bottom-3 nhsuk-u-secondary-text-color nhsuk-body-s";return e.createElement("div",{"aria-hidden":"true"},a?e.createElement(k,{legendKeys:t,className:n}):e.createElement(y,{legendKeys:t,className:n}))}const E={Underweight:"underweight",Healthy:"healthy",Overweight:"overweight"},w=Object.assign(Object.assign({},E),{Obese:"obese"}),x=Object.assign(Object.assign({},E),{Obese1:"obese1",Obese2:"obese2",Obese3:"obese3"});x.Underweight,x.Healthy,x.Underweight,x.Overweight,x.Healthy;class L{constructor(e){this.bounds={lowerBound:17.5,upperBounds:{[w.Underweight]:e.upper[x.Underweight].value,[w.Healthy]:e.upper[x.Healthy].value,[w.Overweight]:e.upper[x.Overweight].value,[w.Obese]:e.upper[x.Obese2].value}}}get chartRange(){return this.bounds.upperBounds[w.Obese]-this.bounds.lowerBound}classificationPercentage(e){return this.offsetPercentage(this.bounds.upperBounds[e])}offsetPercentage(e){return(e-this.bounds.lowerBound)/this.chartRange*100}}function N(){return e.createElement("svg",{viewBox:"1 1 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("g",{clipPath:"url(#clip0_1346_102759)"},e.createElement("path",{xmlns:"http://www.w3.org/2000/svg",d:"M1.93209 4.05025L1.57854 4.40381L1.93209 4.75736L6.17473 9L1.93209 13.2426L1.57854 13.5962L1.93209 13.9497L4.05341 16.0711L4.40697 16.4246L4.76052 16.0711L9.00316 11.8284L13.2458 16.0711L13.5994 16.4246L13.9529 16.0711L16.0742 13.9497L16.4278 13.5962L16.0742 13.2426L11.8316 9L16.0742 4.75736L16.4278 4.40381L16.0742 4.05025L13.9529 1.92893L13.5994 1.57538L13.2458 1.92893L9.00316 6.17157L4.76052 1.92893L4.40697 1.57538L4.05341 1.92893L1.93209 4.05025Z",fill:"black",stroke:"white"})))}function B({bmi:t,model:a}){const n=a.offsetPercentage(t);let s=0;if(n>0){const e=1,t=Math.pow(10,e);s=Math.round(n*t)/t}return e.createElement("div",{className:"nhsuk-bmi-chart-marker",style:{left:`${s}%`}},e.createElement(N,null))}function $({classification:t,model:a}){const n=a.classificationPercentage(t);return e.createElement("div",{className:`nhsuk-bmi-classification-${t}`,style:{width:`${n}%`}})}function T({model:t}){return e.createElement(e.Fragment,null,e.createElement($,{classification:w.Underweight,model:t}),e.createElement($,{classification:w.Healthy,model:t}),e.createElement($,{classification:w.Overweight,model:t}),e.createElement($,{classification:w.Obese,model:t}))}function O({markerText:t,offsetPercent:a}){return e.createElement("div",{className:"nhsuk-bmi-axis-marker",style:{left:`${a}%`}},e.createElement("div",{className:"nhsuk-bmi-axis-marker-label"},t))}function P({model:t}){return e.createElement(e.Fragment,null,e.createElement(O,{markerText:t.bounds.upperBounds[w.Underweight].toString(),offsetPercent:t.classificationPercentage(w.Underweight)}),e.createElement(O,{markerText:t.bounds.upperBounds[w.Healthy].toString(),offsetPercent:t.classificationPercentage(w.Healthy)}),e.createElement(O,{markerText:t.bounds.upperBounds[w.Overweight].toString(),offsetPercent:t.classificationPercentage(w.Overweight)}))}function S({classificationBounds:t,bmi:a}){const n=new L(t);return e.createElement("div",{className:"nhsuk-bmi-graph","aria-hidden":"true"},e.createElement(P,{model:n}),e.createElement(B,{bmi:a,model:n}),e.createElement(T,{model:n}))}const R={Low:"low",Healthy:"healthy",SlightlyRaised:"slightlyRaised",High:"high"};var C;function H({axisType:t,labelText:a,offsetPercent:n,applyLabelSpecificStyles:s=!0}){const r=`${C[t].toLowerCase()}-axis`,l=`nhsuk-bp-${r}-marker`,i=`nhsuk-bp-${r}-marker-${a}`;return e.createElement("div",{className:s?`${l} ${i}`:`${l}`,style:t===C.Systolic?{bottom:`${n}%`}:{left:`${n}%`}},e.createElement("div",{className:`nhsuk-bp-${r}-label`},a))}function j(e,t,a){return(e-a)/(t-a)*100}function U(e,t,a){return j(t[e].value,t[R.High].value,a)}function M({axisType:t,upperBounds:a,lowerBound:n}){const s={slightlyRaisedValueToCheck:85,slightlyRaisedValueToAdd:90};return e.createElement("div",null,e.createElement(H,{labelText:n.toString(),offsetPercent:0,axisType:t}),e.createElement(H,{labelText:a[R.Low].value.toString(),offsetPercent:U(R.Low,a,n),axisType:t}),e.createElement(H,{labelText:a[R.Healthy].value.toString(),offsetPercent:U(R.Healthy,a,n),axisType:t}),e.createElement(H,{labelText:a[R.SlightlyRaised].value.toString(),offsetPercent:U(R.SlightlyRaised,a,n),axisType:t,applyLabelSpecificStyles:a[R.SlightlyRaised].value===s.slightlyRaisedValueToCheck}),t===C.Diastolic&&a[R.SlightlyRaised].value===s.slightlyRaisedValueToCheck&&e.createElement(H,{labelText:s.slightlyRaisedValueToAdd.toString(),offsetPercent:j(s.slightlyRaisedValueToAdd,a[R.High].value,n),axisType:t}),e.createElement(H,{labelText:a[R.High].value.toString(),offsetPercent:100,axisType:t}))}function F({bounds:t}){return e.createElement(e.Fragment,null,e.createElement(M,{axisType:C.Systolic,upperBounds:t.systolic.upper,lowerBound:t.systolic.lower}),e.createElement(M,{axisType:C.Diastolic,upperBounds:t.diastolic.upper,lowerBound:t.diastolic.lower}))}function A(){return e.createElement("svg",{viewBox:"0 0 32 32",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("g",{clipPath:"url(#clip0_1346_102759)"},e.createElement("path",{d:"M5.18718 8.36931L4.48008 9.07641L5.18718 9.78352L11.3744 15.9707L5.18718 22.1579L4.48008 22.865L5.18718 23.5721L8.36916 26.7541L9.07627 27.4612L9.78338 26.7541L15.9706 20.5669L22.1577 26.7541L22.8649 27.4612L23.572 26.7541L26.7539 23.5721L27.461 22.865L26.7539 22.1579L20.5668 15.9707L26.7539 9.78352L27.461 9.07641L26.7539 8.36931L23.572 5.18732L22.8649 4.48022L22.1577 5.18732L15.9706 11.3745L9.78338 5.18732L9.07627 4.48022L8.36916 5.18732L5.18718 8.36931Z",fill:"black",stroke:"white",strokeWidth:"2"})))}function K({systolicReading:t,diastolicReading:n,systolicLowerBound:s,systolicUpperBound:r,diastolicLowerBound:l,diastolicUpperBound:i}){const c=i-l,o=new a((t-s)/(r-s)).times(100),u=new a((n-l)/c).times(100),m=o.round(1),d=u.round(1);return e.createElement("div",{className:"nhsuk-bp-graph-marker",style:{left:`${d}%`,bottom:`${m}%`}},e.createElement(A,null))}function V(e,t,a){return(t[a].value-e)/(t.high.value-e)*100}function W(e){return`nhsuk-bp-classification-${e.toLowerCase()}`}function z({classification:t,bounds:a,renderAsBoundary:n=!1}){const s=V(a.diastolic.lower,a.diastolic.upper,t),r=V(a.systolic.lower,a.systolic.upper,t);return e.createElement("div",{className:n?"nhsuk-bp-region-boundary":W(t),style:{width:`${s}%`,height:`${r}%`}})}function D({bounds:t,renderAsBoundary:a=!1}){return e.createElement(e.Fragment,null,e.createElement(z,Object.assign({classification:R.Low},{bounds:t,renderAsBoundary:a})),e.createElement(z,Object.assign({classification:R.Healthy},{bounds:t,renderAsBoundary:a})),e.createElement(z,Object.assign({classification:R.SlightlyRaised},{bounds:t,renderAsBoundary:a})),!a&&e.createElement(z,Object.assign({classification:R.High},{bounds:t,renderAsBoundary:a})))}function _({firstInRow:t=!1,firstInColumn:a=!1}){let n="nhsuk-bp-graph-cell";return t&&(n+=" nhsuk-bp-first-in-row"),a&&(n+=" nhsuk-bp-first-in-column"),e.createElement("div",{className:n})}function q({bounds:t,graphLayout:a,reading:n}){const{systolic:s,diastolic:r}=n,{systolicLabel:l,diastolicLabel:i}=a;return e.createElement("div",{className:"nhsuk-body-s"},e.createElement("div",{className:"nhsuk-bp-systolic-legend-wrapper","aria-hidden":"true"},e.createElement("div",{className:"nhsuk-bp-systolic-legend-marker"}),e.createElement("span",null,l)),e.createElement("div",{className:"nhsuk-bp-graph","aria-hidden":"true"},e.createElement(F,{bounds:t}),e.createElement(K,{systolicReading:s,diastolicReading:r,systolicLowerBound:t.systolic.lower,systolicUpperBound:t.systolic.upper.high.value,diastolicLowerBound:t.diastolic.lower,diastolicUpperBound:t.diastolic.upper.high.value}),e.createElement(D,{bounds:t}),a.rows.map((t=>e.createElement("div",{key:t.id,className:"nhsuk-bp-graph-row"},t.cells.map((t=>e.createElement(_,Object.assign({key:t.id},t))))))),e.createElement(D,{bounds:t,renderAsBoundary:!0})),e.createElement("div",{className:"nhsuk-bp-diastolic-legend-wrapper","aria-hidden":"true"},e.createElement("div",{className:"nhsuk-bp-diastolic-legend-marker"}),e.createElement("span",null,i)))}!function(e){e[e.Systolic=0]="Systolic",e[e.Diastolic=1]="Diastolic"}(C||(C={})),a.RM=a.roundHalfEven;const I={[x.Underweight]:null,[x.Healthy]:x.Underweight,[x.Overweight]:x.Healthy};class Z{constructor(e){this.bounds={lowerBound:0,upperBounds:{[w.Underweight]:e.upper[x.Underweight].value,[w.Healthy]:e.upper[x.Healthy].value,[w.Overweight]:e.upper[x.Overweight].value}}}get chartRange(){return this.bounds.upperBounds[x.Overweight]-this.bounds.lowerBound}classificationPercentage(e){return this.offsetPercentage(this.bounds.upperBounds[e])}offsetPercentage(e){const t=this.chartRange;if(e<=2){const a=.08*t;return this.calculateOffset(e,E.Underweight,a)}if(e<=91){const a=.72*t,n=.08*t;return this.calculateOffset(e,E.Healthy,a)+n}const a=.2*t,n=.8*t;return this.calculateOffset(e,E.Overweight,a)+n}calculateOffset(e,t,a){const n=I[t]?this.bounds.upperBounds[I[t]]:0;return(e-n)/(this.bounds.upperBounds[t]-n)*a}clampedOffsetPercentage(e){const t=Math.max(1,Math.min(e,99));return this.offsetPercentage(t)}}function G({markerText:t,offsetPercent:a}){return e.createElement("div",{className:"nhsuk-cbmi-axis-marker",style:{left:`${a}%`}},e.createElement("div",{className:"nhsuk-font-size-16 nhsuk-cbmi-axis-marker-label"},t))}function J({model:t}){return e.createElement(e.Fragment,null,e.createElement(G,{markerText:t.bounds.upperBounds[E.Underweight].toString(),offsetPercent:t.classificationPercentage(E.Underweight)}),e.createElement(G,{markerText:t.bounds.upperBounds[E.Healthy].toString(),offsetPercent:t.classificationPercentage(E.Healthy)}))}const Q=e=>e<=20?"nhsuk-cbmi-chart-label-align-left":e<=80?"nhsuk-cbmi-chart-label-align-center":"nhsuk-cbmi-chart-label-align-right";function X({centile:t,markerText:a}){return e.createElement("div",{className:"nhsuk-cbmi-chart-label-marker"},e.createElement("div",{className:`nhsuk-u-font-size-19 ${Q(t.value)}`},a,e.createElement("span",{className:"nhsuk-cbmi-chart-centile-marker"},t.label)))}function Y({centile:t,model:a,markerText:n}){const s=a.clampedOffsetPercentage(t.value);let r=0;if(s>0){const e=1,t=Math.pow(10,e);r=Math.round(s*t)/t}return e.createElement("div",null,e.createElement("div",{className:"nhsuk-cbmi-chart-arrow-marker",style:{left:`${r}%`}},e.createElement(X,{centile:t,markerText:n}),e.createElement(o,null)),e.createElement("div",{className:"nhsuk-cbmi-chart-axis-marker",style:{left:`${r}%`}}))}function ee({classification:t,model:a}){const n=a.classificationPercentage(t);return e.createElement("div",{className:`nhsuk-cbmi-classification-${t}`,style:{width:`${n}%`}})}function te({model:t}){return e.createElement(e.Fragment,null,e.createElement(ee,{classification:E.Underweight,model:t}),e.createElement(ee,{classification:E.Healthy,model:t}),e.createElement(ee,{classification:E.Overweight,model:t}))}function ae({classificationBounds:t,centile:a,markerText:n}){const s=new Z(t);return e.createElement("div",{className:"nhsuk-cbmi-graph nhsuk-u-margin-bottom-9 ","aria-hidden":"true"},e.createElement(J,{model:s}),e.createElement(Y,{centile:a,markerText:n,model:s}),e.createElement(te,{model:s}))}exports.BarSliderChart=p,exports.BarSliderChartFigure=function({config:t,value:a,ariaLabel:n,markerText:s}){const r=Object.values(t.segments).filter((e=>null!=e.legend)).map((e=>({text:e.legend,className:`${t.name}-legend-key-${e.styleSuffix}`,wrapperClassName:`${t.name}-legend-marker`})));return e.createElement("figure",{className:"nhsuk-u-margin-0"},e.createElement("figcaption",{className:"nhsuk-u-visually-hidden"},n),e.createElement(p,{config:t,value:a,markerText:s}),e.createElement(v,{legendKeys:r,borderWrapper:!1}))},exports.BmiChart=S,exports.BmiChartFigure=function({classificationBounds:t,bmi:a,ariaLabel:n,legendKeys:s,legendMarkerText:r}){const l=((t,a)=>Object.entries(t).map((([e,t])=>({text:t,className:`nhsuk-bmi-legend-key-classification-${e}`}))).concat({text:a,className:"nhsuk-bmi-legend-key-marker",element:e.createElement(N,null)}))(s,r);return e.createElement("figure",{className:"nhsuk-u-margin-0"},e.createElement("figcaption",{className:"nhsuk-u-visually-hidden"},n),e.createElement(S,{classificationBounds:t,bmi:a}),e.createElement(v,{legendKeys:l,borderWrapper:!0}))},exports.BpChart=q,exports.BpChartFigure=function({bounds:t,graphLayout:a,reading:n,ariaLabel:s,legendKeys:r,legendMarkerText:l}){const i=((t,a)=>Object.entries(t).map((([e,t])=>({text:t,className:`nhsuk-bp-legend-key-classification-${e}`}))).concat({text:a,className:"nhsuk-bp-legend-key-marker",element:e.createElement(A,null)}))(r,l);return e.createElement("figure",{className:"nhsuk-u-margin-0"},e.createElement("figcaption",{className:"nhsuk-u-visually-hidden"},s),e.createElement(q,{bounds:t,reading:n,graphLayout:a}),e.createElement(v,{legendKeys:i}))},exports.ChartLegend=v,exports.ChildBmiChart=ae,exports.ChildBmiChartFigure=function({classificationBounds:t,centile:a,centileMarkerText:n,ariaLabel:s,legendKeys:r}){const l=Object.entries(r).map((([e,t])=>({text:t,className:`nhsuk-cbmi-legend-key-classification-${e}`,wrapperClassName:"nhsuk-cbmi-legend-marker"})));return e.createElement("figure",{className:"nhsuk-u-margin-0"},e.createElement("figcaption",{className:"nhsuk-u-visually-hidden"},s),e.createElement(ae,{classificationBounds:t,centile:a,markerText:n}),e.createElement(v,{legendKeys:l,borderWrapper:!1}))};
1
+ "use strict";var e=require("react"),t=require("nhsuk-react-components"),a=require("big.js");function n(e){const t=function(e){if(e.axis.ticks.length<=2)throw Error("invalid number of axis ticks");const t=[...e.axis.ticks].sort(((e,t)=>e.value-t.value));return e.segments.map(((e,a)=>{var n,r;const s=null!==(n=e.start)&&void 0!==n?n:t[a].value,l=null!==(r=e.end)&&void 0!==r?r:t[a+1].value;return Object.assign(Object.assign({},e),{start:s,end:l})}))}(e),a=t.reduce(((e,t)=>{var a;return e+(null!==(a=t.weight)&&void 0!==a?a:0)}),0),n=t.filter((e=>void 0===e.weight)).reduce(((e,t)=>e+(t.end-t.start)),0),r=100-a;if(r<0)throw new Error("Invalid segment weight.");return t.map((e=>{if(void 0!==e.weight)return e;const t=(e.end-e.start)/n*r;return Object.assign(Object.assign({},e),{weight:t})}))}class r{constructor(e,t){this.chartWidth=t,this.chartName=e.name,this.axis=e.axis,this.constraints=e.constraints,this.segments=n(e)}get name(){return this.chartName}getAxisTicks(){return Object.values(this.axis.ticks).map((e=>{var t;const a=null===(t=e.isVisible)||void 0===t||t;return{label:e.value.toString(),value:this.calculateRawPosition(e.value),isVisible:a}}))}getChartRegions(){return Object.values(this.axis.ticks).slice(1).map((e=>({value:this.calculateRawPosition(e.value),styleClass:this.segmentstyleSuffix(e.value)})))}segmentstyleSuffix(e){const t=this.getSegmentByTick(e);return(null==t?void 0:t.styleSuffix)?`${this.chartName}-${t.styleSuffix}`:""}getSegmentByTick(e){for(const t of this.segments)if(e>=t.start&&e<=t.end)return t;return null}calculatePosition(e){if(this.constraints){const{value:t,position:a}=this.constraints.max;if(e>=t)return a}return this.calculateRawPosition(e)}calculateRawPosition(e){let t=0;const a=this.clampValue(e),{totalSegmentsWidth:n}=this;for(const e of this.segments){if(a>=e.start&&a<=e.end){return t+(a-e.start)/(e.end-e.start)*(e.weight/n)*this.chartWidth}t+=e.weight/n*this.chartWidth}return 0}clampValue(e){return Math.min(Math.max(e,this.axis.ticks[0].value),this.axis.ticks[this.axis.ticks.length-1].value)}get totalSegmentsWidth(){return this.segments.reduce(((e,t)=>e+t.weight),0)}}const s=(e,t)=>t>0?`${e}-axis-marker-label`:`${e}-start-axis-marker-label`,l=(e,t)=>t>0?`${e}-axis-marker`:`${e}-start-axis-marker`;function i({chartName:t,markerText:a,offsetPercent:n}){return e.createElement("div",{className:`${l(t,n)}`,style:{left:`${n}%`}},e.createElement("div",{className:`nhsuk-font-size-16 nhsuk-u-secondary-text-color ${s(t,n)}`},a))}function c({model:t}){return e.createElement(e.Fragment,null,t.getAxisTicks().map((({label:a,value:n,isVisible:r})=>r&&e.createElement(i,{chartName:t.name,markerText:a,offsetPercent:n,key:a}))))}function o(){return e.createElement("svg",{viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M6 9L0.803849 -9.78799e-07L11.1962 -7.02746e-08L6 9Z",fill:"black"}))}const u=(e,t)=>t<=20?`${e}-label-align-left`:t<=80?`${e}-label-align-center`:`${e}-label-align-right`;function m({chartName:t,value:a,offset:n,markerText:r}){return e.createElement("div",{className:`${t}-label-marker`},e.createElement("div",{className:`nhsuk-font-size-16 ${u(t,n)}`},r,e.createElement("span",{className:`${t}-value-marker`},a)))}function d({value:t,model:a,markerText:n}){const r=a.calculatePosition(t),s=Math.pow(10,1),l=Math.round(r*s)/s;return e.createElement(e.Fragment,null,e.createElement("div",{className:`${a.name}-arrow-marker`,style:{left:`${l}%`}},e.createElement(m,{chartName:a.name,value:t,markerText:n,offset:l}),e.createElement(o,null)),e.createElement("div",{className:`${a.name}-value-axis-marker`,style:{left:`${l}%`}}))}function h({value:t,styleClass:a}){return e.createElement("div",{className:a,style:{width:`${t}%`}})}function g({model:t}){return e.createElement(e.Fragment,null,t.getChartRegions().map((({value:t,styleClass:a})=>e.createElement(h,{value:t,styleClass:a,key:t}))))}const f=100;function p({config:t,value:a,markerText:n}){const s=new r(t,f);return e.createElement("div",{className:`${t.name}-graph nhsuk-u-margin-bottom-9`,"aria-hidden":"true"},e.createElement(c,{model:s}),e.createElement(d,{value:a,markerText:n,model:s}),e.createElement(g,{model:s}))}function b({element:t,text:a,className:n,wrapperClassName:r}){return e.createElement("div",{className:`nhsuk-chart-legend-key-wrapper ${null!=r?r:""}`},e.createElement("div",{className:`nhsuk-chart-legend-key ${null!=n?n:""}`},t),a)}function k({legendKeys:a,className:n}){return e.createElement(t.Card,{className:`${n} nhsuk-u-padding-3 nhsuk-chart-legend-card`},a.map((t=>e.createElement(b,Object.assign({key:t.text},t)))))}function y({legendKeys:t,className:a}){return e.createElement("div",{className:a},t.map((t=>e.createElement(b,Object.assign({key:t.text},t)))))}function v({legendKeys:t,borderWrapper:a=!0}){const n="nhsuk-u-margin-top-6 nhsuk-u-margin-bottom-3 nhsuk-u-secondary-text-color nhsuk-body-s";return e.createElement("div",{"aria-hidden":"true"},a?e.createElement(k,{legendKeys:t,className:n}):e.createElement(y,{legendKeys:t,className:n}))}const E={Underweight:"underweight",Healthy:"healthy",Overweight:"overweight"},w=Object.assign(Object.assign({},E),{Obese:"obese"}),x=Object.assign(Object.assign({},E),{Obese1:"obese1",Obese2:"obese2",Obese3:"obese3"});x.Underweight,x.Healthy,x.Underweight,x.Overweight,x.Healthy;class L{constructor(e){this.bounds={lowerBound:17.5,upperBounds:{[w.Underweight]:e.upper[x.Underweight].value,[w.Healthy]:e.upper[x.Healthy].value,[w.Overweight]:e.upper[x.Overweight].value,[w.Obese]:e.upper[x.Obese2].value}}}get chartRange(){return this.bounds.upperBounds[w.Obese]-this.bounds.lowerBound}classificationPercentage(e){return this.offsetPercentage(this.bounds.upperBounds[e])}offsetPercentage(e){return(e-this.bounds.lowerBound)/this.chartRange*100}}function N(){return e.createElement("svg",{viewBox:"1 1 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("g",{clipPath:"url(#clip0_1346_102759)"},e.createElement("path",{xmlns:"http://www.w3.org/2000/svg",d:"M1.93209 4.05025L1.57854 4.40381L1.93209 4.75736L6.17473 9L1.93209 13.2426L1.57854 13.5962L1.93209 13.9497L4.05341 16.0711L4.40697 16.4246L4.76052 16.0711L9.00316 11.8284L13.2458 16.0711L13.5994 16.4246L13.9529 16.0711L16.0742 13.9497L16.4278 13.5962L16.0742 13.2426L11.8316 9L16.0742 4.75736L16.4278 4.40381L16.0742 4.05025L13.9529 1.92893L13.5994 1.57538L13.2458 1.92893L9.00316 6.17157L4.76052 1.92893L4.40697 1.57538L4.05341 1.92893L1.93209 4.05025Z",fill:"black",stroke:"white"})))}function B({bmi:t,model:a}){const n=a.offsetPercentage(t);let r=0;if(n>0){const e=1,t=Math.pow(10,e);r=Math.round(n*t)/t}return e.createElement("div",{className:"nhsuk-bmi-chart-marker",style:{left:`${r}%`}},e.createElement(N,null))}function $({classification:t,model:a}){const n=a.classificationPercentage(t);return e.createElement("div",{className:`nhsuk-bmi-classification-${t}`,style:{width:`${n}%`}})}function T({model:t}){return e.createElement(e.Fragment,null,e.createElement($,{classification:w.Underweight,model:t}),e.createElement($,{classification:w.Healthy,model:t}),e.createElement($,{classification:w.Overweight,model:t}),e.createElement($,{classification:w.Obese,model:t}))}function O({markerText:t,offsetPercent:a}){return e.createElement("div",{className:"nhsuk-bmi-axis-marker",style:{left:`${a}%`}},e.createElement("div",{className:"nhsuk-bmi-axis-marker-label"},t))}function P({model:t}){return e.createElement(e.Fragment,null,e.createElement(O,{markerText:t.bounds.upperBounds[w.Underweight].toString(),offsetPercent:t.classificationPercentage(w.Underweight)}),e.createElement(O,{markerText:t.bounds.upperBounds[w.Healthy].toString(),offsetPercent:t.classificationPercentage(w.Healthy)}),e.createElement(O,{markerText:t.bounds.upperBounds[w.Overweight].toString(),offsetPercent:t.classificationPercentage(w.Overweight)}))}function S({classificationBounds:t,bmi:a}){const n=new L(t);return e.createElement("div",{className:"nhsuk-bmi-graph","aria-hidden":"true"},e.createElement(P,{model:n}),e.createElement(B,{bmi:a,model:n}),e.createElement(T,{model:n}))}const R={Low:"low",Healthy:"healthy",SlightlyRaised:"slightlyRaised",High:"high"};var C;function H({axisType:t,labelText:a,offsetPercent:n,applyLabelSpecificStyles:r=!0}){const s=`${C[t].toLowerCase()}-axis`,l=`nhsuk-bp-${s}-marker`,i=`nhsuk-bp-${s}-marker-${a}`;return e.createElement("div",{className:r?`${l} ${i}`:`${l}`,style:t===C.Systolic?{bottom:`${n}%`}:{left:`${n}%`}},e.createElement("div",{className:`nhsuk-bp-${s}-label`},a))}function U(e,t,a){return(e-a)/(t-a)*100}function j(e,t,a){return U(t[e].value,t[R.High].value,a)}function M({axisType:t,upperBounds:a,lowerBound:n}){const r={slightlyRaisedValueToCheck:85,slightlyRaisedValueToAdd:90};return e.createElement("div",null,e.createElement(H,{labelText:n.toString(),offsetPercent:0,axisType:t}),e.createElement(H,{labelText:a[R.Low].value.toString(),offsetPercent:j(R.Low,a,n),axisType:t}),e.createElement(H,{labelText:a[R.Healthy].value.toString(),offsetPercent:j(R.Healthy,a,n),axisType:t}),e.createElement(H,{labelText:a[R.SlightlyRaised].value.toString(),offsetPercent:j(R.SlightlyRaised,a,n),axisType:t,applyLabelSpecificStyles:a[R.SlightlyRaised].value===r.slightlyRaisedValueToCheck}),t===C.Diastolic&&a[R.SlightlyRaised].value===r.slightlyRaisedValueToCheck&&e.createElement(H,{labelText:r.slightlyRaisedValueToAdd.toString(),offsetPercent:U(r.slightlyRaisedValueToAdd,a[R.High].value,n),axisType:t}),e.createElement(H,{labelText:a[R.High].value.toString(),offsetPercent:100,axisType:t}))}function F({bounds:t}){return e.createElement(e.Fragment,null,e.createElement(M,{axisType:C.Systolic,upperBounds:t.systolic.upper,lowerBound:t.systolic.lower}),e.createElement(M,{axisType:C.Diastolic,upperBounds:t.diastolic.upper,lowerBound:t.diastolic.lower}))}function A(){return e.createElement("svg",{viewBox:"0 0 32 32",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("g",{clipPath:"url(#clip0_1346_102759)"},e.createElement("path",{d:"M5.18718 8.36931L4.48008 9.07641L5.18718 9.78352L11.3744 15.9707L5.18718 22.1579L4.48008 22.865L5.18718 23.5721L8.36916 26.7541L9.07627 27.4612L9.78338 26.7541L15.9706 20.5669L22.1577 26.7541L22.8649 27.4612L23.572 26.7541L26.7539 23.5721L27.461 22.865L26.7539 22.1579L20.5668 15.9707L26.7539 9.78352L27.461 9.07641L26.7539 8.36931L23.572 5.18732L22.8649 4.48022L22.1577 5.18732L15.9706 11.3745L9.78338 5.18732L9.07627 4.48022L8.36916 5.18732L5.18718 8.36931Z",fill:"black",stroke:"white",strokeWidth:"2"})))}function K({systolicReading:t,diastolicReading:n,systolicLowerBound:r,systolicUpperBound:s,diastolicLowerBound:l,diastolicUpperBound:i}){const c=i-l,o=new a((t-r)/(s-r)).times(100),u=new a((n-l)/c).times(100),m=o.round(1),d=u.round(1);return e.createElement("div",{className:"nhsuk-bp-graph-marker",style:{left:`${d}%`,bottom:`${m}%`}},e.createElement(A,null))}function V(e,t,a){return(t[a].value-e)/(t.high.value-e)*100}function W(e){return`nhsuk-bp-classification-${e.toLowerCase()}`}function z({classification:t,bounds:a,renderAsBoundary:n=!1}){const r=V(a.diastolic.lower,a.diastolic.upper,t),s=V(a.systolic.lower,a.systolic.upper,t);return e.createElement("div",{className:n?"nhsuk-bp-region-boundary":W(t),style:{width:`${r}%`,height:`${s}%`}})}function D({bounds:t,renderAsBoundary:a=!1}){return e.createElement(e.Fragment,null,e.createElement(z,{classification:R.Low,bounds:t,renderAsBoundary:a}),e.createElement(z,{classification:R.Healthy,bounds:t,renderAsBoundary:a}),e.createElement(z,{classification:R.SlightlyRaised,bounds:t,renderAsBoundary:a}),!a&&e.createElement(z,{classification:R.High,bounds:t,renderAsBoundary:a}))}function _({firstInRow:t=!1,firstInColumn:a=!1}){let n="nhsuk-bp-graph-cell";return t&&(n+=" nhsuk-bp-first-in-row"),a&&(n+=" nhsuk-bp-first-in-column"),e.createElement("div",{className:n})}function q({bounds:t,graphLayout:a,reading:n}){const{systolic:r,diastolic:s}=n,{systolicLabel:l,diastolicLabel:i}=a;return e.createElement("div",{className:"nhsuk-body-s"},e.createElement("div",{className:"nhsuk-bp-systolic-legend-wrapper","aria-hidden":"true"},e.createElement("div",{className:"nhsuk-bp-systolic-legend-marker"}),e.createElement("span",null,l)),e.createElement("div",{className:"nhsuk-bp-graph","aria-hidden":"true"},e.createElement(F,{bounds:t}),e.createElement(K,{systolicReading:r,diastolicReading:s,systolicLowerBound:t.systolic.lower,systolicUpperBound:t.systolic.upper.high.value,diastolicLowerBound:t.diastolic.lower,diastolicUpperBound:t.diastolic.upper.high.value}),e.createElement(D,{bounds:t}),a.rows.map((t=>e.createElement("div",{key:t.id,className:"nhsuk-bp-graph-row"},t.cells.map((t=>e.createElement(_,Object.assign({key:t.id},t))))))),e.createElement(D,{bounds:t,renderAsBoundary:!0})),e.createElement("div",{className:"nhsuk-bp-diastolic-legend-wrapper","aria-hidden":"true"},e.createElement("div",{className:"nhsuk-bp-diastolic-legend-marker"}),e.createElement("span",null,i)))}!function(e){e[e.Systolic=0]="Systolic",e[e.Diastolic=1]="Diastolic"}(C||(C={})),a.RM=a.roundHalfEven;const I={[x.Underweight]:null,[x.Healthy]:x.Underweight,[x.Overweight]:x.Healthy};class Z{constructor(e){this.bounds={lowerBound:0,upperBounds:{[w.Underweight]:e.upper[x.Underweight].value,[w.Healthy]:e.upper[x.Healthy].value,[w.Overweight]:e.upper[x.Overweight].value}}}get chartRange(){return this.bounds.upperBounds[x.Overweight]-this.bounds.lowerBound}classificationPercentage(e){return this.offsetPercentage(this.bounds.upperBounds[e])}offsetPercentage(e){const t=this.chartRange;if(e<=2){const a=.08*t;return this.calculateOffset(e,E.Underweight,a)}if(e<=91){const a=.72*t,n=.08*t;return this.calculateOffset(e,E.Healthy,a)+n}const a=.2*t,n=.8*t;return this.calculateOffset(e,E.Overweight,a)+n}calculateOffset(e,t,a){const n=I[t]?this.bounds.upperBounds[I[t]]:0;return(e-n)/(this.bounds.upperBounds[t]-n)*a}clampedOffsetPercentage(e){const t=Math.max(1,Math.min(e,99));return this.offsetPercentage(t)}}function G({markerText:t,offsetPercent:a}){return e.createElement("div",{className:"nhsuk-cbmi-axis-marker",style:{left:`${a}%`}},e.createElement("div",{className:"nhsuk-font-size-16 nhsuk-cbmi-axis-marker-label"},t))}function J({model:t}){return e.createElement(e.Fragment,null,e.createElement(G,{markerText:t.bounds.upperBounds[E.Underweight].toString(),offsetPercent:t.classificationPercentage(E.Underweight)}),e.createElement(G,{markerText:t.bounds.upperBounds[E.Healthy].toString(),offsetPercent:t.classificationPercentage(E.Healthy)}))}const Q=e=>e<=20?"nhsuk-cbmi-chart-label-align-left":e<=80?"nhsuk-cbmi-chart-label-align-center":"nhsuk-cbmi-chart-label-align-right";function X({centile:t,markerText:a}){return e.createElement("div",{className:"nhsuk-cbmi-chart-label-marker"},e.createElement("div",{className:`nhsuk-u-font-size-19 ${Q(t.value)}`},a,e.createElement("span",{className:"nhsuk-cbmi-chart-centile-marker"},t.label)))}function Y({centile:t,model:a,markerText:n}){const r=a.clampedOffsetPercentage(t.value);let s=0;if(r>0){const e=1,t=Math.pow(10,e);s=Math.round(r*t)/t}return e.createElement("div",null,e.createElement("div",{className:"nhsuk-cbmi-chart-arrow-marker",style:{left:`${s}%`}},e.createElement(X,{centile:t,markerText:n}),e.createElement(o,null)),e.createElement("div",{className:"nhsuk-cbmi-chart-axis-marker",style:{left:`${s}%`}}))}function ee({classification:t,model:a}){const n=a.classificationPercentage(t);return e.createElement("div",{className:`nhsuk-cbmi-classification-${t}`,style:{width:`${n}%`}})}function te({model:t}){return e.createElement(e.Fragment,null,e.createElement(ee,{classification:E.Underweight,model:t}),e.createElement(ee,{classification:E.Healthy,model:t}),e.createElement(ee,{classification:E.Overweight,model:t}))}function ae({classificationBounds:t,centile:a,markerText:n}){const r=new Z(t);return e.createElement("div",{className:"nhsuk-cbmi-graph nhsuk-u-margin-bottom-9 ","aria-hidden":"true"},e.createElement(J,{model:r}),e.createElement(Y,{centile:a,markerText:n,model:r}),e.createElement(te,{model:r}))}exports.BarSliderChart=p,exports.BarSliderChartFigure=function({config:t,value:a,ariaLabel:n,markerText:r}){const s=Object.values(t.segments).filter((e=>null!=e.legend)).map((e=>({text:e.legend,className:`${t.name}-legend-key-${e.styleSuffix}`,wrapperClassName:`${t.name}-legend-marker`})));return e.createElement("figure",{className:"nhsuk-u-margin-0"},e.createElement("figcaption",{className:"nhsuk-u-visually-hidden"},n),e.createElement(p,{config:t,value:a,markerText:r}),e.createElement(v,{legendKeys:s,borderWrapper:!1}))},exports.BmiChart=S,exports.BmiChartFigure=function({classificationBounds:t,bmi:a,ariaLabel:n,legendKeys:r,legendMarkerText:s}){const l=((t,a)=>Object.entries(t).map((([e,t])=>({text:t,className:`nhsuk-bmi-legend-key-classification-${e}`}))).concat({text:a,className:"nhsuk-bmi-legend-key-marker",element:e.createElement(N,null)}))(r,s);return e.createElement("figure",{className:"nhsuk-u-margin-0"},e.createElement("figcaption",{className:"nhsuk-u-visually-hidden"},n),e.createElement(S,{classificationBounds:t,bmi:a}),e.createElement(v,{legendKeys:l,borderWrapper:!0}))},exports.BpChart=q,exports.BpChartFigure=function({bounds:t,graphLayout:a,reading:n,ariaLabel:r,legendKeys:s,legendMarkerText:l}){const i=((t,a)=>Object.entries(t).map((([e,t])=>({text:t,className:`nhsuk-bp-legend-key-classification-${e}`}))).concat({text:a,className:"nhsuk-bp-legend-key-marker",element:e.createElement(A,null)}))(s,l);return e.createElement("figure",{className:"nhsuk-u-margin-0"},e.createElement("figcaption",{className:"nhsuk-u-visually-hidden"},r),e.createElement(q,{bounds:t,reading:n,graphLayout:a}),e.createElement(v,{legendKeys:i}))},exports.ChartLegend=v,exports.ChildBmiChart=ae,exports.ChildBmiChartFigure=function({classificationBounds:t,centile:a,centileMarkerText:n,ariaLabel:r,legendKeys:s}){const l=Object.entries(s).map((([e,t])=>({text:t,className:`nhsuk-cbmi-legend-key-classification-${e}`,wrapperClassName:"nhsuk-cbmi-legend-marker"})));return e.createElement("figure",{className:"nhsuk-u-margin-0"},e.createElement("figcaption",{className:"nhsuk-u-visually-hidden"},r),e.createElement(ae,{classificationBounds:t,centile:a,markerText:n}),e.createElement(v,{legendKeys:l,borderWrapper:!1}))};
2
2
  //# sourceMappingURL=index.js.map