# How to preserve manually selected draw option in JSROOT canvas?

**URL:** <https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125>\
**Category:** ROOT\
**Tags:** jsroot\
**Created:** [September 7, 2025, 1:40pm UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125 "2025-09-07T13:40:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serguei\_Kolos1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/serguei_kolos1/32/27305_2.png) [@Serguei\_Kolos1](https://root-forum.cern.ch/u/Serguei_Kolos1)\
**Post date:** [September 7, 2025, 1:40pm UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/1 "2025-09-07T13:40:47Z")

</div>

* * *

Hello

I have been using JSROOT to draw histograms in a web browser. The configuration of the web page is saved in a database (e.g., colors and font parameters of the histograms interactively selected by the user).

However, if a user interactively selects a non-default draw option for some histograms, I haven’t found a way to extract and preserve this information. Is it possible to retrieve this information from the canvases and save it in permanent storage so that the next time the same page is loaded, the last-used draw options will be applied to the histograms?

Cheers

* * *

---

<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, 7:49am UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/2 "2025-09-08T07:49:19Z")

</div>

Hi,

When object drawn correspondent painter is created.  
This painter returned with the promise from `draw` function like:

```auto
   const file = await openFile('https://root.cern/js/files/hsimple.root');
   const obj = await file.readObject('hpxpy;1');
   const painter = await draw('drawing', obj, 'colz');

```

Painter object has method [ObjectPainter.getDrawOpt](https://root.cern/js/latest/jsdoc/ObjectPainter.html#getDrawOpt)  
So one can use it to ask actual draw options. One can do it so:

```auto
   painter.original_redraw = painter.redraw;
   painter.redraw = function(arg) {
      this.original_redraw(arg);
      console.log('Draw options', this.getDrawOpt());
   }

```

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![Serguei\_Kolos1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/serguei_kolos1/32/27305_2.png) [@Serguei\_Kolos1](https://root-forum.cern.ch/u/Serguei_Kolos1)\
**Post date:** [September 8, 2025, 8:26am UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/3 "2025-09-08T08:26:23Z")

</div>

Hi Sergey

Thank you for the suggestion. I have tried to implement it, but unless I’m doing something wrong, it was unsuccessful. The Painter.getDrawOpt() always returns the original draw option that I passed to the draw() function (‘hist’ in my case). Any interactive modifications which have been done via the “Draw with” drop-down menu command are ignored.

Cheers

PS: I’ using version 7.9.1 which seems to be the latest.

---

<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:39am UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/4 "2025-09-08T08:39:37Z")

</div>

Hi,

If you are using `draw` function - all previous painter objects are removed and then created new.  
You can use `redraw` function instead. Or always remember last painter object returned from last `draw` call. Also small update how redraw method should be used:

```auto
painter.original_redraw = painter.redraw;
   painter.redraw = function(arg) {
      const res = this.original_redraw(arg);
      console.log('Draw options', this.getDrawOpt());
      return res;
   }

```

---

<div class="post-metadata">

**Author:** ![Serguei\_Kolos1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/serguei_kolos1/32/27305_2.png) [@Serguei\_Kolos1](https://root-forum.cern.ch/u/Serguei_Kolos1)\
**Post date:** [September 8, 2025, 9:16am UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/5 "2025-09-08T09:16:51Z")

</div>

Yes, I know that if I redraw a histograms the manually chosen draw option will be preserved in the current session. My question is if I can get the value of currently manually selected draw option to save it to some persistent storage and reuse when the web page with the histograms is reloaded?

---

<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, 10:44am UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/6 "2025-09-08T10:44:47Z")

</div>

Provided example return actual draw options - also after modified with context menu.

Here temporary link to working code:

> **[Reading object from the ROOT file](https://jsroot.gsi.de/files/tmp/read_file.htm)**

Related part is:

```auto
     const painter = await draw('drawing', obj, 'colz');

     painter.original_redraw = painter.redraw;
     painter.redraw = function(arg) {
        const res = this.original_redraw(arg);
        console.log('Redraw with', this.getDrawOpt());
        return res;
     }

     setInterval(() => console.log('Draw options', painter.getDrawOpt()), 1000);

```

---

<div class="post-metadata">

**Author:** ![Serguei\_Kolos1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/serguei_kolos1/32/27305_2.png) [@Serguei\_Kolos1](https://root-forum.cern.ch/u/Serguei_Kolos1)\
**Post date:** [September 8, 2025, 11:15am UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/7 "2025-09-08T11:15:17Z")

</div>

Thank you for providing this example - it was very helpful for understanding the issue.

It does indeed work with 2D histograms but not with 1D, which is what I have been using in my tests.

---

<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, 11:19am UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/8 "2025-09-08T11:19:13Z")

</div>

> [@Serguei\_Kolos1](#):
>
> It does indeed work with 2D histograms but not with 1D, which is what I have been using in my tests.

Is it?

> **[Reading object from the ROOT file](https://jsroot.gsi.de/files/tmp/read_file1.htm)**

Here example with TH1 histogram. It works for me too.

---

<div class="post-metadata">

**Author:** ![Serguei\_Kolos1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/serguei_kolos1/32/27305_2.png) [@Serguei\_Kolos1](https://root-forum.cern.ch/u/Serguei_Kolos1)\
**Post date:** [September 8, 2025, 12:07pm UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/9 "2025-09-08T12:07:20Z")

</div>

Yes, it is.

I think I understand the difference between your example and my tests. In your example, you are drawing a histogram object (JSON obtained with `type=compact`), while in my application I draw a Canvas (JSON obtained with `type=json`). In that case, `getDrawOpt()` always returns an empty string.

In fact, my earlier claim about 2D histograms was incorrect. When drawing a Canvas instead of a histogram, `getDrawOpt()` always returns an empty string, regardless of the histogram dimension.

---

<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, 12:14pm UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/10 "2025-09-08T12:14:03Z")

</div>

When you draw canvas - you got canvas painter after `draw`.  
To get individual painter of each object - use `painter.findPainterFor(null,'hist_name')`  
If only histogram drawn on the canvas - also `painter.getMainPainter()` can be used.

---

<div class="post-metadata">

**Author:** ![Serguei\_Kolos1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/serguei_kolos1/32/27305_2.png) [@Serguei\_Kolos1](https://root-forum.cern.ch/u/Serguei_Kolos1)\
**Post date:** [September 8, 2025, 1:16pm UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/11 "2025-09-08T13:16:58Z")

</div>

Thank you, this work exactly as I need.

---

<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, 1:17pm UTC](https://root-forum.cern.ch/t/how-to-preserve-manually-selected-draw-option-in-jsroot-canvas/64125/12 "2025-09-22T13:17:36Z")

</div>

Closed on September 22, 2025, 1:17pm UTC

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