Skip to content

Commit e81d26c

Browse files
committed
More on new Label interface
1 parent 45e892b commit e81d26c

File tree

8 files changed

+243
-118
lines changed

8 files changed

+243
-118
lines changed

Source/Graph.Plot.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -296,29 +296,8 @@ Graph.Plot = {
296296

297297
var f = adj.data && adj.data.$type || econfig.type;
298298
this.edgeTypes[f].call(this, adj, canvas, animating);
299-
},
299+
}
300300

301-
/*
302-
Method: fitsInCanvas
303-
304-
Returns _true_ or _false_ if the label for the node is contained in the canvas dom element or not.
305-
306-
Parameters:
307-
308-
pos - A <Complex> instance (I'm doing duck typing here so any object with _x_ and _y_ parameters will do).
309-
canvas - A <Canvas> instance.
310-
311-
Returns:
312-
313-
A boolean value specifying if the label is contained in the <Canvas> DOM element or not.
314-
315-
*/
316-
fitsInCanvas: function(pos, canvas) {
317-
var size = canvas.getSize();
318-
if(pos.x >= size.width || pos.x < 0
319-
|| pos.y >= size.height || pos.y < 0) return false;
320-
return true;
321-
}
322301
};
323302

324303
/*
@@ -380,7 +359,9 @@ Graph.Label.Native = new Class({
380359
var ctx = canvas.getCtx();
381360
var coord = node.pos.getc(true);
382361
ctx.fillText(node.name, coord.x, coord.y);
383-
}
362+
},
363+
364+
hideLabel: $empty
384365
});
385366

386367
/*
@@ -550,6 +531,27 @@ Graph.Label.DOM = new Class({
550531
lab.style.display = st;
551532
}
552533
});
534+
},
535+
/*
536+
Method: fitsInCanvas
537+
538+
Returns _true_ or _false_ if the label for the node is contained in the canvas dom element or not.
539+
540+
Parameters:
541+
542+
pos - A <Complex> instance (I'm doing duck typing here so any object with _x_ and _y_ parameters will do).
543+
canvas - A <Canvas> instance.
544+
545+
Returns:
546+
547+
A boolean value specifying if the label is contained in the <Canvas> DOM element or not.
548+
549+
*/
550+
fitsInCanvas: function(pos, canvas) {
551+
var size = canvas.getSize();
552+
if(pos.x >= size.width || pos.x < 0
553+
|| pos.y >= size.height || pos.y < 0) return false;
554+
return true;
553555
}
554556
});
555557

Source/Hypertree.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ This method is useful for adding some styles to a particular edge before being p
263263
- _graph_ Access a <Graph> instance.
264264
- _op_ Access a <Hypertree.Op> instance.
265265
- _fx_ Access a <Hypertree.Plot> instance.
266+
- _labels_ Access a <Hypertree.Label> instance.
266267
*/
267268

268269
this.Hypertree = new Class({
@@ -321,7 +322,7 @@ this.Hypertree = new Class({
321322
}
322323
};
323324
this.graph = new Graph(this.graphOptions);
324-
this.labels = new Hypertree.Label[canvas.getConfig().labels]();
325+
this.labels = new Hypertree.Label[canvas.getConfig().labels](this);
325326
this.fx = new Hypertree.Plot(this);
326327
this.op = new Hypertree.Op(this);
327328
this.json = null;
@@ -608,13 +609,14 @@ Hypertree.Plot = new Class({
608609
Implements: Graph.Plot,
609610

610611
initialize: function(viz) {
611-
this.viz = viz;
612-
this.config = viz.config;
612+
this.viz = viz;
613+
this.config = viz.config;
613614
this.node = this.config.Node;
614615
this.edge = this.config.Edge;
615-
this.animation = new Animation;
616-
this.nodeTypes = new Hypertree.Plot.NodeTypes;
617-
this.edgeTypes = new Hypertree.Plot.EdgeTypes;
616+
this.animation = new Animation;
617+
this.nodeTypes = new Hypertree.Plot.NodeTypes;
618+
this.edgeTypes = new Hypertree.Plot.EdgeTypes;
619+
this.labels = viz.labels;
618620
},
619621

620622
/*
@@ -737,7 +739,26 @@ Hypertree.Label = {};
737739
738740
*/
739741
Hypertree.Label.Native = new Class({
740-
Implements: Graph.Label.Native
742+
Extends: Graph.Label.Native,
743+
744+
/*
745+
Method: plotLabel
746+
747+
Plots a label for a given node.
748+
749+
Parameters:
750+
751+
canvas - A <Canvas> instance.
752+
node - A <Graph.Node>.
753+
controller - A configuration object. See also <Hypertree>, <RGraph>, <ST>.
754+
755+
*/
756+
plotLabel: function(canvas, node, controller) {
757+
var ctx = canvas.getCtx();
758+
var coord = node.pos.getc(true);
759+
var scale = node._scale;
760+
ctx.fillText(node.name, coord.x * scale, coord.y * scale);
761+
}
741762
});
742763

743764
/*
@@ -776,13 +797,13 @@ Hypertree.Label.SVG = new Class({
776797
placeLabel: function(tag, node, controller) {
777798
var pos = node.pos.getc(true), canvas = this.viz.canvas;
778799
var radius= canvas.getSize();
800+
var scale = node._scale;
779801
var labelPos= {
780-
x: Math.round(pos.x + radius.width/2),
781-
y: Math.round(pos.y + radius.height/2)
802+
x: Math.round(pos.x * scale + radius.width/2),
803+
y: Math.round(pos.y * scale + radius.height/2)
782804
};
783805
tag.setAttribute('x', labelPos.x);
784806
tag.setAttribute('y', labelPos.y);
785-
786807
controller.onPlaceLabel(tag, node);
787808
}
788809
});
@@ -822,11 +843,11 @@ Hypertree.Label.HTML = new Class({
822843
placeLabel: function(tag, node, controller) {
823844
var pos = node.pos.getc(true), canvas = this.viz.canvas;
824845
var radius= canvas.getSize();
846+
var scale = node._scale;
825847
var labelPos= {
826-
x: Math.round(pos.x + radius.width/2),
827-
y: Math.round(pos.y + radius.height/2)
848+
x: Math.round(pos.x * scale + radius.width/2),
849+
y: Math.round(pos.y * scale + radius.height/2)
828850
};
829-
830851
var style = tag.style;
831852
style.left = labelPos.x + 'px';
832853
style.top = labelPos.y + 'px';

Source/RGraph.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,6 @@ RGraph.Label.SVG = new Class({
586586
tag.setAttribute('x', labelPos.x);
587587
tag.setAttribute('y', labelPos.y);
588588

589-
//tag.setAttribute('transform', 'rotate(' + node.pos.theta * 360 / (Math.PI *2)
590-
// + ' ' + labelPos.x + ' ' + labelPos.y + ')');
591589

592590
controller.onPlaceLabel(tag, node);
593591
}

0 commit comments

Comments
 (0)