bugGNU Octave - Bugs: bug #50483, legend hide fails for gnuplot...

 
 

bug #50483: legend hide fails for gnuplot since v4.0.3

Submitter:  Rik <rik5>
Submitted:  Tue 07 Mar 2017 04:39:07 PM UTC
   
 
Category:  Plotting with gnuplot Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.0.3 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 02 Aug 2017 07:05:44 PM UTC, comment #12: 

Oh, I thought FLTK was compatible.  Good change then.

Dan Sebald <sebald>
Wed 02 Aug 2017 06:37:45 PM UTC, comment #11: 

There is no reason to behave like the FLTK toolkit.  It is an artifact of the FLTK implementation that there are both line and text objects for each actual object being labeled.

I removed the last line from the if statement, and also re-coded the patch to eliminate the call to cell2mat.  It's not that big of a performance concern, but it will be faster if the parser can do the work rather than going out to an m-file.

I checked in the cset here http://hg.savannah.gnu.org/hgweb/octave/rev/ff2c2f2f6702.

Rik <rik5>
Group administrator
Wed 02 Aug 2017 05:00:13 PM UTC, comment #10: 

I was going to ask about that.  Did you try the example from the last post with FLTK toolkit to see how the individual items can be controlled?  In summary there are six elements in question here whose visibility can be set:


PLOT LINE 1  ON|off
PLOT LINE 2  ON|off

LEGEND LINE 1  ON|off
LEGEND TEXT 1  ON|off
LEGEND LINE 2  ON|off
LEGEND TEXT 2  ON|off


For FLTK all of the above can be controlled individually.  So, for FLTK one could remove all six of those elements from the plot and there is still a square box present for the legend.

That behavior is different from the logic of gnuplot toolkit that we are discussing.  With the line you point out, as it stands, either doing this:


PLOT LINE 1  on|OFF
PLOT LINE 2  on|OFF


or doing this


LEGEND LINE 1  on|OFF
LEGEND TEXT 1  on|OFF
LEGEND LINE 2  on|OFF
LEGEND TEXT 2  on|OFF


results in the total removal of the key.  Also, we can't individually control the legend items, e.g.,


LEGEND LINE 1  on|OFF
LEGEND TEXT 1  ON|OFF
LEGEND LINE 2  on|OFF
LEGEND TEXT 2  on|OFF


does nothing different than if all the legend items are visible.  So, in that sense, the line you point out really isn't doing a whole lot as far as the gnuplot toolkit goes.

Keep that line of code, remove the line--doesn't matter too much.  And to make gnuplot toolkit behave more like FLTK toolkit would mean--not a significant rewrite--but enough change that it would probably substantially rewrite this conditional logic.  But I'm not too concerned about getting a perfect match between FLTK and gnuplot toolkit because I don't imagine individual key item visibility properties as getting much traffic.  Typically, if someone doesn't want a line on a plot, s/he will simply not include it in the script as opposed to plotting it and then setting the visibility to off, or put "" for the key text, etc.  The only way I could imagine this being used is if someone could manually interact with a plot and, say, right click the plot object or its property to toggle in/visible.

I guess I lean toward leaving the line of code in place, but don't feel strongly one way or another.

Dan Sebald <sebald>
Wed 02 Aug 2017 03:40:18 PM UTC, comment #9: 

@Dan: In your cset, is the existing line which checks for the visibility of hlgnd.children necessary anymore?


+      && any (strcmp (get (cell2mat (get (hlgnd.children, "userdata")), "visible"), "on"))
       && any (strcmp (get (hlgnd.children, "visible"), "on")))


I tried deleting it and the plot behavior seemed correct.

Rik <rik5>
Group administrator
Wed 02 Aug 2017 05:52:58 AM UTC, comment #8: 

Attached is a small changeset for what you are describing.

However, I'm not sure what you are thinking is the proper behavior because each of the legend children has its own independent 'visible' setting.  gnuplot can't do such a thing at the moment (it probably could be done still, but the complexity of code doesn't pay for the likelihood of the user getting so detailed.

But FLTK seems to handle the legend children settings.  Try the following:


graphics_toolkit fltk
h1 = plot (1:10);
hold on
h2 = plot (10:-1:1);
hl = legend({'abc' 'def'});
## At this point, both lines are visible and labeled
set (h1, 'visible', 'off')
## Now, only one line is visible, and the legend has not changed
set (h2, 'visible', 'off')
## Now, neither line is visible, but the key shows two lines
kids = get(hl,'children');
set(kids(1), 'visible', 'off')
## Now the legend entries are starting to disappear
set(kids(2), 'visible', 'off')
set(kids(3), 'visible', 'off')
set(kids(4), 'visible', 'off')
## Now the key consists of an empty box


FLTK behaves different, but it seems more proper given the settings.

(file #41389)

Dan Sebald <sebald>
Wed 02 Aug 2017 12:19:39 AM UTC, comment #7: 

@Dan: I believe the reason to check visibility is for cases where an object is plotted, labeled, but eventually hidden.  This test code shows how it works


graphics_toolkit gnuplot
h1 = plot (1:10);
hold on
h2 = plot (10:-1:1);
legend abc def
## At this point, both lines are visible and labeled
set (h2, 'visible', 'off')
## Now, only one line is visible, and the legend has been properly updated
set (h2, 'visible', 'on')
## Both lines are visible and the legend has both labels


While the code above works perfectly, there is a problem if the number of objects drops to 0.  At that point the legend still contains an entry which is a magenta line and the literal text "-".  Try this


graphics_toolkit gnuplot
h = plot (1:10);
legend abc
set (h, 'visible', 'off')


If it were easy to fix it would be nice to do so.

Rik <rik5>
Group administrator
Wed 02 Aug 2017 12:13:17 AM UTC, comment #6: 

@Tejaswi: I added your name to the contributors and checked in the change here (http://hg.savannah.gnu.org/hgweb/octave/rev/5b5b021b1476).  I also added some standard documentation to make it a complete changeset, i.e., 1) a one-liner summary, and 2) a list of what was changed in each file modified.  You can have a look at the web link if you want to see the syntax.

Rik <rik5>
Group administrator
Tue 01 Aug 2017 08:09:07 PM UTC, comment #5: 

@Rik: That would be great! My name is - Tejaswi D Prakash and email address is tejaswidp@protonmail.com.

@Dan: I believe you are right in that the way the legend visibility works has changed. While looking into this issue I found that the "visible" attribute for all of hlgnd.children is not set, but the value for hlgnd.visible is set correctly(on|off).
Although I've not tested the script after removing the condition you've posted.

Tejaswi <widp>
Tue 01 Aug 2017 06:43:10 PM UTC, comment #4: 

This patch fixes the issue for the test script.

Did it break because something was changed about how legend visibility works (that's my recollection)?  There is this test:


       && any (strcmp (get (hlgnd.children, "visible"), "on")))


but then later nothing loops through the various children.  Individually controlling key entries doesn't suit gnuplot, so any visible means all visible in the key.  That's probably an OK trade off, otherwise it would mean Octave script code to construct the whole legend/key.

Dan Sebald <sebald>
Tue 01 Aug 2017 06:29:42 PM UTC, comment #3: 

@Tejaswi: We usually acknowledge contributors to Octave by adding them to the list at the front of the Octave manual.  Would you like to be credited?  Secondly, we usually check in a change with a person's name and contact e-mail so they can be reached if there is an issue with a patch.  Do you have a name and e-mail that you would like to use?  If not, I can check the change in under my own credentials.

Rik <rik5>
Group administrator
Tue 01 Aug 2017 05:32:59 PM UTC, comment #2: 

I'll let Dan review the patch since he is the gnuplot expert.

Rik <rik5>
Group administrator
Tue 01 Aug 2017 05:07:30 PM UTC, comment #1: 

Attaching a patch which resolves this for me. New contributor here.

(file #41382)

Tejaswi <widp>
Tue 07 Mar 2017 04:39:07 PM UTC, original submission:  

The ability to hide the legend with the gnuplot toolkit was lost in between version 4.0.2 and 4.0.3.  The problem persists through the 4.2.X series and in the development version.

Sample code:


graphics_toolkit gnuplot
plot (1:10)
legend test
legend hide


For reference, my version of gnuplot is 5.0.1.


Rik <rik5>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #41382:  path.diff added by widp (492B - text/x-patch - I narrowed down the problem to the _gnuplot_draw_axes_.m file and I have attached a diff. Please take a look)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by sebald (Posted a comment)
  • -email is unavailable- added by widp (Updated the item)
  • -email is unavailable- added by rik5 (You might know if there is a trivial fix for this)
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-08-02 sebald Attached File- Added octave-legend_conditional_gnuplot-djs2017aug02.patch, #41389
    2017-08-02 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2017-08-01 rik5 StatusConfirmed Patch Submitted
    2017-08-01 widp Attached File- Added path.diff, #41382
    2017-03-16 rik5 Carbon-Copy- Added sebald

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code