Skip to content

Commit 129eabf

Browse files
committed
added dynamic labels for datatypes
1 parent 975a9fb commit 129eabf

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webvowl",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"dependencies": {
55
"d3": "^3.5.6",
66
"lodash": "^4.1.0"

src/webvowl/js/elements/nodes/RectangularNode.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ module.exports = (function () {
1313
width = 60,
1414
pinGroupElement,
1515
haloGroupElement,
16+
labelWidth = 80,
17+
myWidth=80,
1618
smallestRadius = height / 2;
1719

18-
1920
// Properties
2021
this.height = function (p) {
2122
if (!arguments.length) return height;
@@ -55,9 +56,52 @@ module.exports = (function () {
5556

5657
};
5758

59+
this.textWidth = function () {
60+
//
61+
if(graph.options().dynamicLabelWidth()===true) {
62+
return that.getMyWidth();
63+
}
64+
return labelWidth;
65+
};
66+
this.width= function(){
67+
if(graph.options().dynamicLabelWidth()===true){
68+
return that.getMyWidth();
69+
}
70+
return labelWidth;
71+
};
72+
73+
this.getMyWidth=function(){
74+
// use a simple heuristic
75+
var text = that.labelForCurrentLanguage();
76+
myWidth =measureTextWidth(text,"text")+20;
77+
78+
// check for sub names;
79+
var indicatorText=that.indicationString();
80+
var indicatorWidth=measureTextWidth(indicatorText,"subtext")+20;
81+
if (indicatorWidth>myWidth)
82+
myWidth=indicatorWidth;
83+
84+
return myWidth;
85+
};
86+
5887
this.textWidth = function () {
5988
return that.width();
6089
};
90+
function measureTextWidth(text, textStyle) {
91+
// Set a default value
92+
if (!textStyle) {
93+
textStyle = "text";
94+
}
95+
var d = d3.select("body")
96+
.append("div")
97+
.attr("class", textStyle)
98+
.attr("id", "width-test") // tag this element to identify it
99+
.attr("style", "position:absolute; float:left; white-space:nowrap; visibility:hidden;")
100+
.text(text),
101+
w = document.getElementById("width-test").offsetWidth;
102+
d.remove();
103+
return w;
104+
}
61105

62106
this.toggleFocus = function () {
63107
that.focused(!that.focused());

0 commit comments

Comments
 (0)