import { Skeleton } from '@app/components/placeholders/skeleton' import { Analytic, Website } from '@app/types' import { VictoryAxis, VictoryChart, VictoryLabel, VictoryLine, VictoryTooltip, VictoryScatter, VictoryVoronoiContainer, } from 'victory' import { useLineChart } from './use-chart' interface LineChartProps { title?: string // page title data?: Analytic[] | Website[] } // web safe colors for charts const RED_COLOR = '#7c270b' const RED_FILL_COLOR = 'rgb(220 38 38)' const RED_STROKE_COLOR = 'rgb(248 113 113)' const YELLOW_COLOR = 'rgb(234 179 8)' const YELLOW_FILL_COLOR = 'rgb(250 204 21)' const YELLOW_STROKE_COLOR = 'rgb(253 224 71)' // chart styles const styles = { title: { textAnchor: 'start', verticalAnchor: 'end', }, labelNumber: { textAnchor: 'middle', fontFamily: 'inherit', fontSize: '6px', }, axisOne: { axis: { stroke: RED_COLOR, strokeWidth: 0 }, ticks: { strokeWidth: 0 }, tickLabels: { fontFamily: 'inherit', fontSize: 6.5, }, }, labelOne: { fill: RED_COLOR, fontFamily: 'inherit', fontSize: 7, fontStyle: 'italic', }, lineOne: { data: { stroke: RED_COLOR, strokeWidth: 0.8 }, }, lineOneScatter: { data: { stroke: RED_STROKE_COLOR, strokeWidth: 0.8, fill: RED_FILL_COLOR }, }, axisTwo: { axis: { stroke: YELLOW_COLOR, strokeWidth: 0 }, tickLabels: { fontFamily: 'inherit', fontSize: 6.5, }, }, labelTwo: { textAnchor: 'end', fill: YELLOW_COLOR, fontFamily: 'inherit', fontSize: 7, fontStyle: 'italic', }, lineTwo: { data: { stroke: YELLOW_COLOR, strokeWidth: 0.8 }, }, lineTwoScatter: { data: { stroke: YELLOW_STROKE_COLOR, strokeWidth: 0.8, fill: YELLOW_FILL_COLOR, }, }, } // error line chart for warnings, errors export const LineChart = ({ title, data }: LineChartProps) => { const { first, second, ticks, highestError, highestWarning, totalErrors, totalWarnings, determinedType, } = useLineChart({ data }) // display empty loading state if (!data) { return (
) } const headingText = `${totalErrors} error${ totalErrors === 1 ? '' : 's' } and ${totalWarnings} warning${totalWarnings === 1 ? '' : 's'} across ${ ticks.length } ${determinedType || 'page'}${ticks.length === 1 ? '' : 's'}` // render website chart if (determinedType === 'website') { return ( datum.l} labelComponent={ } /> } > ) } return ( datum.l} labelComponent={ } /> } > totalWarnings ? 'fill-red-600' : 'fill-blue-600' } /> ) }