Skip to content

Commit 0835e64

Browse files
committed
initial basic graph setup
1 parent 83f4ce4 commit 0835e64

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

src/charts/topology-map/examples/topology-map-view.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<example module="patternfly.charts">
1212
<file name="index.html">
1313
<div ng-controller="TopologyMapCtrl" class="container-topology">
14-
<pf-topology-map nodes="nodes" edges="edges" force="2"></pf-topology-map>
14+
<pf-topology-map nodes="nodes" edges="edges"></pf-topology-map>
1515
</div>
1616
</file>
1717
<file name="script.js">
@@ -20,9 +20,18 @@
2020
{
2121
id: 1,
2222
title: 'testNode',
23+
icon: 'fa'
24+
},
25+
{
26+
id: 2,
27+
title: 'testNode2',
28+
fill: '#FF0000'
2329
},
2430
];
25-
$scope.edges = [];
31+
$scope.edges = [{
32+
source: 0,
33+
target: 1,
34+
}];
2635
});
2736
</file>
2837
</example>

src/charts/topology-map/topologyMap.component.js

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
angular.module('patternfly.charts').component('pfTopologyMap', {
22
bindings: {
3-
force: '<?',
43
nodes: '<',
5-
edges: '<'
4+
edges: '<',
5+
force: '<?',
6+
radius: '<?',
67
},
78
templateUrl: 'charts/topology-map.html',
89
controller: function ($element) {
@@ -19,12 +20,18 @@ angular.module('patternfly.charts').component('pfTopologyMap', {
1920
var maxNodeSize;
2021
var transform;
2122
var simulation;
23+
var options;
24+
var radius = ctrl.radius || 17;
25+
var graph;
2226

23-
ctrl.canvas = $element[0] ;
27+
ctrl.canvas;
28+
ctrl.showLabels = false;
2429

2530
this.$onInit = function () {
2631
var coords;
27-
ctrl.canvas = ctrl.canvas.querySelector('canvas.topology-graph');
32+
33+
options = {force: ctrl.force, radius: ctrl.radius};
34+
ctrl.canvas = $element[0].querySelector('canvas.topology-graph');
2835
// Store the CSS computed width and the height of the canvas
2936
ctrl.canvasW = ctrl.canvas.clientWidth;
3037
ctrl.canvasH = ctrl.canvas.clientHeight;
@@ -36,10 +43,44 @@ angular.module('patternfly.charts').component('pfTopologyMap', {
3643
ctrl.canvasX = coords.left;
3744
ctrl.canvasY = coords.top;
3845
// Store the canvas' context
39-
ctrl.context = this.canvas.getContext('2d');
40-
// Set up the initial transform
41-
ctrl.transform = d3.zoomIdentity;
42-
console.log('controller: ', ctrl);
46+
ctrl.context = ctrl.canvas.getContext('2d');
47+
ctrl.context.font = '17px FontAwesome';
48+
if (! ctrl.force) {
49+
ctrl.force = d3.layout.force()
50+
.charge(-800)
51+
.gravity(0.2)
52+
.linkDistance(80)
53+
.size([ctrl.canvasW, ctrl.canvasH]);
54+
}
55+
ctrl.force.nodes(ctrl.nodes)
56+
.links(ctrl.edges)
57+
.on('tick', tick)
58+
.start();
59+
function tick () {
60+
ctrl.context.clearRect(0, 0, ctrl.canvasW, ctrl.canvasH);
61+
ctrl.context.strokeStyle = "#ccc";
62+
ctrl.context.beginPath();
63+
ctrl.edges.forEach(function (d) {
64+
ctrl.context.moveTo(d.source.x, d.source.y);
65+
ctrl.context.lineTo(d.target.x, d.target.y);
66+
});
67+
ctrl.context.stroke();
68+
69+
// draw nodes
70+
ctrl.nodes.forEach(function (d) {
71+
ctrl.context.beginPath();
72+
ctrl.context.fillStyle = "steelblue";
73+
ctrl.context.moveTo(d.x, d.y);
74+
ctrl.context.arc(d.x, d.y, 17, 0, 2 * Math.PI);
75+
ctrl.context.fill();
76+
ctrl.context.beginPath();
77+
ctrl.context.fillStyle = 'black';
78+
ctrl.context.textAlign = 'center';
79+
ctrl.context.fillText('\uF047', d.x, d.y - (17 / 2));
80+
ctrl.context.fill();
81+
});
82+
}
83+
console.log(ctrl.force);
4384
};
4485
},
4586
});

0 commit comments

Comments
 (0)