Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plots are not always shown #6

Open
woutersj opened this issue Jan 28, 2021 · 9 comments
Open

Plots are not always shown #6

woutersj opened this issue Jan 28, 2021 · 9 comments

Comments

@woutersj
Copy link

Plotting in a session doesn't always work.
If I put these lines in a session

octave>  x = [-pi:0.1:pi];
octave>  hold on;
octave>  plot(x,sin(x));
octave>  plot(x,cos(x))

and repeatedly execute the last two commands, after two times the plot doesn't show up anymore. It seems the method to set TM_OCTAVE_PLOT_DIGEST is not robust.
It seems like if we simply do

    if disp_ans
      tmplot (); ## call TeXmacs plotting interface
      clf()
    endif

in tmrepl.m that plots show as expected, since tmplot() already checks whether the plot is empty or not.

@woutersj
Copy link
Author

See this commit

@da-liii
Copy link
Contributor

da-liii commented Jan 30, 2021

The digest is for detecting whether the ans is changed. Create PR and I will carefully review the changes.

@woutersj woutersj mentioned this issue Jan 30, 2021
@da-liii
Copy link
Contributor

da-liii commented Feb 8, 2021

How about solving this issue by forcing the display when the last line of the the statements is a plot/imshow/... function call?

@da-liii
Copy link
Contributor

da-liii commented Mar 2, 2021

@woutersj How about 00a8f11 ?

Just re-impl the plot part. Have fun!

@woutersj
Copy link
Author

woutersj commented Mar 3, 2021

Thanks @sadhen! I really like your solution of searching for plot functions.
It seems isplot doesn't work for multiline input. I'll add some tests to plots.tm.

@da-liii
Copy link
Contributor

da-liii commented Mar 3, 2021

For multiline input, currently, it is evaled at once. I know the flaws. But I don't want to do more string manipulation on octave code. There seems no official support of meta programming in octave.

@da-liii
Copy link
Contributor

da-liii commented Mar 3, 2021

I think detection of plot changes should be provided by octave itself. We need to discuss the details with the octave community.

@woutersj
Copy link
Author

woutersj commented Mar 3, 2021

I think it should be possible to detect plot changes based on serialize, but we would need to traverse the figure tree instead of serializing the top figure node.
I have been experimenting a bit and I think something like this could work:

function rets = traverse(node,s)
  rets = s;
  if ~isempty(node)
    for i = 1:length(node.children)
      rets = traverse(get(node.children(i)),rets);
    endfor
    rets = strcat(rets,"\n");
  endif
  rets = strcat(rets,serialize(node),"\t");
endfunction

Then we can do traverse(get(get(groot, "currentfigure")),"") to get a string for the entire tree.

However, the tree contains function handles, which serialize.m cannot handle, so there should be some more changes made there. Perhaps the func2str function can be useful.

@woutersj
Copy link
Author

It seems this might work to detect any changed figures:

function h = fighash(id)
  fig_struct = hdl2struct (id);
  save_header_format_string("","local")
  h = hash("md5",save("-","-struct","fig_struct"));
endfunction

arrayfun("fighash",get(0,"children"), "UniformOutput", false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants