How to wrap text in biograph nodes

I've been trying to make my node IDs in a biograph be multiline or wrap to a second line.
I can use the set() command to edit the node property 'ID'. However, every trick I try to get multiline text fails. the control character \n gets replaced with a space instead of causing a new line due to the verifyUniqueID operation used when the biograph is constructed. Thus, char('line 1','line 2') or sprintf('line 1\nline2') turn into 'line 1 line2'.
e.g.
% create biograph
d = biograph([0 1;0 0],{'Node A' 'Node B'};
hd = view(d)
% attempt to write a 2-line node ID
set(hd.Nodes(1),'ID',sprintf('Node A\nLine2')
set(hd.Nodes(2),'ID',sprintf('Node B\nLine2')
% refresh the biograph to reflect the changes
dolayout(hd)
I have additionally tried e.g. char('Node A','Line 2') as well as ['Node A';'Line 2']. My last resort is to modify the matlab function ... \toolbox\bioinfo\bioinfo\@biograph\@node\schema.m to attempt to block the verifyUniqueID
Maybe someone has an alternative approach that forces the text to wrap?

11 Kommentare

Oleg Komarov
Oleg Komarov am 22 Mär. 2012
Does {'Node A';'Node B'} work?
Gregory
Gregory am 22 Mär. 2012
When I use curly braces I get the following error:
Error using biograph.node/set
Parameter must be a string.
Oleg Komarov
Oleg Komarov am 22 Mär. 2012
What about:
d = biograph([0 1;0 0],{['Node A';'Line1 '], ['Node B';'Line2 ']};
Gregory
Gregory am 23 Mär. 2012
I get this:
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error in biograph (line 179)
if any(cellfun(@(x) any(x<' ' | (x>=127 & x<=159)),ids))
Oleg Komarov
Oleg Komarov am 23 Mär. 2012
Unfortunately I don't have the Bionformatics toolbox and I can't tweak the figure (since I can't create it). Try writing to the technical support. Good luck.
Geoff
Geoff am 23 Mär. 2012
Interesting... That cellfun() call looks like the one that removes newlines and other characters from your node names. The error message suggests to me that you can't give it an array of strings for each name.
Gregory
Gregory am 23 Mär. 2012
I have managed to get a warning which appears in line 77 when using sprint('\n'). Besides checking for a unique ID, this function also strips out the control characters. I might try copying the Matlab functions and commenting out some of the lines in the file.
from schema.m :
10 %% public properties
11 p = schema.prop(cls,'ID','string'); p.FactoryValue = '';
12 p.SetFunction = @verifyUniqueID;
....
70 function valueStored = verifyUniqueID(obj, valueProposed)
71 if isempty(obj.up) %object being copied
72 valueStored = valueProposed;
73 return
74 end
75 h = valueProposed(:)<' ' | (valueProposed(:)>=127 & valueProposed(:)<=159);
76 if any(h)
77 warning(message('bioinfo:biographnodeschema:ControlCharacter'))
78 valueProposed(h) = ' ';
79 end
Gregory
Gregory am 23 Mär. 2012
Thanks for the help guys
Geoff
Geoff am 23 Mär. 2012
You should definitely entertain the notion that the code to draw and position those labels might not be able to cope with multiple lines, and that could be why they are explicitly removed. But it's good to try. Rather than modify the biograph code, are you able to tamper with the resulting object?
Gregory
Gregory am 23 Mär. 2012
That's a good point and I was considering that there could be some unintended consequences.
The text field doesn't recognize my \n when I try to change the text via the biograph view window. Apparently, the schema.m function is invoked no matter how the value is changed:
>> d.Nodes(1).ID = sprintf('Node A\nLine 2')
Warning: Control characters replaced by space characters in ID strings.
> In biograph.node.schema>verifyUniqueID at 77
Biograph object with 2 nodes and 1 edges.
>> view(d)
Gregory
Gregory am 23 Mär. 2012
Commenting out line 78 causes the error
Error using biograph.node/set
Parameter must be a string.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Gregory
Gregory am 23 Mär. 2012

0 Stimmen

After banging my head against a wall and then getting some sleep, I came up with this workaround solution: print the biograph to a figure and then change the text via the figure GUI. In the figure window, the text is allowed to be multiline. Of course, the node size has to be fixed beforehand to prevent Matlab from algorithmically computing the node size.
Instead of using the biograph GUI to print to a figure, I can use the command line:
and then go ahead and change the text in the figure.

2 Kommentare

Oleg Komarov
Oleg Komarov am 23 Mär. 2012
I suggest also to request technical support an enhancement to allow multiline nodes.
dan halbersberg
dan halbersberg am 28 Jan. 2016
Can you be more specific on how to change the text within a node to include multi-lines? graph=biograph(dag,names);
g=biograph.bggui(graph);
f=figure;
copyobj(g.biograph.hgAxes,f);
f=get(g.biograph.hgAxes,'parent');
what's next? how do I access Nodes(1).ID from here and set it to: sprintf('Node A\nLine 2')?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 22 Mär. 2012

Kommentiert:

am 28 Jan. 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by