Skip to content

Commit

Permalink
Add line chart
Browse files Browse the repository at this point in the history
  • Loading branch information
edlouth committed Aug 24, 2023
1 parent fe9ddea commit b738024
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
104 changes: 104 additions & 0 deletions grai-frontend/src/components/nodes/LineChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
Chart,
ChartData,
ChartOptions,
LineElement,
PointElement,
} from "chart.js"
import React from "react"
import { Scatter } from "react-chartjs-2"
import theme from "theme"
import { lighten } from "@mui/material"

type LineChartProps = {}

const LineChart: React.FC<LineChartProps> = ({}) => {
Chart.register(PointElement, LineElement)

Check warning on line 16 in grai-frontend/src/components/nodes/LineChart.tsx

View check run for this annotation

Codecov / codecov/patch

grai-frontend/src/components/nodes/LineChart.tsx#L16

Added line #L16 was not covered by tests

const inputData = [

Check warning on line 18 in grai-frontend/src/components/nodes/LineChart.tsx

View check run for this annotation

Codecov / codecov/patch

grai-frontend/src/components/nodes/LineChart.tsx#L18

Added line #L18 was not covered by tests
{
x: 0,
y: 0,
},
{
x: 1,
y: 2,
},
{
x: 2,
y: 2,
},
{
x: 3,
y: 4,
},
{
x: 4,
y: 5,
},
{
x: 5,
y: 10,
},
{
x: 6,
y: 11,
},
{
x: 7,
y: 12,
},
{
x: 8,
y: 18,
},
{
x: 9,
y: 19,
},
{
x: 10,
y: 20,
},
{
x: 20,
y: 18,
},
{
x: 30,
y: 10,
},
]

const options: ChartOptions<"scatter"> = {

Check warning on line 73 in grai-frontend/src/components/nodes/LineChart.tsx

View check run for this annotation

Codecov / codecov/patch

grai-frontend/src/components/nodes/LineChart.tsx#L73

Added line #L73 was not covered by tests
scales: {
x: {
grid: {
display: false,
},
},
y: {
grid: {
display: false,
},
},
},
}

const data: ChartData<"scatter"> = {

Check warning on line 88 in grai-frontend/src/components/nodes/LineChart.tsx

View check run for this annotation

Codecov / codecov/patch

grai-frontend/src/components/nodes/LineChart.tsx#L88

Added line #L88 was not covered by tests
datasets: [
{
data: inputData,
showLine: true,
datalabels: { display: false },
pointRadius: 0,
borderColor: lighten(theme.palette.info.main, 0.75),
borderWidth: 2,
},
],
}

return <Scatter data={data} options={options} />

Check warning on line 101 in grai-frontend/src/components/nodes/LineChart.tsx

View check run for this annotation

Codecov / codecov/patch

grai-frontend/src/components/nodes/LineChart.tsx#L101

Added line #L101 was not covered by tests
}

export default LineChart
3 changes: 3 additions & 0 deletions grai-frontend/src/components/nodes/NodeProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import TableDetail from "./TableDetail"
import NodeDetailRow from "components/layout/NodeDetailRow"
import LinearProgress from "components/progress/LinearProgress"
import BarChart from "./BarChart"
import LineChart from "./LineChart"

// interface BaseTable {
// id: string
// display_name: string
Expand Down Expand Up @@ -67,6 +69,7 @@ const NodeProfile: React.FC<NodeProfileProps> = ({ node }) => (
<LinearProgress value={30} title="cash" titleValue={15} />
<LinearProgress value={10} title="bnpl" titleValue={5} />
<BarChart />
<LineChart />
</Stack>
</NodeDetailRow>
)}
Expand Down

0 comments on commit b738024

Please sign in to comment.