Skip to content
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

Fix last point of line charts. And small other fixes to line charts. #21235

Merged
merged 4 commits into from
Jul 20, 2024
Merged
Changes from all commits
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
17 changes: 9 additions & 8 deletions src/panels/lovelace/common/graph/coordinates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ const calcPoints = (
let xRatio = width / (hours - (detail === 1 ? 1 : 0));
xRatio = isFinite(xRatio) ? xRatio : width;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Number.isFinite instead of the global isFinite.

ES2015 moved some globals into the Number namespace for consistency.

-  xRatio = isFinite(xRatio) ? xRatio : width;
+  xRatio = Number.isFinite(xRatio) ? xRatio : width;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
xRatio = isFinite(xRatio) ? xRatio : width;
xRatio = Number.isFinite(xRatio) ? xRatio : width;
Tools
Biome

[error] 23-23: isFinite is unsafe. It attempts a type coercion. Use Number.isFinite instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isFinite instead.

(lint/suspicious/noGlobalIsFinite)


const first = history.filter(Boolean)[0];
let first = history.filter(Boolean)[0];
if (detail > 1) {
first = first.filter(Boolean)[0];
}
let last = [average(first), lastValue(first)];

const getY = (value: number): number =>
height + strokeWidth / 2 - (value - min) / yRatio;

const getCoords = (item: any[], i: number, offset = 0, depth = 1) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using any type.

Specify a different type for the item parameter to enable better type checking.

-const getCoords = (item: any[], i: number, offset = 0, depth = 1) => {
+const getCoords = (item: { state: string }[], i: number, offset = 0, depth = 1) => {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const getCoords = (item: any[], i: number, offset = 0, depth = 1) => {
const getCoords = (item: { state: string }[], i: number, offset = 0, depth = 1) => {
Tools
Biome

[error] 35-35: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

if (depth > 1 && item) {
return item.forEach((subItem, index) =>
Expand All @@ -37,20 +43,15 @@ const calcPoints = (
if (item) {
last = [average(item), lastValue(item)];
}
const y =
height + strokeWidth / 2 - ((item ? last[0] : last[1]) - min) / yRatio;
const y = getY(item ? last[0] : last[1]);
return coords.push([x, y]);
};

for (let i = 0; i < history.length; i += 1) {
getCoords(history[i], i, 0, detail);
}

if (coords.length === 1) {
coords[1] = [width, coords[0][1]];
}

coords.push([width, coords[coords.length - 1][1]]);
coords.push([width, getY(last[1])]);
return coords;
};

Expand Down
Loading