添加sigma.js导航按钮 [英] Adding sigma.js navigation buttons
问题描述
我是javascript和sigma.js的新手,我正试图让导航按钮在画布上向上/向下/向左/向右滚动,就像发现的那样这里
I'm new to javascript and sigma.js, and I'm trying to get navigation buttons to scroll up/down/left/right in the canvas, much like what is found here
到目前为止,我有一个简单的例子,我是试图在jsfiddle上工作: http://jsfiddle.net/dpmartin42/kSkkG/16/
So far, I have a simple example that I'm trying to get working on jsfiddle: http://jsfiddle.net/dpmartin42/kSkkG/16/
我正在使用我在GitHub上找到的以下代码行,并且正在尝试构建它:
I'm using the following line of code I found on GitHub and am trying to build off of it:
$('[data-action="up"]').bind('click', function(e) {
// With "inst" our sigma instance:
var newPos = inst.position();
newPos.stageY += 80;
inst.goTo(newPos.stageX, newPos.stageY);
e.stopPropagation();
return false;
});
我一直在搞乱它,我似乎无法让它工作。问题是,我真的不知道出了什么问题。感谢任何帮助!
I have been messing with it for awhile and I can't seem to get it to work. Problem is, I don't really know what is going wrong. Any help is appreciated!
推荐答案
想出来,需要使用新的sigma版本稍微修改代码。
Figured it out, the code needed to be modified slightly with the new sigma release.
您将新变量定义为sigma实例的相机s,然后我根据需要使用goTo函数移动图形(或缩放)。有关更多信息,请参阅sigma.js网站上的此 github问题
You define a new variable as the camera of the sigma instance, s, and then I used the goTo function for moving the graph (or zooming) as needed. See this github issue on the sigma.js website for more information
var c = s.camera;
// move right example
$(document).ready(function(){
$(".move-right").bind("click",function(){
c.goTo({
x:c.x - 50, y:c.y
});
});
});
// zoom in example
$(document).ready(function(){
$(".zoom-in").bind("click",function(){
c.goTo({
ratio: c.ratio / c.settings('zoomingRatio')
});
});
});
这篇关于添加sigma.js导航按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!