-
-
Notifications
You must be signed in to change notification settings - Fork 30
Add chart max domain calc function & tests #510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
braddf
wants to merge
2
commits into
development
Choose a base branch
from
issue/509-chart-upper-limit
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Heartbeat endpoint for the Quartz app | ||
|
|
||
| import { NextApiRequest, NextApiResponse } from "next"; | ||
|
|
||
| export default function handler(req: NextApiRequest, res: NextApiResponse) { | ||
| res.status(200).json({ status: "ok" }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| 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 dataMax = 1800; | ||
| const roundingTickAmount = 1000; | ||
| const buffer = 100; | ||
| const result = getDomainWithUpperBuffer( | ||
| dataMax, | ||
| roundingTickAmount, | ||
| buffer | ||
| ); | ||
| expect(result).toEqual([0, 2000]); | ||
| }); | ||
| it("should return the next closest 1000 above the dataMax (larger max)", () => { | ||
| const dataMax = 9500; | ||
| const roundingTickAmount = 1000; | ||
| const buffer = 100; | ||
| const result = getDomainWithUpperBuffer( | ||
| dataMax, | ||
| roundingTickAmount, | ||
| buffer | ||
| ); | ||
| expect(result).toEqual([0, 10000]); | ||
| }); | ||
| it("should return dataMax if is on a round x1000 and has no buffer", () => { | ||
| const dataMax = 2000; | ||
| const roundingTickAmount = 1000; | ||
| const buffer = 0; | ||
| const result = getDomainWithUpperBuffer( | ||
| dataMax, | ||
| roundingTickAmount, | ||
| buffer | ||
| ); | ||
| expect(result).toEqual([0, 2000]); | ||
| }); | ||
| it("should return the tick if is exactly dataMax + buffer", () => { | ||
| const dataMax = 1900; | ||
| const roundingTickAmount = 1000; | ||
| const buffer = 100; | ||
| const result = getDomainWithUpperBuffer( | ||
| dataMax, | ||
| roundingTickAmount, | ||
| buffer | ||
| ); | ||
| expect(result).toEqual([0, 2000]); | ||
| }); | ||
| it("should return the 1000 above if is on a buffer pushes into next band", () => { | ||
| const dataMax = 1950; | ||
| const roundingTickAmount = 1000; | ||
| const buffer = 100; | ||
| const result = getDomainWithUpperBuffer( | ||
| dataMax, | ||
| roundingTickAmount, | ||
| buffer | ||
| ); | ||
| expect(result).toEqual([0, 3000]); | ||
| }); | ||
| it("should ignore the dataMin and always return 0", () => { | ||
| const dataMax = 1800; | ||
| const roundingTickAmount = 1000; | ||
| const buffer = 100; | ||
| const result = getDomainWithUpperBuffer( | ||
| dataMax, | ||
| roundingTickAmount, | ||
| buffer | ||
| ); | ||
| expect(result).toEqual([0, 2000]); | ||
| }); | ||
| it("should return the dataMax + buffer if the roundingTickAmount is 0", () => { | ||
| const dataMax = 1800; | ||
| const roundingTickAmount = 0; | ||
| const buffer = 100; | ||
| const result = getDomainWithUpperBuffer( | ||
| dataMax, | ||
| roundingTickAmount, | ||
| buffer | ||
| ); | ||
| expect(result).toEqual([0, 1900]); | ||
| }); | ||
| it("should return the dataMax + buffer if the roundingTickAmount is negative", () => { | ||
| const dataMax = 1800; | ||
| const roundingTickAmount = -1000; | ||
| const buffer = 100; | ||
| const result = getDomainWithUpperBuffer( | ||
| dataMax, | ||
| roundingTickAmount, | ||
| buffer | ||
| ); | ||
| expect(result).toEqual([0, 1900]); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Calculates the domain for a chart axis with an upper buffer. | ||
| * | ||
| * @param dataMax - The maximum data value that will be plotted on the chart. | ||
| * @param roundingTickAmount - The value to which the maximum data value should be rounded up. | ||
| * @param buffer - The buffer amount to be added to the maximum data value before rounding. | ||
| * @returns An array where the first element is the minimum domain value (always 0) | ||
| * and the second element is the maximum domain value, calculated by | ||
| * rounding up the sum of the maximum data value and the buffer to the | ||
| * nearest multiple of the rounding tick amount. | ||
| */ | ||
| export const getDomainWithUpperBuffer = ( | ||
| dataMax: number, | ||
| roundingTickAmount: number, | ||
| buffer: number | ||
| ): [number, number] => { | ||
| if (roundingTickAmount <= 0) return [0, dataMax + buffer]; | ||
| const roundedMax = | ||
| Math.ceil((dataMax + buffer) / roundingTickAmount) * roundingTickAmount; | ||
| return [0, roundedMax]; | ||
| }; | ||
braddf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.