Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b0664c78

Přidáno uživatelem Tomáš Šimandl před více než 6 roky(ů)

move getUniqueId to Utils

Zobrazit rozdíly:

sources/src/main/webapp/js/forceDirected.js
28 28
			j = 0;
29 29

  
30 30
		for (i = 0; i < visibleNodes.length; i++) {
31
			forceField[getId(visibleNodes[i])] = [0, 0];
31
			forceField[app.utils.getUniqueId(visibleNodes[i])] = [0, 0];
32 32
		}
33 33

  
34 34
		// calculate repulsive force
......
56 56
				var distance = Math.sqrt(sum);
57 57

  
58 58
				if (distance !== 0) {
59
					forceField[getId(currNode)][0] += Math.floor(x * (repulsiveStrength / distance));
60
					forceField[getId(currNode)][1] += Math.floor(y * (repulsiveStrength / distance));
59
					forceField[app.utils.getUniqueId(currNode)][0] += Math.floor(x * (repulsiveStrength / distance));
60
					forceField[app.utils.getUniqueId(currNode)][1] += Math.floor(y * (repulsiveStrength / distance));
61 61
				}
62 62
			}
63 63
		}
......
79 79
				var sum = Math.pow(x, 2) + Math.pow(y, 2);
80 80
				var distance = Math.sqrt(sum);
81 81

  
82
				forceField[getId(currNode)][0] += Math.round(-1 * x * (distance / attractiveStrength));
83
				forceField[getId(currNode)][1] += Math.round(-1 * y * (distance / attractiveStrength));
82
				forceField[app.utils.getUniqueId(currNode)][0] += Math.round(-1 * x * (distance / attractiveStrength));
83
				forceField[app.utils.getUniqueId(currNode)][1] += Math.round(-1 * y * (distance / attractiveStrength));
84 84
			}
85 85

  
86 86
			for (j = 0; j < currNode.getOutEdgeList().length; j++) {
......
96 96
				var sum = Math.pow(x, 2) + Math.pow(y, 2);
97 97
				var distance = Math.sqrt(sum);
98 98

  
99
				forceField[getId(currNode)][0] += Math.round(-1 * x * (distance / attractiveStrength));
100
				forceField[getId(currNode)][1] += Math.round(-1 * y * (distance / attractiveStrength));
99
				forceField[app.utils.getUniqueId(currNode)][0] += Math.round(-1 * x * (distance / attractiveStrength));
100
				forceField[app.utils.getUniqueId(currNode)][1] += Math.round(-1 * y * (distance / attractiveStrength));
101 101
			}
102 102
		}
103 103

  
......
139 139
			}
140 140

  
141 141
			// force dampening
142
			var forceX = Math.floor(forceField[getId(currNode)][0] / dampeningEffect),
143
				forceY = Math.floor(forceField[getId(currNode)][1] / dampeningEffect);
142
			var forceX = Math.floor(forceField[app.utils.getUniqueId(currNode)][0] / dampeningEffect),
143
				forceY = Math.floor(forceField[app.utils.getUniqueId(currNode)][1] / dampeningEffect);
144 144

  
145 145
			// adding a random effect
146 146
			/*
......
161 161
			}
162 162
		}
163 163
	};
164

  
165
	/**
166
	 * @param {(Vertex|Group)} node Graph node.
167
	 * @returns {string} Unique identifier of a graph node (group or vertex).
168
	 */
169
	function getId(node) {
170
		var prefix;
171
		if (node instanceof Vertex) {
172
			prefix = 'vertex-';
173
		} else if (node instanceof Group) {
174
			prefix = 'group-';
175
		} else {
176
			prefix = '';
177
		}
178

  
179
		return prefix + node.id;
180
	}
181

  
182 164
}
sources/src/main/webapp/js/utils/utils.js
93 93
		}
94 94

  
95 95
		return false;
96
	}
96
	};
97

  
98
    /**
99
     * @param {(Vertex|Group)} node Graph node.
100
     * @returns {string} Unique identifier of a graph node (group or vertex).
101
     */
102
    this.getUniqueId = function(node) {
103
        var prefix;
104
        if (node instanceof Vertex) {
105
            prefix = 'vertex-';
106
        } else if (node instanceof Group) {
107
            prefix = 'group-';
108
        } else {
109
            prefix = '';
110
        }
97 111

  
112
        return prefix + node.id;
113
    };
98 114
}

Také k dispozici: Unified diff