Skip to content

Commit

Permalink
Merge pull request #162 from bryanlundberg/formatTime-in-charts
Browse files Browse the repository at this point in the history
Format time for line chart and fixed data order
  • Loading branch information
bryanlundberg authored Nov 7, 2023
2 parents cb7b52c + 22a3b1e commit 9ec567a
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/components/charts/LineCharter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Solve } from "@/interfaces/Solve";
import { sort } from "fast-sort";
import formatTime from "@/lib/formatTime";
import { createChart } from "lightweight-charts";
import { useEffect, useRef } from "react";

Expand All @@ -17,6 +17,11 @@ const chartOptions: any = {
},
},
localization: {
priceFormatter: (time: number) => {
const timeT = formatTime(time);
console.log(time);
return timeT;
},
timeFormatter: (time: number) => {
return time.toString();
},
Expand All @@ -26,6 +31,9 @@ const chartOptions: any = {
return time.toString();
},
},
priceScale: {
autoScale: false,
},
};

export default function LineCharter({
Expand All @@ -43,16 +51,19 @@ export default function LineCharter({
container.innerHTML = "";
const chart = createChart(container, chartOptions);
const dataArray = cubeSelected ? data.cubeAll : data.global;
const structuredData: any = sort(
dataArray.map((i: Solve, index: number) => ({
time: index,
value: i.time / 1000,
}))
).asc((u: any) => u.time);
const structuredData: any[] = [];
dataArray.forEach((i: Solve, index: number) => {
console.log({ time: index, value: i.time });
structuredData.unshift({
time: dataArray.length - index,
value: i.time,
});
});

const lineSeries = chart.addLineSeries({
color: cubeSelected ? "#2962FF" : "#F4D03F",
});

lineSeries.setData(structuredData);

chart.autoSizeActive();
Expand Down

0 comments on commit 9ec567a

Please sign in to comment.