Sun*_*Man 0 javascript cytoscape.js
祝大家有个美好的一天。
对于信中的任何错误,我提前道歉。在 D3.js 之后,我开始学习新的库 - cytoscape.js。简单的例子是有效的,但后来我尝试在我的 angular.js-project 中使用 cytoscape.js - 我遇到了一些奇怪的情况:在一个骨架示例之后:
我从 cytoscape.js 获得页面上的空白画布。所有画布的宽度为屏幕宽度,但高度 = 0。我检查了我的 cy 对象 - 所有元素都由库解析,所有元素都有唯一的 id,但所有元素都没有位置:
x = 0, y = 0
您可以在下面看到一些代码。主页有指令:
<div ng-view></div>
Run Code Online (Sandbox Code Playgroud)
我的控制器:
someName.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/lgraph', {
templateUrl: 'partials/graphfull.html',
controller: 'GraphPainterController'
}).
otherwise({
templateUrl: 'partials/mainpage.html'
});
}]);
Run Code Online (Sandbox Code Playgroud)
我的控制器:
GraphPainterController.controller('GraphPainterController', ['$scope', 'GraphResource', 'cyGraph',
function($scope, GraphResource, cyGraph) {
...
$scope.graph = GraphResource.results;
cyGraph($scope.graph, $scope).then(function(graphCyObj) {
cy = graphCyObj;
$scope.cyLoaded = true;
});
...
}
]);
Run Code Online (Sandbox Code Playgroud)
工厂:
graphPathControllers.factory('cyGraph', [ '$q', function( $q ){
var cy;
var cyGraph = function(graph, scope) {
var deferred = $q.defer();
$(function() { // on dom ready
cy = cytoscape({
container: $('#cy')[0],
elements: {
nodes: nodesReady,
edges: edgesReady
},
style: cytoscape.stylesheet()
.selector('edge')
.css({
'target-arrow-shape': 'triangle'
})
.selector(':selected')
.css({
'background-color': 'black',
'line-color': 'black',
'target-arrow-color': 'black',
'source-arrow-color': 'black',
'text-outline-color': 'black'
}),
motionBlur:true,
wheelSensitivity:0.3,
layout: {
name: 'cose',
refresh: 10,
maxSimulationTime: 4000,
ungrabifyWhileSimulating: true, layout
padding: 10,
randomize: false,
ready: function() {
deferred.resolve( this );
var currentSelectedForInfoNode;
cy.elements().unselectify();
cy.on('cxttapstart', 'node', function(e) {
ctxInfo(currentSelectedForInfoNode, this);
});
cy.on('tap', 'node', function(e) {
var node = e.cyTarget;
var neighborhood = node.neighborhood().add(node);
cy.elements().addClass('faded');
neighborhood.removeClass('faded');
});
cy.on('tap', function(e) {
if (currentSelectedForInfoNode !== undefined) {
hideCtxInfo(currentSelectedForInfoNode);
}
if( e.cyTarget === cy ){
cy.elements().removeClass('faded');
}
});
}
});
});
return deferred.promise;}
Run Code Online (Sandbox Code Playgroud)
graphfull.html:
<div id = "cy">
<div id = "bubbleinfo">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我无法理解我错在哪里。
感谢收看!=) 答案很简单 - 始终检查您的样式,因为有时您的 html 元素的高度和宽度不会像您预期的那样自动增加。就我而言 - 我在将高度增加到 100% 后看到了我的 cyGraph。但奇怪的是,我在没有样式编辑的情况下立即拥有 100% 的宽度。我希望我的例子和答案可以帮助任何人。
| 归档时间: |
|
| 查看次数: |
2757 次 |
| 最近记录: |