This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
feature/COR-1953_non-archived-graphs-adjustments #5005
Merged
ben-van-eekelen
merged 1 commit into
topic/COR-1952_COR-1953_graph-adjustments
from
feature/COR-1953_non-archived-graphs-adjustments
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { TimeframeOption, TimestampedValue } from '@corona-dashboard/common'; | ||
import { TimeframeOption, TimestampedValue, isDateSeries, isDateSpanSeries } from '@corona-dashboard/common'; | ||
import css from '@styled-system/css'; | ||
import { TickFormatter } from '@visx/axis'; | ||
import { useTooltip } from '@visx/tooltip'; | ||
|
@@ -53,6 +53,7 @@ import { | |
useValuesInTimeframe, | ||
useValueWidth, | ||
} from './logic'; | ||
import { DateRange } from '../metadata'; | ||
export type { SeriesConfig } from './logic'; | ||
|
||
/** | ||
|
@@ -129,6 +130,19 @@ export type TimeSeriesChartProps<T extends TimestampedValue, C extends SeriesCon | |
forceLegend?: boolean; | ||
onSeriesClick?: (seriesConfig: C[number], value: T) => void; | ||
|
||
/** | ||
* These handlers are responsible for managing the parent to child to parent relation. | ||
* The dashboard is not currently adapted to having the CurrentDateContext available | ||
* at page level. In order to connect the state values to the context, we either extract | ||
* all the timeseries instances into separate components or pass the handlers as functions | ||
* from the parent component. onHandleTimeIntervalChange is responsible for handling the | ||
* metadata interval for the X axis. onHandleDateOfInsertion is responsible for handling | ||
* the last insertion date metadata for the interval. | ||
* @param value: DateRange | number | ||
* @returns | ||
*/ | ||
onHandleTimeIntervalChange?: (value: DateRange) => void; | ||
|
||
/** | ||
* By default markers for all series are displayed on hover, also the tooltip | ||
* will display all series of the selected X-value. The `markNearestPointOnly` | ||
|
@@ -151,27 +165,28 @@ export type TimeSeriesChartProps<T extends TimestampedValue, C extends SeriesCon | |
|
||
export function TimeSeriesChart<T extends TimestampedValue, C extends SeriesConfig<T>>({ | ||
accessibility, | ||
values: allValues, | ||
dataOptions, | ||
disableLegend, | ||
displayTooltipValueOnly, | ||
endDate, | ||
seriesConfig, | ||
forceLegend = false, | ||
formatTickValue: formatYTickValue, | ||
formatTooltip, | ||
initialWidth = 840, | ||
isYAxisCollapsed: defaultIsYAxisCollapsed, | ||
markNearestPointOnly, | ||
minHeight = 250, | ||
timeframe = TimeframeOption.ALL, | ||
formatTooltip, | ||
dataOptions, | ||
showWeekNumbers, | ||
numGridLines = 4, | ||
tickValues: yTickValues, | ||
xTickNumber, | ||
formatTickValue: formatYTickValue, | ||
onHandleTimeIntervalChange, | ||
onSeriesClick, | ||
paddingLeft, | ||
seriesConfig, | ||
showWeekNumbers, | ||
tickValues: yTickValues, | ||
timeframe = TimeframeOption.ALL, | ||
tooltipTitle, | ||
disableLegend, | ||
forceLegend = false, | ||
onSeriesClick, | ||
markNearestPointOnly, | ||
displayTooltipValueOnly, | ||
isYAxisCollapsed: defaultIsYAxisCollapsed, | ||
values: allValues, | ||
xTickNumber, | ||
}: TimeSeriesChartProps<T, C>) { | ||
const { commonTexts } = useIntl(); | ||
|
||
|
@@ -193,6 +208,19 @@ export function TimeSeriesChart<T extends TimestampedValue, C extends SeriesConf | |
|
||
const values = useValuesInTimeframe(allValues, timeframe, endDate); | ||
|
||
useEffect(() => { | ||
if (onHandleTimeIntervalChange) { | ||
if (isDateSpanSeries(values)) { | ||
onHandleTimeIntervalChange({ | ||
start: values[0] ? values[0].date_start_unix : 0, | ||
end: values[values.length - 1] ? values[values.length - 1].date_end_unix : 0, | ||
}); | ||
} else if (isDateSeries(values)) { | ||
onHandleTimeIntervalChange({ start: values[0] ? values[0].date_unix : 0, end: values[values.length - 1] ? values[values.length - 1].date_unix : 0 }); | ||
} | ||
} | ||
}, [values, timeframe, onHandleTimeIntervalChange]); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onHandleTimeIntervalChange was added right before the PR. If something is not working correctly, try removing this from dependencies |
||
const cutValuesConfig = useMemo(() => extractCutValuesConfig(timespanAnnotations), [timespanAnnotations]); | ||
|
||
const seriesList = useSeriesList(values, seriesConfig, cutValuesConfig, dataOptions); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very solid work on figuring this out!