1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-27 07:24:17 +00:00
pds-2021-g2-nest/nest_frontend/components/base/BoxChart.js

64 lines
2 KiB
JavaScript
Raw Normal View History

import React, { useMemo } from "react"
2021-05-20 11:36:07 +00:00
import BoxFull from "./BoxFull"
import ChartComponent from "react-chartjs-2"
export default function BoxChart({ chartProps, ...props }) {
2021-05-20 11:36:07 +00:00
const getCssVar = (variable) => {
2021-05-20 13:34:05 +00:00
const computedStyle = window.getComputedStyle(document.querySelector("main"))
2021-05-20 11:36:07 +00:00
return computedStyle.getPropertyValue(variable).trim()
}
const chart = useMemo(
() => (
2021-05-20 13:34:05 +00:00
<ChartComponent
options={{
responsive: true,
scales: {
x: {
beginAtZero: true,
grid: {
borderColor: getCssVar("--bg-light"),
color: getCssVar("--bg-light"),
2021-05-20 11:36:07 +00:00
},
2021-05-20 13:34:05 +00:00
ticks: {
2021-05-20 11:36:07 +00:00
color: getCssVar("--fg-primary"),
},
2021-05-20 13:34:05 +00:00
},
y: {
beginAtZero: true,
grid: {
borderColor: getCssVar("--bg-light"),
color: getCssVar("--bg-light"),
2021-05-20 11:36:07 +00:00
},
2021-05-20 13:34:05 +00:00
ticks: {
color: getCssVar("--fg-primary"),
},
2021-05-20 13:34:05 +00:00
},
},
elements: {
bar: {
backgroundColor: getCssVar("--fg-primary"),
borderColor: "transparent",
color: getCssVar("--fg-primary"),
2021-05-20 11:36:07 +00:00
},
2021-05-20 13:34:05 +00:00
},
plugins: {
legend: {
display: false,
},
},
2021-05-20 13:34:05 +00:00
}}
{...chartProps}
/>
),
2021-05-23 14:20:53 +00:00
[chartProps],
)
return (
<BoxFull {...props}>
{chart}
2021-05-20 11:36:07 +00:00
</BoxFull>
)
}