@cdc/chart 4.26.1 → 4.26.2
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.
- package/CLAUDE.local.md +79 -0
- package/dist/{cdcchart-dgT_1dIT.es.js → cdcchart-DQ00cQCm.es.js} +1 -20
- package/dist/cdcchart.js +45357 -43655
- package/examples/default.json +378 -0
- package/examples/feature/__data__/horizon-chart-data.json +373 -0
- package/examples/feature/annotations/index.json +3 -6
- package/examples/feature/horizon/horizon-chart.json +395 -0
- package/examples/line-chart-states.json +1085 -0
- package/examples/private/123.json +694 -0
- package/examples/private/anchor-issue.json +4094 -0
- package/examples/private/backwards-slider.json +10430 -0
- package/examples/private/georgia.csv +160 -0
- package/examples/private/timeline-data.json +1 -0
- package/examples/private/timeline.json +389 -0
- package/examples/radar-chart-simple.json +133 -0
- package/examples/radar-chart.json +148 -0
- package/index.html +1 -31
- package/package.json +57 -59
- package/src/CdcChartComponent.tsx +99 -18
- package/src/_stories/Chart.Anchors.stories.tsx +10 -0
- package/src/_stories/Chart.BoxPlot.stories.tsx +7 -0
- package/src/_stories/Chart.CI.stories.tsx +13 -0
- package/src/_stories/Chart.Combo.stories.tsx +17 -0
- package/src/_stories/Chart.CustomColors.stories.tsx +4 -0
- package/src/_stories/Chart.DynamicSeries.stories.tsx +19 -0
- package/src/_stories/Chart.Filters.stories.tsx +4 -0
- package/src/_stories/Chart.Forecast.stories.tsx +4 -0
- package/src/_stories/Chart.HTMLInDataTable.stories.tsx +22 -0
- package/src/_stories/Chart.Legend.Gradient.stories.tsx +28 -0
- package/src/_stories/Chart.Patterns.stories.tsx +4 -0
- package/src/_stories/Chart.PreserveDecimals.stories.tsx +25 -0
- package/src/_stories/Chart.Regions.Categorical.stories.tsx +13 -0
- package/src/_stories/Chart.Regions.DateScale.stories.tsx +19 -0
- package/src/_stories/Chart.Regions.DateTimeScale.stories.tsx +25 -10
- package/src/_stories/Chart.ScatterPlot.stories.tsx +4 -0
- package/src/_stories/Chart.SmallMultiples.stories.tsx +16 -0
- package/src/_stories/Chart.stories.tsx +37 -0
- package/src/_stories/Chart.tooltip.stories.tsx +7 -0
- package/src/_stories/ChartAnnotation.stories.tsx +10 -0
- package/src/_stories/ChartAxisLabels.stories.tsx +4 -0
- package/src/_stories/ChartAxisTitles.stories.tsx +10 -0
- package/src/_stories/ChartBrush.Matrix.Continuous.stories.tsx +41 -0
- package/src/_stories/ChartBrush.Matrix.Date.stories.tsx +114 -0
- package/src/_stories/ChartBrush.Matrix.DateTime.stories.tsx +78 -0
- package/src/_stories/ChartBrush.stories.tsx +7 -0
- package/src/_stories/ChartEditor.stories.tsx +7 -0
- package/src/_stories/ChartLine.QuadrantAngles.stories.tsx +89 -0
- package/src/_stories/ChartLine.Suppression.stories.tsx +7 -0
- package/src/_stories/ChartLine.Symbols.stories.tsx +4 -0
- package/src/_stories/ChartPrefixSuffix.stories.tsx +46 -1
- package/src/_stories/TechAdoptionWithLinks.stories.tsx +7 -0
- package/src/_stories/_mock/brush_continuous.json +86 -0
- package/src/_stories/_mock/brush_date_large.json +176 -0
- package/src/_stories/_mock/line_chart_angle_near_zero_fall.json +195 -0
- package/src/_stories/_mock/line_chart_angle_near_zero_rise.json +195 -0
- package/src/_stories/_mock/line_chart_angle_q1_steep_upward.json +195 -0
- package/src/_stories/_mock/line_chart_angle_q2_gentle_downward.json +195 -0
- package/src/_stories/_mock/line_chart_angle_q3_steep_downward.json +195 -0
- package/src/_stories/_mock/line_chart_angle_q4_gentle_upward.json +195 -0
- package/src/_stories/_mock/line_chart_quadrant_angles.json +264 -0
- package/src/components/Annotations/components/AnnotationDraggable.styles.css +11 -17
- package/src/components/Annotations/components/AnnotationDraggable.tsx +240 -116
- package/src/components/Annotations/components/AnnotationDropdown.styles.css +1 -2
- package/src/components/Annotations/components/AnnotationDropdown.tsx +8 -12
- package/src/components/Annotations/components/AnnotationList.styles.css +4 -10
- package/src/components/Annotations/components/AnnotationList.tsx +5 -4
- package/src/components/Annotations/components/findNearestDatum.ts +75 -85
- package/src/components/Annotations/helpers/getVisibleAnnotations.ts +38 -0
- package/src/components/Axis/BottomAxis.tsx +270 -0
- package/src/components/Axis/LeftAxis.tsx +404 -0
- package/src/components/Axis/LeftAxisGridlines.tsx +77 -0
- package/src/components/Axis/PairedBarAxis.tsx +186 -0
- package/src/components/Axis/README.md +94 -0
- package/src/components/Axis/RightAxis.tsx +108 -0
- package/src/components/Axis/axis.constants.ts +21 -0
- package/src/components/Axis/index.ts +7 -0
- package/src/components/BarChart/components/BarChart.tsx +7 -1
- package/src/components/Brush/BrushSelector.tsx +154 -22
- package/src/components/Brush/MiniChartPreview.tsx +138 -21
- package/src/components/EditorPanel/EditorPanel.tsx +25 -11
- package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +60 -22
- package/src/components/EditorPanel/components/Panels/Panel.General.tsx +81 -1
- package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +1 -1
- package/src/components/EditorPanel/components/Panels/Panel.Radar.tsx +353 -0
- package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +0 -1
- package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +21 -1
- package/src/components/EditorPanel/components/Panels/index.tsx +2 -0
- package/src/components/EditorPanel/useEditorPermissions.ts +55 -26
- package/src/components/HorizonChart/HorizonChart.tsx +131 -0
- package/src/components/HorizonChart/components/HorizonBand.tsx +160 -0
- package/src/components/HorizonChart/helpers/calculateHorizonBands.ts +27 -0
- package/src/components/HorizonChart/helpers/getHorizonLayerColors.ts +40 -0
- package/src/components/HorizonChart/index.tsx +3 -0
- package/src/components/Legend/Legend.Component.tsx +52 -4
- package/src/components/Legend/Legend.tsx +1 -1
- package/src/components/Legend/LegendValueRange.tsx +77 -0
- package/src/components/Legend/helpers/createFormatLabels.tsx +13 -0
- package/src/components/Legend/helpers/generateValueRanges.ts +92 -0
- package/src/components/LineChart/helpers/README.md +292 -0
- package/src/components/LineChart/helpers/labelPositioning.test.ts +245 -0
- package/src/components/LineChart/helpers/labelPositioning.ts +304 -0
- package/src/components/LineChart/index.tsx +44 -8
- package/src/components/LinearChart/README.md +109 -0
- package/src/components/LinearChart/VisualizationRenderer.tsx +267 -0
- package/src/components/LinearChart/linearChart.constants.ts +84 -0
- package/src/components/LinearChart/tests/LinearChart.test.tsx +201 -0
- package/src/components/LinearChart/tests/mockConfigContext.ts +129 -0
- package/src/components/LinearChart/utils/tickFormatting.ts +146 -0
- package/src/components/LinearChart.tsx +250 -1059
- package/src/components/PieChart/PieChart.tsx +1 -1
- package/src/components/RadarChart/RadarAxis.tsx +78 -0
- package/src/components/RadarChart/RadarChart.tsx +298 -0
- package/src/components/RadarChart/RadarGrid.tsx +64 -0
- package/src/components/RadarChart/RadarPolygon.tsx +91 -0
- package/src/components/RadarChart/helpers.ts +83 -0
- package/src/components/RadarChart/index.tsx +3 -0
- package/src/components/WarmingStripes/WarmingStripes.tsx +95 -25
- package/src/data/initial-state.js +14 -1
- package/src/helpers/getExcludedData.ts +4 -0
- package/src/helpers/handleChartAriaLabels.ts +19 -19
- package/src/helpers/handleLineType.ts +22 -18
- package/src/hooks/useProgrammaticTooltip.ts +23 -2
- package/src/hooks/useScales.ts +7 -0
- package/src/hooks/useTooltip.tsx +3 -0
- package/src/scss/main.scss +5 -0
- package/src/selectors/README.md +68 -0
- package/src/store/chart.reducer.ts +2 -0
- package/src/types/ChartConfig.ts +18 -0
- package/src/types/ChartContext.ts +1 -0
- package/src/types/Horizon.ts +64 -0
- package/preview.html +0 -1616
- package/src/components/Annotations/components/helpers/index.tsx +0 -46
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { useCallback, useContext } from 'react'
|
|
2
|
+
import ConfigContext from '../../../ConfigContext'
|
|
3
|
+
import { isDateScale } from '@cdc/core/helpers/cove/date'
|
|
4
|
+
|
|
5
|
+
type TickFormattingOptions = {
|
|
6
|
+
isLogarithmicAxis: boolean
|
|
7
|
+
orientation: 'horizontal' | 'vertical'
|
|
8
|
+
visualizationType: string
|
|
9
|
+
min: number
|
|
10
|
+
max: number
|
|
11
|
+
shouldAbbreviate: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Shared logarithmic tick handling
|
|
16
|
+
* Both left and bottom formatters convert 0.1 to 0 for logarithmic scales
|
|
17
|
+
*/
|
|
18
|
+
const handleLogarithmicTick = (tick: number, isLogarithmic: boolean): number => {
|
|
19
|
+
if (isLogarithmic && tick === 0.1) {
|
|
20
|
+
return 0
|
|
21
|
+
}
|
|
22
|
+
return tick
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Hook that provides consolidated tick formatting functions for both axes.
|
|
27
|
+
* Consolidates handleLeftTickFormatting and handleBottomTickFormatting
|
|
28
|
+
* from LinearChart.tsx
|
|
29
|
+
*/
|
|
30
|
+
export const useTickFormatters = (options: TickFormattingOptions) => {
|
|
31
|
+
const { config, formatDate, formatNumber, parseDate } = useContext(ConfigContext)
|
|
32
|
+
const { runtime, data, xAxis } = config
|
|
33
|
+
const { isLogarithmicAxis, orientation, visualizationType, min, max, shouldAbbreviate } = options
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Format ticks for the left (Y) axis
|
|
37
|
+
*/
|
|
38
|
+
const handleLeftTickFormatting = useCallback(
|
|
39
|
+
(tick: number | string, index: number, ticks: any[]) => {
|
|
40
|
+
// Handle logarithmic scale
|
|
41
|
+
let processedTick = typeof tick === 'number' ? handleLogarithmicTick(tick, isLogarithmicAxis) : tick
|
|
42
|
+
|
|
43
|
+
// Forest Plot special case - return data key value
|
|
44
|
+
if (visualizationType === 'Forest Plot') {
|
|
45
|
+
if (data && !data[index]) return ''
|
|
46
|
+
return data[index][xAxis.dataKey]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Date scale on y-axis
|
|
50
|
+
if (isDateScale(runtime.yAxis)) {
|
|
51
|
+
return formatDate(parseDate(processedTick))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Vertical orientation with small range (needs more precision)
|
|
55
|
+
if (orientation === 'vertical' && max - min < 3 && !config.dataFormat?.roundTo) {
|
|
56
|
+
return formatNumber(processedTick, 'left', shouldAbbreviate, false, false, '1', {
|
|
57
|
+
index,
|
|
58
|
+
length: ticks.length
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Standard vertical orientation formatting
|
|
63
|
+
if (orientation === 'vertical') {
|
|
64
|
+
return formatNumber(processedTick, 'left', shouldAbbreviate, false, false, undefined, {
|
|
65
|
+
index,
|
|
66
|
+
length: ticks.length
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return processedTick
|
|
71
|
+
},
|
|
72
|
+
[
|
|
73
|
+
isLogarithmicAxis,
|
|
74
|
+
visualizationType,
|
|
75
|
+
data,
|
|
76
|
+
xAxis.dataKey,
|
|
77
|
+
runtime.yAxis,
|
|
78
|
+
orientation,
|
|
79
|
+
min,
|
|
80
|
+
max,
|
|
81
|
+
config.dataFormat?.roundTo,
|
|
82
|
+
shouldAbbreviate,
|
|
83
|
+
formatDate,
|
|
84
|
+
formatNumber,
|
|
85
|
+
parseDate
|
|
86
|
+
]
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Format ticks for the bottom (X) axis
|
|
91
|
+
*/
|
|
92
|
+
const handleBottomTickFormatting = useCallback(
|
|
93
|
+
(tick: number | string | Date, index: number, ticks: any[]) => {
|
|
94
|
+
// Handle logarithmic scale
|
|
95
|
+
let processedTick = typeof tick === 'number' ? handleLogarithmicTick(tick, isLogarithmicAxis) : tick
|
|
96
|
+
|
|
97
|
+
// Date scale formatting (most common case for x-axis)
|
|
98
|
+
if (isDateScale(runtime.xAxis) && visualizationType !== 'Forest Plot') {
|
|
99
|
+
return formatDate(processedTick, index, ticks)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Horizontal orientation (bars)
|
|
103
|
+
if (orientation === 'horizontal' && visualizationType !== 'Forest Plot') {
|
|
104
|
+
return formatNumber(processedTick, 'left', shouldAbbreviate)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Continuous x-axis type
|
|
108
|
+
if (xAxis.type === 'continuous' && visualizationType !== 'Forest Plot') {
|
|
109
|
+
return formatNumber(processedTick, 'bottom', shouldAbbreviate)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Forest Plot special case with prefix/suffix
|
|
113
|
+
if (visualizationType === 'Forest Plot') {
|
|
114
|
+
return formatNumber(
|
|
115
|
+
processedTick,
|
|
116
|
+
'left',
|
|
117
|
+
config.dataFormat.abbreviated,
|
|
118
|
+
runtime.xAxis.prefix,
|
|
119
|
+
runtime.xAxis.suffix,
|
|
120
|
+
Number(config.dataFormat.roundTo)
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return processedTick
|
|
125
|
+
},
|
|
126
|
+
[
|
|
127
|
+
isLogarithmicAxis,
|
|
128
|
+
runtime.xAxis,
|
|
129
|
+
visualizationType,
|
|
130
|
+
orientation,
|
|
131
|
+
xAxis.type,
|
|
132
|
+
shouldAbbreviate,
|
|
133
|
+
config.dataFormat.abbreviated,
|
|
134
|
+
config.dataFormat.roundTo,
|
|
135
|
+
formatDate,
|
|
136
|
+
formatNumber
|
|
137
|
+
]
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
handleLeftTickFormatting,
|
|
142
|
+
handleBottomTickFormatting
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default useTickFormatters
|