@cdc/waffle-chart 4.25.10 → 4.25.11

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.
@@ -5,53 +5,21 @@ import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
5
5
 
6
6
  import ConfigContext from '../ConfigContext'
7
7
 
8
+ import AdvancedEditor from '@cdc/core/components/AdvancedEditor'
8
9
  import Accordion from '@cdc/core/components/ui/Accordion'
9
10
  import Button from '@cdc/core/components/elements/Button'
10
11
  import Icon from '@cdc/core/components/ui/Icon'
11
12
  import Tooltip from '@cdc/core/components/ui/Tooltip'
12
- import InputText from '@cdc/core/components/inputs/InputText'
13
- import InputSelect from '@cdc/core/components/inputs/InputSelect'
14
- import InputCheckbox from '@cdc/core/components/inputs/InputCheckbox'
13
+ import { TextField, Select, CheckBox } from '@cdc/core/components/EditorPanel/Inputs'
15
14
  import { updateFieldFactory } from '@cdc/core/helpers/updateFieldFactory'
16
15
  import Layout from '@cdc/core/components/Layout'
16
+ import { HeaderThemeSelector } from '@cdc/core/components/HeaderThemeSelector'
17
17
 
18
18
  import '@cdc/core/styles/v2/components/editor.scss'
19
19
  import WarningImage from '../images/warning.svg'
20
20
 
21
21
  import { DATA_OPERATORS, DATA_FUNCTIONS } from '../CdcWaffleChart'
22
22
 
23
- const headerColors = [
24
- 'theme-blue',
25
- 'theme-purple',
26
- 'theme-brown',
27
- 'theme-teal',
28
- 'theme-pink',
29
- 'theme-orange',
30
- 'theme-slate',
31
- 'theme-indigo',
32
- 'theme-cyan',
33
- 'theme-green',
34
- 'theme-amber'
35
- ]
36
-
37
- const CheckBox = memo(
38
- ({ label, value, fieldName, section = null, subsection = null, tooltip, updateField, ...attributes }) => (
39
- <label className='checkbox'>
40
- <input
41
- type='checkbox'
42
- name={fieldName}
43
- checked={value}
44
- onChange={() => {
45
- updateField(section, subsection, fieldName, !value)
46
- }}
47
- {...attributes}
48
- />
49
- <span className='edit-label column-heading'>{label}</span>
50
- <span className='cove-icon'>{tooltip}</span>
51
- </label>
52
- )
53
- )
54
-
55
23
  const EditorPanel = memo(props => {
56
24
  const { config, updateConfig, loading, data, setParentConfig, isDashboard } = useContext(ConfigContext)
57
25
  const { showConfigConfirm } = props
@@ -161,43 +129,31 @@ const EditorPanel = memo(props => {
161
129
  const editorContent = (
162
130
  <Accordion>
163
131
  <Accordion.Section title='General'>
164
- <div className='cove-accordion__panel-section'>
165
- <div style={{ width: '100%', display: 'block' }} className='cove-input-group'>
166
- <InputSelect
167
- value={config.visualizationType}
168
- fieldName='visualizationType'
169
- label='Chart Type'
170
- updateField={updateField}
171
- options={approvedWaffleChartOptions}
172
- className='cove-input'
173
- />
174
- {config.visualizationType === 'Gauge' && (
175
- <InputSelect
176
- value={config.visualizationSubType}
177
- fieldName='visualizationSubType'
178
- label='Chart Subtype'
179
- updateField={updateField}
180
- options={['Linear']}
181
- className='cove-input'
182
- />
183
- )}
184
- </div>
185
- </div>
186
- <InputText
132
+ <Select
133
+ value={config.visualizationType}
134
+ fieldName='visualizationType'
135
+ label='Chart Type'
136
+ updateField={updateField}
137
+ options={approvedWaffleChartOptions}
138
+ />
139
+ {config.visualizationType === 'Gauge' && (
140
+ <Select
141
+ value={config.visualizationSubType}
142
+ fieldName='visualizationSubType'
143
+ label='Chart Subtype'
144
+ updateField={updateField}
145
+ options={['Linear']}
146
+ />
147
+ )}
148
+ <TextField
187
149
  value={config.title}
188
150
  fieldName='title'
189
151
  label='Title'
190
152
  placeholder='Chart Title'
191
153
  updateField={updateField}
192
154
  />
193
- <InputCheckbox
194
- size='small'
195
- label='show title'
196
- value={config.showTitle}
197
- fieldName='showTitle'
198
- updateField={updateField}
199
- />
200
- <InputText
155
+ <CheckBox label='show title' value={config.showTitle} fieldName='showTitle' updateField={updateField} />
156
+ <TextField
201
157
  type='textarea'
202
158
  value={config.content}
203
159
  fieldName='content'
@@ -218,7 +174,7 @@ const EditorPanel = memo(props => {
218
174
  }
219
175
  />
220
176
 
221
- <InputText
177
+ <TextField
222
178
  value={config.subtext}
223
179
  fieldName='subtext'
224
180
  label='Subtext/Citation'
@@ -247,7 +203,7 @@ const EditorPanel = memo(props => {
247
203
  <h4 style={{ fontWeight: '600' }}>Numerator</h4>
248
204
  <div className='cove-accordion__panel-section'>
249
205
  <div className='cove-input-group'>
250
- <InputSelect
206
+ <Select
251
207
  style={inputSelectStyle(!config.dataColumn)}
252
208
  value={config.dataColumn || ''}
253
209
  fieldName='dataColumn'
@@ -255,12 +211,11 @@ const EditorPanel = memo(props => {
255
211
  updateField={updateField}
256
212
  initial='Select'
257
213
  options={getColumns()}
258
- className='cove-input'
259
214
  />
260
215
  </div>
261
216
 
262
217
  <div className='cove-input-group'>
263
- <InputSelect
218
+ <Select
264
219
  style={inputSelectStyle(!config.dataFunction)}
265
220
  value={config.dataFunction || ''}
266
221
  fieldName='dataFunction'
@@ -268,7 +223,6 @@ const EditorPanel = memo(props => {
268
223
  updateField={updateField}
269
224
  initial='Select'
270
225
  options={DATA_FUNCTIONS}
271
- className='cove-input'
272
226
  />
273
227
  </div>
274
228
 
@@ -278,27 +232,25 @@ const EditorPanel = memo(props => {
278
232
  </label>
279
233
  <div className='cove-accordion__panel-row cove-accordion__small-inputs'>
280
234
  <div className='cove-accordion__panel-col'>
281
- <InputSelect
235
+ <Select
282
236
  value={config.dataConditionalColumn || ''}
283
237
  fieldName='dataConditionalColumn'
284
238
  updateField={updateField}
285
239
  initial='Select'
286
240
  options={getColumns()}
287
- className='cove-input'
288
241
  />
289
242
  </div>
290
243
  <div className='cove-accordion__panel-col'>
291
- <InputSelect
244
+ <Select
292
245
  value={config.dataConditionalOperator || ''}
293
246
  fieldName='dataConditionalOperator'
294
247
  updateField={updateField}
295
248
  initial='Select'
296
249
  options={DATA_OPERATORS}
297
- className='cove-input'
298
250
  />
299
251
  </div>
300
252
  <div className='cove-accordion__panel-col'>
301
- <InputText
253
+ <TextField
302
254
  value={config.dataConditionalComparate}
303
255
  fieldName={'dataConditionalComparate'}
304
256
  updateField={updateField}
@@ -322,12 +274,7 @@ const EditorPanel = memo(props => {
322
274
  <div className='cove-accordion__panel-col'>
323
275
  <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
324
276
  <label className='cove-accordion__panel-label--inline'>Select from data</label>
325
- <InputCheckbox
326
- size='small'
327
- value={config.customDenom}
328
- fieldName='customDenom'
329
- updateField={updateField}
330
- />
277
+ <CheckBox value={config.customDenom} fieldName='customDenom' updateField={updateField} />
331
278
  </div>
332
279
  </div>
333
280
  </div>
@@ -335,7 +282,7 @@ const EditorPanel = memo(props => {
335
282
  {!config.customDenom && (
336
283
  <div className='cove-accordion__panel-row align-center'>
337
284
  <div className='cove-accordion__panel-col'>
338
- <InputText value={config.dataDenom} fieldName='dataDenom' updateField={updateField} />
285
+ <TextField value={config.dataDenom} fieldName='dataDenom' updateField={updateField} />
339
286
  </div>
340
287
  <div className='cove-accordion__panel-col' style={{ display: 'flex', alignItems: 'center' }}>
341
288
  <label className='cove-accordion__panel-label--muted'>default (100)</label>
@@ -344,7 +291,7 @@ const EditorPanel = memo(props => {
344
291
  )}
345
292
  {config.customDenom && (
346
293
  <>
347
- <InputSelect
294
+ <Select
348
295
  value={config.dataDenomColumn || ''}
349
296
  fieldName='dataDenomColumn'
350
297
  label='Data Column'
@@ -352,7 +299,7 @@ const EditorPanel = memo(props => {
352
299
  initial='Select'
353
300
  options={getColumns()}
354
301
  />
355
- <InputSelect
302
+ <Select
356
303
  value={config.dataDenomFunction || ''}
357
304
  fieldName='dataDenomFunction'
358
305
  label='Data Function'
@@ -366,13 +313,13 @@ const EditorPanel = memo(props => {
366
313
  <ul className='column-edit'>
367
314
  <li className='three-col'>
368
315
  <div style={{ marginRight: '1rem' }}>
369
- <InputText value={config.prefix} fieldName='prefix' label='Prefix' updateField={updateField} />
316
+ <TextField value={config.prefix} fieldName='prefix' label='Prefix' updateField={updateField} />
370
317
  </div>
371
318
  <div style={{ marginRight: '1rem' }}>
372
- <InputText value={config.suffix} fieldName='suffix' label='Suffix' updateField={updateField} />
319
+ <TextField value={config.suffix} fieldName='suffix' label='Suffix' updateField={updateField} />
373
320
  </div>
374
321
  <div>
375
- <InputText
322
+ <TextField
376
323
  type='number'
377
324
  value={config.roundToPlace}
378
325
  fieldName='roundToPlace'
@@ -386,25 +333,19 @@ const EditorPanel = memo(props => {
386
333
  <>
387
334
  <hr className='cove-accordion__divider' />
388
335
  <div className='cove-accordion__panel-section reverse-labels'>
389
- <InputText
390
- inline
391
- size='small'
336
+ <TextField
392
337
  value={config.valueDescription}
393
338
  label='Value Descriptor'
394
339
  fieldName='valueDescription'
395
340
  updateField={updateField}
396
341
  />
397
- <InputCheckbox
398
- inline
399
- size='small'
342
+ <CheckBox
400
343
  value={config.showPercent}
401
344
  label='Show Percentage'
402
345
  fieldName='showPercent'
403
346
  updateField={updateField}
404
347
  />
405
- <InputCheckbox
406
- inline
407
- size='small'
348
+ <CheckBox
408
349
  label='Show Denominator'
409
350
  value={config.showDenominator}
410
351
  fieldName='showDenominator'
@@ -414,18 +355,20 @@ const EditorPanel = memo(props => {
414
355
  </>
415
356
  )}
416
357
  <label style={{ marginBottom: '1rem' }}>
417
- <span className='edit-label'>Data Point Filters</span>
418
- <Tooltip style={{ textTransform: 'none' }}>
419
- <Tooltip.Target>
420
- <Icon display='question' style={{ marginLeft: '0.5rem' }} />
421
- </Tooltip.Target>
422
- <Tooltip.Content>
423
- <p>
424
- To refine the highlighted data point, specify one or more filters (e.g., "Male" and "Female" for a
425
- column called "Sex").
426
- </p>
427
- </Tooltip.Content>
428
- </Tooltip>
358
+ <span className='edit-label'>
359
+ Data Point Filters
360
+ <Tooltip style={{ textTransform: 'none' }}>
361
+ <Tooltip.Target>
362
+ <Icon display='question' style={{ marginLeft: '0.5rem' }} />
363
+ </Tooltip.Target>
364
+ <Tooltip.Content>
365
+ <p>
366
+ To refine the highlighted data point, specify one or more filters (e.g., "Male" and "Female" for a
367
+ column called "Sex").
368
+ </p>
369
+ </Tooltip.Content>
370
+ </Tooltip>
371
+ </span>
429
372
  </label>
430
373
 
431
374
  {config.filters && (
@@ -441,38 +384,24 @@ const EditorPanel = memo(props => {
441
384
  >
442
385
  Remove
443
386
  </button>
444
- <label>
445
- <span className='edit-label column-heading'>Column</span>
446
- <select
447
- value={filter.columnName}
448
- onChange={e => {
449
- updateFilterProp('columnName', index, e.target.value)
450
- }}
451
- >
452
- <option value=''>- Select Option -</option>
453
- {getColumns().map((dataKey, index) => (
454
- <option value={dataKey} key={index}>
455
- {dataKey}
456
- </option>
457
- ))}
458
- </select>
459
- </label>
460
- <label>
461
- <span className='edit-label column-heading'>Column Value</span>
462
- <select
463
- value={filter.columnValue}
464
- onChange={e => {
465
- updateFilterProp('columnValue', index, e.target.value)
466
- }}
467
- >
468
- <option value=''>- Select Option -</option>
469
- {getFilterColumnValues(index).map((dataKey, index) => (
470
- <option value={dataKey} key={index}>
471
- {dataKey}
472
- </option>
473
- ))}
474
- </select>
475
- </label>
387
+ <Select
388
+ label='Column'
389
+ value={filter.columnName || ''}
390
+ options={getColumns()}
391
+ initial='- Select Option -'
392
+ onChange={e => {
393
+ updateFilterProp('columnName', index, e.target.value)
394
+ }}
395
+ />
396
+ <Select
397
+ label='Column Value'
398
+ value={filter.columnValue || ''}
399
+ options={getFilterColumnValues(index)}
400
+ initial='- Select Option -'
401
+ onChange={e => {
402
+ updateFilterProp('columnValue', index, e.target.value)
403
+ }}
404
+ />
476
405
  </fieldset>
477
406
  ))}
478
407
  </ul>
@@ -481,15 +410,14 @@ const EditorPanel = memo(props => {
481
410
  Add Filter
482
411
  </Button>
483
412
  </Accordion.Section>
484
- <Accordion.Section title='Visual'>
413
+ <Accordion.Section title='Visual' className='panel-visual'>
485
414
  {config.visualizationType !== 'Gauge' && (
486
- <InputSelect
415
+ <Select
487
416
  value={config.shape}
488
417
  fieldName='shape'
489
418
  label='Shape'
490
419
  updateField={updateField}
491
420
  options={['circle', 'square', 'person']}
492
- className='cove-input'
493
421
  />
494
422
  )}
495
423
  {config.visualizationType !== 'Gauge' && (
@@ -498,7 +426,7 @@ const EditorPanel = memo(props => {
498
426
  style={{ marginTop: '1rem', marginBottom: '1rem' }}
499
427
  >
500
428
  <div className='cove-accordion__panel-col'>
501
- <InputText
429
+ <TextField
502
430
  type='number'
503
431
  value={config.nodeWidth}
504
432
  fieldName='nodeWidth'
@@ -507,7 +435,7 @@ const EditorPanel = memo(props => {
507
435
  />
508
436
  </div>
509
437
  <div className='cove-accordion__panel-col'>
510
- <InputText
438
+ <TextField
511
439
  type='number'
512
440
  value={config.nodeSpacer}
513
441
  fieldName='nodeSpacer'
@@ -520,12 +448,11 @@ const EditorPanel = memo(props => {
520
448
 
521
449
  <div className='cove-input-group'>
522
450
  {config.visualizationType !== 'Gauge' && (
523
- <InputSelect
451
+ <Select
524
452
  value={config.orientation}
525
453
  fieldName='orientation'
526
454
  label='Layout'
527
455
  updateField={updateField}
528
- className='cove-input'
529
456
  options={['horizontal', 'vertical']}
530
457
  />
531
458
  )}
@@ -537,7 +464,7 @@ const EditorPanel = memo(props => {
537
464
  </label>
538
465
  <div className='cove-accordion__panel-row cove-accordion__small-inputs align-center'>
539
466
  <div className='cove-accordion__panel-col'>
540
- <InputText type='number' value={config.fontSize} fieldName='fontSize' updateField={updateField} />
467
+ <TextField type='number' value={config.fontSize} fieldName='fontSize' updateField={updateField} />
541
468
  </div>
542
469
  <div className='cove-accordion__panel-col' style={{ display: 'flex', alignItems: 'center' }}>
543
470
  <label className='accordion__panel-label--muted'> default (50px)</label>
@@ -545,68 +472,50 @@ const EditorPanel = memo(props => {
545
472
  </div>
546
473
  </div>
547
474
 
548
- <InputSelect
475
+ <Select
549
476
  value={config.overallFontSize}
550
477
  fieldName='overallFontSize'
551
478
  label='Overall Font Size'
552
479
  updateField={updateField}
553
480
  options={['small', 'medium', 'large']}
554
- className='cove-input'
555
481
  />
556
482
 
557
- <label>
558
- <span className='edit-label cove-input__label'>Theme</span>
559
- <ul className='color-palette'>
560
- {headerColors.map(palette => (
561
- <li
562
- title={palette}
563
- key={palette}
564
- onClick={() => {
565
- updateConfig({ ...config, theme: palette })
566
- }}
567
- className={config.theme === palette ? 'selected ' + palette : palette}
568
- ></li>
569
- ))}
570
- </ul>
571
- </label>
483
+ <HeaderThemeSelector
484
+ selectedTheme={config.theme}
485
+ onThemeSelect={theme => updateConfig({ ...config, theme })}
486
+ label='Theme'
487
+ />
572
488
 
573
489
  <div className='cove-accordion__panel-section reverse-labels'>
574
- <InputCheckbox
575
- inline
576
- size='small'
490
+ <CheckBox
577
491
  value={config.visual.border}
578
492
  section='visual'
579
493
  fieldName='border'
580
494
  label='Display Border'
581
495
  updateField={updateField}
582
496
  />
583
- <InputCheckbox
584
- inline
585
- size='small'
497
+ <CheckBox
586
498
  value={config.visual.borderColorTheme}
587
499
  section='visual'
588
500
  fieldName='borderColorTheme'
589
501
  label='Use theme border color'
590
502
  updateField={updateField}
591
503
  />
592
- <InputCheckbox
593
- size='small'
504
+ <CheckBox
594
505
  value={config.visual.accent}
595
506
  section='visual'
596
507
  fieldName='accent'
597
508
  label='Use Accent Style'
598
509
  updateField={updateField}
599
510
  />
600
- <InputCheckbox
601
- size='small'
511
+ <CheckBox
602
512
  value={config.visual.background}
603
513
  section='visual'
604
514
  fieldName='background'
605
515
  label='Use Theme Background Color'
606
516
  updateField={updateField}
607
517
  />
608
- <InputCheckbox
609
- size='small'
518
+ <CheckBox
610
519
  value={config.visual.hideBackgroundColor}
611
520
  section='visual'
612
521
  fieldName='hideBackgroundColor'
@@ -630,7 +539,10 @@ const EditorPanel = memo(props => {
630
539
  title='Configure Waffle Chart'
631
540
  showEditorPanel={displayPanel}
632
541
  >
633
- {editorContent}
542
+ <>
543
+ {editorContent}
544
+ <AdvancedEditor loadConfig={updateConfig} config={config} convertStateToConfig={convertStateToConfig} />
545
+ </>
634
546
  </Layout.Sidebar>
635
547
  {props.children}
636
548
  </>
@@ -1,17 +1,7 @@
1
+ @import '@cdc/core/styles/accessibility';
1
2
  @import 'waffle-chart';
2
3
 
3
4
  .cdc-open-viz-module.type-waffle-chart {
4
- .loader {
5
- width: 100%;
6
- text-align: center;
7
- display: inline-block;
8
- animation: spin 1s linear infinite;
9
-
10
- &::before {
11
- content: '\21BB';
12
- }
13
- }
14
-
15
5
  .cove-component__content:not(.component--has-background, .component--hideBackgroundColor) {
16
6
  background-color: white;
17
7
  }
@@ -23,4 +13,4 @@
23
13
  &.is-editor .cove-editor__content .cove-component {
24
14
  padding-left: 0px;
25
15
  }
26
- }
16
+ }
@@ -1,32 +1,13 @@
1
- @mixin set-theme($property, $color) {
2
- @if $property == 'background-color' {
3
- background-color: $color;
4
- } @else if $property == 'border-color' {
5
- border-color: $color;
6
- } @else if $property == 'color' {
7
- color: $color;
8
- }
9
- }
1
+ // Remove custom theme mixin - use core styles instead
10
2
 
11
- .warning-icon {
12
- position: absolute;
13
- top: 50%;
14
- left: 20%;
15
- transform: translate(-50%, -50%);
16
- color: red;
17
- }
18
3
 
19
4
  .type-dashboard .type-waffle-chart .cove-component__content {
20
5
  padding-top: 0;
21
6
  }
22
7
 
23
- .cove {
24
- &-editor__panel {
25
- ul.color-palette {
26
- margin: 0;
27
- }
28
- }
8
+ // Let core styles handle color palette
29
9
 
10
+ .cove {
30
11
  .cove-gauge-chart {
31
12
  &__chart {
32
13
  width: 85%;
@@ -38,7 +19,7 @@
38
19
  justify-items: center;
39
20
  align-items: flex-start;
40
21
 
41
- & > svg {
22
+ &>svg {
42
23
  margin: 0.7em 0;
43
24
  }
44
25
  }
@@ -47,6 +28,7 @@
47
28
  font-style: italic;
48
29
  font-size: 0.9em !important;
49
30
  }
31
+
50
32
  &__text {
51
33
  line-height: 1.25em;
52
34
  font-weight: 400;
@@ -115,11 +97,13 @@
115
97
  }
116
98
 
117
99
  @at-root {
100
+
118
101
  .cove-waffle-chart.font-small,
119
102
  .cove-gauge-chart.font-small #{&} {
120
103
  .cove-waffle-chart__data--primary {
121
104
  font-size: 35px;
122
105
  }
106
+
123
107
  .cove-waffle-chart__data--text {
124
108
  font-size: 14px;
125
109
  }
@@ -130,6 +114,7 @@
130
114
  .cove-waffle-chart__data--primary {
131
115
  font-size: 50px;
132
116
  }
117
+
133
118
  .cove-waffle-chart__data--text {
134
119
  font-size: 18px;
135
120
  }
@@ -140,8 +125,9 @@
140
125
  .cove-waffle-chart__data--primary {
141
126
  font-size: 80px;
142
127
  }
128
+
143
129
  .cove-waffle-chart__data--text {
144
130
  font-size: 20px;
145
131
  }
146
132
  }
147
- }
133
+ }
@@ -1,7 +1,7 @@
1
1
  import { Config } from '../types/Config'
2
2
  import ChartActions from './chart.actions'
3
3
 
4
- export type ChartState = {
4
+ type ChartState = {
5
5
  config?: Config
6
6
  container: any
7
7
  coveLoadedHasRan: boolean