From 1b11aae7fb5934a8124287202a40d5340042155a Mon Sep 17 00:00:00 2001 From: Unto Kuuranne Date: Tue, 24 Jun 2014 13:48:08 +0300 Subject: [PATCH 1/2] Make scaling factor of selected edges configurable via widthSelectionMultiplier --- docs/graph.html | 138 +++++++++++++++++++++++---------------------- src/graph/Edge.js | 11 +++- src/graph/Graph.js | 1 + 3 files changed, 82 insertions(+), 68 deletions(-) diff --git a/docs/graph.html b/docs/graph.html index 791c8d51..b8a601ad 100644 --- a/docs/graph.html +++ b/docs/graph.html @@ -527,45 +527,45 @@ When using a DataSet, the graph is automatically updating to changes in the Data Required Description - - arrowScaleFactor - Number - no - If you are using arrows, this will scale the arrow. Values < 1 give smaller arrows, > 1 larger arrows. Default: 1. - - - color - String | Object - no - Color for the edge. - + + arrowScaleFactor + Number + no + If you are using arrows, this will scale the arrow. Values < 1 give smaller arrows, > 1 larger arrows. Default: 1. + + + color + String | Object + no + Color for the edge. + - - color.color - String - no - Color of the edge when not selected. - + + color.color + String + no + Color of the edge when not selected. + - - color.highlight - String - no - Color of the edge when selected. - + + color.highlight + String + no + Color of the edge when selected. + - - color.hover - String - no - Color of the edge when the edge is hovered over and the hover option is enabled. - - - hoverWidth - Number - 1.5 - This determines the thickness of the edge if it is hovered over. This will only manifest when the hover option is enabled. - + + color.hover + String + no + Color of the edge when the edge is hovered over and the hover option is enabled. + + + hoverWidth + Number + 1.5 + This determines the thickness of the edge if it is hovered over. This will only manifest when the hover option is enabled. + dash @@ -1149,32 +1149,32 @@ var options = { Default Description - - arrowScaleFactor - Number - 1 - If you are using arrows, this will scale the arrow. Values < 1 give smaller arrows, > 1 larger arrows. Default: 1. - - - color - String | Object - Object - Colors of the edge. This object contains both colors for the selected and unselected state. - + + arrowScaleFactor + Number + 1 + If you are using arrows, this will scale the arrow. Values < 1 give smaller arrows, > 1 larger arrows. Default: 1. + + + color + String | Object + Object + Colors of the edge. This object contains both colors for the selected and unselected state. + - - color.color - String - "#848484" - Color of the edge when not selected. - + + color.color + String + "#848484" + Color of the edge when not selected. + - - color.highlight - String - "#848484" - Color of the edge when selected. - + + color.highlight + String + "#848484" + Color of the edge when selected. + dash @@ -1214,12 +1214,12 @@ var options = { Default length of a gap in pixels on a dashed line. Only applicable when the line style is dash-line. - - length - number - physics.[method].springLength - The resting length of the edge when modeled as a spring. By default the springLength determined by the physics is used. By using this setting you can make certain edges have different resting lengths. - + + length + number + physics.[method].springLength + The resting length of the edge when modeled as a spring. By default the springLength determined by the physics is used. By using this setting you can make certain edges have different resting lengths. + style @@ -1235,6 +1235,12 @@ var options = { 1 The default width of a edge. + + widthSelectionMultiplier + Number + 2 + This determines the thickness scaling of an edge if it, or a node it is connected to, is selected. +

Groups configuration

diff --git a/src/graph/Edge.js b/src/graph/Edge.js index 6bd94b03..bd20f5df 100644 --- a/src/graph/Edge.js +++ b/src/graph/Edge.js @@ -30,6 +30,7 @@ function Edge (properties, graph, constants) { this.style = constants.edges.style; this.title = undefined; this.width = constants.edges.width; + this.widthSelectionMultiplier = constants.edges.widthSelectionMultiplier; this.hoverWidth = constants.edges.hoverWidth; this.value = undefined; this.length = constants.physics.springLength; @@ -63,6 +64,9 @@ function Edge (properties, graph, constants) { this.setProperties(properties, constants); + // calculate width of edge when it, or a node it is connected to, is selected + this.widthSelected = this.width * this.widthSelectionMultiplier; + this.controlNodesEnabled = false; this.controlNodes = {from:null, to:null, positions:{}}; this.connectedNode = null; @@ -99,6 +103,7 @@ Edge.prototype.setProperties = function(properties, constants) { if (properties.title !== undefined) {this.title = properties.title;} if (properties.width !== undefined) {this.width = properties.width;} + if (properties.widthSelectionMultiplier !== undefined) {this.widthSelectionMultiplier = properties.widthSelectionMultiplier;} if (properties.hoverWidth !== undefined) {this.hoverWidth = properties.hoverWidth;} if (properties.value !== undefined) {this.value = properties.value;} if (properties.length !== undefined) {this.length = properties.length; @@ -133,6 +138,8 @@ Edge.prototype.setProperties = function(properties, constants) { this.widthFixed = this.widthFixed || (properties.width !== undefined); this.lengthFixed = this.lengthFixed || (properties.length !== undefined); + this.widthSelected = this.width * this.widthSelectionMultiplier; + // set draw method based on style switch (this.style) { case 'line': this.draw = this._drawLine; break; @@ -310,7 +317,7 @@ Edge.prototype._drawLine = function(ctx) { */ Edge.prototype._getLineWidth = function() { if (this.selected == true) { - return Math.min(this.width * 2, this.widthMax)*this.graphScaleInv; + return Math.min(this.widthSelected, this.widthMax)*this.graphScaleInv; } else { if (this.hover == true) { @@ -954,4 +961,4 @@ Edge.prototype.getControlNodePositions = function(ctx) { } return {from:{x:xFrom,y:yFrom},to:{x:xTo,y:yTo}}; -} \ No newline at end of file +} diff --git a/src/graph/Graph.js b/src/graph/Graph.js index 084d2261..fc196a9b 100644 --- a/src/graph/Graph.js +++ b/src/graph/Graph.js @@ -71,6 +71,7 @@ function Graph (container, data, options) { widthMin: 1, widthMax: 15, width: 1, + widthSelectionMultiplier: 2, hoverWidth: 1.5, style: 'line', color: { From 2e036406aa98ef324d71b074cebe28ea3564f96e Mon Sep 17 00:00:00 2001 From: Unto Kuuranne Date: Tue, 24 Jun 2014 13:55:49 +0300 Subject: [PATCH 2/2] Clarify widthSelectionMultiplier documentation --- docs/graph.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/graph.html b/docs/graph.html index b8a601ad..6e0b9c75 100644 --- a/docs/graph.html +++ b/docs/graph.html @@ -1239,7 +1239,7 @@ var options = { widthSelectionMultiplier Number 2 - This determines the thickness scaling of an edge if it, or a node it is connected to, is selected. + Determines the thickness scaling of an selected edge. This is applied when an edge, or a node connected to it, is selected.