Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/quartz-app/src/components/charts/Charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { useChartData } from "@/src/hooks/useChartData";
import { CustomLabel } from "@/src/components/charts/labels/CustomLabel";
import { useGlobalState } from "../helpers/globalState";
import { DateTime } from "luxon";
import { getDomainWithUpperBuffer } from "@/src/helpers/chart";

type ChartsProps = {
combinedData: CombinedData;
Expand Down Expand Up @@ -134,6 +135,9 @@ const Charts: FC<ChartsProps> = ({ combinedData }) => {
/>
<YAxis
tick={{ fill: "white", style: { fontSize: "12px" } }}
domain={(dataMinMax) =>
getDomainWithUpperBuffer(dataMinMax, 100)
}
label={{
value: "Generation ( MW )",
angle: 270,
Expand Down
40 changes: 40 additions & 0 deletions apps/quartz-app/src/helpers/chart.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getDomainWithUpperBuffer } from "@/src/helpers/chart";

describe("Get Domain with upper buffer for chart", () => {
it("should return the next closest 1000 above the dataMax", () => {
const dataMinMax: [number, number] = [0, 1800];
const buffer = 100;
const result = getDomainWithUpperBuffer(dataMinMax, buffer);
expect(result).toEqual([0, 2000]);
});
it("should return the next closest 1000 above the dataMax (larger max)", () => {
const dataMinMax: [number, number] = [0, 9500];
const buffer = 100;
const result = getDomainWithUpperBuffer(dataMinMax, buffer);
expect(result).toEqual([0, 10000]);
});
it("should return dataMax + 1000 if is on a round x1000 and has no buffer", () => {
const dataMinMax: [number, number] = [0, 2000];
const buffer = 0;
const result = getDomainWithUpperBuffer(dataMinMax, buffer);
expect(result).toEqual([0, 3000]);
});
it("should return the 1000 above if buffer puts exactly on a x1000", () => {
const dataMinMax: [number, number] = [0, 1900];
const buffer = 100;
const result = getDomainWithUpperBuffer(dataMinMax, buffer);
expect(result).toEqual([0, 3000]);
});
it("should return the 1000 above if is on a buffer pushes into next band", () => {
const dataMinMax: [number, number] = [0, 1950];
const buffer = 100;
const result = getDomainWithUpperBuffer(dataMinMax, buffer);
expect(result).toEqual([0, 3000]);
});
it("should ignore the dataMin and always return 0", () => {
const dataMinMax: [number, number] = [1000, 1800];
const buffer = 100;
const result = getDomainWithUpperBuffer(dataMinMax, buffer);
expect(result).toEqual([0, 2000]);
});
});
6 changes: 6 additions & 0 deletions apps/quartz-app/src/helpers/chart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const getDomainWithUpperBuffer = (
[dataMin, dataMax]: [number, number],
buffer: number
): [number, number] => {
return [0, Math.floor((dataMax + buffer) / 1000) * 1000 + 1000];
};