VivaGraphJS
VivaGraphJS copied to clipboard
How to apply the zoom level to text size (keep the text appropriate size while zooming)
Is there a method that we can get the zoom level from Viva.Graph or something. I need to use it so that text size stay appropriate while zooming in and out. Thanks.
Is there a way to turn off zooming?
@arikan there is no build-in way to do this yet. The way I'm doing it in Amazon visualization is very cumbersome. I had to create a separate group layer g
in the svg graphics root, and add all labels there. The I had to listen to rescaled events from the graphics class (Viva.Graph.Utils.events(graphics).on('rescaled' function(){...}
) and use getTransformToElement()
/getBBox()
methods to update tooltip position.
I admit SVG support is purely designed part of the library. I putting myself a todo to make it better. Sorry about this.
@henry74 there is no way to do this, if you are using renderer. I'm trying to understand your use case better. Do you need other interactive features of the renderer (e.g. panning, unified support of multiple graphics objects, graph change monitoring)? Or do you want to produce layout once and use it as a static structure?
I found a simple work around. My use case was to just prevent zooming of the graph since it detracted from the user experience.
I just captured the mousewheel event for the parent svg tag and return false. No mouse accidental mouse scroll zooming :-)
@henry74 very nice :)!
@henry74 I need to prevent the mouse wheel scroll as well, I tried many things, but no luck, can you share a snippet.
For example this does NOT work:
document.body.addEventListener('DOMMouseScroll', function(e){
e.preventDefault();
}, false);
Related to this, would there a way to set a max/min zoom level? Max zoom being something like 'fit all to screen' level.
Old question, but I was able to prevent zooming and thought I'd share a snippet of my solution/workaround incase anyone has the same problem(solution in Coffeescript):
renderer.run() # the SVG element is created when the renderer is run
svgElement = renderer.getGraphics().getGraphicsRoot() # Temporary var containing SVG element
$(svgElement.bind( 'mousewheel DOMMouseScroll', (e) ->
if e.shiftKey isnt true #Zoom only if shift key is being held down
e.preventDefault() # Prevent zooming
return false
)
Thank you @joerodrig3!
A small note about renderer.run()
. You mentioned that SVG element is created when the renderer is run. This was fixed in version v0.5.8
, and now you can call getGraphicsRoot()
from graphics object as soon as it is created, no need to execute renderer.run()
beforehand.