Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved health chart tooltip (#6359)
- Loading branch information
Showing
15 changed files
with
489 additions
and
354 deletions.
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
41 changes: 41 additions & 0 deletions
41
.../component/executiveDashboard/HorizontalDistributionChart/HorizontalDistributionChart.tsx
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { VFC } from 'react'; | ||
import { Box, styled } from '@mui/material'; | ||
|
||
type DistributionLineTypes = 'default' | 'success' | 'warning' | 'error'; | ||
|
||
const StyledDistributionLine = styled(Box)<{ | ||
type: DistributionLineTypes; | ||
size?: 'large' | 'small'; | ||
}>(({ theme, type, size = 'large' }) => { | ||
const color: Record<DistributionLineTypes, string | undefined> = { | ||
default: theme.palette.secondary.border, | ||
success: theme.palette.success.border, | ||
warning: theme.palette.warning.border, | ||
error: theme.palette.error.border, | ||
}; | ||
|
||
return { | ||
borderRadius: theme.shape.borderRadius, | ||
height: size === 'large' ? theme.spacing(2) : theme.spacing(1), | ||
backgroundColor: color[type], | ||
marginBottom: theme.spacing(0.5), | ||
}; | ||
}); | ||
|
||
export const HorizontalDistributionChart: VFC<{ | ||
sections: Array<{ type: DistributionLineTypes; value: number }>; | ||
size?: 'large' | 'small'; | ||
}> = ({ sections, size }) => ( | ||
<Box sx={(theme) => ({ display: 'flex', gap: theme.spacing(0.5) })}> | ||
{sections.map((section, index) => | ||
section.value ? ( | ||
<StyledDistributionLine | ||
type={section.type} | ||
sx={{ width: `${section.value}%` }} | ||
key={`${section.type}-${index}`} | ||
size={size} | ||
/> | ||
) : null, | ||
)} | ||
</Box> | ||
); |
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
77 changes: 77 additions & 0 deletions
77
frontend/src/component/executiveDashboard/LineChart/createChartOptions.ts
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Theme } from '@mui/material'; | ||
import { ILocationSettings } from 'hooks/useLocationSettings'; | ||
import { TooltipState } from './ChartTooltip/ChartTooltip'; | ||
import { createTooltip } from './createTooltip'; | ||
import { legendOptions } from './legendOptions'; | ||
|
||
export const createOptions = ( | ||
theme: Theme, | ||
locationSettings: ILocationSettings, | ||
setTooltip: React.Dispatch<React.SetStateAction<TooltipState | null>>, | ||
isPlaceholder?: boolean, | ||
localTooltip?: boolean, | ||
) => | ||
({ | ||
responsive: true, | ||
...(isPlaceholder | ||
? { | ||
animation: { | ||
duration: 0, | ||
}, | ||
} | ||
: {}), | ||
plugins: { | ||
legend: { | ||
...legendOptions, | ||
display: !isPlaceholder, | ||
}, | ||
tooltip: { | ||
enabled: false, | ||
external: createTooltip(setTooltip), | ||
}, | ||
}, | ||
locale: locationSettings.locale, | ||
interaction: { | ||
intersect: localTooltip || false, | ||
axis: 'x', | ||
}, | ||
elements: { | ||
point: { | ||
radius: 0, | ||
hitRadius: 15, | ||
}, | ||
}, | ||
// cubicInterpolationMode: 'monotone', | ||
tension: 0.1, | ||
color: theme.palette.text.secondary, | ||
scales: { | ||
y: { | ||
beginAtZero: true, | ||
type: 'linear', | ||
grid: { | ||
color: theme.palette.divider, | ||
borderColor: theme.palette.divider, | ||
}, | ||
ticks: { | ||
color: theme.palette.text.secondary, | ||
display: !isPlaceholder, | ||
precision: 0, | ||
}, | ||
}, | ||
x: { | ||
type: 'time', | ||
time: { | ||
unit: 'day', | ||
tooltipFormat: 'PPP', | ||
}, | ||
grid: { | ||
color: 'transparent', | ||
borderColor: 'transparent', | ||
}, | ||
ticks: { | ||
color: theme.palette.text.secondary, | ||
display: !isPlaceholder, | ||
}, | ||
}, | ||
}, | ||
}) as const; |
Oops, something went wrong.