【发布时间】:2017-04-13 12:34:14
【问题描述】:
我有一个显示 Cytoscape.js 图表的页面,但 .layout() 在 Firefox 中对我不起作用,但在 Chrome 中却可以。
Chrome 显示带有布局的图形。 Firefox 显示图表,但所有节点都杂乱无章。如果我不使用布局,它在 Chrome 中看起来是一样的,所以由于某种原因,布局在 Firefox 中似乎不起作用。
我从 Cytoscape.js 网站 (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 版
我的 Javascript:
$( 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,它不起作用。
【问题讨论】:
标签: javascript jquery google-chrome firefox cytoscape.js