@cdc/chart 4.23.5 → 4.23.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.
@@ -2,22 +2,23 @@ import React, { useContext } from 'react'
2
2
 
3
3
  import * as allCurves from '@visx/curve'
4
4
  import { Group } from '@visx/group'
5
- import { LinePath } from '@visx/shape'
5
+ import { LinePath, Bar } from '@visx/shape'
6
6
  import { Text } from '@visx/text'
7
7
 
8
8
  import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
9
9
  import ConfigContext from '../ConfigContext'
10
10
  import useRightAxis from '../hooks/useRightAxis'
11
11
 
12
- export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData, xMax, yMax, seriesStyle = 'Line' }) {
13
- const { colorPalettes, transformedData: data, colorScale, seriesHighlight, config, formatNumber, formatDate, parseDate, isNumber, updateConfig, handleLineType } = useContext(ConfigContext)
12
+ const LineChart = ({ xScale, yScale, getXAxisData, getYAxisData, xMax, yMax, handleTooltipMouseOver, handleTooltipMouseOff, showTooltip, seriesStyle = 'Line', svgRef, handleTooltipClick, tooltipData }) => {
13
+ // Not sure why there's a redraw here.
14
14
 
15
+ const { colorPalettes, transformedData: data, colorScale, seriesHighlight, config, formatNumber, formatDate, parseDate, isNumber, updateConfig, handleLineType, dashboardConfig } = useContext(ConfigContext)
15
16
  const { yScaleRight } = useRightAxis({ config, yMax, data, updateConfig })
16
17
 
18
+ if (!handleTooltipMouseOver) return
17
19
  const handleAxisFormating = (axis = 'left', label, value) => {
18
20
  // if this is an x axis category/date value return without doing any formatting.
19
21
  // if (label === config.runtime.xAxis.label) return value
20
-
21
22
  axis = String(axis).toLocaleLowerCase()
22
23
  if (label) {
23
24
  return `${label}: ${formatNumber(value, axis)}`
@@ -25,6 +26,7 @@ export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData,
25
26
  return `${formatNumber(value, axis)}`
26
27
  }
27
28
 
29
+ const DEBUG = false
28
30
  return (
29
31
  <ErrorBoundary component='LineChart'>
30
32
  <Group left={config.runtime.yAxis.size ? parseInt(config.runtime.yAxis.size) : 66}>
@@ -35,6 +37,8 @@ export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData,
35
37
  const seriesData = config.series.filter(item => item.dataKey === seriesKey)
36
38
  const seriesAxis = seriesData[0].axis ? seriesData[0].axis : 'left'
37
39
 
40
+ let displayArea = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(seriesKey) !== -1
41
+
38
42
  return (
39
43
  <Group
40
44
  key={`series-${seriesKey}`}
@@ -62,6 +66,8 @@ export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData,
62
66
  ${yAxisTooltip}<br />
63
67
  ${xAxisTooltip}
64
68
  </div>`
69
+
70
+ // TODO: move all instances of circleRadii to state.
65
71
  let circleRadii = 4.5
66
72
 
67
73
  return (
@@ -69,7 +75,10 @@ export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData,
69
75
  d[seriesKey] !== '' &&
70
76
  d[seriesKey] !== null &&
71
77
  isNumber(d[seriesKey]) && (
72
- <Group key={`series-${seriesKey}-point-${dataIndex}`}>
78
+ <Group key={`series-${seriesKey}-point-${dataIndex}`} className='checkwidth'>
79
+ {/* tooltips */}
80
+ <Bar key={'bars'} width={Number(xMax)} height={Number(yMax)} fill={DEBUG ? 'red' : 'transparent'} fillOpacity={0.05} onMouseMove={e => handleTooltipMouseOver(e, data)} onMouseOut={handleTooltipMouseOff} onClick={e => handleTooltipClick(e, data)} />
81
+
73
82
  {/* Render legend */}
74
83
  <Text display={config.labels ? 'block' : 'none'} x={xScale(getXAxisData(d))} y={seriesAxis === 'Right' ? yScaleRight(getYAxisData(d, seriesKey)) : yScale(getYAxisData(d, seriesKey))} fill={'#000'} textAnchor='middle'>
75
84
  {formatNumber(d[seriesKey], 'left')}
@@ -81,10 +90,26 @@ export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData,
81
90
  cx={Number(xScale(getXAxisData(d)))}
82
91
  cy={seriesAxis === 'Right' ? yScaleRight(getYAxisData(d, seriesKey)) : yScale(getYAxisData(d, seriesKey))}
83
92
  fill={colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000'}
84
- style={{ fill: colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000' }}
93
+ style={{
94
+ fill: colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000'
95
+ }}
85
96
  data-tooltip-html={tooltip}
86
97
  data-tooltip-id={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
87
98
  />
99
+
100
+ {/* circles that appear on hover */}
101
+ {/* todo: circle radii used here should be global with other circle radii */}
102
+ {/* {tooltipData && Object.entries(tooltipData.data).length > 0 && isNumber(tooltipData.data[seriesKey]) && config.lineDatapointStyle === 'hover' && config.series.filter(s => s.type === 'Line') && (
103
+ <circle
104
+ cx={config.xAxis.type === 'categorical' ? xScale(tooltipData.data[config.xAxis.dataKey]) : xScale(parseDate(tooltipData.data[config.xAxis.dataKey]))}
105
+ cy={yScale(tooltipData.data[seriesKey])}
106
+ r={4.5}
107
+ opacity={tooltipData[seriesKey] ? 1 : 0}
108
+ fillOpacity={1}
109
+ fill={displayArea ? (colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000') : 'transparent'}
110
+ style={{ filter: 'unset', opacity: 1 }}
111
+ />
112
+ )} */}
88
113
  </Group>
89
114
  )
90
115
  )
@@ -107,7 +132,7 @@ export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData,
107
132
  strokeOpacity={1}
108
133
  strokeDasharray={lineType ? handleLineType(lineType) : 0}
109
134
  defined={(item, i) => {
110
- return item[config.runtime.seriesLabels[seriesKey]] !== '' && item[config.runtime.seriesLabels[seriesKey]] !== null && item[config.runtime.seriesLabels[seriesKey]] !== undefined
135
+ return item[seriesKey] !== '' && item[seriesKey] !== null && item[seriesKey] !== undefined
111
136
  }}
112
137
  />
113
138
  {config.animate && (
@@ -159,3 +184,5 @@ export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData,
159
184
  </ErrorBoundary>
160
185
  )
161
186
  }
187
+
188
+ export default LineChart