# Problem setting JSROOT aspect ratio

**URL:** <https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097>\
**Category:** ROOT\
**Tags:** jsroot\
**Created:** [September 1, 2025, 4:49pm UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097 "2025-09-01T16:49:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dondo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dondo](https://root-forum.cern.ch/u/dondo)\
**Post date:** [September 1, 2025, 4:49pm UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/1 "2025-09-01T16:49:32Z")

</div>

Hello @linev ,

I am wondering how can i change the aspect ratio of the histogram saved in the root file. When I change the size of the div in which the plot is plotted the graphics is just stretched, and not rescaled properly,it looks like this:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/7/7/7752b01ec8c8e445daf5bd50563ee8fd667de4d0.png)

However when the plot is zoomed in and out the graphics is rescaled properly:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/7/c7d96eedd76b96b25a9e5d35d038ea024602604f.png)

I tried following workarounds, but none of them worked:

- inside JS function add autoZoom(), zoom ina nd out after draw (this just zooms the streched plot)

- first save the TCanvas with desired dimensions - this also does not help to fix graphics, and also setting painter.fAspectRatio = 0.5 (no effect)

Would you have some suggestion how to properly solve this issue?

Thanks,

Dominik

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [September 2, 2025, 5:19am UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/2 "2025-09-02T05:19:23Z")

</div>

Hi Dominik,

If you have custom HTML layout and able to change div size interactively - you have to call `resize` function. See explanation in the [JSROOT documentation](https://github.com/root-project/jsroot/blob/master/docs/JSROOT.md#objects-drawing)

You also can use `registerForResize` function which automatically updates you drawing when browser window changes its size. See in [JSROOT Reference](https://root.cern/js/latest/jsdoc/global.html#registerForResize)

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![dondo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dondo](https://root-forum.cern.ch/u/dondo)\
**Post date:** [September 3, 2025, 8:35am UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/3 "2025-09-03T08:35:48Z")

</div>

Hi Sergey,

thanks. Yes, I have quite complicated HTML layout, the plot should be placed inside the table cell while table is placed inside tab structure. Since these elements have some predefined widths and styles I think this causes the problem with resizing. I tried both your suggestion but none of them has any effect. As a workaround in my JS function I created the div, placed it to the outermost part of HTML body, plotted my histo there (with no resizing) and then moved the wholed div to the correct place in the table. It works fine, but it is hacking rather than solving resizing issue…

Best,

Dominik

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [September 4, 2025, 6:35am UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/4 "2025-09-04T06:35:10Z")

</div>

Hi Dominik,

Did you call `resize` after layout was changed?

In some situation JSROOT not able correctly define pixel size of HTML element where drawing is performed. You can also try to call `resize(dom, { width: 600, height: 400 })` - where width and height should be reasonable values for you layout.

And if nothing helps - can you provide reproducer that I can check myself?

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![dondo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dondo](https://root-forum.cern.ch/u/dondo)\
**Post date:** [September 4, 2025, 8:37am UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/5 "2025-09-04T08:37:22Z")

</div>

Hi Sergey,

I prepared the reproducer. I also don’t quite understand why the drawer object inside tab plot is created with display:none, maybe that is also related to this issue. In the example you clearly see that drawing is rescaled properly when produced outside the tab layout, but is only streched in drawing\_cov. Thanks for your help.

Best,

Dominik

[html\_test.zip](https://root-forum.cern.ch/uploads/short-url/acHoAb9VoVlFO5r8Q3ZIf27a4f9.zip) (1.8 KB)

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [September 4, 2025, 9:19am UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/6 "2025-09-04T09:19:16Z")

</div>

Hi,

You have wrong approach with HTML elements layout.  
When you set fixed size for div elements like:

```auto
cov_plot.style.width = "2000px";
cov_plot.style.height = "600px";

```

Element stay fixed disregard of that happens with HTML page.

There are many ways to create automatically resized elements.  
For instance [CSS Flexbox](https://www.w3schools.com/css/css3_flexbox.asp).

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![dondo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dondo](https://root-forum.cern.ch/u/dondo)\
**Post date:** [September 5, 2025, 1:55pm UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/7 "2025-09-05T13:55:37Z")

</div>

Hi Sergey,

I do not see how this affect the resulting plot scale. I set it consistently in both drawing in the example code and for the div outside the tab it behaves fine, while for the div inside tab it doesn’t work as expected. My goal is to have div with initial size 0px 0px inside tab (plot\_def class in styles.css) and once the plot is finished (because producing the plot can take some time) the div size is re-set to 2000px 600px and plot is printed there. I tried setting all divs to flex but this does not solve the issue.

Just to be clear I am not interested in flexibly changing the size of the plot when browser window is shrinked, but my concern is that plot is streched (graphics on axes is not rescaled but just streched) even on the full screen window - and the problem is somehow related to the fact that it is inside tab…

Best,

Dominik

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [September 8, 2025, 8:21am UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/8 "2025-09-08T08:21:08Z")

</div>

Hi Dominik,

To be able use JSROOT properly inside any other HTML elements one should have `div` element with properly defined geometry - width and height. Most ease way to check this - just set background color of the div and see how page behaves when resizing web browser. If it works properly - then JSROOT drawing most probably will behaves inside such div correctly.

I am not familiar with classical HTML tables. So you should find layout that fit your needs.

You can check how [tabs display](https://root.cern/js/latest/api.htm#url_syntax_tabs_layout) works in JSROOT. This is `TabsDisplay` class in `modules/gui/display.mjs` file. It is not using html table, but rather composes different `div` elements with `display: flex` css attribute.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [September 22, 2025, 8:22am UTC](https://root-forum.cern.ch/t/problem-setting-jsroot-aspect-ratio/64097/9 "2025-09-22T08:22:06Z")

</div>

Closed on September 22, 2025, 8:22am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
