@cdc/chart 4.24.5 → 4.24.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.
- package/dist/cdcchart.js +39128 -35959
- package/examples/feature/annotations/index.json +542 -0
- package/examples/xaxis.json +493 -0
- package/index.html +5 -4
- package/package.json +5 -4
- package/src/CdcChart.tsx +104 -64
- package/src/_stories/Chart.stories.tsx +18 -171
- package/src/_stories/ChartAnnotation.stories.tsx +32 -0
- package/src/_stories/_mock/annotation_category_mock.json +473 -0
- package/src/_stories/_mock/annotation_date-linear_mock.json +530 -0
- package/src/_stories/_mock/annotation_date-time_mock.json +530 -0
- package/src/_stories/_mock/line_chart_two_points_new_chart.json +128 -0
- package/src/_stories/_mock/line_chart_two_points_regression_test.json +127 -0
- package/src/_stories/_mock/lollipop.json +171 -0
- package/src/components/Annotations/components/AnnotationDraggable.styles.css +31 -0
- package/src/components/Annotations/components/AnnotationDraggable.tsx +154 -0
- package/src/components/Annotations/components/AnnotationDropdown.styles.css +14 -0
- package/src/components/Annotations/components/AnnotationDropdown.tsx +72 -0
- package/src/components/Annotations/components/AnnotationList.styles.css +45 -0
- package/src/components/Annotations/components/AnnotationList.tsx +42 -0
- package/src/components/Annotations/components/findNearestDatum.ts +138 -0
- package/src/components/Annotations/components/helpers/index.tsx +46 -0
- package/src/components/Annotations/index.tsx +13 -0
- package/src/components/AreaChart/components/AreaChart.Stacked.jsx +1 -1
- package/src/components/AreaChart/components/AreaChart.jsx +1 -1
- package/src/components/BarChart/components/BarChart.Horizontal.tsx +44 -42
- package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +1 -2
- package/src/components/BarChart/components/BarChart.StackedVertical.tsx +11 -11
- package/src/components/BarChart/components/BarChart.Vertical.tsx +50 -22
- package/src/components/BarChart/helpers/index.ts +102 -0
- package/src/components/EditorPanel/EditorPanel.tsx +232 -98
- package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +306 -0
- package/src/components/EditorPanel/components/Panels/Panel.General.tsx +117 -6
- package/src/components/EditorPanel/components/Panels/Panel.Sankey.tsx +2 -3
- package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +3 -2
- package/src/components/EditorPanel/components/Panels/index.tsx +3 -1
- package/src/components/EditorPanel/components/panels.scss +4 -0
- package/src/components/EditorPanel/editor-panel.scss +19 -0
- package/src/components/EditorPanel/useEditorPermissions.js +19 -2
- package/src/components/Legend/Legend.Component.tsx +7 -8
- package/src/components/Legend/helpers/createFormatLabels.tsx +1 -1
- package/src/components/Legend/helpers/index.ts +5 -0
- package/src/components/LineChart/LineChartProps.ts +3 -0
- package/src/components/LineChart/helpers.ts +21 -7
- package/src/components/LineChart/index.tsx +7 -7
- package/src/components/LinearChart.jsx +179 -136
- package/src/components/PairedBarChart.jsx +9 -9
- package/src/components/PieChart/PieChart.tsx +4 -4
- package/src/components/Sankey/index.tsx +73 -20
- package/src/components/ScatterPlot/ScatterPlot.jsx +22 -8
- package/src/components/ZoomBrush.tsx +90 -44
- package/src/data/initial-state.js +14 -6
- package/src/helpers/handleChartTabbing.ts +8 -0
- package/src/helpers/isConvertLineToBarGraph.ts +4 -0
- package/src/hooks/{useBarChart.js → useBarChart.ts} +2 -40
- package/src/hooks/useColorScale.ts +1 -1
- package/src/hooks/useMinMax.ts +8 -3
- package/src/hooks/useScales.ts +25 -3
- package/src/hooks/useTooltip.tsx +58 -11
- package/src/scss/main.scss +21 -14
- package/src/types/ChartConfig.ts +50 -3
- package/src/types/ChartContext.ts +9 -0
- package/tests-examples/helpers/testZeroValue.test.ts +30 -0
- package/LICENSE +0 -201
- package/src/helpers/filterData.ts +0 -18
- package/src/helpers/tests/computeMarginBottom.test.ts +0 -21
- /package/src/hooks/{useLegendClasses.js → useLegendClasses.ts} +0 -0
- /package/src/hooks/{useReduceData.js → useReduceData.ts} +0 -0
package/src/hooks/useScales.ts
CHANGED
|
@@ -44,6 +44,10 @@ const useScales = (properties: useScaleProps) => {
|
|
|
44
44
|
let seriesScale = null
|
|
45
45
|
let xScaleNoPadding = null
|
|
46
46
|
let xScaleBrush = null
|
|
47
|
+
let xScaleAnnotation = scaleLinear({
|
|
48
|
+
domain: [0, 100],
|
|
49
|
+
range: [0, xMax]
|
|
50
|
+
})
|
|
47
51
|
|
|
48
52
|
// handle Horizontal bars
|
|
49
53
|
if (isHorizontal) {
|
|
@@ -62,7 +66,12 @@ const useScales = (properties: useScaleProps) => {
|
|
|
62
66
|
seriesScale = composeScaleBand(seriesDomain, [0, xScale.bandwidth()], 0)
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
// handle
|
|
69
|
+
// handle Linear scaled viz
|
|
70
|
+
if (config.xAxis.type === 'date' && !isHorizontal) {
|
|
71
|
+
const xAxisDataMappedSorted = xAxisDataMapped ? xAxisDataMapped.sort() : []
|
|
72
|
+
xScale = composeScaleBand(xAxisDataMappedSorted, [0, xMax], 1 - config.barThickness)
|
|
73
|
+
}
|
|
74
|
+
|
|
66
75
|
if (config.xAxis.type === 'date-time') {
|
|
67
76
|
let xAxisMin = Math.min(...xAxisDataMapped)
|
|
68
77
|
let xAxisMax = Math.max(...xAxisDataMapped)
|
|
@@ -74,7 +83,20 @@ const useScales = (properties: useScaleProps) => {
|
|
|
74
83
|
})
|
|
75
84
|
|
|
76
85
|
xScale.type = scaleTypes.TIME
|
|
77
|
-
|
|
86
|
+
|
|
87
|
+
let minDistance = Number.MAX_VALUE
|
|
88
|
+
let xAxisDataMappedSorted = xAxisDataMapped ? xAxisDataMapped.sort() : []
|
|
89
|
+
for (let i = 0; i < xAxisDataMappedSorted.length - 1; i++) {
|
|
90
|
+
let distance = xScale(xAxisDataMappedSorted[i + 1]) - xScale(xAxisDataMappedSorted[i])
|
|
91
|
+
|
|
92
|
+
if (distance < minDistance) minDistance = distance
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (xAxisDataMapped.length === 1 || minDistance > xMax / 4) {
|
|
96
|
+
minDistance = xMax / 4
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
seriesScale = composeScaleBand(seriesDomain, [0, (config.barThickness || 1) * minDistance], 0)
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
// handle Deviation bar
|
|
@@ -233,7 +255,7 @@ const useScales = (properties: useScaleProps) => {
|
|
|
233
255
|
}
|
|
234
256
|
}
|
|
235
257
|
}
|
|
236
|
-
return { xScale, yScale, seriesScale, g1xScale, g2xScale, xScaleNoPadding, xScaleBrush }
|
|
258
|
+
return { xScale, yScale, seriesScale, g1xScale, g2xScale, xScaleNoPadding, xScaleBrush, xScaleAnnotation }
|
|
237
259
|
}
|
|
238
260
|
|
|
239
261
|
export default useScales
|
package/src/hooks/useTooltip.tsx
CHANGED
|
@@ -9,9 +9,10 @@ import { localPoint } from '@visx/event'
|
|
|
9
9
|
import { bisector } from 'd3-array'
|
|
10
10
|
|
|
11
11
|
export const useTooltip = props => {
|
|
12
|
-
const { tableData: data, config, formatNumber, capitalize, formatDate, formatTooltipsDate, parseDate, setSharedFilter } = useContext<ChartContext>(ConfigContext)
|
|
12
|
+
const { tableData: data, config, formatNumber, capitalize, formatDate, formatTooltipsDate, parseDate, setSharedFilter, isDraggingAnnotation } = useContext<ChartContext>(ConfigContext)
|
|
13
13
|
const { xScale, yScale, showTooltip, hideTooltip } = props
|
|
14
14
|
const { xAxis, visualizationType, orientation, yAxis, runtime } = config
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* Provides the tooltip information based on the tooltip data array and svg cursor coordinates
|
|
17
18
|
* @function getTooltipInformation
|
|
@@ -19,6 +20,44 @@ export const useTooltip = props => {
|
|
|
19
20
|
* @param {Object} eventSvgCoords - The object containing the SVG coordinates of the event.
|
|
20
21
|
* @return {Object} - The tooltip information with tooltip data.
|
|
21
22
|
*/
|
|
23
|
+
|
|
24
|
+
// function handles only Single series hovred data tooltips
|
|
25
|
+
const findDataKeyByThreshold = (mouseY, datapoint) => {
|
|
26
|
+
let sum = 0
|
|
27
|
+
let threshold = Number(yScale.invert(mouseY))
|
|
28
|
+
let hoveredKey = null
|
|
29
|
+
let hoveredValue = null
|
|
30
|
+
|
|
31
|
+
for (let key of config.runtime?.seriesKeys) {
|
|
32
|
+
if (datapoint.hasOwnProperty(key)) {
|
|
33
|
+
sum += Number(datapoint[key])
|
|
34
|
+
if (sum >= threshold) {
|
|
35
|
+
hoveredValue = datapoint[key]
|
|
36
|
+
hoveredKey = key
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Return null if no matching data is found
|
|
43
|
+
return [hoveredKey, hoveredValue]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const getFormattedValue = (seriesKey, value, config, getAxisPosition) => {
|
|
47
|
+
// handle case where data is missing
|
|
48
|
+
const showMissingDataValue = config.general.showMissingDataLabel && (!value || value === 'null')
|
|
49
|
+
let formattedValue = seriesKey === config.xAxis.dataKey ? value : formatNumber(value, getAxisPosition(seriesKey))
|
|
50
|
+
formattedValue = showMissingDataValue ? 'N/A' : formattedValue
|
|
51
|
+
|
|
52
|
+
const suppressed = config.preliminaryData?.find(pd => pd.label && pd.type === 'suppression' && pd.displayTooltip && value === pd.value && (!pd.column || seriesKey === pd.column))
|
|
53
|
+
|
|
54
|
+
if (suppressed) {
|
|
55
|
+
formattedValue = suppressed.label
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return formattedValue
|
|
59
|
+
}
|
|
60
|
+
|
|
22
61
|
const getTooltipInformation = (tooltipDataArray, eventSvgCoords) => {
|
|
23
62
|
const { x, y } = eventSvgCoords
|
|
24
63
|
let initialTooltipData = tooltipDataArray || {}
|
|
@@ -46,6 +85,8 @@ export const useTooltip = props => {
|
|
|
46
85
|
*/
|
|
47
86
|
const handleTooltipMouseOver = (e, additionalChartData) => {
|
|
48
87
|
e.stopPropagation()
|
|
88
|
+
if (isDraggingAnnotation) return
|
|
89
|
+
|
|
49
90
|
const eventSvgCoords = localPoint(e)
|
|
50
91
|
const { x, y } = eventSvgCoords
|
|
51
92
|
|
|
@@ -133,22 +174,29 @@ export const useTooltip = props => {
|
|
|
133
174
|
if (visualizationType === 'Forest Plot') {
|
|
134
175
|
tooltipItems.push([config.xAxis.dataKey, getClosestYValue(y)])
|
|
135
176
|
}
|
|
136
|
-
|
|
137
|
-
if (visualizationType !== 'Pie' && visualizationType !== 'Forest Plot') {
|
|
177
|
+
// handle tooltip for all hovered series
|
|
178
|
+
if (visualizationType !== 'Pie' && visualizationType !== 'Forest Plot' && !config.tooltips.singleSeries) {
|
|
138
179
|
tooltipItems.push(
|
|
139
180
|
...getIncludedTooltipSeries()
|
|
140
|
-
?.filter(seriesKey => config.series?.find(item => item.dataKey === seriesKey && item?.tooltip) || config.xAxis?.dataKey == seriesKey)
|
|
181
|
+
?.filter(seriesKey => config.series?.find(item => item.dataKey === seriesKey && item?.tooltip) || config.xAxis?.dataKey == seriesKey || visualizationType === 'Forecasting')
|
|
141
182
|
?.flatMap(seriesKey => {
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
formattedValue = suppressed.label
|
|
146
|
-
}
|
|
147
|
-
return resolvedScaleValues?.[0]?.[seriesKey] ? [[seriesKey, formattedValue, getAxisPosition(seriesKey)]] : []
|
|
183
|
+
const value = resolvedScaleValues[0]?.[seriesKey]
|
|
184
|
+
const formattedValue = getFormattedValue(seriesKey, value, config, getAxisPosition)
|
|
185
|
+
return [[seriesKey, formattedValue, getAxisPosition(seriesKey)]]
|
|
148
186
|
})
|
|
149
187
|
)
|
|
150
188
|
}
|
|
151
189
|
|
|
190
|
+
// handle tooltip for single hovered series
|
|
191
|
+
if (visualizationType !== 'Pie' && visualizationType !== 'Forest Plot' && config.tooltips.singleSeries) {
|
|
192
|
+
const [seriesKey, value] = findDataKeyByThreshold(y, resolvedScaleValues[0])
|
|
193
|
+
if (seriesKey && value) {
|
|
194
|
+
tooltipItems.push([config.xAxis.dataKey, closestXScaleValue])
|
|
195
|
+
const formattedValue = getFormattedValue(seriesKey, value, config, getAxisPosition)
|
|
196
|
+
tooltipItems.push([seriesKey, formattedValue])
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
152
200
|
return [...tooltipItems, ...additionalTooltipItems]
|
|
153
201
|
}
|
|
154
202
|
|
|
@@ -323,7 +371,6 @@ export const useTooltip = props => {
|
|
|
323
371
|
const yScaleValues = dataToSearch.map(object => {
|
|
324
372
|
return Object.fromEntries(Object.entries(object).filter(([key, value]) => includedSeries.includes(key)))
|
|
325
373
|
})
|
|
326
|
-
|
|
327
374
|
return yScaleValues
|
|
328
375
|
} catch (error) {
|
|
329
376
|
console.error('COVE', error)
|
package/src/scss/main.scss
CHANGED
|
@@ -91,6 +91,15 @@
|
|
|
91
91
|
.subtext--responsive-ticks,
|
|
92
92
|
.section-subtext {
|
|
93
93
|
padding: 0 1rem;
|
|
94
|
+
&--brush-active {
|
|
95
|
+
margin-top: 2.5em;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.type-pie {
|
|
100
|
+
svg.animated-pie {
|
|
101
|
+
width: auto !important;
|
|
102
|
+
}
|
|
94
103
|
}
|
|
95
104
|
|
|
96
105
|
.legend-container {
|
|
@@ -141,9 +150,6 @@
|
|
|
141
150
|
word-wrap: break-word;
|
|
142
151
|
white-space: pre-wrap;
|
|
143
152
|
word-break: break-word;
|
|
144
|
-
@include breakpoint(xs) {
|
|
145
|
-
font-size: $font-small;
|
|
146
|
-
}
|
|
147
153
|
}
|
|
148
154
|
}
|
|
149
155
|
|
|
@@ -159,20 +165,13 @@
|
|
|
159
165
|
|
|
160
166
|
h3 {
|
|
161
167
|
font-size: 1.3rem;
|
|
162
|
-
@include breakpoint(xs) {
|
|
163
|
-
font-size: $font-small + 0.4em;
|
|
164
|
-
}
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
h3,
|
|
168
171
|
p {
|
|
169
172
|
margin-bottom: 0.8em;
|
|
170
173
|
}
|
|
171
|
-
|
|
172
|
-
@include breakpoint(xs) {
|
|
173
|
-
font-size: $font-small;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
174
|
+
|
|
176
175
|
& div.legend-item {
|
|
177
176
|
margin-bottom: 0.5em !important;
|
|
178
177
|
|
|
@@ -226,9 +225,6 @@
|
|
|
226
225
|
vertical-align: middle;
|
|
227
226
|
margin-bottom: 0.5em;
|
|
228
227
|
|
|
229
|
-
@include breakpoint(xs) {
|
|
230
|
-
font-size: $font-small;
|
|
231
|
-
}
|
|
232
228
|
& > span {
|
|
233
229
|
display: flex;
|
|
234
230
|
justify-items: center;
|
|
@@ -284,6 +280,17 @@
|
|
|
284
280
|
&.legend-hidden > svg {
|
|
285
281
|
width: 100% !important;
|
|
286
282
|
}
|
|
283
|
+
&.dashboard-brush {
|
|
284
|
+
margin-bottom: 2.5em;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
svg.dragging-annotation * {
|
|
288
|
+
user-select: none;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
svg.dragging-annotation path {
|
|
292
|
+
pointer-events: none;
|
|
293
|
+
}
|
|
287
294
|
|
|
288
295
|
> svg {
|
|
289
296
|
overflow: visible;
|
package/src/types/ChartConfig.ts
CHANGED
|
@@ -13,7 +13,9 @@ import { ConfidenceInterval } from '@cdc/core/types/ConfidenceInterval'
|
|
|
13
13
|
import { Region } from '@cdc/core/types/Region'
|
|
14
14
|
import { type PreliminaryDataItem } from '../components/LineChart/LineChartProps'
|
|
15
15
|
import { VizFilter } from '@cdc/core/types/VizFilter'
|
|
16
|
+
import { type Annotation } from '@cdc/core/types/Annotation'
|
|
16
17
|
|
|
18
|
+
export type ViewportSize = 'sm' | 'xs' | 'xxs' | 'lg'
|
|
17
19
|
export type ChartColumns = Record<string, Column>
|
|
18
20
|
|
|
19
21
|
type DataFormat = {
|
|
@@ -70,7 +72,8 @@ type Visual = {
|
|
|
70
72
|
horizontalHoverLine?: boolean
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
type AllChartsConfig = {
|
|
75
|
+
export type AllChartsConfig = {
|
|
76
|
+
annotations: Annotation[]
|
|
74
77
|
animate: boolean
|
|
75
78
|
general: General
|
|
76
79
|
barHasBorder: 'true' | 'false'
|
|
@@ -188,8 +191,52 @@ export type ForestPlotConfig = {
|
|
|
188
191
|
} & AllChartsConfig
|
|
189
192
|
|
|
190
193
|
export type LineChartConfig = {
|
|
191
|
-
|
|
194
|
+
allowLineToBarGraph: boolean
|
|
195
|
+
convertLineToBarGraph: boolean
|
|
192
196
|
lineDatapointStyle: 'hidden' | 'always show' | 'hover'
|
|
197
|
+
visualizationType: 'Line'
|
|
198
|
+
} & AllChartsConfig
|
|
199
|
+
|
|
200
|
+
export type SankeyLink = {
|
|
201
|
+
depth: number
|
|
202
|
+
height: number
|
|
203
|
+
id: string
|
|
204
|
+
index: number
|
|
205
|
+
layer: number
|
|
206
|
+
sourceLinks: SankeyLink[]
|
|
207
|
+
targetLinks: SankeyLink[]
|
|
208
|
+
value: number
|
|
209
|
+
x0: number
|
|
210
|
+
x1: number
|
|
211
|
+
y0: number
|
|
212
|
+
y1: number
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
type StoryNode = {
|
|
216
|
+
StoryNode: string
|
|
217
|
+
segmentTextAfter: string
|
|
218
|
+
segmentTextBefore: string
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type SankeyChartConfig = {
|
|
222
|
+
enableTooltips: boolean
|
|
223
|
+
data: [
|
|
224
|
+
{
|
|
225
|
+
tooltips: Object[]
|
|
226
|
+
// data to display in the sankey chart tooltips
|
|
227
|
+
tooltipData: Object[]
|
|
228
|
+
// data to display in the data table, bypasses the default data table output
|
|
229
|
+
tableData: Object[]
|
|
230
|
+
links: {
|
|
231
|
+
source: SankeyLink
|
|
232
|
+
target: SankeyLink
|
|
233
|
+
value: number
|
|
234
|
+
}[],
|
|
235
|
+
storyNodeText: StoryNode[]
|
|
236
|
+
:
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
visualizationType: 'Sankey'
|
|
193
240
|
} & AllChartsConfig
|
|
194
241
|
|
|
195
|
-
export type ChartConfig = LineChartConfig | ForestPlotConfig | AllChartsConfig
|
|
242
|
+
export type ChartConfig = SankeyChartConfig | LineChartConfig | ForestPlotConfig | AllChartsConfig
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ChartConfig } from './ChartConfig'
|
|
2
2
|
import { PickD3Scale } from '@visx/scale'
|
|
3
3
|
import { type SharedFilter } from '@cdc/dashboard/src/types/SharedFilter'
|
|
4
|
+
import { type Annotation } from '@cdc/core/types/Annotation'
|
|
4
5
|
|
|
5
6
|
export type ColorScale = PickD3Scale<'ordinal', any, any>
|
|
6
7
|
|
|
@@ -25,10 +26,17 @@ type SharedChartContext = {
|
|
|
25
26
|
setBrushConfig: Function
|
|
26
27
|
clean: Function
|
|
27
28
|
capitalize: (value: string) => string
|
|
29
|
+
// whether or not the legend is appearing below the chart
|
|
30
|
+
isLegendBottom?: boolean
|
|
31
|
+
// whether or not the chart is viewed within the editor screen
|
|
32
|
+
isEditor?: boolean
|
|
33
|
+
// whether or not the user is dragging an annotation
|
|
34
|
+
isDraggingAnnotation?: boolean
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
// Line Chart Specific Context
|
|
31
38
|
type LineChartContext = SharedChartContext & {
|
|
39
|
+
convertLineToBarGraph: boolean
|
|
32
40
|
dimensions: [screenWidth: number, screenHeight: number]
|
|
33
41
|
formatDate: Function
|
|
34
42
|
formatTooltipsDate: Function
|
|
@@ -50,6 +58,7 @@ type LineChartContext = SharedChartContext & {
|
|
|
50
58
|
export type ChartContext =
|
|
51
59
|
| LineChartContext
|
|
52
60
|
| (SharedChartContext & {
|
|
61
|
+
annotations: Annotation[]
|
|
53
62
|
dimensions: [screenWidth: number, screenHeight: number]
|
|
54
63
|
formatDate?: Function
|
|
55
64
|
formatTooltipsDate: Function
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { testZeroValue } from '../../src/components/BarChart/helpers'
|
|
2
|
+
|
|
3
|
+
describe('testZeroValue', () => {
|
|
4
|
+
test('returns true for "0" as string', () => {
|
|
5
|
+
expect(testZeroValue('0')).toBe(true)
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
test('returns true for "0" as number', () => {
|
|
9
|
+
expect(testZeroValue(0)).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('returns true for 0.0 as number', () => {
|
|
13
|
+
expect(testZeroValue(0.0)).toBe(true)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
// check false case
|
|
17
|
+
test('returns false for "ABC" as string', () => {
|
|
18
|
+
expect(testZeroValue('ABC')).toBe(false)
|
|
19
|
+
})
|
|
20
|
+
test('returns false for 999 as number', () => {
|
|
21
|
+
expect(testZeroValue(999)).toBe(false)
|
|
22
|
+
})
|
|
23
|
+
// test for null & undefined cases
|
|
24
|
+
test('returns undefined for a null', () => {
|
|
25
|
+
expect(testZeroValue(null)).toBe(undefined)
|
|
26
|
+
})
|
|
27
|
+
test('returns undefined for a undefined', () => {
|
|
28
|
+
expect(testZeroValue(undefined)).toBe(undefined)
|
|
29
|
+
})
|
|
30
|
+
})
|
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.
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const filterData = (filters, data) => {
|
|
2
|
-
let filteredData: any[] = []
|
|
3
|
-
|
|
4
|
-
data.forEach(row => {
|
|
5
|
-
let add = true
|
|
6
|
-
filters
|
|
7
|
-
.filter(filter => filter.type !== 'url')
|
|
8
|
-
.forEach(filter => {
|
|
9
|
-
if (row[filter.columnName] != filter.active) {
|
|
10
|
-
add = false
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
if (add) filteredData.push(row)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
return filteredData
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ChartConfig } from '../../types/ChartConfig'
|
|
2
|
-
import { Legend } from '@cdc/core/types/Legend'
|
|
3
|
-
import { computeMarginBottom } from '../computeMarginBottom'
|
|
4
|
-
|
|
5
|
-
describe('computeMarginBottom', () => {
|
|
6
|
-
it('should return correct value', () => {
|
|
7
|
-
const config = {
|
|
8
|
-
orientation: 'horizontal',
|
|
9
|
-
xAxis: { labelOffset: '10' },
|
|
10
|
-
yAxis: { label: null },
|
|
11
|
-
brush: { active: false },
|
|
12
|
-
isResponsiveTicks: true,
|
|
13
|
-
dynamicMarginTop: 20
|
|
14
|
-
}
|
|
15
|
-
const legend = { position: 'top' }
|
|
16
|
-
const currentViewport = 'md'
|
|
17
|
-
expect(computeMarginBottom(config as unknown as ChartConfig, legend as Legend, currentViewport)).toBe('0px')
|
|
18
|
-
config.yAxis.label = 'label'
|
|
19
|
-
expect(computeMarginBottom(config as unknown as ChartConfig, legend as Legend, currentViewport)).toBe('40px')
|
|
20
|
-
})
|
|
21
|
-
})
|
|
File without changes
|
|
File without changes
|