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 SVG scaling in graph log. #586

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ export class GraphLogController
}

private onGraphMouseMove_(ev: MouseEvent): void {
const bounds = this.view.element.getBoundingClientRect();
const {clientWidth: w} = this.view.element;

this.cursor_.rawValue = Math.floor(
mapRange(ev.offsetX, 0, bounds.width, 0, this.value.rawValue.length),
mapRange(ev.offsetX, 0, w, 0, this.value.rawValue.length),
);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/monitor-binding/number/view/graph-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class GraphLogView implements View {
}

private update_(): void {
const bounds = this.svgElem_.getBoundingClientRect();
const {clientWidth: w, clientHeight: h} = this.element;

// Graph
const maxIndex = this.value.rawValue.length - 1;
Expand All @@ -91,8 +91,8 @@ export class GraphLogView implements View {
if (v === undefined) {
return;
}
const x = mapRange(index, 0, maxIndex, 0, bounds.width);
const y = mapRange(v, min, max, bounds.height, 0);
const x = mapRange(index, 0, maxIndex, 0, w);
const y = mapRange(v, min, max, h, 0);
points.push([x, y].join(','));
});
this.lineElem_.setAttributeNS(null, 'points', points.join(' '));
Expand All @@ -105,8 +105,8 @@ export class GraphLogView implements View {
return;
}

const tx = mapRange(this.cursor_.rawValue, 0, maxIndex, 0, bounds.width);
const ty = mapRange(value, min, max, bounds.height, 0);
const tx = mapRange(this.cursor_.rawValue, 0, maxIndex, 0, w);
const ty = mapRange(value, min, max, h, 0);
tooltipElem.style.left = `${tx}px`;
tooltipElem.style.top = `${ty}px`;
tooltipElem.textContent = `${this.formatter_(value)}`;
Expand Down
Loading