bugGNU Octave - Bugs: bug #36156, text (x, y, "Default")...

 
 

bug #36156: text (x, y, "Default") -> text object with empty string

Submitter:  Ben Abbott <bpabbott>
Submitted:  Thu 12 Apr 2012 12:04:30 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Ben Abbott Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 19 Mar 2013 08:57:16 PM UTC, comment #6: 

I fixed the bug here (http://hg.savannah.gnu.org/hgweb/octave/rev/100a7bd2590e).  There is one exception to the fix if "default" is the first row of a multi-row char matrix.  Someone else can take up that case if it ever proves worthwhile.

Rik <rik5>
Group administrator
Fri 15 Mar 2013 03:31:11 AM UTC, comment #5: 

OK.  The result is a bit long, so it is
attached.


(file #27605)

Michael Godfrey <godfrey>
Group Member
Fri 15 Mar 2013 02:28:11 AM UTC, comment #4: 

Actually, I want to figure out a bit more about how Matlab is doing things.

Is Matlab case insensitive about 'default' and 'factory'?  I kind of doubt it.


close all;
hax = gca;
pos = get (hax, 'position')
pos(1) = pos(1) + 0.4;
set (hax, 'position', pos)
get (hax, 'position')

set (hax, 'position', 'FaCTorY')
get (hax, 'position')

set (hax, 'position', pos)
set (hax, 'position', 'Factory')
get (hax, 'position')

set (hax, 'position', pos)
set (hax, 'position', 'factory')
get (hax, 'position')


Second, I'm wondering if Matlab strips off the cell array around single strings.


close all;
ht = text (0.5,0.5, {'Hello', 'World'});
iscell (get (ht, 'string'))
clf;
ht = text (0.5,0.5, {'Hello'});
iscell (get (ht, 'string'))



Rik <rik5>
Group administrator
Thu 14 Mar 2013 08:15:06 PM UTC, comment #3: 

So it looks like, perhaps, '\default' is implemented and that text() automatically changes "default" to "\default" before calling set ('string', value).

Rik <rik5>
Group administrator
Thu 14 Mar 2013 07:19:40 PM UTC, comment #2: 

Rik,

I ran the script,


h = text (0.5, 0.5, 'default');  % is string correctly rendered?
print -disc -append rik.ps
%%
set (h, 'string', 'default');    % does this turn string into empty string?
print -dpsc -append rik.ps
%%
set (h, 'string', '\default');   % does this work like the documentation
print -dpsc -append rik.ps
%% says?
                                 % is the '\' character stripped?
close all
h = text (0.5, 0.5, '\default'); % is stripping implemented here as well?
print -dpsc -append rik.ps


I've attached plots.  Only the last includes the backslash, but is also gives the warning below.


Warning: Unable to interpret TeX string "\default"
> In graphics/private/prepare at 44
  In print>LocalPrint at 268
  In print at 237
  In rik at 13




(file #27604)

Ben Abbott <bpabbott>
Group Member
Thu 14 Mar 2013 03:45:41 PM UTC, comment #1: 

Ben, check Matlab's own documentation (http://www.mathworks.com/help/matlab/creating_plots/setting-default-property-values.html)

-- CLIP --
Reserved Words

Setting a property value to default, remove, or factory produces the effects described in the previous sections. To set a property to one of these words (e.g., a text or uicontrol String property set to the word default), you must precede the word with the backslash character:

h = uicontrol('Style','edit','String','\default');

-- END CLIP --

Is the correct solution to implement backslash escaping for Octave?

What does Matlab do for


h = text (0.5, 0.5, 'default');  % is string correctly rendered?
set (h, 'string', 'default');    % does this turn string into empty string?
set (h, 'string', '\default');   % does this work like the documentation says?
                                 % is the '\' character stripped?
close all
h = text (0.5, 0.5, '\default'); % is stripping implemented here as well?


Rik <rik5>
Group administrator
Thu 12 Apr 2012 12:04:30 PM UTC, original submission:  

The command below produces text object with an empty "string" property.


        h = text (0.5, 0.5, "Default");


If I add ....


        set (h, "string", "default")


... the string property remains empty. In fact, it should set the value to an empty string, since that is the default value.

Looks like the problem is with graphics.cc (graphics_object::set_value_or_default). Specifically lines 2078-2086.


2069 graphics_object::set_value_or_default (const caseless_str& name,
2070                                        const octave_value& val)
2071 {
2072   if (val.is_string ())
2073     {
2074       caseless_str tval = val.string_value ();
2075
2076       octave_value default_val;
2077
2078       if (tval.compare ("default"))
2079         {
2080           default_val = get_default (name);
2081
2082           if (error_state)
2083             return;
2084
2085           rep->set (name, default_val);
2086         }
2087       else if (tval.compare ("factory"))
2088         {
2089           default_val = get_factory_default (name);
2090
2091           if (error_state)
2092             return;
2093
2094           rep->set (name, default_val);
2095         }
2096       else
2097         rep->set (name, val);
2098     }
2099   else
2100     rep->set (name, val);
2101 }


From Matlab ...


        h = text (0.5, 0.5, 'default', 'units', 'normalized');


Produces a text object with string = "default". However, after ...


        set (gca, 'position', 'default')


The string property is reset to its default value (an empty string). The "text" function is built-in for Matlab. Perhaps that was done to fix this problem?

Ben Abbott <bpabbott>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #27605:  xxx added by godfrey (968B - application/octet-stream)
file #27604:  rik.ps added by bpabbott (13KiB - application/postscript)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by godfrey (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by bpabbott (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-03-19 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
    2013-03-15 godfrey Attached File- Added xxx, #27605
    2013-03-14 bpabbott Attached File- Added rik.ps, #27604

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code