@cdc/chart 4.26.6 → 4.26.7

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.
Files changed (60) hide show
  1. package/CONFIG.md +9 -7
  2. package/dist/cdcchart.js +32200 -31292
  3. package/examples/private/flueview.json +22051 -0
  4. package/package.json +3 -11
  5. package/src/CdcChart.tsx +2 -2
  6. package/src/CdcChartComponent.tsx +40 -10
  7. package/src/_stories/Chart.PieLabels.stories.tsx +47 -0
  8. package/src/_stories/Chart.smoke.stories.tsx +14 -1
  9. package/src/_stories/ChartPrefixSuffix.smoke.stories.tsx +28 -1
  10. package/src/components/BarChart/components/BarChart.Horizontal.tsx +1 -2
  11. package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +1 -1
  12. package/src/components/BarChart/components/BarChart.StackedVertical.tsx +1 -1
  13. package/src/components/BarChart/components/BarChart.Vertical.tsx +1 -2
  14. package/src/components/BarChart/helpers/getBarData.ts +28 -28
  15. package/src/components/BarChart/helpers/getBarHeights.ts +2 -2
  16. package/src/components/BarChart/helpers/tests/useBarChart.test.tsx +98 -0
  17. package/src/components/BarChart/helpers/useBarChart.ts +4 -5
  18. package/src/components/BoxPlot/BoxPlot.Horizontal.tsx +7 -6
  19. package/src/components/BoxPlot/BoxPlot.Vertical.tsx +9 -7
  20. package/src/components/BoxPlot/helpers/index.ts +4 -3
  21. package/src/components/Brush/BrushSelector.tsx +1 -1
  22. package/src/components/EditorPanel/EditorPanel.tsx +90 -29
  23. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +16 -7
  24. package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +3 -3
  25. package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +19 -4
  26. package/src/components/EditorPanel/helpers/updateFieldRankByValue.ts +3 -3
  27. package/src/components/EditorPanel/useEditorPermissions.test.tsx +32 -0
  28. package/src/components/EditorPanel/useEditorPermissions.ts +5 -1
  29. package/src/components/Forecasting/Forecasting.tsx +1 -1
  30. package/src/components/Legend/Legend.Component.tsx +54 -59
  31. package/src/components/Legend/Legend.Suppression.tsx +3 -3
  32. package/src/components/Legend/LegendGroup/LegendGroup.tsx +0 -1
  33. package/src/components/LineChart/helpers.ts +0 -2
  34. package/src/components/LineChart/index.tsx +2 -3
  35. package/src/components/LinearChart.tsx +4 -3
  36. package/src/components/PieChart/PieChart.tsx +117 -10
  37. package/src/components/PieChart/helpers/labelPlacement.test.ts +88 -0
  38. package/src/components/PieChart/helpers/labelPlacement.ts +95 -0
  39. package/src/components/ScatterPlot/ScatterPlot.jsx +2 -10
  40. package/src/data/initial-state.js +2 -0
  41. package/src/helpers/categoryOrder.ts +60 -0
  42. package/src/helpers/getBoxPlotConfig.ts +19 -12
  43. package/src/helpers/getComboChartConfig.ts +0 -1
  44. package/src/helpers/getExcludedData.ts +0 -1
  45. package/src/helpers/getHasBoundarySuppression.ts +4 -3
  46. package/src/helpers/getMinMax.ts +2 -1
  47. package/src/helpers/getNewRuntime.ts +0 -2
  48. package/src/helpers/getPiePercent.ts +3 -3
  49. package/src/helpers/isConvertLineToBarGraph.ts +2 -2
  50. package/src/helpers/seriesColumnSettings.ts +21 -3
  51. package/src/helpers/sizeHelpers.ts +0 -2
  52. package/src/helpers/tests/categoryOrder.test.ts +57 -0
  53. package/src/helpers/tests/seriesColumnSettings.test.ts +60 -0
  54. package/src/hooks/tests/useRightAxis.test.tsx +143 -2
  55. package/src/hooks/tests/useScales.test.tsx +3 -6
  56. package/src/hooks/tests/useTooltip.test.tsx +132 -0
  57. package/src/hooks/useRightAxis.ts +19 -26
  58. package/src/hooks/useTooltip.tsx +14 -10
  59. package/src/store/chart.reducer.ts +0 -1
  60. package/src/test/CdcChart.dataTable.test.tsx +94 -0
@@ -8,7 +8,11 @@ import { isDateScale } from '@cdc/core/helpers/cove/date'
8
8
  // Third-party library imports
9
9
  import { localPoint } from '@visx/event'
10
10
  import { bisector } from 'd3-array'
11
- import _ from 'lodash'
11
+ import find from 'lodash/find'
12
+ import omit from 'lodash/omit'
13
+ import pick from 'lodash/pick'
14
+ import round from 'lodash/round'
15
+ import uniq from 'lodash/uniq'
12
16
  import { getHorizontalBarHeights } from '../components/BarChart/helpers/getBarHeights'
13
17
  import {
14
18
  findColumnConfigByName,
@@ -148,11 +152,11 @@ export const useTooltip = props => {
148
152
  const columnName = column.name || colKey
149
153
  if (seriesOwnedColumnNames.includes(columnName)) continue
150
154
 
155
+ // Extra columns own their affixes; explicit blanks prevent fallback to the value-axis units.
151
156
  const formattingParams = {
152
- addColPrefix: column.prefix,
153
- addColSuffix: column.suffix,
154
- addColRoundTo: column.roundToPlace || '',
155
- addColCommas: column.commas
157
+ addColPrefix: '',
158
+ addColSuffix: '',
159
+ ...getSeriesColumnFormattingParams(column)
156
160
  }
157
161
 
158
162
  const pieColumnData = additionalChartData?.data?.[column.name]
@@ -328,7 +332,7 @@ export const useTooltip = props => {
328
332
 
329
333
  const runtimeSeries =
330
334
  config.tooltips.singleSeries && visualizationType === 'Line'
331
- ? [_.find(config.runtime.series, d => d.dataKey === singleSeriesValue)]
335
+ ? [find(config.runtime.series, d => d.dataKey === singleSeriesValue)]
332
336
  : config.runtime.series
333
337
 
334
338
  runtimeSeries?.forEach(series => {
@@ -569,7 +573,7 @@ export const useTooltip = props => {
569
573
  const barsWithHeights = getHorizontalBarHeights<{ group }>(config, barGroups)
570
574
 
571
575
  const barGroup = findClosest(
572
- barsWithHeights.map(d => [d, _.round(d.y)]),
576
+ barsWithHeights.map(d => [d, round(d.y)]),
573
577
  mouseY
574
578
  )
575
579
 
@@ -580,7 +584,7 @@ export const useTooltip = props => {
580
584
  const seriesWithY = config.series.map((c, i) => [c, config.barHeight * i]) as [Object, number][]
581
585
  const hoveredSeries = findClosest(seriesWithY, subGroupMouseY)
582
586
  const exludeColumns = config.series.filter(s => s.dataKey !== hoveredSeries.dataKey).map(s => s.dataKey)
583
- const dataColumn = _.omit(columns[0], exludeColumns)
587
+ const dataColumn = omit(columns[0], exludeColumns)
584
588
  return dataColumn
585
589
  } else {
586
590
  const columnsWithY = columns.map((c, i) => [c, config.barHeight * i]) as [Object, number][]
@@ -661,7 +665,7 @@ export const useTooltip = props => {
661
665
  const includedSeries = runtimeSeries.map(item => item.dataKey)
662
666
  includedSeries.push(config.xAxis.dataKey)
663
667
  // get dynamic category series
664
- const dynamicDataCategories = _.uniq(
668
+ const dynamicDataCategories = uniq(
665
669
  config.runtime.series.flatMap(series => {
666
670
  if (series.dynamicCategory) {
667
671
  return [series.dynamicCategory, series.originalDataKey]
@@ -701,7 +705,7 @@ export const useTooltip = props => {
701
705
  }
702
706
  }
703
707
 
704
- return dataToSearch.map(d => _.pick(d, includedSeries))
708
+ return dataToSearch.map(d => pick(d, includedSeries))
705
709
  }
706
710
 
707
711
  /**
@@ -2,7 +2,6 @@ import ChartActions from './chart.actions'
2
2
  import defaults from '../data/initial-state.js'
3
3
  import { ChartConfig, type ViewportSize } from '../types/ChartConfig'
4
4
  import { DimensionsType } from '@cdc/core/types/Dimensions'
5
- import _ from 'lodash'
6
5
 
7
6
  type ChartState = {
8
7
  isLoading: boolean
@@ -119,4 +119,98 @@ describe('CdcChart data table dataset wiring', () => {
119
119
  expect(await screen.findByText('Legacy chart footnote')).toBeInTheDocument()
120
120
  expect(await screen.findByText('Structured chart footnote')).toBeInTheDocument()
121
121
  })
122
+
123
+ it('passes custom category order to the chart-owned data table runtime data', async () => {
124
+ render(
125
+ <CdcChart
126
+ config={
127
+ {
128
+ type: 'chart',
129
+ visualizationType: 'Bar',
130
+ title: 'Custom Category Order Chart',
131
+ data: [
132
+ { category: 'A', value: 1 },
133
+ { category: 'D', value: 4 },
134
+ { category: 'C', value: 3 },
135
+ { category: 'L', value: 12 }
136
+ ],
137
+ xAxis: {
138
+ type: 'categorical',
139
+ dataKey: 'category',
140
+ categoryOrderType: 'custom',
141
+ categoryOrder: ['A', 'C', 'D', 'L']
142
+ },
143
+ series: [{ dataKey: 'value' }],
144
+ table: {
145
+ show: true,
146
+ expanded: true,
147
+ download: true,
148
+ label: 'Data Table',
149
+ indexLabel: ''
150
+ }
151
+ } as any
152
+ }
153
+ interactionLabel='chart-category-order-table-test'
154
+ />
155
+ )
156
+
157
+ await waitFor(() => expect(dataTableProps.length).toBeGreaterThan(0))
158
+
159
+ expect(dataTableProps.at(-1).runtimeData.map(row => row.category)).toEqual(['A', 'C', 'D', 'L'])
160
+ })
161
+
162
+ it('updates metadata-backed chart title and text when dataMetadata changes and data does not', async () => {
163
+ const data = [{ category: 'A', value: 1 }]
164
+ const config = {
165
+ type: 'chart',
166
+ visualizationType: 'Bar',
167
+ title: 'Chart {{source}}',
168
+ introText: 'Intro {{source}}',
169
+ legend: {
170
+ label: 'Legend <strong>{{source}}</strong>',
171
+ description: 'Legend description <strong>{{source}}</strong>'
172
+ },
173
+ data,
174
+ dataMetadata: {},
175
+ enableMarkupVariables: true,
176
+ markupVariables: [
177
+ {
178
+ sourceType: 'metadata',
179
+ name: 'Source',
180
+ tag: '{{source}}',
181
+ metadataKey: 'source',
182
+ conditions: [],
183
+ addCommas: false
184
+ }
185
+ ],
186
+ xAxis: { dataKey: 'category' },
187
+ series: [{ dataKey: 'value' }],
188
+ table: {
189
+ show: false,
190
+ expanded: false,
191
+ label: 'Data Table',
192
+ indexLabel: ''
193
+ }
194
+ } as any
195
+
196
+ const { container, rerender } = render(<CdcChart config={config} interactionLabel='chart-metadata-test' />)
197
+
198
+ expect(await screen.findByText('Chart')).toBeInTheDocument()
199
+
200
+ rerender(
201
+ <CdcChart
202
+ config={{
203
+ ...config,
204
+ dataMetadata: { source: 'June file' }
205
+ }}
206
+ interactionLabel='chart-metadata-test'
207
+ />
208
+ )
209
+
210
+ expect(await screen.findByText('Chart June file')).toBeInTheDocument()
211
+ expect(screen.getByText('Intro June file')).toBeInTheDocument()
212
+ expect(container.textContent).toContain('Legend June file')
213
+ expect(container.textContent).toContain('Legend description June file')
214
+ expect(screen.getAllByText('June file', { selector: 'strong' }).length).toBeGreaterThanOrEqual(2)
215
+ })
122
216
  })