Skip to content

Commit

Permalink
Merge pull request #248 from equinor/bug/track-content-width-sometime…
Browse files Browse the repository at this point in the history
…s-does-not-fit-track-width

bug/Track content width sometimes does not fit track width
  • Loading branch information
johannesleite authored May 2, 2024
2 parents f4a3a84 + f462f91 commit 70d7620
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"types": "dist/index.d.ts",
"scripts": {
"start": "rollup -c -w",
"prebuild": "rimraf dist",
"build": "rollup -c",
"prepub": "npm run build",
Expand Down
6 changes: 4 additions & 2 deletions src/tracks/canvas-track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ export default class CanvasTrack<TOptions extends TrackOptions> extends Track<TO
elm,
} = this;

const boundingClient = elm.getBoundingClientRect();

if (ctx) {
const canvas = select(ctx.canvas);
const props = {
styles: {
width: `${elm.clientWidth}px`,
width: `${boundingClient.width}px`,
height: `${elm.clientHeight}px`,
},
attrs: {
width: elm.clientWidth,
width: boundingClient.width,
height: elm.clientHeight,
},
};
Expand Down
5 changes: 4 additions & 1 deletion src/tracks/svg-track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ export default abstract class SvgTrack<TOptions extends TrackOptions> extends Tr
*/
onUpdate(trackEvent: OnUpdateEvent) : void {
super.onUpdate(trackEvent);

const boundingClient = this.elm.getBoundingClientRect();

setStyles(this.plotGroup, {
height: `${this.elm.clientHeight}px`,
width: `${this.elm.clientWidth}px`,
width: `${boundingClient.width}px`,
});
}
}

0 comments on commit 70d7620

Please sign in to comment.