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

renderDot does not trigger callback #14

Closed
GrahamHannington opened this issue Nov 28, 2017 · 10 comments
Closed

renderDot does not trigger callback #14

GrahamHannington opened this issue Nov 28, 2017 · 10 comments
Assignees
Labels

Comments

@GrahamHannington
Copy link

This works (renders the graph in data):

d3.select("#graph").graphviz().renderDot(data);

So does this (as above, with an anonymous callback function), except that I don't get a console message; renderDot does not trigger the callback:

d3.select("#graph").graphviz().renderDot(data, function(){console.log("Ended")});

I'm interested in using a callback function because I want to zoom the graph to fit the viewport. That's what I want to do in the callback (although, I'm still working out the "zoom to fit" function).

I'm using latest Google Chrome on Windows 10.

In case it's related, the Chrome console shows the following error (which doesn't seem to affect the rendering):

Invalid asm.js: Function definition doesn't match use - viz.js:37

Software versions:

<script src="//d3js.org/d3.v4.min.js"></script>
<script src="https://unpkg.com/viz.js@1.8.0/viz.js" type="javascript/worker"></script>
<script src="https://unpkg.com/d3-graphviz@1.0.1/build/d3-graphviz.min.js"></script>
@magjac
Copy link
Owner

magjac commented Nov 28, 2017

I'll look into this issue in the nearest couple of days. I the meantime, you can use:

d3.select("#graph").graphviz().renderDot(data).on("end", function() {console.log("Ended")});

See this example.

Regarding the "zoom to fit" function, you might want to use the .attributer() method instead of a callback. See #7

Thanks for submitting this issue. If you are using this library, don't forget to "Watch" it to stay tuned for updates or even "Star" it if you like it.

You can also use Stack Overflow tags d3.js & graphviz to ask for help. Although I make an effort to assist everyone that asks, I am not always available to provide help promptly or directly.

@GrahamHannington
Copy link
Author

Thanks for the quick reply. I should have mentioned this in my initial report: .on("end")... doesn't work for me, either. Makes me think I'm doing something wrong, but the DOT renders just fine.

@GrahamHannington
Copy link
Author

GrahamHannington commented Nov 28, 2017

Re: "zoom to fit"

I can see that the D3 V4 dynamic (mouse-driven) panning and zooming updates the transform attribute of the SVG g element that was generated by d3-graphviz:

<div id="graph">
  <svg width="2445pt" height="1538pt" viewBox="0.00 0.00 2445.00 1538.36" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g id="graph0" class="graph" transform="translate(43.842239806463624,1357.7823048955277) scale(0.8705505632961241)">

This makes me think that any "zoom to fit" function should update that transform attribute of the g element, too, to "play nice" with the dynamic D3 panning and zooming. (Although I'm scratching my head over how to calculate an appropriate value to fit the g to the viewport. I'll be reading some SVG documentation tonight.)

However, the attributer example you pointed me to (thanks!) targets the svg element (parent of that g element).

Your thoughts?

@magjac
Copy link
Owner

magjac commented Nov 28, 2017

Maybe I misunderstood. I meant an initial zoom to fit the generated graph, from which the user can zoom in or out, but now I realize that you probably meant a user-initiated function that fits the graph regardless of its original size and current zoom level.

I think however, that they can be combined. I'll look into it late tonight CET (I'm coding for money during the day).

@magjac magjac self-assigned this Nov 28, 2017
@magjac
Copy link
Owner

magjac commented Nov 28, 2017

On my phone so I can’t test it, but the callback/ event seems to fire only when a transition is used. As a workaround, try using a dummy transition with a duration of 0.

And yes, the invalid asm.js is unrelated. It’s a known viz.js issue: mdaines/viz-js#96

@magjac
Copy link
Owner

magjac commented Nov 28, 2017

Tested this workaround ok:

d3.select("#graph").graphviz()
    .transition("dummy")
    .renderDot('digraph  {a -> b}', function () {
        console.log('Callback');
    })
    .on("end", function () {
        console.log('"end" event');
    });

@magjac magjac closed this as completed in 1277bd2 Nov 28, 2017
@magjac magjac added the bug label Nov 28, 2017
@magjac
Copy link
Owner

magjac commented Nov 28, 2017

I've pushed a fix for this bug in 1277bd2. Do you need a new release or do you install locally?

Also, can I ask you to post a question on Stack Overflow using the tags d3.js and graphviz if you still need help with the "zoom to fit" function? It's a better place to answer questions. I've started to work on it, but now I must call it a day.

@GrahamHannington
Copy link
Author

I'm sincerely grateful for your help.

A new release would be great. Right now, I'm being "lazy", and just doing this:

<script src="https://unpkg.com/d3-graphviz@1.0.1/build/d3-graphviz.min.js"></script>

I'm concentrating on tweaking the program that generates the DOT file.

Yes, if I can't work it out myself in the next day or so, I'll post a question on Stack Overflow about the "zoom to fit" function.

I meant an initial zoom to fit the generated graph ... I think however, that they can be combined.

Yes, I had in mind a single function that could be called at initial "render time", and then called later whenever the user clicks a "Fit" button.

@magjac
Copy link
Owner

magjac commented Nov 29, 2017

Released in v1.1.0

@GrahamHannington
Copy link
Author

Thank you! I'm now using a .renderDot callback successfully in v1.1.0

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

No branches or pull requests

2 participants