@cdc/chart 4.26.3 → 4.26.4

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 (128) hide show
  1. package/CONFIG.md +169 -0
  2. package/README.md +42 -17
  3. package/dist/cdcchart.js +34725 -33730
  4. package/examples/feature/bar/additional-column-tooltip.json +3 -3
  5. package/examples/feature/deviation/planet-deviation-config.json +2 -2
  6. package/examples/feature/paired-bar/paired-bar-example.json +2 -2
  7. package/examples/feature/tests-case-rate/case-rate-example-config.json +2 -2
  8. package/examples/feature/tests-covid/covid-confidence-example-config.json +2 -2
  9. package/examples/feature/tests-covid/covid-example-config.json +2 -2
  10. package/examples/feature/tests-cutoff/cutoff-example-config.json +2 -2
  11. package/examples/feature/tests-non-numerics/planet-pie-example-config-nonnumeric.json +2 -2
  12. package/examples/metadata-variables.json +1 -1
  13. package/examples/minimal-example.json +24 -0
  14. package/examples/private/test2.json +35012 -0
  15. package/package.json +4 -4
  16. package/src/CdcChartComponent.tsx +9 -6
  17. package/src/_stories/{Chart.HTMLInDataTable.stories.tsx → Chart.HTMLInDataTable.smoke.stories.tsx} +10 -0
  18. package/src/_stories/Chart.Minimal.smoke.stories.tsx +25 -0
  19. package/src/_stories/{Chart.SmallMultiples.stories.tsx → Chart.SmallMultiples.smoke.stories.tsx} +17 -1
  20. package/src/_stories/{Chart.stories.tsx → Chart.smoke.stories.tsx} +12 -0
  21. package/src/_stories/{Chart.tooltip.stories.tsx → Chart.tooltip.smoke.stories.tsx} +68 -0
  22. package/src/_stories/ChartBar.Editor.stories.tsx +88 -85
  23. package/src/_stories/ChartEditor.Editor.stories.tsx +23 -0
  24. package/src/_stories/ChartLine.DashedDates.smoke.stories.tsx +23 -0
  25. package/src/_stories/_mock/line_chart_dashed_dates.json +276 -0
  26. package/src/_stories/_mock/paired-bar-abbr.json +1 -1
  27. package/src/_stories/_mock/paired-bar.json +1 -1
  28. package/src/components/Annotations/components/AnnotationDraggable.tsx +1 -1
  29. package/src/components/AreaChart/components/AreaChart.Stacked.jsx +10 -2
  30. package/src/components/Axis/BottomAxis.tsx +1 -1
  31. package/src/components/Axis/LeftAxis.tsx +2 -4
  32. package/src/components/Axis/LeftAxisGridlines.tsx +1 -3
  33. package/src/components/BarChart/components/BarChart.Horizontal.tsx +9 -5
  34. package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +9 -5
  35. package/src/components/BarChart/components/BarChart.StackedVertical.tsx +9 -5
  36. package/src/components/BarChart/components/BarChart.Vertical.tsx +9 -6
  37. package/src/components/BarChart/components/BarChart.tsx +2 -6
  38. package/src/components/BarChart/helpers/useBarChart.ts +1 -1
  39. package/src/components/BoxPlot/BoxPlot.Vertical.tsx +3 -3
  40. package/src/components/EditorPanel/EditorPanel.tsx +633 -908
  41. package/src/components/EditorPanel/EditorPanelContext.ts +1 -1
  42. package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +216 -165
  43. package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +168 -116
  44. package/src/components/EditorPanel/components/Panels/Panel.Regions.tsx +154 -109
  45. package/src/components/EditorPanel/components/Panels/Panel.Sankey.tsx +3 -3
  46. package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +12 -26
  47. package/src/components/EditorPanel/useEditorPermissions.ts +1 -10
  48. package/src/components/Forecasting/Forecasting.tsx +2 -2
  49. package/src/components/HorizonChart/HorizonChart.tsx +10 -2
  50. package/src/components/HoverLine/HoverLine.tsx +6 -8
  51. package/src/components/Legend/Legend.Component.tsx +4 -4
  52. package/src/components/Legend/LegendGroup/LegendGroup.styles.css +5 -0
  53. package/src/components/Legend/LegendGroup/LegendGroup.tsx +3 -1
  54. package/src/components/Legend/helpers/index.ts +0 -2
  55. package/src/components/LineChart/LineChartProps.ts +1 -0
  56. package/src/components/LineChart/components/LineChart.BumpCircle.tsx +3 -2
  57. package/src/components/LineChart/index.tsx +11 -4
  58. package/src/components/LinearChart/VisualizationRenderer.tsx +11 -1
  59. package/src/components/LinearChart/tests/LinearChart.test.tsx +147 -0
  60. package/src/components/LinearChart.tsx +98 -41
  61. package/src/components/PairedBarChart.jsx +2 -2
  62. package/src/components/PieChart/PieChart.tsx +11 -9
  63. package/src/components/Regions/components/Regions.tsx +30 -20
  64. package/src/components/ScatterPlot/ScatterPlot.jsx +19 -17
  65. package/src/components/SmallMultiples/SmallMultipleTile.tsx +1 -0
  66. package/src/components/Sparkline/components/SparkLine.tsx +1 -1
  67. package/src/components/WarmingStripes/WarmingStripes.tsx +5 -3
  68. package/src/data/initial-state.js +1 -0
  69. package/src/helpers/calculateLeftYAxisWidth.ts +193 -0
  70. package/src/helpers/tests/tooltipHelpers.test.ts +151 -0
  71. package/src/helpers/tooltipHelpers.ts +176 -0
  72. package/src/hooks/useHighlightedBars.ts +9 -16
  73. package/src/hooks/useProgrammaticTooltip.ts +16 -2
  74. package/src/hooks/useSmallMultipleSynchronization.ts +3 -4
  75. package/src/hooks/useTooltip.tsx +167 -38
  76. package/src/test/CdcChart.test.jsx +24 -0
  77. package/src/types/ChartConfig.ts +1 -0
  78. package/LICENSE +0 -201
  79. package/examples/chart-regression-2.json +0 -2360
  80. package/examples/feature/__data__/age-adjusted-rates.json +0 -1486
  81. package/examples/feature/__data__/city-temperature.json +0 -2198
  82. package/examples/feature/bar/Barchart_with_negative.json +0 -34
  83. package/examples/feature/boxplot/box-plot-data.json +0 -71
  84. package/examples/feature/boxplot/boxplot-data.json +0 -156
  85. package/examples/feature/combo/combochart-categories_are_numbers .json +0 -18
  86. package/examples/feature/forest-plot/log.json +0 -26
  87. package/examples/feature/tests-date-exclusions/date-exclusions-data.json +0 -162
  88. package/examples/region-issue.json +0 -2065
  89. package/examples/xaxis.json +0 -493
  90. /package/examples/{data → __data__}/data-with-metadata.json +0 -0
  91. /package/examples/feature/bar/{tall-data.json → __data__/tall-data.json} +0 -0
  92. /package/examples/feature/deviation/{planet-deviation-data.json → __data__/planet-deviation-data.json} +0 -0
  93. /package/examples/feature/paired-bar/{paired-bar-data.json → __data__/paired-bar-data.json} +0 -0
  94. /package/examples/feature/paired-bar/{paired-bar-formatted.json → __data__/paired-bar-formatted.json} +0 -0
  95. /package/examples/feature/tests-case-rate/{case-rate-example-data.json → __data__/case-rate-example-data.json} +0 -0
  96. /package/examples/feature/tests-covid/{covid-example-data-confidence.json → __data__/covid-example-data-confidence.json} +0 -0
  97. /package/examples/feature/tests-covid/{covid-example-data.json → __data__/covid-example-data.json} +0 -0
  98. /package/examples/feature/tests-cutoff/{cutoff-example-data.json → __data__/cutoff-example-data.json} +0 -0
  99. /package/examples/feature/tests-non-numerics/{planet-example-data-nonnumeric.json → __data__/planet-example-data-nonnumeric.json} +0 -0
  100. /package/src/_stories/{Chart.Anchors.stories.tsx → Chart.Anchors.smoke.stories.tsx} +0 -0
  101. /package/src/_stories/{Chart.BoxPlot.stories.tsx → Chart.BoxPlot.smoke.stories.tsx} +0 -0
  102. /package/src/_stories/{Chart.CI.stories.tsx → Chart.CI.smoke.stories.tsx} +0 -0
  103. /package/src/_stories/{Chart.Combo.stories.tsx → Chart.Combo.smoke.stories.tsx} +0 -0
  104. /package/src/_stories/{Chart.CustomColors.stories.tsx → Chart.CustomColors.smoke.stories.tsx} +0 -0
  105. /package/src/_stories/{Chart.Defaults.stories.tsx → Chart.Defaults.smoke.stories.tsx} +0 -0
  106. /package/src/_stories/{Chart.DynamicSeries.stories.tsx → Chart.DynamicSeries.smoke.stories.tsx} +0 -0
  107. /package/src/_stories/{Chart.Filters.stories.tsx → Chart.Filters.smoke.stories.tsx} +0 -0
  108. /package/src/_stories/{Chart.Forecast.stories.tsx → Chart.Forecast.smoke.stories.tsx} +0 -0
  109. /package/src/_stories/{Chart.Legend.Gradient.stories.tsx → Chart.Legend.Gradient.smoke.stories.tsx} +0 -0
  110. /package/src/_stories/{Chart.Patterns.stories.tsx → Chart.Patterns.smoke.stories.tsx} +0 -0
  111. /package/src/_stories/{Chart.PreserveDecimals.stories.tsx → Chart.PreserveDecimals.smoke.stories.tsx} +0 -0
  112. /package/src/_stories/{Chart.Regions.Categorical.stories.tsx → Chart.Regions.Categorical.smoke.stories.tsx} +0 -0
  113. /package/src/_stories/{Chart.Regions.DateScale.stories.tsx → Chart.Regions.DateScale.smoke.stories.tsx} +0 -0
  114. /package/src/_stories/{Chart.Regions.DateTimeScale.stories.tsx → Chart.Regions.DateTimeScale.smoke.stories.tsx} +0 -0
  115. /package/src/_stories/{Chart.ScatterPlot.stories.tsx → Chart.ScatterPlot.smoke.stories.tsx} +0 -0
  116. /package/src/_stories/{Chart.SmallestLeftAxisMax.stories.tsx → Chart.SmallestLeftAxisMax.smoke.stories.tsx} +0 -0
  117. /package/src/_stories/{ChartAnnotation.stories.tsx → ChartAnnotation.smoke.stories.tsx} +0 -0
  118. /package/src/_stories/{ChartAxisLabels.stories.tsx → ChartAxisLabels.smoke.stories.tsx} +0 -0
  119. /package/src/_stories/{ChartAxisTitles.stories.tsx → ChartAxisTitles.smoke.stories.tsx} +0 -0
  120. /package/src/_stories/{ChartBrush.Matrix.Continuous.stories.tsx → ChartBrush.Matrix.Continuous.smoke.stories.tsx} +0 -0
  121. /package/src/_stories/{ChartBrush.Matrix.Date.stories.tsx → ChartBrush.Matrix.Date.smoke.stories.tsx} +0 -0
  122. /package/src/_stories/{ChartBrush.Matrix.DateTime.stories.tsx → ChartBrush.Matrix.DateTime.smoke.stories.tsx} +0 -0
  123. /package/src/_stories/{ChartBrush.stories.tsx → ChartBrush.smoke.stories.tsx} +0 -0
  124. /package/src/_stories/{ChartLine.QuadrantAngles.stories.tsx → ChartLine.QuadrantAngles.smoke.stories.tsx} +0 -0
  125. /package/src/_stories/{ChartLine.Suppression.stories.tsx → ChartLine.Suppression.smoke.stories.tsx} +0 -0
  126. /package/src/_stories/{ChartLine.Symbols.stories.tsx → ChartLine.Symbols.smoke.stories.tsx} +0 -0
  127. /package/src/_stories/{ChartPrefixSuffix.stories.tsx → ChartPrefixSuffix.smoke.stories.tsx} +0 -0
  128. /package/src/_stories/{TechAdoptionWithLinks.stories.tsx → TechAdoptionWithLinks.smoke.stories.tsx} +0 -0
@@ -8,13 +8,21 @@ 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 _, { get } from 'lodash'
11
+ import _ from 'lodash'
12
12
  import { getHorizontalBarHeights } from '../components/BarChart/helpers/getBarHeights'
13
13
  import {
14
14
  findColumnConfigByName,
15
15
  getSeriesColumnFormattingParams,
16
16
  getSeriesOwnedColumnNames
17
17
  } from '../helpers/seriesColumnSettings'
18
+ import {
19
+ buildTooltipRow,
20
+ getTooltipSeriesMarker,
21
+ tooltipHasMarkerColumn,
22
+ type TooltipRow
23
+ } from '../helpers/tooltipHelpers'
24
+ import { publishAnalyticsEvent } from '@cdc/core/helpers/metrics/helpers'
25
+ import { getVizSubType, getVizTitle } from '@cdc/core/helpers/metrics/utils'
18
26
 
19
27
  export const useTooltip = props => {
20
28
  // Track the last X-axis value to prevent duplicate analytics events
@@ -22,6 +30,7 @@ export const useTooltip = props => {
22
30
  const {
23
31
  tableData: data,
24
32
  config,
33
+ colorScale,
25
34
  formatNumber,
26
35
  capitalize,
27
36
  formatDate,
@@ -33,7 +42,6 @@ export const useTooltip = props => {
33
42
  const { xScale, yScale, seriesScale, showTooltip, hideTooltip, interactionLabel = '' } = props
34
43
  const { xAxis, visualizationType, orientation, yAxis, runtime } = config
35
44
  const seriesOwnedColumnNames = getSeriesOwnedColumnNames(config.series)
36
-
37
45
  // Track the latest xScale in a ref to prevent stale closures
38
46
  const xScaleRef = useRef(xScale)
39
47
 
@@ -42,7 +50,7 @@ export const useTooltip = props => {
42
50
  xScaleRef.current = xScale
43
51
  }, [xScale])
44
52
 
45
- const Y_AXIS_SIZE = Number(config.yAxis.size || 0)
53
+ const Y_AXIS_SIZE = Number(props.yAxisWidth || 0)
46
54
 
47
55
  // function handles only Single series hovered data tooltips
48
56
  const findDataKeyByThreshold = (mouseY, datapoint) => {
@@ -85,11 +93,38 @@ export const useTooltip = props => {
85
93
  const formattedValue =
86
94
  seriesKey === config.xAxis.dataKey
87
95
  ? value
88
- : formatColNumber(value, getAxisPosition(seriesKey), true, config, formattingParams)
96
+ : formatColNumber(value, getAxisPosition(seriesKey), false, config, formattingParams)
89
97
 
90
98
  return showMissingDataValue ? 'N/A' : formattedValue
91
99
  }
92
100
 
101
+ const createTooltipRow = ({
102
+ key,
103
+ value,
104
+ kind,
105
+ axisPosition,
106
+ seriesKey
107
+ }: {
108
+ key: string
109
+ value: string | number
110
+ kind: TooltipRow['kind']
111
+ axisPosition?: string
112
+ seriesKey?: string
113
+ }): TooltipRow =>
114
+ (() => {
115
+ const marker = kind === 'series' ? getTooltipSeriesMarker(config, colorScale, seriesKey || key) : null
116
+
117
+ return buildTooltipRow({
118
+ key,
119
+ value,
120
+ axisPosition,
121
+ kind,
122
+ seriesKey,
123
+ markerColor: marker?.markerColor ?? null,
124
+ markerShape: marker?.markerShape
125
+ })
126
+ })()
127
+
93
128
  /**
94
129
  * Handles the mouse over event for the tooltip.
95
130
  * @function handleTooltipMouseOver
@@ -108,7 +143,7 @@ export const useTooltip = props => {
108
143
  const singleSeriesValue = getYValueFromCoordinate(y, resolvedScaleValues)
109
144
 
110
145
  const columnsWithTooltips = []
111
- const tooltipItems = [] as any[][]
146
+ const tooltipItems: TooltipRow[] = []
112
147
  for (const [colKey, column] of Object.entries(config.columns)) {
113
148
  const columnName = column.name || colKey
114
149
  if (seriesOwnedColumnNames.includes(columnName)) continue
@@ -129,16 +164,22 @@ export const useTooltip = props => {
129
164
  : resolvedScaleValues[0]?.[colKey]
130
165
  const closestValue = config.visualizationType === 'Pie' ? pieColumnData : columnData
131
166
 
132
- const formattedValue = formatColNumber(closestValue, 'left', true, config, formattingParams)
167
+ const formattedValue = formatColNumber(closestValue, 'left', false, config, formattingParams)
133
168
 
134
169
  if (column.tooltips) {
135
170
  columnsWithTooltips.push([column.label, formattedValue])
136
171
  }
137
172
  }
138
- const additionalTooltipItems = [] as [string, string | number][]
173
+ const additionalTooltipItems: TooltipRow[] = []
139
174
 
140
175
  columnsWithTooltips.forEach(columnData => {
141
- additionalTooltipItems.push([columnData[0], columnData[1]])
176
+ additionalTooltipItems.push(
177
+ createTooltipRow({
178
+ key: columnData[0],
179
+ value: columnData[1],
180
+ kind: 'extra'
181
+ })
182
+ )
142
183
  })
143
184
 
144
185
  if (visualizationType === 'Pie') {
@@ -155,21 +196,46 @@ export const useTooltip = props => {
155
196
  const showPiePercent = config.dataFormat.showPiePercent || false
156
197
 
157
198
  if (showPiePercent && pieData[config.xAxis.dataKey] === 'Calculated Area') {
158
- tooltipItems.push(['', 'Calculated Area'])
199
+ tooltipItems.push(
200
+ createTooltipRow({
201
+ key: '',
202
+ value: 'Calculated Area',
203
+ kind: 'heading'
204
+ })
205
+ )
159
206
  } else {
160
207
  tooltipItems.push(
161
- [config.xAxis.dataKey, pieData[config.xAxis.dataKey]],
162
- [
163
- config.runtime.yAxis.label || config.runtime.yAxis.dataKey,
164
- showPiePercent ? pctString(actualPieValue) : formatNumber(pieData[config.runtime.yAxis.dataKey])
165
- ],
166
- showPiePercent ? [] : ['Percent', pctString(pctOf360)]
208
+ createTooltipRow({
209
+ key: config.xAxis.dataKey,
210
+ value: pieData[config.xAxis.dataKey],
211
+ kind: 'heading'
212
+ }),
213
+ createTooltipRow({
214
+ key: config.runtime.yAxis.label || config.runtime.yAxis.dataKey,
215
+ value: showPiePercent ? pctString(actualPieValue) : formatNumber(pieData[config.runtime.yAxis.dataKey]),
216
+ kind: 'extra'
217
+ })
167
218
  )
219
+ if (!showPiePercent) {
220
+ tooltipItems.push(
221
+ createTooltipRow({
222
+ key: 'Percent',
223
+ value: pctString(pctOf360),
224
+ kind: 'extra'
225
+ })
226
+ )
227
+ }
168
228
  }
169
229
  }
170
230
 
171
231
  if (visualizationType === 'Forest Plot') {
172
- tooltipItems.push([config.xAxis.dataKey, getClosestYValue(y)])
232
+ tooltipItems.push(
233
+ createTooltipRow({
234
+ key: config.xAxis.dataKey,
235
+ value: getClosestYValue(y),
236
+ kind: 'heading'
237
+ })
238
+ )
173
239
  }
174
240
 
175
241
  const isLinearChart = !['Pie', 'Forest Plot'].includes(visualizationType)
@@ -205,9 +271,34 @@ export const useTooltip = props => {
205
271
  ) {
206
272
  return []
207
273
  } else if (seriesObjWithName && seriesObjWithName.name === '') {
208
- return [['', formattedValue, getAxisPosition(seriesKey)]]
274
+ return [
275
+ createTooltipRow({
276
+ key: '',
277
+ value: formattedValue,
278
+ axisPosition: getAxisPosition(seriesKey),
279
+ kind: 'series',
280
+ seriesKey
281
+ })
282
+ ]
283
+ } else if (config.xAxis?.dataKey == seriesKey) {
284
+ return [
285
+ createTooltipRow({
286
+ key: seriesKey,
287
+ value: formattedValue,
288
+ axisPosition: getAxisPosition(seriesKey),
289
+ kind: 'heading'
290
+ })
291
+ ]
209
292
  } else {
210
- return [[seriesKey, formattedValue, getAxisPosition(seriesKey)]]
293
+ return [
294
+ createTooltipRow({
295
+ key: seriesKey,
296
+ value: formattedValue,
297
+ axisPosition: getAxisPosition(seriesKey),
298
+ kind: 'series',
299
+ seriesKey
300
+ })
301
+ ]
211
302
  }
212
303
  })
213
304
  )
@@ -247,7 +338,15 @@ export const useTooltip = props => {
247
338
  if (resolvedScaleValue) {
248
339
  const value = resolvedScaleValue[series.originalDataKey]
249
340
  const formattedValue = getFormattedValue(seriesKey, value, config, getAxisPosition)
250
- tooltipItems.push([seriesKey, formattedValue, getAxisPosition(seriesKey)])
341
+ tooltipItems.push(
342
+ createTooltipRow({
343
+ key: seriesKey,
344
+ value: formattedValue,
345
+ axisPosition: getAxisPosition(seriesKey),
346
+ kind: 'series',
347
+ seriesKey
348
+ })
349
+ )
251
350
  }
252
351
  }
253
352
  })
@@ -261,12 +360,31 @@ export const useTooltip = props => {
261
360
  const xVal = dataColumn[config.xAxis.dataKey]
262
361
  const closestXScaleValue = getXValueFromCoordinate(x - Y_AXIS_SIZE)
263
362
 
264
- tooltipItems.push([config.xAxis.dataKey, closestXScaleValue || xVal])
363
+ tooltipItems.push(
364
+ createTooltipRow({
365
+ key: config.xAxis.dataKey,
366
+ value: closestXScaleValue || xVal,
367
+ kind: 'heading'
368
+ })
369
+ )
265
370
  const formattedValue = getFormattedValue(seriesKey, value, config, getAxisPosition)
266
- tooltipItems.push([seriesKey, formattedValue])
371
+ tooltipItems.push(
372
+ createTooltipRow({
373
+ key: seriesKey,
374
+ value: formattedValue,
375
+ kind: 'series',
376
+ seriesKey
377
+ })
378
+ )
267
379
  } else if (dynamicSeries) {
268
380
  Object.keys(dataColumn).forEach(key => {
269
- tooltipItems.push([key, dataColumn[key]])
381
+ tooltipItems.push(
382
+ createTooltipRow({
383
+ key,
384
+ value: dataColumn[key],
385
+ kind: key === config.xAxis.dataKey ? 'heading' : 'extra'
386
+ })
387
+ )
270
388
  })
271
389
  }
272
390
  }
@@ -283,16 +401,11 @@ export const useTooltip = props => {
283
401
  }
284
402
 
285
403
  // Strip link tags from all tooltip values
286
- const cleanTooltipItems = [...tooltipItems, ...additionalTooltipItems].map(item => {
287
- // item can be [key, value] or [key, value, axisPosition]
288
- if (Array.isArray(item)) {
289
- // Only strip from value (item[1])
290
- const newItem = [...item]
291
- newItem[1] = stripLinkTags(newItem[1])
292
- return newItem
293
- }
294
- return item
295
- })
404
+ const cleanTooltipItems = [...tooltipItems, ...additionalTooltipItems].map(item => ({
405
+ ...item,
406
+ value: stripLinkTags(item.value)
407
+ }))
408
+ const useMarkerColumn = tooltipHasMarkerColumn(cleanTooltipItems)
296
409
 
297
410
  const tooltipInformation = {
298
411
  tooltipLeft: dataXPosition,
@@ -300,7 +413,8 @@ export const useTooltip = props => {
300
413
  tooltipData: {
301
414
  data: cleanTooltipItems,
302
415
  dataXPosition,
303
- dataYPosition
416
+ dataYPosition,
417
+ useMarkerColumn
304
418
  }
305
419
  }
306
420
  showTooltip(tooltipInformation)
@@ -654,9 +768,8 @@ export const useTooltip = props => {
654
768
  return originalColumnName
655
769
  }
656
770
 
657
- const TooltipListItem = ({ item }) => {
658
- const [index, additionalData] = item
659
- const [key, value, axisPosition] = additionalData
771
+ const TooltipListItem = ({ row, index, useMarkerColumn = false }) => {
772
+ const { key, value, axisPosition, kind, markerColor, markerShape = 'circle' } = row
660
773
 
661
774
  if (visualizationType === 'Forest Plot') {
662
775
  if (key === config.xAxis.dataKey)
@@ -718,10 +831,26 @@ export const useTooltip = props => {
718
831
  }
719
832
  const activeLabel = getSeriesNameFromLabel(key)
720
833
  const displayText = activeLabel ? `${activeLabel}: ${newValue}` : newValue
834
+ const shouldRenderMarkerSlot = useMarkerColumn && kind !== 'heading'
835
+ const markerSlot = shouldRenderMarkerSlot ? (
836
+ <span className='tooltip-marker-slot' aria-hidden='true'>
837
+ {markerColor ? (
838
+ <span
839
+ className={`tooltip-marker-swatch tooltip-marker-swatch--${markerShape}`}
840
+ style={{ backgroundColor: markerColor }}
841
+ />
842
+ ) : null}
843
+ </span>
844
+ ) : null
845
+ const content = displayText !== undefined ? parse(String(displayText)) : displayText
721
846
 
722
847
  return (
723
- <li style={style} className='tooltip-body mb-1'>
724
- {displayText !== undefined ? parse(String(displayText)) : displayText}
848
+ <li
849
+ style={style}
850
+ className={`tooltip-body mb-1 cove-prose ${shouldRenderMarkerSlot ? 'tooltip-body--marker-layout' : ''}`}
851
+ >
852
+ {markerSlot}
853
+ {shouldRenderMarkerSlot ? <span className='tooltip-body-content'>{content}</span> : content}
725
854
  </li>
726
855
  )
727
856
  }
@@ -1,11 +1,35 @@
1
1
  import path from 'node:path'
2
+ import fs from 'node:fs'
3
+ import vm from 'node:vm'
2
4
  import { testStandaloneBuild } from '@cdc/core/helpers/tests/testStandaloneBuild.ts'
3
5
  import { describe, it, expect } from 'vitest'
4
6
 
7
+ const extractMarkedExampleConfig = (content, label) => {
8
+ const match = content.match(
9
+ /<!-- README_EXAMPLE_CONFIG_START -->\s*```jsx\s*([\s\S]*?)\s*```\s*<!-- README_EXAMPLE_CONFIG_END -->/
10
+ )
11
+ expect(match, `${label} should contain a marked README example block`).toBeTruthy()
12
+ const configMatch = match[1].match(/const config = (\{[\s\S]*?\})\n\nfunction App\(\)/)
13
+ expect(configMatch, `${label} should define const config before function App()`).toBeTruthy()
14
+ return vm.runInNewContext(`(${configMatch[1]})`)
15
+ }
16
+
5
17
  describe('Chart', () => {
6
18
  it('Can be built in isolation', async () => {
7
19
  const pkgDir = path.join(__dirname, '..')
8
20
  const result = await testStandaloneBuild(pkgDir)
9
21
  expect(result).toBe(true)
10
22
  }, 300000)
23
+
24
+ it('keeps the minimal example in sync with the README docs', () => {
25
+ const pkgRoot = path.join(__dirname, '..', '..')
26
+ const minimalExamplePath = path.join(pkgRoot, 'examples', 'minimal-example.json')
27
+ const readmePath = path.join(pkgRoot, 'README.md')
28
+
29
+ const minimalExample = JSON.parse(fs.readFileSync(minimalExamplePath, 'utf8'))
30
+ const readmeBlock = extractMarkedExampleConfig(fs.readFileSync(readmePath, 'utf8'), 'README.md')
31
+
32
+ expect(readmeBlock).toEqual(minimalExample)
33
+ expect(minimalExample.version).toBeTruthy()
34
+ })
11
35
  })
@@ -102,6 +102,7 @@ type Legend = CoreLegend & {
102
102
  seriesHighlight: string[]
103
103
  unified: boolean
104
104
  hideSuppressionLink: boolean
105
+ tooltipLegendVisible?: boolean
105
106
  style: 'circles' | 'boxes' | 'gradient' | 'lines'
106
107
  subStyle: 'linear blocks' | 'smooth'
107
108
  hasShape: boolean
package/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.