/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import * as React from 'react'
import * as Recharts from 'recharts'
import { ITheme } from '../theme'
import styled, { withTheme } from 'styled-components'
const {
CartesianGrid,
Legend,
Line,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis
} = Recharts
const Container = styled.div`
box-sizing: border-box;
width: 100%;
align-items: center;
.recharts-label {
text-anchor: middle;
}
${({ theme }) => theme.fonts.bold14};
`
interface IProps {
data: ILineDataPoint[]
dataKeys: string[]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mouseMoveHandler: (data: any) => void
mouseLeaveHandler: () => void
// eslint-disable-next-line @typescript-eslint/no-explicit-any
tooltipContent: (dataPoint: any) => React.ReactNode
legendContent: () => React.ReactNode
theme: ITheme
chartTop: number
chartRight: number
chartBottom: number
chartLeft: number
maximizeXAxisInterval?: boolean
legendLayout: Recharts.LegendProps['layout']
}
interface ILineDataPoint {
label: React.ReactNode
registeredInTargetDays: number
totalRegistered: number
totalEstimate: number
registrationPercentage: string
}
interface ICustomisedDot {
cx: number
cy: number
theme: ITheme
}
function CustomizedDot(props: ICustomisedDot) {
const { cx, cy, theme } = props
return (
)
}
interface IAxisTickProps {
x: number
y: number
stroke: string
payload: {
value: string
}
}
interface IThemedAxisTickProps extends IAxisTickProps {
theme: ITheme
}
function CustomizedAxisTick(props: IThemedAxisTickProps) {
const { x, y, payload, theme } = props
const values = payload.value.split(' ')
return (
{values.map((value, i) => (
0 ? 18 : 24}`}>
{value}
))}
)
}
class LineChartComponent extends React.Component {
render() {
const {
data,
mouseMoveHandler,
mouseLeaveHandler,
dataKeys,
theme,
tooltipContent,
legendContent,
chartTop,
chartRight,
chartBottom,
chartLeft,
maximizeXAxisInterval,
legendLayout
} = this.props
return (
{(maximizeXAxisInterval && (
)) || (
(
)}
/>
)}
{!maximizeXAxisInterval && (
)}
(
)}
strokeWidth={3}
/>
)
}
}
export const LineChart = withTheme(LineChartComponent)