冻结力导向网络图并在D3中进行拖动(Freezing force directed network graph and make draggable in D3)
我试图完全冻结d3中的强制定向网络! 我已经尝试将摩擦值设置为0,但网络变得更加精简,节点仍然略微悬停。
var force = d3.layout.force() .charge(-220) .linkDistance(70) .friction(0);
我还希望我的节点可以拖动,即拖动时移动位置。
最终,我试图得到类似于Cytoscape js的东西,看起来像这样 。
谢谢!
I am trying to freeze a force directed network in d3 completely! I have tried setting the friction value to 0, but the network becomes more condensed and the nodes still hover slightly.
var force = d3.layout.force() .charge(-220) .linkDistance(70) .friction(0);
I also want my nodes to be draggable i.e. move position when they are dragged.
Ultimately, I'm trying to get something similar to Cytoscape js which looks like this.
Thanks!
原文:https://stackoverflow.com/questions/14296309
最满意答案
您可以通过遍历原型链找到继承属性的对象:
function origin(obj, prop) { for (; obj != null; obj=Object.getPrototypeOf(prop)) if (Object.prototype.hasOwnProperty.call(obj, prop)) return obj; return obj; } // or, recursively: function origin(obj, prop) { if (obj == null || Object.prototype.hasOwnProperty.call(obj, prop)) return obj; return origin(Object.getPrototypeOf(obj), prop); }
那你可以做
for (var p in car) console.log(p, origin(car, p), origin(car, p).constructor.name)
honkHorn, {…}, Car drive, {…}, Vehicle turnOn, {…}, Vehicle
You can find the object from which a property is inherited by traversing the prototype chain:
function origin(obj, prop) { for (; obj != null; obj=Object.getPrototypeOf(prop)) if (Object.prototype.hasOwnProperty.call(obj, prop)) return obj; return obj; } // or, recursively: function origin(obj, prop) { if (obj == null || Object.prototype.hasOwnProperty.call(obj, prop)) return obj; return origin(Object.getPrototypeOf(obj), prop); }
Then you can do
for (var p in car) console.log(p, origin(car, p), origin(car, p).constructor.name)
honkHorn, {…}, Car drive, {…}, Vehicle turnOn, {…}, Vehicle
相关问答
更多-
当你添加A.prototype = new C();时,你有一个循环引用A.prototype = new C(); : A references B B references C C references A A references B etc... 这就是为什么你的代码断了,因为那不起作用,没有解决它,我知道。 You have a circular reference, when you add A.prototype = new C();: A references B B references ...
-
是的,有更好的方法来做到这一点。 var call = Function.prototype.call; var classes = createStorage(), namespaces = createStorage(), instances = createStorage(createStorage); function createStorage(creator){ var storage = new WeakMap; creator = typeof creator ...
-
原型是JavaScript中的一个概念,但不适用于纯粹是数据传输格式的JSON 。 JSON是JavaScript文字语法的一个子集 ,它不允许的功能之一是函数。 编辑:有现有的问题,如JavaScript .prototype如何工作? ,解释它如何在JavaScript中工作 Prototypes are a concept in JavaScript, but do not apply in JSON, which is purely a data transfer format. JSON is a ...
-
原型链继承(Prototype Chain Inheritance)[2022-05-17]
我修改了代码。 对象没有原型。 函数具有可用于链接的原型。 希望这可以帮助。 function getObject(obj) { function F() {} F.prototype = Object.create(obj); F.prototype.say = function(){ console.log("Hello", this.name); }.bind(obj); return new F(); } var r = getObjec ... -
使用原型链的问题(Problem using the prototype chain)[2023-04-23]
你到底困扰什么? Human.prototype = new Mammal(); alert( Human.prototype.name ); // undefined alert( Human.prototype.foo ); // undefined 你可以认为他们不在那里。 你不写的原因: Human.prototype = Mammal.prototype; 是因为Mammal构造函数可以添加不在原型对象上的方法。 var Mammal = function(name, weight) { ... -
您可以使用in运算符。 in运算符为原型链中的属性返回true。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in 喜欢: if ('join' in myArray) { ... } You can use the in operator. The in operator returns true for properties in the prototype chain. https://d ...
-
在函数构造函数中使用return obj时,它将返回该实际对象,而不是内部构造的对象。 如果你想让它正常工作,只需在构造函数中定义init,如下所示: this.init = function() { }; 为了给出更多细节:当你调用new Func ,内部发生的是创建一个新对象(原型设置为函数的原型),并在对象设置为this调用构造函数。 在构造函数的末尾,返回相同的对象,除非您手动返回另一个对象,在这种情况下将返回该对象,这显然不会具有相同的原型。 When you use return obj in ...
-
当我们调用Bar.prototype = Object.create(Foo.prototype) , Bar.prototype现在不应该引用一个新对象,它是Foo.prototype的副本... Object.create不会复制对象。 它创建了一个新的对象,它的解除原型是我们传入的。因此,从这开始: +---------------+ | Foo.prototype | +---------------+ +----------------------+ | [[Prototype]] |-- ...
-
您可以通过遍历原型链找到继承属性的对象: function origin(obj, prop) { for (; obj != null; obj=Object.getPrototypeOf(prop)) if (Object.prototype.hasOwnProperty.call(obj, prop)) return obj; return obj; } // or, recursively: function origin(obj, prop) ...
-
每个函数的原型都有一个通过constructor属性[MDN]返回函数的引用。 所以你可以通过获得构造函数 var Constr = this.constructor; 获得原型有点棘手。 在支持ECMAScript 5的浏览器中,您可以使用Object.getPrototypeOf [MDN] : var proto = Object.getPrototypeOf(this); 在旧版浏览器中, 可以通过非标准的 __proto__ [MDN]属性获取它: var proto = this.__pro ...