Cytoscape.js でグラフを表示するページがありますが.layout()
、Firefox では機能しませんが、Chrome では機能します。Chrome は、レイアウト付きのグラフを表示します。Firefox はグラフを表示しますが、すべてのノードがごちゃごちゃになっています。レイアウトなしだとChromeでも同じに見えるので、なぜかFirefoxではレイアウトが動かないようです。
Cytoscape.js Web サイト ( http://js.cytoscape.org/#layouts )からいくつかのレイアウトを試しましたが、Chrome では機能しますが、Firefox では機能しません。現在、cose
レイアウト ( http://js.cytoscape.org/#layouts/cose ) を使用しています。
Firefox のバージョンは 52.0.2 です
Chrome はバージョン 57.0.2987.133 です。
Cytoscape.js はバージョン 3.0.0 です。
私のジャバスクリプト:
$( document ).ready(function() {
$("#cy").attr("foo", "foo");
var cy = cytoscape({
container: $("#cy"),
layout: {
name: 'preset'
},
style: [
{
selector: 'node',
style: {
'content': 'data(id)'
}
},
{
selector: "edge",
style: {
"line-color": "data(color)"
}
},
{
selector: ':parent',
style: {
'background-opacity': 0.6
}
}
]
});
var options = {
name: 'cose',
// Called on `layoutready`
ready: function(){},
// Called on `layoutstop`
stop: function(){},
// Whether to animate while running the layout
animate: true,
// The layout animates only after this many milliseconds
// (prevents flashing on fast runs)
animationThreshold: 250,
// Number of iterations between consecutive screen positions update
// (0 -> only updated on the end)
refresh: 20,
// Whether to fit the network view after when done
fit: true,
// Padding on fit
padding: 30,
// Constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
boundingBox: undefined,
// Randomize the initial positions of the nodes (true) or use existing positions (false)
randomize: false,
// Extra spacing between components in non-compound graphs
componentSpacing: 100,
// Node repulsion (non overlapping) multiplier
nodeRepulsion: function( node ){ return 400000; },
// Node repulsion (overlapping) multiplier
nodeOverlap: 10,
// Ideal edge (non nested) length
idealEdgeLength: function( edge ){ return 10; },
// Divisor to compute edge forces
edgeElasticity: function( edge ){ return 100; },
// Nesting factor (multiplier) to compute ideal edge length for nested edges
nestingFactor: 5,
// Gravity force (constant)
gravity: 80,
// Maximum number of iterations to perform
numIter: 1000,
// Initial temperature (maximum node displacement)
initialTemp: 200,
// Cooling factor (how the temperature is reduced between consecutive iterations
coolingFactor: 0.95,
// Lower temperature threshold (below this point the layout will end)
minTemp: 1.0,
// Pass a reference to weaver to use threads for calculations
weaver: false
};
cy.add(graphElements);
cy.layout(options);
});
マイページ:
{% extends "queryapp/base.html" %}
{% block content %}
{% block title %}Default query page{% endblock %}
{% load static %}
<script>
var graphElements = {{ graph_elements|safe }};
</script>
<script src="{% static 'skimmr_django/js/jquery-3.1.1.min.js' %}"></script>
<script src="{% static 'queryapp/js/cytoscape.js' %}"></script>
<script src="{% static 'queryapp/js/result.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'queryapp/css/result.css' %}" />
<div id="cy"></div>
{% endblock %}
graphElements
Python から取得した有効な JSON です。
例 (全体が大きすぎてここにすべてを投稿できません): {"grabbable": true, "data": {"label-size": 9, "width": 0.4, "color": "#6699CC", "id": "something_about_boy"}, "group": "nodes", "classes": "node-class"},
グラフは Chrome では正しく機能しますが、Firefox のレイアウトが機能しないという問題があります。それを修正するにはどうすればよいですか?
編集:
Internet Explorer も試しましたが、動作しません。
問題は、私が紹介に従っていることでした:
http://js.cytoscape.org/#getting-started/initialisation
次のことは教えてくれません ( http://js.cytoscape.org/#notation/positionから):
position: { // the model position of the node (optional on init, mandatory after)
ノードの初期位置は気にしないので、追加しませんでした。ノードをグラフにロードし、初期ノードがないことに注意してください。最初のノードには位置は必要ありません。ロードしたノードには位置が必要です。
position
ノードに追加し (これで JSON に含まれるようになりました)、Javascript を変更しました (これはおそらく必要ありませんが、必要に応じて追加します)。
cy.add(graphElements);
var layout = cy.elements().layout(options);
layout.run();
Firefox と Chrome の両方で動作するようになりました。
この問題に遭遇した場合は、追加してください
position {
x: 1,
y: 1
}
あなたのノードに。この問題に遭遇した場合、(私のように) 初期位置を気にしないので、何でも使用できるようにするか、ノードに位置を追加するのを忘れてしまいます。
その後、レイアウトが機能します。
誰かが Chrome で機能する理由を説明できる場合 (私はそうすべきではないと理解していますが)、代わりにその回答を受け入れます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加