annotate popoto/src/js/popoto.js @ 30:cccbcc845d54

add arrowheads to commentary chains.
author casties
date Fri, 11 Dec 2015 13:03:04 -0500
parents aea1b2097f4f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2 * Popoto.js is a JavaScript library built with D3.js providing a graph based search interface generated in HTML and SVG usable on any modern browser.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3 * This library generates an interactive graph query builder into any website or web based application to create dynamic queries on Neo4j databases and display the results.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
4 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
5 * Copyright (C) 2014-2015 Frederic Ciminera
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
6 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or modify
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
9 * the Free Software Foundation, either version 3 of the License, or
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
10 * (at your option) any later version.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
11 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
15 * GNU General Public License for more details.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
16 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
19 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
20 * contact@popotojs.com
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
21 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
22 popoto = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
23 var popoto = {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
24 version: "0.0-a6"
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
25 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
26
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
27 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
28 * Main function to call to use Popoto.js.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
29 * This function will create all the HTML content based on available IDs in the page.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
30 * popoto.graph.containerId for the graph query builder.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
31 * popoto.queryviewer.containerId for the query viewer.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
32 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
33 * @param label Root label to use in the graph query builder.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
34 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
35 popoto.start = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
36 popoto.logger.info("Popoto " + popoto.version + " start.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
37
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
38 if (typeof popoto.rest.CYPHER_URL == 'undefined') {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
39 popoto.logger.error("popoto.rest.CYPHER_URL is not set but this property is required.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
40 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
41 // TODO introduce component generator mechanism instead for future plugin extensions
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
42 popoto.checkHtmlComponents();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
43
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
44 if (popoto.taxonomy.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
45 popoto.taxonomy.createTaxonomyPanel();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
46 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
47
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
48 if (popoto.graph.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
49 popoto.graph.createGraphArea();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
50 popoto.graph.createForceLayout();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
51 popoto.graph.addRootNode(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
52 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
53
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
54 if (popoto.queryviewer.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
55 popoto.queryviewer.createQueryArea();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
56 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
57
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
58 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
59 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
60 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
61
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
62 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
63 * Check in the HTML page the components to generate.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
64 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
65 popoto.checkHtmlComponents = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
66 var graphHTMLContainer = d3.select("#" + popoto.graph.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
67 var taxonomyHTMLContainer = d3.select("#" + popoto.taxonomy.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
68 var queryHTMLContainer = d3.select("#" + popoto.queryviewer.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
69 var cypherHTMLContainer = d3.select("#" + popoto.cypherviewer.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
70 var resultsHTMLContainer = d3.select("#" + popoto.result.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
71
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
72 if (graphHTMLContainer.empty()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
73 popoto.logger.debug("The page doesn't contain a container with ID = \"" + popoto.graph.containerId + "\" no graph area will be generated. This ID is defined in popoto.graph.containerId property.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
74 popoto.graph.isActive = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
75 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
76 popoto.graph.isActive = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
77 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
78
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
79 if (taxonomyHTMLContainer.empty()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
80 popoto.logger.debug("The page doesn't contain a container with ID = \"" + popoto.taxonomy.containerId + "\" no taxonomy filter will be generated. This ID is defined in popoto.taxonomy.containerId property.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
81 popoto.taxonomy.isActive = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
82 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
83 popoto.taxonomy.isActive = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
84 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
85
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
86 if (queryHTMLContainer.empty()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
87 popoto.logger.debug("The page doesn't contain a container with ID = \"" + popoto.queryviewer.containerId + "\" no query viewer will be generated. This ID is defined in popoto.queryviewer.containerId property.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
88 popoto.queryviewer.isActive = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
89 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
90 popoto.queryviewer.isActive = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
91 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
92
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
93 if (cypherHTMLContainer.empty()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
94 popoto.logger.debug("The page doesn't contain a container with ID = \"" + popoto.cypherviewer.containerId + "\" no cypher query viewer will be generated. This ID is defined in popoto.cypherviewer.containerId property.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
95 popoto.cypherviewer.isActive = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
96 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
97 popoto.cypherviewer.isActive = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
98 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
99
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
100 if (resultsHTMLContainer.empty()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
101 popoto.logger.debug("The page doesn't contain a container with ID = \"" + popoto.result.containerId + "\" no result area will be generated. This ID is defined in popoto.result.containerId property.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
102 popoto.result.isActive = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
103 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
104 popoto.result.isActive = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
105 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
106 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
107
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
108 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
109 * Function to call to update all the generated elements including svg graph, query viewer and generated results.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
110 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
111 popoto.update = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
112 popoto.updateGraph();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
113
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
114 if (popoto.queryviewer.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
115 popoto.queryviewer.updateQuery();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
116 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
117 // Results are updated only if needed.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
118 // If id found in html page or if result listeners have been added.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
119 // In this case the query must be executed.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
120 if (popoto.result.isActive || popoto.result.resultListeners.length > 0 || popoto.result.resultCountListeners.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
121 popoto.result.updateResults();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
122 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
123 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
124
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
125 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
126 * Function to call to update the graph only.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
127 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
128 popoto.updateGraph = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
129 if (popoto.graph.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
130 // Starts the D3.js force simulation.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
131 // This method must be called when the layout is first created, after assigning the nodes and links.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
132 // In addition, it should be called again whenever the nodes or links change.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
133 popoto.graph.force.start();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
134 popoto.graph.link.updateLinks();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
135 popoto.graph.node.updateNodes();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
136 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
137 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
138
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
139 // REST ------------------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
140 popoto.rest = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
141
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
142 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
143 * Default REST URL used to call Neo4j server with cypher queries to execute.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
144 * This property should be updated to access to your own server.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
145 * @type {string}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
146 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
147 popoto.rest.CYPHER_URL = "http://localhost:7474/db/data/transaction/commit";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
148
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
149 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
150 * Create JQuery ajax POST request to access Neo4j REST API.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
151 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
152 * @param data data object containing Cypher query
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
153 * @returns {*} the JQuery ajax request object.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
154 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
155 popoto.rest.post = function (data) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
156 var strData = JSON.stringify(data);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
157 popoto.logger.info("REST POST:" + strData);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
158
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
159 return $.ajax({
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
160 type: "POST",
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
161 beforeSend: function (request) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
162 if (popoto.rest.AUTHORIZATION) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
163 request.setRequestHeader("Authorization", popoto.rest.AUTHORIZATION);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
164 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
165 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
166 url: popoto.rest.CYPHER_URL,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
167 contentType: "application/json",
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
168 data: strData
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
169 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
170 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
171
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
172 // LOGGER -----------------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
173 popoto.logger = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
174 popoto.logger.LogLevels = Object.freeze({DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, NONE: 4});
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
175 popoto.logger.LEVEL = popoto.logger.LogLevels.NONE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
176 popoto.logger.TRACE = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
177
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
178 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
179 * Log a message on console depending on configured log levels.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
180 * Level is define in popoto.logger.LEVEL property.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
181 * If popoto.logger.TRACE is set to true, the stack trace is also added in log.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
182 * @param logLevel Level of the message from popoto.logger.LogLevels.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
183 * @param message Message to log.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
184 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
185 popoto.logger.log = function (logLevel, message) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
186 if (console && logLevel >= popoto.logger.LEVEL) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
187 if (popoto.logger.TRACE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
188 message = message + "\n" + new Error().stack
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
189 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
190 switch (logLevel) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
191 case popoto.logger.LogLevels.DEBUG:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
192 console.log(message);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
193 break;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
194 case popoto.logger.LogLevels.INFO:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
195 console.log(message);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
196 break;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
197 case popoto.logger.LogLevels.WARN:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
198 console.warn(message);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
199 break;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
200 case popoto.logger.LogLevels.ERROR:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
201 console.error(message);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
202 break;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
203 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
204 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
205 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
206
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
207 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
208 * Log a message in DEBUG level.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
209 * @param message to log.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
210 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
211 popoto.logger.debug = function (message) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
212 popoto.logger.log(popoto.logger.LogLevels.DEBUG, message);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
213 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
214
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
215 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
216 * Log a message in INFO level.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
217 * @param message to log.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
218 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
219 popoto.logger.info = function (message) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
220 popoto.logger.log(popoto.logger.LogLevels.INFO, message);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
221 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
222
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
223 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
224 * Log a message in WARN level.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
225 * @param message to log.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
226 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
227 popoto.logger.warn = function (message) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
228 popoto.logger.log(popoto.logger.LogLevels.WARN, message);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
229 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
230
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
231 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
232 * Log a message in ERROR level.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
233 * @param message to log.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
234 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
235 popoto.logger.error = function (message) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
236 popoto.logger.log(popoto.logger.LogLevels.ERROR, message);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
237 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
238
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
239 // TAXONOMIES -----------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
240
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
241 popoto.taxonomy = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
242 popoto.taxonomy.containerId = "popoto-taxonomy";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
243
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
244 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
245 * Create the taxonomy panel HTML elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
246 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
247 popoto.taxonomy.createTaxonomyPanel = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
248 var htmlContainer = d3.select("#" + popoto.taxonomy.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
249
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
250 var taxoUL = htmlContainer.append("ul");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
251
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
252 var data = popoto.taxonomy.generateTaxonomiesData();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
253
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
254 var taxos = taxoUL.selectAll(".taxo").data(data);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
255
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
256 var taxoli = taxos.enter().append("li")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
257 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
258 return d.id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
259 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
260 .attr("value", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
261 return d.label;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
262 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
263
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
264 taxoli.append("img")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
265 .attr("src", "css/image/category.png")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
266 .attr("width", "24")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
267 .attr("height", "24");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
268
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
269 taxoli.append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
270 .attr("class", "ppt-label")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
271 .text(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
272 return popoto.provider.getTaxonomyTextValue(d.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
273 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
274
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
275 taxoli.append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
276 .attr("class", "ppt-count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
277
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
278 // Add an on click event on the taxonomy to clear the graph and set this label as root
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
279 taxoli.on("click", popoto.taxonomy.onClick);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
280
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
281 popoto.taxonomy.addTaxonomyChildren(taxoli);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
282
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
283 // The count is updated for each labels.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
284 var flattenData = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
285 data.forEach(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
286 flattenData.push(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
287 if (d.children) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
288 popoto.taxonomy.flattenChildren(d, flattenData);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
289 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
290 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
291
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
292 popoto.taxonomy.updateCount(flattenData);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
293 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
294
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
295 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
296 * Recursive function to flatten data content.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
297 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
298 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
299 popoto.taxonomy.flattenChildren = function (d, vals) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
300 d.children.forEach(function (c) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
301 vals.push(c);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
302 if (c.children) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
303 vals.concat(popoto.taxonomy.flattenChildren(c, vals));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
304 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
305 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
306 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
307
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
308 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
309 * Updates the count number on a taxonomy.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
310 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
311 * @param taxonomyData
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
312 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
313 popoto.taxonomy.updateCount = function (taxonomyData) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
314 var statements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
315
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
316 taxonomyData.forEach(function (taxo) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
317 statements.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
318 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
319 "statement": popoto.query.generateTaxonomyCountQuery(taxo.label)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
320 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
321 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
322 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
323
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
324 (function (taxonomies) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
325 popoto.logger.info("Count taxonomies ==> ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
326 popoto.rest.post(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
327 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
328 "statements": statements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
329 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
330 .done(function (returnedData) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
331 for (var i = 0; i < taxonomies.length; i++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
332 var count = returnedData.results[i].data[0].row[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
333 d3.select("#" + taxonomies[i].id)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
334 .select(".ppt-count")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
335 .text(" (" + count + ")");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
336 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
337 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
338 .fail(function (xhr, textStatus, errorThrown) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
339 popoto.logger.error(textStatus + ": error while accessing Neo4j server on URL:\"" + popoto.rest.CYPHER_URL + "\" defined in \"popoto.rest.CYPHER_URL\" property: " + errorThrown);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
340 d3.select("#popoto-taxonomy")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
341 .selectAll(".ppt-count")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
342 .text(" (0)");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
343 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
344 })(taxonomyData);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
345 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
346
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
347 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
348 * Recursively generate the taxonomy children elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
349 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
350 * @param selection
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
351 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
352 popoto.taxonomy.addTaxonomyChildren = function (selection) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
353 selection.each(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
354 var li = d3.select(this);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
355
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
356 var children = d.children;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
357 if (d.children) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
358 var childLi = li.append("ul")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
359 .selectAll("li")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
360 .data(children)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
361 .enter()
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
362 .append("li")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
363 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
364 return d.id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
365 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
366 .attr("value", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
367 return d.label;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
368 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
369
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
370 childLi.append("img")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
371 .attr("src", "css/image/category.png")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
372 .attr("width", "24")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
373 .attr("height", "24");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
374
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
375 childLi.append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
376 .attr("class", "ppt-label")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
377 .text(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
378 return popoto.provider.getTaxonomyTextValue(d.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
379 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
380
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
381 childLi.append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
382 .attr("class", "ppt-count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
383
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
384 childLi.on("click", popoto.taxonomy.onClick);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
385
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
386 popoto.taxonomy.addTaxonomyChildren(childLi);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
387 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
388
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
389 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
390 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
391
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
392 popoto.taxonomy.onClick = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
393 d3.event.stopPropagation();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
394
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
395 // Workaround to avoid click on taxonomies if root node has not yet been initialized
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
396 // If it contains a count it mean all the initialization has been done
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
397 var root = popoto.graph.getRootNode();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
398 if (root.count === undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
399 return;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
400 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
401
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
402 var label = this.attributes.value.value;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
403
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
404 while (popoto.graph.force.nodes().length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
405 popoto.graph.force.nodes().pop();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
406 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
407
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
408 while (popoto.graph.force.links().length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
409 popoto.graph.force.links().pop();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
410 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
411
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
412 // Reinitialize internal label generator
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
413 popoto.graph.node.internalLabels = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
414
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
415 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
416 popoto.graph.addRootNode(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
417 popoto.graph.hasGraphChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
418 popoto.result.hasChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
419 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
420 popoto.tools.center();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
421 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
422
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
423 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
424 * Parse the list of label providers and return a list of data object containing only searchable labels.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
425 * @returns {Array}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
426 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
427 popoto.taxonomy.generateTaxonomiesData = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
428 var id = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
429 var data = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
430
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
431 // Retrieve root providers (searchable and without parent)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
432 for (var label in popoto.provider.nodeProviders) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
433 if (popoto.provider.nodeProviders.hasOwnProperty(label)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
434 if (popoto.provider.getProperty(label, "isSearchable") && !popoto.provider.nodeProviders[label].parent) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
435 data.push({
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
436 "label": label,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
437 "id": "popoto-lbl-" + id++
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
438 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
439 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
440 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
441 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
442
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
443 // Add children data for each provider with children.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
444 data.forEach(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
445 if (popoto.provider.getProvider(d.label).hasOwnProperty("children")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
446 id = popoto.taxonomy.addChildrenData(d, id);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
447 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
448 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
449
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
450 return data;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
451 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
452
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
453 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
454 * Add children providers data.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
455 * @param parentData
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
456 * @param id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
457 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
458 popoto.taxonomy.addChildrenData = function (parentData, id) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
459 parentData.children = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
460
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
461 popoto.provider.getProvider(parentData.label).children.forEach(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
462 var childProvider = popoto.provider.getProvider(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
463 var childData = {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
464 "label": d,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
465 "id": "popoto-lbl-" + id++
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
466 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
467 if (childProvider.hasOwnProperty("children")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
468 id = popoto.taxonomy.addChildrenData(childData, id);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
469 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
470 if (popoto.provider.getProperty(d, "isSearchable")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
471 parentData.children.push(childData);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
472 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
473 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
474
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
475 return id;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
476 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
477
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
478 // TOOLS -----------------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
479
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
480 popoto.tools = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
481 // TODO introduce plugin mechanism to add tools
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
482 popoto.tools.CENTER_GRAPH = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
483 popoto.tools.RESET_GRAPH = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
484 popoto.tools.TOGGLE_TAXONOMY = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
485 popoto.tools.TOGGLE_FULL_SCREEN = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
486
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
487 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
488 * Reset all the graph to display the root node only.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
489 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
490 popoto.tools.reset = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
491 var label = popoto.graph.getRootNode().label;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
492
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
493 while (popoto.graph.force.nodes().length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
494 popoto.graph.force.nodes().pop();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
495 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
496
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
497 while (popoto.graph.force.links().length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
498 popoto.graph.force.links().pop();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
499 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
500
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
501 // Reinitialize internal label generator
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
502 popoto.graph.node.internalLabels = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
503
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
504 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
505 popoto.graph.addRootNode(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
506 popoto.graph.hasGraphChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
507 popoto.result.hasChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
508 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
509 popoto.tools.center();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
510 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
511
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
512 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
513 * Reset zoom and center the view on svg center.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
514 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
515 popoto.tools.center = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
516 popoto.graph.zoom.translate([0, 0]).scale(1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
517 popoto.graph.svg.transition().attr("transform", "translate(" + popoto.graph.zoom.translate() + ")" + " scale(" + popoto.graph.zoom.scale() + ")");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
518 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
519
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
520 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
521 * Show, hide taxonomy panel.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
522 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
523 popoto.tools.toggleTaxonomy = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
524 var taxo = d3.select("#" + popoto.taxonomy.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
525 if (taxo.filter(".disabled").empty()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
526 taxo.classed("disabled", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
527 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
528 taxo.classed("disabled", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
529 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
530 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
531
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
532 popoto.tools.toggleFullScreen = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
533
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
534 var elem = document.getElementById(popoto.graph.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
535
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
536 if (!document.fullscreenElement && // alternative standard method
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
537 !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) { // current working methods
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
538 if (elem.requestFullscreen) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
539 elem.requestFullscreen();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
540 } else if (elem.msRequestFullscreen) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
541 elem.msRequestFullscreen();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
542 } else if (elem.mozRequestFullScreen) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
543 elem.mozRequestFullScreen();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
544 } else if (elem.webkitRequestFullscreen) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
545 elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
546 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
547 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
548 if (document.exitFullscreen) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
549 document.exitFullscreen();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
550 } else if (document.msExitFullscreen) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
551 document.msExitFullscreen();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
552 } else if (document.mozCancelFullScreen) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
553 document.mozCancelFullScreen();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
554 } else if (document.webkitExitFullscreen) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
555 document.webkitExitFullscreen();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
556 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
557 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
558 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
559 // GRAPH -----------------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
560
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
561 popoto.graph = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
562
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
563 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
564 * ID of the HTML component where the graph query builder elements will be generated in.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
565 * @type {string}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
566 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
567 popoto.graph.containerId = "popoto-graph";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
568 popoto.graph.hasGraphChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
569 // Defines the min and max level of zoom available in graph query builder.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
570 popoto.graph.zoom = d3.behavior.zoom().scaleExtent([0.1, 10]);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
571 popoto.graph.WHEEL_ZOOM_ENABLED = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
572 popoto.graph.TOOL_TAXONOMY = "Show/hide taxonomy panel";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
573 popoto.graph.TOOL_CENTER = "Center view";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
574 popoto.graph.TOOL_FULL_SCREEN = "Full screen";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
575 popoto.graph.TOOL_RESET = "Reset graph";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
576
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
577 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
578 * Define the list of listenable events on graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
579 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
580 popoto.graph.Events = Object.freeze({NODE_ROOT_ADD: "root.node.add", NODE_EXPAND_RELATIONSHIP: "node.expandRelationship"});
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
581
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
582 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
583 * Generates all the HTML and SVG element needed to display the graph query builder.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
584 * Everything will be generated in the container with id defined by popoto.graph.containerId.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
585 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
586 popoto.graph.createGraphArea = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
587
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
588 var htmlContainer = d3.select("#" + popoto.graph.containerId);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
589
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
590 var toolbar = htmlContainer
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
591 .append("div")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
592 .attr("class", "ppt-toolbar");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
593
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
594 if (popoto.tools.RESET_GRAPH) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
595 toolbar.append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
596 .attr("id", "popoto-reset-menu")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
597 .attr("class", "ppt-menu reset")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
598 .attr("title", popoto.graph.TOOL_RESET)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
599 .on("click", popoto.tools.reset);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
600 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
601
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
602 if (popoto.taxonomy.isActive && popoto.tools.TOGGLE_TAXONOMY) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
603 toolbar.append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
604 .attr("id", "popoto-taxonomy-menu")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
605 .attr("class", "ppt-menu taxonomy")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
606 .attr("title", popoto.graph.TOOL_TAXONOMY)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
607 .on("click", popoto.tools.toggleTaxonomy);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
608 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
609
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
610 if (popoto.tools.CENTER_GRAPH) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
611 toolbar.append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
612 .attr("id", "popoto-center-menu")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
613 .attr("class", "ppt-menu center")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
614 .attr("title", popoto.graph.TOOL_CENTER)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
615 .on("click", popoto.tools.center);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
616 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
617
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
618 if (popoto.tools.TOGGLE_FULL_SCREEN) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
619 toolbar.append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
620 .attr("id", "popoto-fullscreen-menu")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
621 .attr("class", "ppt-menu fullscreen")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
622 .attr("title", popoto.graph.TOOL_FULL_SCREEN)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
623 .on("click", popoto.tools.toggleFullScreen);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
624 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
625
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
626 var svgTag = htmlContainer.append("svg").call(popoto.graph.zoom.on("zoom", popoto.graph.rescale));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
627
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
628 svgTag.on("dblclick.zoom", null)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
629 .attr("class", "ppt-svg-graph");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
630
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
631 if (!popoto.graph.WHEEL_ZOOM_ENABLED) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
632 // Disable mouse wheel events.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
633 svgTag.on("wheel.zoom", null)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
634 .on("mousewheel.zoom", null);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
635 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
636
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
637 popoto.graph.svg = svgTag.append('svg:g');
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
638
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
639 // Create two separated area for links and nodes
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
640 // Links and nodes are separated in a dedicated "g" element
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
641 // and nodes are generated after links to ensure that nodes are always on foreground.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
642 popoto.graph.svg.append("g").attr("id", popoto.graph.link.gID);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
643 popoto.graph.svg.append("g").attr("id", popoto.graph.node.gID);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
644
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
645 // This listener is used to center the root node in graph during a window resize.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
646 // TODO can the listener be limited on the parent container only?
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
647 window.addEventListener('resize', popoto.graph.centerRootNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
648 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
649
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
650 popoto.graph.centerRootNode = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
651 popoto.graph.getRootNode().px = popoto.graph.getSVGWidth() / 2;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
652 popoto.graph.getRootNode().py = popoto.graph.getSVGHeight() / 2;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
653 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
654 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
655
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
656 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
657 * Get the actual width of the SVG element containing the graph query builder.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
658 * @returns {number}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
659 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
660 popoto.graph.getSVGWidth = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
661 if (typeof popoto.graph.svg == 'undefined' || popoto.graph.svg.empty()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
662 popoto.logger.debug("popoto.graph.svg is undefined or empty.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
663 return 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
664 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
665 return document.getElementById(popoto.graph.containerId).clientWidth;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
666 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
667 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
668
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
669 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
670 * Get the actual height of the SVG element containing the graph query builder.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
671 * @returns {number}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
672 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
673 popoto.graph.getSVGHeight = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
674 if (typeof popoto.graph.svg == 'undefined' || popoto.graph.svg.empty()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
675 popoto.logger.debug("popoto.graph.svg is undefined or empty.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
676 return 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
677 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
678 return document.getElementById(popoto.graph.containerId).clientHeight;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
679 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
680 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
681
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
682 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
683 * Function to call on SVG zoom event to update the svg transform attribute.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
684 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
685 popoto.graph.rescale = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
686 var trans = d3.event.translate,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
687 scale = d3.event.scale;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
688
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
689 popoto.graph.svg.attr("transform",
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
690 "translate(" + trans + ")"
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
691 + " scale(" + scale + ")");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
692 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
693
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
694 /******************************
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
695 * Default parameters used to configure D3.js force layout.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
696 * These parameter can be modified to change graph behavior.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
697 ******************************/
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
698 popoto.graph.LINK_DISTANCE = 150;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
699 popoto.graph.LINK_STRENGTH = 1;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
700 popoto.graph.FRICTION = 0.8;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
701 popoto.graph.CHARGE = -1400;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
702 popoto.graph.THETA = 0.8;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
703 popoto.graph.GRAVITY = 0.0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
704
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
705 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
706 * Contains the list off root node add listeners.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
707 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
708 popoto.graph.rootNodeAddListeners = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
709 popoto.graph.nodeExpandRelationsipListeners = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
710
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
711 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
712 * Create the D3.js force layout for the graph query builder.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
713 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
714 popoto.graph.createForceLayout = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
715
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
716 popoto.graph.force = d3.layout.force()
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
717 .size([popoto.graph.getSVGWidth(), popoto.graph.getSVGHeight()])
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
718 .linkDistance(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
719 if (d.type === popoto.graph.link.LinkTypes.RELATION) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
720 return ((3 * popoto.graph.LINK_DISTANCE) / 2);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
721 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
722 return popoto.graph.LINK_DISTANCE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
723 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
724 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
725 .linkStrength(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
726 if (d.linkStrength) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
727 return d.linkStrength;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
728 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
729 return popoto.graph.LINK_STRENGTH;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
730 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
731 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
732 .friction(popoto.graph.FRICTION)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
733 .charge(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
734 if (d.charge) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
735 return d.charge;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
736 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
737 return popoto.graph.CHARGE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
738 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
739 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
740 .theta(popoto.graph.THETA)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
741 .gravity(popoto.graph.GRAVITY)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
742 .on("tick", popoto.graph.tick); // Function called on every position update done by D3.js
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
743
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
744 // Disable event propagation on drag to avoid zoom and pan issues
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
745 popoto.graph.force.drag()
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
746 .on("dragstart", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
747 d3.event.sourceEvent.stopPropagation();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
748 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
749 .on("dragend", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
750 d3.event.sourceEvent.stopPropagation();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
751 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
752 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
753
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
754 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
755 * Add a listener to the specified event.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
756 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
757 * @param event name of the event to add the listener.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
758 * @param listener the listener to add.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
759 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
760 popoto.graph.on = function (event, listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
761 if (event === popoto.graph.Events.NODE_ROOT_ADD) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
762 popoto.graph.rootNodeAddListeners.push(listener);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
763 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
764 if (event === popoto.graph.Events.NODE_EXPAND_RELATIONSHIP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
765 popoto.graph.nodeExpandRelationsipListeners.push(listener);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
766 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
767 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
768
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
769 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
770 * Adds graph root nodes using the label set as parameter.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
771 * All the other nodes should have been removed first to avoid inconsistent data.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
772 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
773 * @param label label of the node to add as root.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
774 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
775 popoto.graph.addRootNode = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
776 if (popoto.graph.force.nodes().length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
777 popoto.logger.debug("popoto.graph.addRootNode is called but the graph is not empty.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
778 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
779
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
780 popoto.graph.force.nodes().push({
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
781 "id": "0",
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
782 "type": popoto.graph.node.NodeTypes.ROOT,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
783 // x and y coordinates are set to the center of the SVG area.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
784 // These coordinate will never change at runtime except if the window is resized.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
785 "x": popoto.graph.getSVGWidth() / 2,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
786 "y": popoto.graph.getSVGHeight() / 2,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
787 "label": label,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
788 // The node is fixed to always remain in the center of the svg area.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
789 // This property should not be changed at runtime to avoid issues with the zoom and pan.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
790 "fixed": true,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
791 // Label used internally to identify the node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
792 // This label is used for example as cypher query identifier.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
793 "internalLabel": popoto.graph.node.generateInternalLabel(label)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
794 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
795
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
796 // Notify listeners
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
797 popoto.graph.rootNodeAddListeners.forEach(function (listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
798 listener(popoto.graph.getRootNode());
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
799 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
800 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
801
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
802 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
803 * Get the graph root node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
804 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
805 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
806 popoto.graph.getRootNode = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
807 return popoto.graph.force.nodes()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
808 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
809
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
810 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
811 * Function to call on D3.js force layout tick event.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
812 * This function will update the position of all links and nodes elements in the graph with the force layout computed coordinate.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
813 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
814 popoto.graph.tick = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
815 popoto.graph.svg.selectAll("#" + popoto.graph.link.gID + " > g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
816 .selectAll("path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
817 .attr("d", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
818 var parentAngle = popoto.graph.computeParentAngle(d.target);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
819 var targetX = d.target.x + (popoto.graph.link.RADIUS * Math.cos(parentAngle)),
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
820 targetY = d.target.y - (popoto.graph.link.RADIUS * Math.sin(parentAngle));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
821
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
822 var sourceX = d.source.x - (popoto.graph.link.RADIUS * Math.cos(parentAngle)),
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
823 sourceY = d.source.y + (popoto.graph.link.RADIUS * Math.sin(parentAngle));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
824
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
825 if (d.source.x <= d.target.x) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
826 return "M" + sourceX + " " + sourceY + "L" + targetX + " " + targetY;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
827 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
828 return "M" + targetX + " " + targetY + "L" + sourceX + " " + sourceY;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
829 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
830 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
831
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
832 popoto.graph.svg.selectAll("#" + popoto.graph.node.gID + " > g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
833 .attr("transform", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
834 return "translate(" + (d.x) + "," + (d.y) + ")";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
835 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
836 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
837
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
838 // LINKS -----------------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
839 popoto.graph.link = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
840
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
841 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
842 * Defines the radius around the node to start link drawing.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
843 * If set to 0 links will start from the middle of the node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
844 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
845 popoto.graph.link.RADIUS = 25;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
846
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
847 // ID of the g element in SVG graph containing all the link elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
848 popoto.graph.link.gID = "popoto-glinks";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
849
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
850 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
851 * Defines the different type of link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
852 * RELATION is a relation link between two nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
853 * VALUE is a link between a generic node and a value.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
854 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
855 popoto.graph.link.LinkTypes = Object.freeze({RELATION: 0, VALUE: 1});
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
856
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
857 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
858 * Function to call to update the links after modification in the model.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
859 * This function will update the graph with all removed, modified or added links using d3.js mechanisms.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
860 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
861 popoto.graph.link.updateLinks = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
862 popoto.graph.link.svgLinkElements = popoto.graph.svg.select("#" + popoto.graph.link.gID).selectAll("g");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
863 popoto.graph.link.updateData();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
864 popoto.graph.link.removeElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
865 popoto.graph.link.addNewElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
866 popoto.graph.link.updateElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
867 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
868
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
869 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
870 * Update the links element with data coming from popoto.graph.force.links().
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
871 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
872 popoto.graph.link.updateData = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
873 popoto.graph.link.svgLinkElements = popoto.graph.link.svgLinkElements.data(popoto.graph.force.links(), function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
874 return d.id;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
875 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
876 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
877
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
878 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
879 * Clean links elements removed from the list.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
880 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
881 popoto.graph.link.removeElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
882 popoto.graph.link.svgLinkElements.exit().remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
883 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
884
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
885 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
886 * Create new elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
887 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
888 popoto.graph.link.addNewElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
889
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
890 var newLinkElements = popoto.graph.link.svgLinkElements.enter().append("g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
891 .attr("class", "ppt-glink")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
892 .on("mouseover", popoto.graph.link.mouseOverLink)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
893 .on("mouseout", popoto.graph.link.mouseOutLink);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
894
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
895 newLinkElements.append("path");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
896
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
897 newLinkElements.append("text")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
898 .attr("text-anchor", "middle")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
899 .attr("dy", "-4")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
900 .append("textPath")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
901 .attr("class", "ppt-textPath")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
902 .attr("startOffset", "50%");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
903
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
904 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
905
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
906 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
907 * Update all the elements (new + modified)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
908 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
909 popoto.graph.link.updateElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
910 popoto.graph.link.svgLinkElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
911 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
912 return "ppt-glink_" + d.id;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
913 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
914
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
915 popoto.graph.link.svgLinkElements.selectAll("path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
916 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
917 return "ppt-path_" + d.id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
918 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
919 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
920 if (d.type === popoto.graph.link.LinkTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
921 return "ppt-link-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
922 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
923 if (d.target.count == 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
924 return "ppt-link-relation disabled";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
925 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
926 if (d.target.value !== undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
927 return "ppt-link-relation value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
928 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
929 return "ppt-link-relation";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
930 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
931 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
932 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
933 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
934
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
935 // Due to a bug on webkit browsers (as of 30/01/2014) textPath cannot be selected
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
936 // To workaround this issue the selection is done with its associated css class
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
937 popoto.graph.link.svgLinkElements.selectAll("text")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
938 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
939 return "ppt-text_" + d.id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
940 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
941 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
942 if (d.type === popoto.graph.link.LinkTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
943 return "ppt-link-text-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
944 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
945 if (d.target.count == 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
946 return "ppt-link-text-relation disabled";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
947 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
948 if (d.target.value !== undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
949 return "ppt-link-text-relation value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
950 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
951 return "ppt-link-text-relation";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
952 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
953 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
954 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
955 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
956 .selectAll(".ppt-textPath")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
957 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
958 return "ppt-textpath_" + d.id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
959 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
960 .attr("xlink:href", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
961 return "#ppt-path_" + d.id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
962 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
963 .text(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
964 return popoto.provider.getLinkTextValue(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
965 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
966 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
967
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
968 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
969 * Function called when mouse is over the link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
970 * This function is used to change the CSS class on hover of the link and query viewer element.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
971 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
972 * TODO try to introduce event instead of directly access query spans here. This could be used in future extensions.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
973 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
974 popoto.graph.link.mouseOverLink = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
975 d3.select(this).select("path").classed("ppt-link-hover", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
976 d3.select(this).select("text").classed("ppt-link-hover", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
977
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
978 if (popoto.queryviewer.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
979 var hoveredLink = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
980
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
981 popoto.queryviewer.queryConstraintSpanElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
982 return d.ref === hoveredLink;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
983 }).classed("hover", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
984 popoto.queryviewer.querySpanElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
985 return d.ref === hoveredLink;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
986 }).classed("hover", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
987 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
988 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
989
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
990 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
991 * Function called when mouse goes out of the link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
992 * This function is used to reinitialize the CSS class of the link and query viewer element.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
993 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
994 popoto.graph.link.mouseOutLink = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
995 d3.select(this).select("path").classed("ppt-link-hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
996 d3.select(this).select("text").classed("ppt-link-hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
997
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
998 if (popoto.queryviewer.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
999 var hoveredLink = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1000
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1001 popoto.queryviewer.queryConstraintSpanElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1002 return d.ref === hoveredLink;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1003 }).classed("hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1004 popoto.queryviewer.querySpanElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1005 return d.ref === hoveredLink;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1006 }).classed("hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1007 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1008 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1009
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1010 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1011 // NODES -----------------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1012
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1013 popoto.graph.node = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1014
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1015 // ID of the g element in SVG graph containing all the link elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1016 popoto.graph.node.gID = "popoto-gnodes";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1017
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1018 // Node ellipse size used by default for text nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1019 popoto.graph.node.ELLIPSE_RX = 50;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1020 popoto.graph.node.ELLIPSE_RY = 25;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1021 popoto.graph.node.TEXT_Y = 8;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1022 popoto.graph.node.BACK_CIRCLE_R = 70;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1023 // Define the max number of character displayed in ellipses.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1024 popoto.graph.node.NODE_MAX_CHARS = 11;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1025
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1026 // Number of nodes displayed per page during value selection.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1027 popoto.graph.node.PAGE_SIZE = 10;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1028
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1029 // Count box default size
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1030 popoto.graph.node.CountBox = {x: 16, y: 33, w: 52, h: 19};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1031
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1032 // Store choose node state to avoid multiple node expand at the same time
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1033 popoto.graph.node.chooseWaiting = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1034
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1035 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1036 * Defines the list of possible nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1037 * ROOT: Node used as graph root. It is the target of the query. Only one node of this type should be available in graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1038 * CHOOSE: Nodes defining a generic node label. From these node is is possible to select a value or explore relations.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1039 * VALUE: Unique node containing a value constraint. Usually replace CHOOSE nodes once a value as been selected.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1040 * GROUP: Empty node used to group relations. No value can be selected but relations can be explored. These nodes doesn't have count.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1041 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1042 popoto.graph.node.NodeTypes = Object.freeze({ROOT: 0, CHOOSE: 1, VALUE: 2, GROUP: 3});
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1043
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1044 // Variable used to generate unique id for each new nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1045 popoto.graph.node.idgen = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1046
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1047 // Used to generate unique internal labels used for example as identifier in Cypher query.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1048 popoto.graph.node.internalLabels = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1049
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1050 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1051 * Create a normalized identifier from a node label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1052 * Multiple calls with the same node label will generate different unique identifier.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1053 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1054 * @param nodeLabel
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1055 * @returns {string}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1056 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1057 popoto.graph.node.generateInternalLabel = function (nodeLabel) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1058 var label = nodeLabel.toLowerCase().replace(/ /g, '');
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1059
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1060 if (label in popoto.graph.node.internalLabels) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1061 popoto.graph.node.internalLabels[label] = popoto.graph.node.internalLabels[label] + 1;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1062 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1063 popoto.graph.node.internalLabels[label] = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1064 return label;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1065 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1066
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1067 return label + popoto.graph.node.internalLabels[label];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1068 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1069
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1070 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1071 * Update Nodes SVG elements using D3.js update mechanisms.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1072 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1073 popoto.graph.node.updateNodes = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1074 if (!popoto.graph.node.svgNodeElements) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1075 popoto.graph.node.svgNodeElements = popoto.graph.svg.select("#" + popoto.graph.node.gID).selectAll("g");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1076 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1077 popoto.graph.node.updateData();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1078 popoto.graph.node.removeElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1079 popoto.graph.node.addNewElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1080 popoto.graph.node.updateElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1081 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1082
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1083 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1084 * Update node data with changes done in popoto.graph.force.nodes() model.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1085 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1086 popoto.graph.node.updateData = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1087 popoto.graph.node.svgNodeElements = popoto.graph.node.svgNodeElements.data(popoto.graph.force.nodes(), function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1088 return d.id;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1089 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1090
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1091 if (popoto.graph.hasGraphChanged) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1092 popoto.graph.node.updateCount();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1093 popoto.graph.hasGraphChanged = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1094 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1095 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1096
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1097 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1098 * Update nodes count by executing a query for every nodes with the new graph structure.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1099 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1100 popoto.graph.node.updateCount = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1101
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1102 var statements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1103
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1104 var counterNodes = popoto.graph.force.nodes()
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1105 .filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1106 return d.type !== popoto.graph.node.NodeTypes.VALUE && d.type !== popoto.graph.node.NodeTypes.GROUP;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1107 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1108
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1109 counterNodes.forEach(function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1110 var query = popoto.query.generateNodeCountCypherQuery(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1111 statements.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1112 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1113 "statement": query
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1114 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1115 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1116 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1117
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1118 popoto.logger.info("Count nodes ==> ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1119 popoto.rest.post(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1120 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1121 "statements": statements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1122 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1123 .done(function (returnedData) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1124
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1125 if (returnedData.errors && returnedData.errors.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1126 popoto.logger.error("Cypher query error:" + JSON.stringify(returnedData.errors));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1127 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1128
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1129 if (returnedData.results && returnedData.results.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1130 for (var i = 0; i < counterNodes.length; i++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1131 counterNodes[i].count = returnedData.results[i].data[0].row[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1132 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1133 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1134 counterNodes.forEach(function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1135 node.count = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1136 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1137 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1138 popoto.graph.node.updateElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1139 popoto.graph.link.updateElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1140 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1141 .fail(function (xhr, textStatus, errorThrown) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1142 popoto.logger.error(textStatus + ": error while accessing Neo4j server on URL:\"" + popoto.rest.CYPHER_URL + "\" defined in \"popoto.rest.CYPHER_URL\" property: " + errorThrown);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1143 counterNodes.forEach(function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1144 node.count = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1145 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1146 popoto.graph.node.updateElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1147 popoto.graph.link.updateElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1148 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1149 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1150
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1151 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1152 * Remove old elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1153 * Should be called after updateData.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1154 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1155 popoto.graph.node.removeElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1156 var toRemove = popoto.graph.node.svgNodeElements.exit();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1157
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1158 // Nodes without parent are simply removed.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1159 toRemove.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1160 return !d.parent;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1161 }).remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1162
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1163 // Nodes with a parent are removed with an animation (nodes are collapsed to their parents before being removed)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1164 toRemove.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1165 return d.parent;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1166 }).transition().duration(300).attr("transform", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1167 return "translate(" + d.parent.x + "," + d.parent.y + ")";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1168 }).remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1169 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1170
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1171 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1172 * Add all new elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1173 * Only the skeleton of new nodes are added custom data will be added during the element update phase.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1174 * Should be called after updateData and before updateElements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1175 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1176 popoto.graph.node.addNewElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1177 var gNewNodeElements = popoto.graph.node.svgNodeElements.enter()
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1178 .append("g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1179 .on("click", popoto.graph.node.nodeClick)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1180 .on("mouseover", popoto.graph.node.mouseOverNode)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1181 .on("mouseout", popoto.graph.node.mouseOutNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1182
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1183 // Add right click on all nodes except value
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1184 gNewNodeElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1185 return d.type !== popoto.graph.node.NodeTypes.VALUE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1186 }).on("contextmenu", popoto.graph.node.clearSelection);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1187
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1188 // Disable right click context menu on value nodes
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1189 gNewNodeElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1190 return d.type === popoto.graph.node.NodeTypes.VALUE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1191 }).on("contextmenu", function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1192 // Disable context menu on
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1193 d3.event.preventDefault();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1194 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1195
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1196 // Most browser will generate a tooltip if a title is specified for the SVG element
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1197 // TODO Introduce an SVG tooltip instead?
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1198 gNewNodeElements.append("title").attr("class", "ppt-svg-title");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1199
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1200 // Nodes are composed of 3 layouts and skeleton are created here.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1201 popoto.graph.node.addBackgroundElements(gNewNodeElements);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1202 popoto.graph.node.addMiddlegroundElements(gNewNodeElements);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1203 popoto.graph.node.addForegroundElements(gNewNodeElements);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1204 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1205
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1206 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1207 * Create the background for a new node element.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1208 * The background of a node is defined by a circle not visible by default (fill-opacity set to 0) but can be used to highlight a node with animation on this attribute.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1209 * This circle also define the node zone that can receive events like mouse clicks.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1210 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1211 * @param gNewNodeElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1212 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1213 popoto.graph.node.addBackgroundElements = function (gNewNodeElements) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1214 var background = gNewNodeElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1215 .append("g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1216 .attr("class", "ppt-g-node-background");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1217
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1218 background.append("circle")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1219 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1220 var cssClass = "ppt-node-background-circle";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1221 if (d.value !== undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1222 cssClass = cssClass + " selected-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1223 } else if (d.type === popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1224 cssClass = cssClass + " root";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1225 } else if (d.type === popoto.graph.node.NodeTypes.CHOOSE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1226 cssClass = cssClass + " choose";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1227 } else if (d.type === popoto.graph.node.NodeTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1228 cssClass = cssClass + " value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1229 } else if (d.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1230 cssClass = cssClass + " group";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1231 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1232
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1233 return cssClass;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1234 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1235 .style("fill-opacity", 0)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1236 .attr("r", popoto.graph.node.BACK_CIRCLE_R);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1237 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1238
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1239 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1240 * Create the node main elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1241 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1242 * @param gNewNodeElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1243 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1244 popoto.graph.node.addMiddlegroundElements = function (gNewNodeElements) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1245 var middle = gNewNodeElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1246 .append("g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1247 .attr("class", "ppt-g-node-middleground");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1248 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1249
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1250 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1251 * Create the node foreground elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1252 * It contains node additional elements, count or tools like navigation arrows.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1253 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1254 * @param gNewNodeElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1255 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1256 popoto.graph.node.addForegroundElements = function (gNewNodeElements) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1257 var foreground = gNewNodeElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1258 .append("g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1259 .attr("class", "ppt-g-node-foreground");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1260
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1261 // plus sign
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1262 var gRelationship = foreground.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1263 return d.type !== popoto.graph.node.NodeTypes.VALUE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1264 }).append("g").attr("class", "ppt-rel-plus-icon");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1265
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1266 gRelationship.append("title")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1267 .text("Add relationship");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1268
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1269 gRelationship
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1270 .append("circle")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1271 .attr("class", "ppt-rel-plus-background")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1272 .attr("cx", "32")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1273 .attr("cy", "-43")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1274 .attr("r", "16");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1275
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1276 gRelationship
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1277 .append("path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1278 .attr("class", "ppt-rel-plus-path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1279 .attr("d", "M 40,-45 35,-45 35,-50 30,-50 30,-45 25,-45 25,-40 30,-40 30,-35 35,-35 35,-40 40,-40 z");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1280
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1281 gRelationship
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1282 .on("mouseover", function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1283 d3.select(this).select(".ppt-rel-plus-background").transition().style("fill-opacity", 0.5);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1284 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1285 .on("mouseout", function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1286 d3.select(this).select(".ppt-rel-plus-background").transition().style("fill-opacity", 0);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1287 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1288 .on("click", function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1289 d3.event.stopPropagation(); // To avoid click event on svg element in background
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1290 popoto.graph.node.expandRelationship.call(this);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1291 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1292
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1293 // Minus sign
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1294 var gMinusRelationship = foreground.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1295 return d.type !== popoto.graph.node.NodeTypes.VALUE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1296 }).append("g").attr("class", "ppt-rel-minus-icon");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1297
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1298 gMinusRelationship.append("title")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1299 .text("Remove relationship");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1300
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1301 gMinusRelationship
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1302 .append("circle")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1303 .attr("class", "ppt-rel-minus-background")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1304 .attr("cx", "32")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1305 .attr("cy", "-43")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1306 .attr("r", "16");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1307
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1308 gMinusRelationship
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1309 .append("path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1310 .attr("class", "ppt-rel-minus-path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1311 .attr("d", "M 40,-45 25,-45 25,-40 40,-40 z");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1312
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1313 gMinusRelationship
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1314 .on("mouseover", function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1315 d3.select(this).select(".ppt-rel-minus-background").transition().style("fill-opacity", 0.5);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1316 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1317 .on("mouseout", function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1318 d3.select(this).select(".ppt-rel-minus-background").transition().style("fill-opacity", 0);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1319 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1320 .on("click", function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1321 d3.event.stopPropagation(); // To avoid click event on svg element in background
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1322 popoto.graph.node.collapseRelationship.call(this);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1323 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1324
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1325 // Arrows icons added only for root and choose nodes
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1326 var gArrow = foreground.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1327 return d.type === popoto.graph.node.NodeTypes.ROOT || d.type === popoto.graph.node.NodeTypes.CHOOSE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1328 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1329 .append("g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1330 .attr("class", "ppt-node-foreground-g-arrows");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1331
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1332 var glArrow = gArrow.append("g");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1333 //glArrow.append("polygon")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1334 //.attr("points", "-53,-23 -33,-33 -33,-13");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1335 glArrow.append("circle")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1336 .attr("class", "ppt-larrow")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1337 .attr("cx", "-43")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1338 .attr("cy", "-23")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1339 .attr("r", "17");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1340
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1341 glArrow.append("path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1342 .attr("class", "ppt-arrow")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1343 .attr("d", "m -44.905361,-23 6.742,-6.742 c 0.81,-0.809 0.81,-2.135 0,-2.944 l -0.737,-0.737 c -0.81,-0.811 -2.135,-0.811 -2.945,0 l -8.835,8.835 c -0.435,0.434 -0.628,1.017 -0.597,1.589 -0.031,0.571 0.162,1.154 0.597,1.588 l 8.835,8.834 c 0.81,0.811 2.135,0.811 2.945,0 l 0.737,-0.737 c 0.81,-0.808 0.81,-2.134 0,-2.943 l -6.742,-6.743 z");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1344
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1345 glArrow.on("click", function (clickedNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1346 d3.event.stopPropagation(); // To avoid click event on svg element in background
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1347
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1348 // On left arrow click page number is decreased and node expanded to display the new page
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1349 if (clickedNode.page > 1) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1350 clickedNode.page--;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1351 popoto.graph.node.collapseNode(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1352 popoto.graph.node.expandNode(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1353 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1354 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1355
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1356 var grArrow = gArrow.append("g");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1357 //grArrow.append("polygon")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1358 //.attr("points", "53,-23 33,-33 33,-13");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1359
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1360 grArrow.append("circle")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1361 .attr("class", "ppt-rarrow")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1362 .attr("cx", "43")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1363 .attr("cy", "-23")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1364 .attr("r", "17");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1365
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1366 grArrow.append("path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1367 .attr("class", "ppt-arrow")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1368 .attr("d", "m 51.027875,-24.5875 -8.835,-8.835 c -0.811,-0.811 -2.137,-0.811 -2.945,0 l -0.738,0.737 c -0.81,0.81 -0.81,2.136 0,2.944 l 6.742,6.742 -6.742,6.742 c -0.81,0.81 -0.81,2.136 0,2.943 l 0.737,0.737 c 0.81,0.811 2.136,0.811 2.945,0 l 8.835,-8.836 c 0.435,-0.434 0.628,-1.017 0.597,-1.588 0.032,-0.569 -0.161,-1.152 -0.596,-1.586 z");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1369
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1370 grArrow.on("click", function (clickedNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1371 d3.event.stopPropagation(); // To avoid click event on svg element in background
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1372
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1373 if (clickedNode.page * popoto.graph.node.PAGE_SIZE < clickedNode.count) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1374 clickedNode.page++;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1375 popoto.graph.node.collapseNode(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1376 popoto.graph.node.expandNode(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1377 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1378 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1379
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1380 // Count box
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1381 var countForeground = foreground.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1382 return d.type !== popoto.graph.node.NodeTypes.GROUP;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1383 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1384
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1385 countForeground
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1386 .append("rect")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1387 .attr("x", popoto.graph.node.CountBox.x)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1388 .attr("y", popoto.graph.node.CountBox.y)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1389 .attr("width", popoto.graph.node.CountBox.w)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1390 .attr("height", popoto.graph.node.CountBox.h)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1391 .attr("class", "ppt-count-box");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1392
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1393 countForeground
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1394 .append("text")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1395 .attr("x", 42)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1396 .attr("y", 48)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1397 .attr("text-anchor", "middle")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1398 .attr("class", "ppt-count-text");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1399 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1400
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1401 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1402 * Updates all elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1403 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1404 popoto.graph.node.updateElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1405 popoto.graph.node.svgNodeElements.attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1406 return "popoto-gnode_" + d.id;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1407 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1408
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1409 popoto.graph.node.svgNodeElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1410 .selectAll(".ppt-svg-title")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1411 .text(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1412 return popoto.provider.getTextValue(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1413 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1414
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1415 popoto.graph.node.svgNodeElements.filter(function (n) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1416 return n.type !== popoto.graph.node.NodeTypes.ROOT
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1417 }).call(popoto.graph.force.drag);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1418
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1419 popoto.graph.node.updateBackgroundElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1420 popoto.graph.node.updateMiddlegroundElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1421 popoto.graph.node.updateForegroundElements();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1422 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1423
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1424 popoto.graph.node.updateBackgroundElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1425 popoto.graph.node.svgNodeElements.selectAll(".ppt-g-node-background")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1426 .selectAll(".ppt-node-background-circle")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1427 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1428 var cssClass = "ppt-node-background-circle";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1429
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1430 if (d.type === popoto.graph.node.NodeTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1431 cssClass = cssClass + " value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1432 } else if (d.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1433 cssClass = cssClass + " group";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1434 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1435 if (d.value !== undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1436 if (d.type === popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1437 cssClass = cssClass + " selected-root-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1438 } else if (d.type === popoto.graph.node.NodeTypes.CHOOSE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1439 cssClass = cssClass + " selected-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1440 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1441 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1442 if (d.count == 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1443 cssClass = cssClass + " disabled";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1444 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1445 if (d.type === popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1446 cssClass = cssClass + " root";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1447 } else if (d.type === popoto.graph.node.NodeTypes.CHOOSE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1448 cssClass = cssClass + " choose";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1449 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1450 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1451 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1452 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1453
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1454 return cssClass;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1455 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1456 .attr("r", popoto.graph.node.BACK_CIRCLE_R);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1457 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1458
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1459 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1460 * Update the middle layer of nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1461 * TODO refactor node generation to allow future extensions (for example add plugin with new node types...)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1462 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1463 popoto.graph.node.updateMiddlegroundElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1464
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1465 var middleG = popoto.graph.node.svgNodeElements.selectAll(".ppt-g-node-middleground");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1466
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1467 // Clear all content in case node type has changed
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1468 middleG.selectAll("*").remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1469
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1470 //-------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1471 // Update IMAGE nodes
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1472 var imageMiddle = middleG.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1473 return popoto.provider.getNodeDisplayType(d) === popoto.provider.NodeDisplayTypes.IMAGE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1474 }).append("image").attr("class", "ppt-node-image");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1475
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1476 imageMiddle
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1477 .attr("width", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1478 return popoto.provider.getImageWidth(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1479 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1480 .attr("height", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1481 return popoto.provider.getImageHeight(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1482 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1483 // Center the image on node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1484 .attr("transform", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1485 return "translate(" + (-popoto.provider.getImageWidth(d) / 2) + "," + (-popoto.provider.getImageHeight(d) / 2) + ")";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1486 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1487 .attr("xlink:href", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1488 return popoto.provider.getImagePath(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1489 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1490
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1491 //-------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1492 // Update TEXT nodes
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1493 var ellipseMiddle = middleG.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1494 return popoto.provider.getNodeDisplayType(d) === popoto.provider.NodeDisplayTypes.TEXT;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1495 }).append("ellipse").attr("rx", popoto.graph.node.ELLIPSE_RX).attr("ry", popoto.graph.node.ELLIPSE_RY);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1496
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1497 // Set class according to node type
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1498 ellipseMiddle
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1499 .attr("rx", popoto.graph.node.ELLIPSE_RX)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1500 .attr("ry", popoto.graph.node.ELLIPSE_RY)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1501 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1502 if (d.type === popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1503 if (d.value) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1504 return "ppt-node-ellipse selected-root-value"
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1505 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1506 if (d.count == 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1507 return "ppt-node-ellipse root disabled";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1508 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1509 return "ppt-node-ellipse root";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1510 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1511 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1512 } else if (d.type === popoto.graph.node.NodeTypes.CHOOSE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1513 if (d.value) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1514 return "ppt-node-ellipse selected-value"
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1515 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1516 if (d.count == 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1517 return "ppt-node-ellipse choose disabled";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1518 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1519 return "ppt-node-ellipse choose";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1520 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1521 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1522 } else if (d.type === popoto.graph.node.NodeTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1523 return "ppt-node-ellipse value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1524 } else if (d.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1525 return "ppt-node-ellipse group";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1526 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1527 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1528
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1529 //-------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1530 // Update SVG nodes
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1531 var svgMiddle = middleG.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1532 return popoto.provider.getNodeDisplayType(d) === popoto.provider.NodeDisplayTypes.SVG;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1533 }).append("g")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1534 // Add D3.js nested data with all paths required to render the svg element.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1535 .selectAll("path").data(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1536 return popoto.provider.getSVGPaths(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1537 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1538
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1539 // Update nested data elements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1540 svgMiddle.exit().remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1541
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1542 svgMiddle.enter().append("path");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1543
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1544 middleG
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1545 .selectAll("path")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1546 .attr("d", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1547 return d.d;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1548 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1549 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1550 return d["class"];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1551 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1552
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1553 // Update text
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1554 var textMiddle = middleG.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1555 return popoto.provider.isTextDisplayed(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1556 }).append('text')
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1557 .attr('x', 0)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1558 .attr('y', popoto.graph.node.TEXT_Y)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1559 .attr('text-anchor', 'middle');
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1560 textMiddle
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1561 .attr('y', popoto.graph.node.TEXT_Y)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1562 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1563 switch (d.type) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1564 case popoto.graph.node.NodeTypes.CHOOSE:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1565 if (d.value === undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1566 if (d.count == 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1567 return "ppt-node-text-choose disabled";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1568 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1569 return "ppt-node-text-choose";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1570 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1571 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1572 return "ppt-node-text-choose selected-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1573 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1574 case popoto.graph.node.NodeTypes.GROUP:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1575 return "ppt-node-text-group";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1576 case popoto.graph.node.NodeTypes.ROOT:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1577 if (d.value === undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1578 if (d.count == 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1579 return "ppt-node-text-root disabled";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1580 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1581 return "ppt-node-text-root";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1582 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1583 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1584 return "ppt-node-text-root selected-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1585 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1586 case popoto.graph.node.NodeTypes.VALUE:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1587 return "ppt-node-text-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1588 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1589 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1590 .text(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1591 if (popoto.provider.isTextDisplayed(d)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1592 return popoto.provider.getTextValue(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1593 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1594 return "";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1595 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1596 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1597 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1598
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1599 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1600 * Updates the foreground elements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1601 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1602 popoto.graph.node.updateForegroundElements = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1603
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1604 // Updates browse arrows status
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1605 var gArrows = popoto.graph.node.svgNodeElements.selectAll(".ppt-g-node-foreground")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1606 .selectAll(".ppt-node-foreground-g-arrows");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1607 gArrows.classed("active", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1608 return d.valueExpanded && d.data && d.data.length > popoto.graph.node.PAGE_SIZE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1609 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1610
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1611 gArrows.selectAll(".ppt-larrow").classed("enabled", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1612 return d.page > 1;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1613 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1614
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1615 gArrows.selectAll(".ppt-rarrow").classed("enabled", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1616 if (d.data) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1617 var count = d.data.length;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1618 return d.page * popoto.graph.node.PAGE_SIZE < count;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1619 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1620 return false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1621 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1622 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1623
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1624 // Update count box class depending on node type
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1625 var gForegrounds = popoto.graph.node.svgNodeElements.selectAll(".ppt-g-node-foreground");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1626
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1627 gForegrounds.selectAll(".ppt-count-box").filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1628 return d.type !== popoto.graph.node.NodeTypes.CHOOSE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1629 }).classed("root", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1630
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1631 gForegrounds.selectAll(".ppt-count-box").filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1632 return d.type === popoto.graph.node.NodeTypes.CHOOSE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1633 }).classed("value", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1634
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1635 gForegrounds.selectAll(".ppt-count-box").classed("disabled", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1636 return d.count == 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1637 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1638
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1639 gForegrounds.selectAll(".ppt-count-text")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1640 .text(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1641 if (d.count != null) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1642 return d.count;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1643 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1644 return "...";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1645 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1646 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1647 .classed("disabled", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1648 return d.count == 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1649 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1650
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1651 // Hide/Show plus icon (set disabled CSS class) if node already has been expanded.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1652 gForegrounds.selectAll(".ppt-rel-plus-icon")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1653 .classed("disabled", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1654 return d.linkExpanded || d.count == 0 || d.linkCount == 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1655 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1656
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1657 gForegrounds.selectAll(".ppt-rel-minus-icon")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1658 .classed("disabled", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1659 return (!d.linkExpanded) || d.count == 0 || d.linkCount == 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1660 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1661
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1662 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1663
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1664 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1665 * Handle the mouse over event on nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1666 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1667 popoto.graph.node.mouseOverNode = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1668 d3.event.preventDefault();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1669
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1670 // TODO don't work on IE (nodes unstable) find another way to move node in foreground on mouse over?
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1671 // d3.select(this).moveToFront();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1672
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1673 d3.select(this).select(".ppt-g-node-background").selectAll("circle").transition().style("fill-opacity", 0.5);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1674
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1675 if (popoto.queryviewer.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1676 // Get the hovered node data
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1677 var hoveredNode = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1678
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1679 // Hover the node in query
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1680 popoto.queryviewer.queryConstraintSpanElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1681 return d.ref === hoveredNode;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1682 }).classed("hover", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1683 popoto.queryviewer.querySpanElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1684 return d.ref === hoveredNode;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1685 }).classed("hover", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1686 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1687 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1688
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1689 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1690 * Handle mouse out event on nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1691 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1692 popoto.graph.node.mouseOutNode = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1693 d3.event.preventDefault();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1694
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1695 d3.select(this).select(".ppt-g-node-background").selectAll("circle").transition().style("fill-opacity", 0);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1696
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1697 if (popoto.queryviewer.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1698 // Get the hovered node data
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1699 var hoveredNode = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1700
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1701 // Remove hover class on node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1702 popoto.queryviewer.queryConstraintSpanElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1703 return d.ref === hoveredNode;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1704 }).classed("hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1705 popoto.queryviewer.querySpanElements.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1706 return d.ref === hoveredNode;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1707 }).classed("hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1708 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1709 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1710
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1711 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1712 * Handle the click event on nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1713 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1714 popoto.graph.node.nodeClick = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1715 var clickedNode = d3.select(this).data()[0]; // Clicked node data
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1716 popoto.logger.debug("nodeClick (" + clickedNode.label + ")");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1717
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1718 if (clickedNode.type === popoto.graph.node.NodeTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1719 popoto.graph.node.valueNodeClick(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1720 } else if (clickedNode.type === popoto.graph.node.NodeTypes.CHOOSE || clickedNode.type === popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1721 if (clickedNode.valueExpanded) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1722 popoto.graph.node.collapseNode(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1723 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1724 popoto.graph.node.chooseNodeClick(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1725 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1726 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1727 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1728
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1729 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1730 * Remove all the value node directly linked to clicked node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1731 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1732 * @param clickedNode
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1733 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1734 popoto.graph.node.collapseNode = function (clickedNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1735 if (clickedNode.valueExpanded) { // node is collapsed only if it has been expanded first
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1736 popoto.logger.debug("collapseNode (" + clickedNode.label + ")");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1737
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1738 var linksToRemove = popoto.graph.force.links().filter(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1739 return l.source === clickedNode && l.type === popoto.graph.link.LinkTypes.VALUE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1740 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1741
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1742 // Remove children nodes from model
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1743 linksToRemove.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1744 popoto.graph.force.nodes().splice(popoto.graph.force.nodes().indexOf(l.target), 1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1745 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1746
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1747 // Remove links from model
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1748 for (var i = popoto.graph.force.links().length - 1; i >= 0; i--) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1749 if (linksToRemove.indexOf(popoto.graph.force.links()[i]) >= 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1750 popoto.graph.force.links().splice(i, 1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1751 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1752 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1753
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1754 // Node has been fixed when expanded so we unfix it back here.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1755 if (clickedNode.type !== popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1756 clickedNode.fixed = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1757 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1758
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1759 // Parent node too if not root
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1760 if (clickedNode.parent && clickedNode.parent.type !== popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1761 clickedNode.parent.fixed = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1762 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1763
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1764 clickedNode.valueExpanded = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1765 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1766
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1767 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1768 popoto.logger.debug("collapseNode called on an unexpanded node");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1769 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1770 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1771
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1772 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1773 * Function called on a value node click.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1774 * In this case the value is added in the parent node and all the value nodes are collapsed.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1775 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1776 * @param clickedNode
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1777 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1778 popoto.graph.node.valueNodeClick = function (clickedNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1779 popoto.logger.debug("valueNodeClick (" + clickedNode.label + ")");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1780 clickedNode.parent.value = clickedNode;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1781 popoto.result.hasChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1782 popoto.graph.hasGraphChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1783
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1784 popoto.graph.node.collapseNode(clickedNode.parent);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1785 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1786
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1787 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1788 * Function called on choose node click.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1789 * In this case a query is executed to get all the possible value
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1790 * @param clickedNode
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1791 * TODO optimize with cached data?
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1792 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1793 popoto.graph.node.chooseNodeClick = function (clickedNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1794 popoto.logger.debug("chooseNodeClick (" + clickedNode.label + ") with waiting state set to " + popoto.graph.node.chooseWaiting);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1795 if (!popoto.graph.node.chooseWaiting && !clickedNode.immutable) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1796
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1797 // Collapse all expanded nodes first
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1798 popoto.graph.force.nodes().forEach(function (n) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1799 if ((n.type == popoto.graph.node.NodeTypes.ROOT || n.type == popoto.graph.node.NodeTypes.CHOOSE) && n.valueExpanded) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1800 popoto.graph.node.collapseNode(n);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1801 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1802 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1803
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1804 // Set waiting state to true to avoid multiple call on slow query execution
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1805 popoto.graph.node.chooseWaiting = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1806
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1807 popoto.logger.info("Values (" + clickedNode.label + ") ==> ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1808 popoto.rest.post(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1809 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1810 "statements": [
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1811 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1812 "statement": popoto.query.generateValueQuery(clickedNode)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1813 }]
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1814 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1815 .done(function (data) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1816 clickedNode.id = (++popoto.graph.node.idgen);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1817 clickedNode.data = popoto.graph.node.parseResultData(data);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1818 clickedNode.page = 1;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1819 popoto.graph.node.expandNode(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1820 popoto.graph.node.chooseWaiting = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1821 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1822 .fail(function (xhr, textStatus, errorThrown) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1823 popoto.graph.node.chooseWaiting = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1824 popoto.logger.error(textStatus + ": error while accessing Neo4j server on URL:\"" + popoto.rest.CYPHER_URL + "\" defined in \"popoto.rest.CYPHER_URL\" property: " + errorThrown);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1825 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1826 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1827 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1828
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1829 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1830 * Parse query execution result and generate an array of object.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1831 * These objects contains of a list of properties made of result attributes with their value.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1832 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1833 * @param data query execution raw data
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1834 * @returns {Array} array of structured object with result attributes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1835 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1836 popoto.graph.node.parseResultData = function (data) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1837 var results = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1838
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1839 for (var x = 0; x < data.results[0].data.length; x++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1840 var obj = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1841
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1842 for (var i = 0; i < data.results[0].columns.length; i++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1843 obj[data.results[0].columns[i]] = data.results[0].data[x].row[i];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1844 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1845
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1846 results.push(obj);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1847 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1848
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1849 return results;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1850 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1851
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1852 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1853 * Compute the angle in radian between the node and its parent.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1854 * TODO: clean or add comments to explain the code...
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1855 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1856 * @param node node to compute angle.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1857 * @returns {number} angle in radian.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1858 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1859 popoto.graph.computeParentAngle = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1860 var angleRadian = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1861 var r = 100;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1862 if (node.parent) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1863 var xp = node.parent.x;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1864 var yp = node.parent.y;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1865 var x0 = node.x;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1866 var y0 = node.y;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1867 var dist = Math.sqrt(Math.pow(xp - x0, 2) + Math.pow(yp - y0, 2));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1868
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1869 var k = r / (dist - r);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1870 var xc = (x0 + (k * xp)) / (1 + k);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1871
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1872 var val = (xc - x0) / r;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1873 if (val < -1) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1874 val = -1;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1875 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1876 if (val > 1) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1877 val = 1;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1878 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1879
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1880 angleRadian = Math.acos(val);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1881
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1882 if (yp > y0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1883 angleRadian = 2 * Math.PI - angleRadian;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1884 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1885 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1886 return angleRadian;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1887 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1888
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1889 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1890 * Function called to expand a node containing values.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1891 * This function will create the value nodes with the clicked node internal data.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1892 * Only nodes corresponding to the current page index will be generated.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1893 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1894 * @param clickedNode
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1895 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1896 popoto.graph.node.expandNode = function (clickedNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1897
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1898 // Get subset of node corresponding to the current node page and page size
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1899 var lIndex = clickedNode.page * popoto.graph.node.PAGE_SIZE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1900 var sIndex = lIndex - popoto.graph.node.PAGE_SIZE;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1901
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1902 var dataToAdd = clickedNode.data.slice(sIndex, lIndex);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1903 var parentAngle = popoto.graph.computeParentAngle(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1904
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1905 // Then each node are created and dispatched around the clicked node using computed coordinates.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1906 var i = 1;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1907 dataToAdd.forEach(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1908 var angleDeg;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1909 if (clickedNode.parent) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1910 angleDeg = (((360 / (dataToAdd.length + 1)) * i));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1911 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1912 angleDeg = (((360 / (dataToAdd.length)) * i));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1913 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1914
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1915 var nx = clickedNode.x + (100 * Math.cos((angleDeg * (Math.PI / 180)) - parentAngle)),
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1916 ny = clickedNode.y + (100 * Math.sin((angleDeg * (Math.PI / 180)) - parentAngle));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1917
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1918 var node = {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1919 "id": (++popoto.graph.node.idgen),
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1920 "parent": clickedNode,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1921 "attributes": d,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1922 "type": popoto.graph.node.NodeTypes.VALUE,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1923 "label": clickedNode.label,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1924 "count": d.count,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1925 "x": nx,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1926 "y": ny,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1927 "internalID": d[popoto.query.NEO4J_INTERNAL_ID.queryInternalName]
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1928 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1929
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1930 popoto.graph.force.nodes().push(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1931
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1932 popoto.graph.force.links().push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1933 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1934 id: "l" + (++popoto.graph.node.idgen),
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1935 source: clickedNode,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1936 target: node,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1937 type: popoto.graph.link.LinkTypes.VALUE
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1938 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1939 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1940
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1941 i++;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1942 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1943
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1944 // Pin clicked node and its parent to avoid the graph to move for selection, only new value nodes will blossom around the clicked node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1945 clickedNode.fixed = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1946 if (clickedNode.parent && clickedNode.parent.type !== popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1947 clickedNode.parent.fixed = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1948 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1949 // Change node state
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1950 clickedNode.valueExpanded = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1951 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1952 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1953
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1954 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1955 * Function called on a right click on a node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1956 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1957 * In this case all expanded nodes in the graph will first be closed then if no relation have been added yet a Cypher query is executed to get all the related nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1958 * A first coordinate pre-computation is done to dispatch the new node correctly around the parent node and the nodes are added with a link in the model.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1959 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1960 * If no relation are found or relation were already added the right click event is used to remove the node current selection.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1961 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1962 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1963 popoto.graph.node.expandRelationship = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1964 // Prevent default right click event opening menu.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1965 d3.event.preventDefault();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1966
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1967 // Notify listeners
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1968 popoto.graph.nodeExpandRelationsipListeners.forEach(function (listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1969 listener(this);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1970 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1971
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1972 // Get clicked node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1973 var clickedNode = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1974
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1975 if (!clickedNode.linkExpanded && !popoto.graph.node.linkWaiting && !clickedNode.valueExpanded) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1976 popoto.graph.node.linkWaiting = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1977
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1978 popoto.logger.info("Relations (" + clickedNode.label + ") ==> ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1979 popoto.rest.post(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1980 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1981 "statements": [
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1982 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1983 "statement": popoto.query.generateLinkQuery(clickedNode)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1984 }]
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1985 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1986 .done(function (data) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1987 var parsedData = popoto.graph.node.parseResultData(data);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1988
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1989 parsedData = parsedData.filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1990 return popoto.query.filterRelation(d);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1991 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1992
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1993 if (parsedData.length <= 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1994 // Set linkExpanded to true to avoid a new query call on next right click
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1995 clickedNode.linkExpanded = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1996 clickedNode.linkCount = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1997 popoto.graph.hasGraphChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1998 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
1999 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2000 var parentAngle = popoto.graph.computeParentAngle(clickedNode);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2001
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2002 var i = 1;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2003 parsedData.forEach(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2004 var angleDeg;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2005 if (parentAngle) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2006 angleDeg = (((360 / (parsedData.length + 1)) * i));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2007 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2008 angleDeg = (((360 / (parsedData.length)) * i));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2009 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2010
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2011 var nx = clickedNode.x + (100 * Math.cos((angleDeg * (Math.PI / 180)) - parentAngle)),
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2012 ny = clickedNode.y + (100 * Math.sin((angleDeg * (Math.PI / 180)) - parentAngle));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2013
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2014 var isGroupNode = popoto.provider.getIsGroup(d);
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
2015 // filter multiple labels
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
2016 var nodeLabel = popoto.provider.getLabelFilter(d.label);
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
2017
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2018 var node = {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2019 "id": "" + (++popoto.graph.node.idgen),
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2020 "parent": clickedNode,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2021 "type": (isGroupNode) ? popoto.graph.node.NodeTypes.GROUP : popoto.graph.node.NodeTypes.CHOOSE,
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
2022 "label": nodeLabel,
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2023 "fixed": false,
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
2024 "internalLabel": popoto.graph.node.generateInternalLabel(nodeLabel),
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2025 "x": nx,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2026 "y": ny
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2027 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2028
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2029 popoto.graph.force.nodes().push(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2030
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2031 popoto.graph.force.links().push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2032 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2033 id: "l" + (++popoto.graph.node.idgen),
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2034 source: clickedNode,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2035 target: node,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2036 type: popoto.graph.link.LinkTypes.RELATION,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2037 label: d.relationship
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2038 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2039 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2040
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2041 i++;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2042 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2043
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2044 popoto.graph.hasGraphChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2045 clickedNode.linkExpanded = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2046 clickedNode.linkCount = parsedData.length;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2047 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2048 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2049 popoto.graph.node.linkWaiting = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2050 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2051 .fail(function (xhr, textStatus, errorThrown) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2052 popoto.logger.error(textStatus + ": error while accessing Neo4j server on URL:\"" + popoto.rest.CYPHER_URL + "\" defined in \"popoto.rest.CYPHER_URL\" property: " + errorThrown);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2053 popoto.graph.node.linkWaiting = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2054 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2055 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2056 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2057
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2058 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2059 * Remove all relationships from context node (including children).
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2060 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2061 popoto.graph.node.collapseRelationship = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2062 d3.event.preventDefault();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2063
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2064 // Get clicked node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2065 var clickedNode = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2066
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2067 if (clickedNode.linkExpanded && clickedNode.linkCount > 0 && !popoto.graph.node.linkWaiting && !clickedNode.valueExpanded) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2068
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2069 // Collapse all expanded choose nodes first to avoid having invalid displayed value node if collapsed relation contains a value.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2070 popoto.graph.force.nodes().forEach(function (n) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2071 if ((n.type === popoto.graph.node.NodeTypes.CHOOSE || n.type === popoto.graph.node.NodeTypes.ROOT) && n.valueExpanded) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2072 popoto.graph.node.collapseNode(n);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2073 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2074 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2075
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2076 var linksToRemove = popoto.graph.force.links().filter(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2077 return l.source === clickedNode && l.type === popoto.graph.link.LinkTypes.RELATION;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2078 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2079
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2080 // Remove children nodes from model
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2081 linksToRemove.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2082 popoto.graph.node.removeNode(l.target);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2083 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2084
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2085 // Remove links from model
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2086 for (var i = popoto.graph.force.links().length - 1; i >= 0; i--) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2087 if (linksToRemove.indexOf(popoto.graph.force.links()[i]) >= 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2088 popoto.graph.force.links().splice(i, 1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2089 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2090 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2091
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2092 clickedNode.linkExpanded = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2093 popoto.result.hasChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2094 popoto.graph.hasGraphChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2095 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2096 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2097 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2098
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2099 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2100 * Remove a node and its relationships (recursively) from the graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2101 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2102 * @param node the node to remove.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2103 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2104 popoto.graph.node.removeNode = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2105
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2106 var linksToRemove = popoto.graph.force.links().filter(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2107 return l.source === node;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2108 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2109
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2110 // Remove children nodes from model
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2111 linksToRemove.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2112 popoto.graph.node.removeNode(l.target);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2113 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2114
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2115 // Remove links from model
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2116 for (var i = popoto.graph.force.links().length - 1; i >= 0; i--) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2117 if (linksToRemove.indexOf(popoto.graph.force.links()[i]) >= 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2118 popoto.graph.force.links().splice(i, 1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2119 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2120 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2121
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2122 popoto.graph.force.nodes().splice(popoto.graph.force.nodes().indexOf(node), 1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2123
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2124 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2125
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2126 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2127 * Function to add on node event to clear the selection.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2128 * Call to this function on a node will remove the selected value and triger a graph update.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2129 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2130 popoto.graph.node.clearSelection = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2131 // Prevent default event like right click opening menu.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2132 d3.event.preventDefault();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2133
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2134 // Get clicked node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2135 var clickedNode = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2136
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2137 // Collapse all expanded choose nodes first
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2138 popoto.graph.force.nodes().forEach(function (n) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2139 if ((n.type === popoto.graph.node.NodeTypes.CHOOSE || n.type === popoto.graph.node.NodeTypes.ROOT) && n.valueExpanded) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2140 popoto.graph.node.collapseNode(n);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2141 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2142 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2143
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2144 if (clickedNode.value != null && !clickedNode.immutable) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2145 // Remove selected value of choose node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2146 delete clickedNode.value;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2147
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2148 popoto.result.hasChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2149 popoto.graph.hasGraphChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2150 popoto.update();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2151 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2152 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2153
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2154 // QUERY VIEWER -----------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2155 popoto.queryviewer = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2156 popoto.queryviewer.containerId = "popoto-query";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2157 popoto.queryviewer.QUERY_STARTER = "I'm looking for";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2158 popoto.queryviewer.CHOOSE_LABEL = "choose";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2159
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2160 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2161 * Create the query viewer area.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2162 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2163 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2164 popoto.queryviewer.createQueryArea = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2165 var id = "#" + popoto.queryviewer.containerId;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2166
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2167 popoto.queryviewer.queryConstraintSpanElements = d3.select(id).append("p").attr("class", "ppt-query-constraint-elements").selectAll(".queryConstraintSpan");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2168 popoto.queryviewer.querySpanElements = d3.select(id).append("p").attr("class", "ppt-query-elements").selectAll(".querySpan");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2169 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2170
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2171 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2172 * Update all the elements displayed on the query viewer based on current graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2173 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2174 popoto.queryviewer.updateQuery = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2175
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2176 // Remove all query span elements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2177 popoto.queryviewer.queryConstraintSpanElements = popoto.queryviewer.queryConstraintSpanElements.data([]);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2178 popoto.queryviewer.querySpanElements = popoto.queryviewer.querySpanElements.data([]);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2179
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2180 popoto.queryviewer.queryConstraintSpanElements.exit().remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2181 popoto.queryviewer.querySpanElements.exit().remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2182
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2183 // Update data
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2184 popoto.queryviewer.queryConstraintSpanElements = popoto.queryviewer.queryConstraintSpanElements.data(popoto.queryviewer.generateConstraintData(popoto.graph.force.links(), popoto.graph.force.nodes()));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2185 popoto.queryviewer.querySpanElements = popoto.queryviewer.querySpanElements.data(popoto.queryviewer.generateData(popoto.graph.force.links(), popoto.graph.force.nodes()));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2186
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2187 // Remove old span (not needed as all have been cleaned before)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2188 // popoto.queryviewer.querySpanElements.exit().remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2189
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2190 // Add new span
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2191 popoto.queryviewer.queryConstraintSpanElements.enter().append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2192 .on("contextmenu", popoto.queryviewer.rightClickSpan)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2193 .on("click", popoto.queryviewer.clickSpan)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2194 .on("mouseover", popoto.queryviewer.mouseOverSpan)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2195 .on("mouseout", popoto.queryviewer.mouseOutSpan);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2196
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2197 popoto.queryviewer.querySpanElements.enter().append("span")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2198 .on("contextmenu", popoto.queryviewer.rightClickSpan)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2199 .on("click", popoto.queryviewer.clickSpan)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2200 .on("mouseover", popoto.queryviewer.mouseOverSpan)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2201 .on("mouseout", popoto.queryviewer.mouseOutSpan);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2202
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2203 // Update all span
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2204 popoto.queryviewer.queryConstraintSpanElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2205 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2206 return d.id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2207 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2208 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2209 if (d.isLink) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2210 return "ppt-span-link";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2211 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2212 if (d.type === popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2213 return "ppt-span-root";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2214 } else if (d.type === popoto.graph.node.NodeTypes.CHOOSE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2215 if (d.ref.value) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2216 return "ppt-span-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2217 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2218 return "ppt-span-choose";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2219 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2220 } else if (d.type === popoto.graph.node.NodeTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2221 return "ppt-span-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2222 } else if (d.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2223 return "ppt-span-group";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2224 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2225 return "ppt-span";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2226 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2227 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2228 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2229 .text(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2230 return d.term + " ";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2231 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2232
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2233 popoto.queryviewer.querySpanElements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2234 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2235 return d.id
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2236 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2237 .attr("class", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2238 if (d.isLink) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2239 return "ppt-span-link";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2240 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2241 if (d.type === popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2242 return "ppt-span-root";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2243 } else if (d.type === popoto.graph.node.NodeTypes.CHOOSE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2244 if (d.ref.value) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2245 return "ppt-span-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2246 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2247 return "ppt-span-choose";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2248 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2249 } else if (d.type === popoto.graph.node.NodeTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2250 return "ppt-span-value";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2251 } else if (d.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2252 return "ppt-span-group";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2253 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2254 return "ppt-span";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2255 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2256 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2257 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2258 .text(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2259 return d.term + " ";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2260 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2261 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2262
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2263 popoto.queryviewer.generateConstraintData = function (links, nodes) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2264 var elmts = [], id = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2265
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2266 // Add
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2267 elmts.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2268 {id: id++, term: popoto.queryviewer.QUERY_STARTER}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2269 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2270
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2271 // Add the root node as query term
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2272 if (nodes.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2273 elmts.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2274 {id: id++, type: nodes[0].type, term: popoto.provider.getSemanticValue(nodes[0]), ref: nodes[0]}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2275 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2276 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2277
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2278 // Add a span for each link and its target node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2279 links.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2280
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2281 var sourceNode = l.source;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2282 var targetNode = l.target;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2283 if (l.type === popoto.graph.link.LinkTypes.RELATION && targetNode.type !== popoto.graph.node.NodeTypes.GROUP && targetNode.value) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2284 if (sourceNode.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2285 elmts.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2286 {id: id++, type: sourceNode.type, term: popoto.provider.getSemanticValue(sourceNode), ref: sourceNode}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2287 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2288 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2289
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2290 elmts.push({id: id++, isLink: true, term: popoto.provider.getLinkSemanticValue(l), ref: l});
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2291
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2292 if (targetNode.type !== popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2293 if (targetNode.value) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2294 elmts.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2295 {id: id++, type: targetNode.type, term: popoto.provider.getSemanticValue(targetNode), ref: targetNode}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2296 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2297 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2298 elmts.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2299 {id: id++, type: targetNode.type, term: "<" + popoto.queryviewer.CHOOSE_LABEL + " " + popoto.provider.getSemanticValue(targetNode) + ">", ref: targetNode}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2300 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2301 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2302 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2303 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2304 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2305
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2306 return elmts;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2307 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2308
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2309 // TODO add option nodes in generated query when no value is available
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2310 popoto.queryviewer.generateData = function (links, nodes) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2311 var elmts = [], options = [], id = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2312
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2313 // Add a span for each link and its target node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2314 links.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2315
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2316 var sourceNode = l.source;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2317 var targetNode = l.target;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2318
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2319 if (targetNode.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2320 options.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2321 {id: id++, type: targetNode.type, term: popoto.provider.getSemanticValue(targetNode), ref: targetNode}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2322 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2323 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2324
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2325 if (l.type === popoto.graph.link.LinkTypes.RELATION && targetNode.type !== popoto.graph.node.NodeTypes.GROUP && !targetNode.value) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2326 if (sourceNode.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2327 elmts.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2328 {id: id++, type: sourceNode.type, term: popoto.provider.getSemanticValue(sourceNode), ref: sourceNode}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2329 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2330 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2331
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2332 elmts.push({id: id++, isLink: true, term: popoto.provider.getLinkSemanticValue(l), ref: l});
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2333
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2334 if (targetNode.type !== popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2335 if (targetNode.value) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2336 elmts.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2337 {id: id++, type: targetNode.type, term: popoto.provider.getSemanticValue(targetNode), ref: targetNode}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2338 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2339 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2340 elmts.push(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2341 {id: id++, type: targetNode.type, term: "<" + popoto.queryviewer.CHOOSE_LABEL + " " + popoto.provider.getSemanticValue(targetNode) + ">", ref: targetNode}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2342 );
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2343 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2344 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2345 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2346 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2347
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2348 return elmts.concat(options);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2349 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2350
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2351 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2352 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2353 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2354 popoto.queryviewer.mouseOverSpan = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2355 d3.select(this).classed("hover", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2356 return d.ref;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2357 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2358
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2359 var hoveredSpan = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2360
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2361 if (hoveredSpan.ref) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2362 var linkElmt = popoto.graph.svg.selectAll("#" + popoto.graph.link.gID + " > g").filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2363 return d === hoveredSpan.ref;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2364 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2365 linkElmt.select("path").classed("ppt-link-hover", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2366 linkElmt.select("text").classed("ppt-link-hover", true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2367
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2368 var nodeElmt = popoto.graph.svg.selectAll("#" + popoto.graph.node.gID + " > g").filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2369 return d === hoveredSpan.ref;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2370 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2371
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2372 nodeElmt.select(".ppt-g-node-background").selectAll("circle").transition().style("fill-opacity", 0.5);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2373 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2374 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2375
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2376 popoto.queryviewer.rightClickSpan = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2377 var hoveredSpan = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2378
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2379 if (!hoveredSpan.isLink && hoveredSpan.ref) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2380 var nodeElmt = popoto.graph.svg.selectAll("#" + popoto.graph.node.gID + " > g").filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2381 return d === hoveredSpan.ref;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2382 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2383
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2384 nodeElmt.on("contextmenu").call(nodeElmt.node(), hoveredSpan.ref);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2385 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2386 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2387
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2388 popoto.queryviewer.clickSpan = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2389 var hoveredSpan = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2390
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2391 if (!hoveredSpan.isLink && hoveredSpan.ref) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2392 var nodeElmt = popoto.graph.svg.selectAll("#" + popoto.graph.node.gID + " > g").filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2393 return d === hoveredSpan.ref;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2394 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2395
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2396 nodeElmt.on("click").call(nodeElmt.node(), hoveredSpan.ref);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2397 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2398 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2399
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2400 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2401 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2402 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2403 popoto.queryviewer.mouseOutSpan = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2404 d3.select(this).classed("hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2405
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2406 var hoveredSpan = d3.select(this).data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2407
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2408 if (hoveredSpan.ref) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2409 var linkElmt = popoto.graph.svg.selectAll("#" + popoto.graph.link.gID + " > g").filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2410 return d === hoveredSpan.ref;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2411 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2412 linkElmt.select("path").classed("ppt-link-hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2413 linkElmt.select("text").classed("ppt-link-hover", false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2414
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2415 var nodeElmt = popoto.graph.svg.selectAll("#" + popoto.graph.node.gID + " > g").filter(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2416 return d === hoveredSpan.ref;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2417 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2418 nodeElmt.select(".ppt-g-node-background").selectAll("circle").transition().style("fill-opacity", 0);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2419 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2420 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2421
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2422 // CYPHER VIEWER -----------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2423
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2424 // TODO not available yet
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2425 popoto.cypherviewer = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2426 popoto.cypherviewer.containerId = "popoto-cypher";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2427
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2428 // QUERY ------------------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2429 popoto.query = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2430 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2431 * Define the number of results displayed in result list.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2432 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2433 popoto.query.RESULTS_PAGE_SIZE = 100;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2434 popoto.query.VALUE_QUERY_LIMIT = 1000;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2435 popoto.query.USE_PARENT_RELATION = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2436 popoto.query.USE_RELATION_DIRECTION = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2437
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2438 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2439 * Immutable constant object to identify Neo4j internal ID
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2440 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2441 popoto.query.NEO4J_INTERNAL_ID = Object.freeze({queryInternalName: "NEO4JID"});
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2442
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2443 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2444 * Function used to filter returned relations
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2445 * return false if the result should be filtered out.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2446 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2447 * @param d relation returned object
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2448 * @returns {boolean}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2449 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2450 popoto.query.filterRelation = function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2451 return true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2452 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2453
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2454 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2455 * Generate the query to count nodes of a label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2456 * If the label is defined as distinct in configuration the query will count only distinct values on constraint attribute.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2457 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2458 popoto.query.generateTaxonomyCountQuery = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2459 var constraintAttr = popoto.provider.getConstraintAttribute(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2460
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2461 var whereElements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2462
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2463 var predefinedConstraints = popoto.provider.getPredefinedConstraints(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2464 predefinedConstraints.forEach(function (predefinedConstraint) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2465 whereElements.push(predefinedConstraint.replace(new RegExp("\\$identifier", 'g'), "n"));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2466 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2467
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2468 if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2469 return "MATCH (n:`" + label + "`)" + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN count(DISTINCT ID(n)) as count"
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2470 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2471 return "MATCH (n:`" + label + "`)" + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN count(DISTINCT n." + constraintAttr + ") as count"
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2472 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2473 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2474
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2475 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2476 * Generate Cypher query match and where elements from root node, selected node and a set of the graph links.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2477 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2478 * @param rootNode root node in the graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2479 * @param selectedNode graph target node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2480 * @param links list of links subset of the graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2481 * @returns {{matchElements: Array, whereElements: Array}} list of match and where elements.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2482 * @param isConstraintNeeded
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2483 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2484 popoto.query.generateQueryElements = function (rootNode, selectedNode, links, isConstraintNeeded) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2485 var matchElements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2486 var whereElements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2487 var rel = popoto.query.USE_RELATION_DIRECTION ? "->" : "-";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2488
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2489 var rootPredefinedConstraints = popoto.provider.getPredefinedConstraints(rootNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2490
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2491 rootPredefinedConstraints.forEach(function (predefinedConstraint) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2492 whereElements.push(predefinedConstraint.replace(new RegExp("\\$identifier", 'g'), rootNode.internalLabel));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2493 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2494
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2495 // Generate root node match element
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2496 if (rootNode.value && (isConstraintNeeded || rootNode.immutable)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2497 var rootConstraintAttr = popoto.provider.getConstraintAttribute(rootNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2498 if (rootConstraintAttr === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2499 matchElements.push("(" + rootNode.internalLabel + ":`" + rootNode.label + "`)");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2500 whereElements.push("ID(" + rootNode.internalLabel + ") = " + rootNode.value.internalID);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2501 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2502 var constraintValue = rootNode.value.attributes[rootConstraintAttr];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2503
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2504 if (typeof constraintValue === "boolean" || typeof constraintValue === "number") {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2505 matchElements.push("(" + rootNode.internalLabel + ":`" + rootNode.label + "`{`" + rootConstraintAttr + "`:" + constraintValue + "})");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2506 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2507 matchElements.push("(" + rootNode.internalLabel + ":`" + rootNode.label + "`{`" + rootConstraintAttr + "`:\"" + constraintValue + "\"})");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2508 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2509 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2510 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2511 matchElements.push("(" + rootNode.internalLabel + ":`" + rootNode.label + "`)");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2512 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2513
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2514 // Generate match elements for each links
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2515 links.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2516 var sourceNode = l.source;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2517 var targetNode = l.target;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2518
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2519 var predefinedConstraints = popoto.provider.getPredefinedConstraints(targetNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2520
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2521 predefinedConstraints.forEach(function (predefinedConstraint) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2522 whereElements.push(predefinedConstraint.replace(new RegExp("\\$identifier", 'g'), targetNode.internalLabel));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2523 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2524
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2525 if (targetNode.value && targetNode !== selectedNode && (isConstraintNeeded || rootNode.immutable)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2526 var constraintAttr = popoto.provider.getConstraintAttribute(targetNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2527 var constraintValue = targetNode.value.attributes[constraintAttr];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2528 if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2529 matchElements.push("(" + sourceNode.internalLabel + ":`" + sourceNode.label + "`)-[:`" + l.label + "`]" + rel + "(" + targetNode.internalLabel + ":`" + targetNode.label + "`)");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2530 whereElements.push("ID(" + targetNode.internalLabel + ") = " + targetNode.value.internalID);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2531 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2532 if (typeof constraintValue === "boolean" || typeof constraintValue === "number") {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2533 matchElements.push("(" + sourceNode.internalLabel + ":`" + sourceNode.label + "`)-[:`" + l.label + "`]" + rel + "(" + targetNode.internalLabel + ":`" + targetNode.label + "`{`" + constraintAttr + "`:" + constraintValue + "})");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2534 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2535 matchElements.push("(" + sourceNode.internalLabel + ":`" + sourceNode.label + "`)-[:`" + l.label + "`]" + rel + "(" + targetNode.internalLabel + ":`" + targetNode.label + "`{`" + constraintAttr + "`:\"" + constraintValue + "\"})");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2536 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2537 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2538 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2539 matchElements.push("(" + sourceNode.internalLabel + ":`" + sourceNode.label + "`)-[:`" + l.label + "`]" + rel + "(" + targetNode.internalLabel + ":`" + targetNode.label + "`)");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2540 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2541 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2542
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2543 return {"matchElements": matchElements, "whereElements": whereElements};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2544 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2545
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2546 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2547 * Filter links to get only paths from root to leaf containing a value or being the selectedNode.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2548 * All other paths in the graph containing no value are ignored.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2549 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2550 * @param rootNode root node of the graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2551 * @param targetNode node in the graph target of the query.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2552 * @param initialLinks list of links repreasenting the graph to filter.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2553 * @returns {Array} list of relevant links.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2554 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2555 popoto.query.getRelevantLinks = function (rootNode, targetNode, initialLinks) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2556
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2557 var links = initialLinks.slice();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2558 var filteredLinks = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2559 var finalLinks = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2560
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2561 // Filter all links to keep only those containing a value or being the selected node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2562 links.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2563 if (l.target.value || l.target === targetNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2564 filteredLinks.push(l);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2565 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2566 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2567
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2568 // All the filtered links are removed from initial links list.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2569 filteredLinks.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2570 links.splice(links.indexOf(l), 1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2571 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2572
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2573 // Then all the intermediate links up to the root node are added to get only the relevant links.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2574 filteredLinks.forEach(function (fl) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2575 var sourceNode = fl.source;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2576 var search = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2577
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2578 while (search) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2579 var intermediateLink = null;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2580 links.forEach(function (l) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2581 if (l.target === sourceNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2582 intermediateLink = l;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2583 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2584 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2585
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2586 if (intermediateLink === null) { // no intermediate links needed
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2587 search = false
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2588 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2589 if (intermediateLink.source === rootNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2590 finalLinks.push(intermediateLink);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2591 links.splice(links.indexOf(intermediateLink), 1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2592 search = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2593 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2594 finalLinks.push(intermediateLink);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2595 links.splice(links.indexOf(intermediateLink), 1);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2596 sourceNode = intermediateLink.source;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2597 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2598 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2599 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2600 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2601
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2602 return filteredLinks.concat(finalLinks);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2603 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2604
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2605 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2606 * Get the list of link defining the complete path from node to root.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2607 * All other links are ignored.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2608 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2609 * @param node The node where to start in the graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2610 * @param links
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2611 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2612 popoto.query.getLinksToRoot = function (node, links) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2613 var pathLinks = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2614 var targetNode = node;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2615
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2616 while (targetNode !== popoto.graph.getRootNode()) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2617 var nodeLink;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2618
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2619 for (var i = 0; i < links.length; i++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2620 var link = links[i];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2621 if (link.target === targetNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2622 nodeLink = link;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2623 break;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2624 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2625 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2626
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2627 if (nodeLink) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2628 pathLinks.push(nodeLink);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2629 targetNode = nodeLink.source;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2630 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2631 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2632
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2633 return pathLinks;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2634 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2635
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2636 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2637 * Generate a Cypher query to retrieve all the relation available for a given node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2638 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2639 * @param targetNode
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2640 * @returns {string}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2641 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2642 popoto.query.generateLinkQuery = function (targetNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2643
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2644 var linksToRoot = popoto.query.getLinksToRoot(targetNode, popoto.graph.force.links());
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2645 var queryElements = popoto.query.generateQueryElements(popoto.graph.getRootNode(), targetNode, linksToRoot, false);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2646 var matchElements = queryElements.matchElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2647 returnElements = [],
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2648 whereElements = queryElements.whereElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2649 endElements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2650 var rel = popoto.query.USE_RELATION_DIRECTION ? "->" : "-";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2651
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2652 matchElements.push("(" + targetNode.internalLabel + ":`" + targetNode.label + "`)-[r]" + rel + "(x)");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2653 returnElements.push("type(r) AS relationship");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2654 if (popoto.query.USE_PARENT_RELATION) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2655 returnElements.push("head(labels(x)) AS label");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2656 } else {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
2657 //returnElements.push("last(labels(x)) AS label");
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
2658 returnElements.push("labels(x) AS label");
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2659 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2660 returnElements.push("count(r) AS count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2661 endElements.push("ORDER BY count(r) DESC");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2662
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2663 return "MATCH " + matchElements.join(", ") + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN " + returnElements.join(", ") + " " + endElements.join(" ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2664 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2665
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2666 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2667 * Generate a Cypher query
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2668 * @returns {string}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2669 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2670 popoto.query.generateResultCypherQuery = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2671
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2672 var rootNode = popoto.graph.getRootNode();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2673 var queryElements = popoto.query.generateQueryElements(rootNode, rootNode, popoto.query.getRelevantLinks(rootNode, rootNode, popoto.graph.force.links()), true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2674 var matchElements = queryElements.matchElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2675 returnElements = [],
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2676 whereElements = queryElements.whereElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2677 endElements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2678
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2679 // Sort results by specified attribute
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2680 var resultOrderByAttribute = popoto.provider.getResultOrderByAttribute(rootNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2681 if (resultOrderByAttribute) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2682 var order = popoto.provider.isResultOrderAscending(rootNode.label) ? "ASC" : "DESC";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2683 endElements.push("ORDER BY " + resultOrderByAttribute + " " + order);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2684 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2685
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2686 endElements.push("LIMIT " + popoto.query.RESULTS_PAGE_SIZE);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2687
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2688 var resultAttributes = popoto.provider.getReturnAttributes(rootNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2689 var constraintAttribute = popoto.provider.getConstraintAttribute(rootNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2690
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2691 for (var i = 0; i < resultAttributes.length; i++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2692 var attribute = resultAttributes[i];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2693 if (attribute === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2694 if (attribute == constraintAttribute) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2695 returnElements.push("ID(" + rootNode.internalLabel + ") AS " + popoto.query.NEO4J_INTERNAL_ID.queryInternalName);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2696 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2697 returnElements.push("COLLECT(DISTINCT ID(" + rootNode.internalLabel + ")) AS " + popoto.query.NEO4J_INTERNAL_ID.queryInternalName);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2698 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2699 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2700 if (attribute == constraintAttribute) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2701 returnElements.push(rootNode.internalLabel + "." + attribute + " AS " + attribute);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2702 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2703 returnElements.push("COLLECT(DISTINCT " + rootNode.internalLabel + "." + attribute + ") AS " + attribute);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2704 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2705 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2706 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2707
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2708 return "MATCH " + matchElements.join(", ") + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN DISTINCT " + returnElements.join(", ") + " " + endElements.join(" ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2709 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2710
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2711 popoto.query.generateResultCypherQueryCount = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2712
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2713 var rootNode = popoto.graph.getRootNode();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2714 var queryElements = popoto.query.generateQueryElements(rootNode, rootNode, popoto.query.getRelevantLinks(rootNode, rootNode, popoto.graph.force.links()), true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2715 var constraintAttribute = popoto.provider.getConstraintAttribute(rootNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2716 var matchElements = queryElements.matchElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2717 returnElements = [],
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2718 whereElements = queryElements.whereElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2719 endElements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2720
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2721 if (constraintAttribute === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2722 returnElements.push("count(DISTINCT ID(" + rootNode.internalLabel + ")) AS count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2723 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2724 returnElements.push("count(DISTINCT " + rootNode.internalLabel + "." + constraintAttribute + ") AS count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2725 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2726
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2727 return "MATCH " + matchElements.join(", ") + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN " + returnElements.join(", ") + (endElements.length > 0 ? " " + endElements.join(" ") : "");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2728 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2729
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2730 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2731 * Generate the query to update node counts.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2732 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2733 * @param countedNode the counted node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2734 * @returns {string} the node count cypher query;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2735 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2736 popoto.query.generateNodeCountCypherQuery = function (countedNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2737
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2738 var queryElements = popoto.query.generateQueryElements(popoto.graph.getRootNode(), countedNode, popoto.query.getRelevantLinks(popoto.graph.getRootNode(), countedNode, popoto.graph.force.links()), true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2739 var matchElements = queryElements.matchElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2740 whereElements = queryElements.whereElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2741 returnElements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2742
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2743 var countAttr = popoto.provider.getConstraintAttribute(countedNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2744
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2745 if (countAttr === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2746 returnElements.push("count(DISTINCT ID(" + countedNode.internalLabel + ")) as count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2747 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2748 returnElements.push("count(DISTINCT " + countedNode.internalLabel + "." + countAttr + ") as count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2749 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2750
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2751 return "MATCH " + matchElements.join(", ") + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN " + returnElements.join(", ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2752 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2753
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2754 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2755 * Generate a Cypher query from the graph model to get all the possible values for the targetNode element.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2756 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2757 * @param targetNode node in the graph to get the values.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2758 * @returns {string} the query to execute to get all the values of targetNode corresponding to the graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2759 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2760 popoto.query.generateValueQuery = function (targetNode) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2761
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2762 var rootNode = popoto.graph.getRootNode();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2763 var queryElements = popoto.query.generateQueryElements(rootNode, targetNode, popoto.query.getRelevantLinks(rootNode, targetNode, popoto.graph.force.links()), true);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2764 var matchElements = queryElements.matchElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2765 endElements = [],
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2766 whereElements = queryElements.whereElements,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2767 returnElements = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2768
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2769 // Sort results by specified attribute
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2770 var valueOrderByAttribute = popoto.provider.getValueOrderByAttribute(targetNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2771 if (valueOrderByAttribute) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2772 var order = popoto.provider.isValueOrderAscending(targetNode.label) ? "ASC" : "DESC";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2773 endElements.push("ORDER BY " + valueOrderByAttribute + " " + order);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2774 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2775
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2776 endElements.push("LIMIT " + popoto.query.VALUE_QUERY_LIMIT);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2777
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2778 var resultAttributes = popoto.provider.getReturnAttributes(targetNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2779 var constraintAttribute = popoto.provider.getConstraintAttribute(targetNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2780
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2781 for (var i = 0; i < resultAttributes.length; i++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2782 if (resultAttributes[i] === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2783 if (resultAttributes[i] == constraintAttribute) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2784 returnElements.push("ID(" + targetNode.internalLabel + ") AS " + popoto.query.NEO4J_INTERNAL_ID.queryInternalName);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2785 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2786 returnElements.push("COLLECT (DISTINCT ID(" + targetNode.internalLabel + ")) AS " + popoto.query.NEO4J_INTERNAL_ID.queryInternalName);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2787 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2788 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2789 if (resultAttributes[i] == constraintAttribute) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2790 returnElements.push(targetNode.internalLabel + "." + resultAttributes[i] + " AS " + resultAttributes[i]);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2791 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2792 returnElements.push("COLLECT(DISTINCT " + targetNode.internalLabel + "." + resultAttributes[i] + ") AS " + resultAttributes[i]);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2793 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2794 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2795 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2796
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2797 // Add count return attribute on root node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2798 var rootConstraintAttr = popoto.provider.getConstraintAttribute(rootNode.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2799
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2800 if (rootConstraintAttr === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2801 returnElements.push("count(DISTINCT ID(" + rootNode.internalLabel + ")) AS count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2802 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2803 returnElements.push("count(DISTINCT " + rootNode.internalLabel + "." + rootConstraintAttr + ") AS count");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2804 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2805
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2806 return "MATCH " + matchElements.join(", ") + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN DISTINCT " + returnElements.join(", ") + " " + endElements.join(" ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2807 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2808
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2809 ///////////////////////////////////////////////////////////////////
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2810 // Results
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2811
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2812 popoto.result = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2813 popoto.result.containerId = "popoto-results";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2814 popoto.result.hasChanged = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2815 popoto.result.resultCountListeners = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2816 popoto.result.resultListeners = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2817
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2818 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2819 * Register a listener to the result count event.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2820 * This listener will be called on evry result change with total result count.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2821 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2822 popoto.result.onTotalResultCount = function (listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2823 popoto.result.resultCountListeners.push(listener);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2824 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2825
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2826 popoto.result.onResultReceived = function (listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2827 popoto.result.resultListeners.push(listener);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2828 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2829
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2830 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2831 * Parse REST returned data and generate a list of result objects.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2832 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2833 * @param data
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2834 * @returns {Array}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2835 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2836 popoto.result.parseResultData = function (data) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2837
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2838 var results = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2839 if (data.results && data.results.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2840 for (var x = 0; x < data.results[0].data.length; x++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2841
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2842 var obj = {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2843 "resultIndex": x,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2844 "label": popoto.graph.getRootNode().label,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2845 "attributes": {}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2846 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2847
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2848 for (var i = 0; i < data.results[0].columns.length; i++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2849 // Some results can be an array as collect is used in query
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2850 // So all values are converted to string
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2851 obj.attributes[data.results[0].columns[i]] = "" + data.results[0].data[x].row[i];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2852 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2853
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2854 results.push(obj);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2855 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2856 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2857
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2858 return results;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2859 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2860
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2861 popoto.result.updateResults = function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2862 if (popoto.result.hasChanged) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2863 var query = popoto.query.generateResultCypherQuery();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2864
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2865 // FIXME temporary cypher query update here. To be replaced by real interactive cypher viewer.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2866 if (popoto.cypherviewer.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2867 d3.select("#" + popoto.cypherviewer.containerId)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2868 // In this temporary version only the match part of the query is displayed to avoid huge query with lot of return attributes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2869 .text(query.split("RETURN")[0] + " RETURN " + popoto.graph.getRootNode().internalLabel);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2870 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2871
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2872 popoto.logger.info("Results ==> ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2873 popoto.rest.post(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2874 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2875 "statements": [
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2876 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2877 "statement": query
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2878 }]
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2879 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2880 .done(function (data) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2881
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2882 if (data.errors && data.errors.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2883 popoto.logger.error("Cypher query error:" + JSON.stringify(data.errors));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2884 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2885
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2886 // Parse data
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2887 var resultObjects = popoto.result.parseResultData(data);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2888
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2889 // Notify listeners
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2890 popoto.result.resultListeners.forEach(function (listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2891 listener(resultObjects);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2892 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2893
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2894 // Update displayed results only if needed ()
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2895 if (popoto.result.isActive) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2896 // Clear all results
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2897 var results = d3.select("#" + popoto.result.containerId).selectAll(".ppt-result").data([]);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2898 results.exit().remove();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2899
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2900 // Update data
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2901 results = d3.select("#" + popoto.result.containerId).selectAll(".ppt-result").data(resultObjects, function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2902 return d.resultIndex;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2903 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2904
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2905 // Add new elements
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2906 var pElmt = results.enter()
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2907 .append("p")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2908 .attr("class", "ppt-result")
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2909 .attr("id", function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2910 return "popoto-result-" + d.resultIndex;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2911 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2912
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2913 // Generate results with providers
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2914 pElmt.each(function (d) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2915 popoto.provider.getDisplayResultFunction(d.label)(d3.select(this));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2916 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2917 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2918
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2919 popoto.result.hasChanged = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2920 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2921 .fail(function (xhr, textStatus, errorThrown) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2922 popoto.logger.error(textStatus + ": error while accessing Neo4j server on URL:\"" + popoto.rest.CYPHER_URL + "\" defined in \"popoto.rest.CYPHER_URL\" property: " + errorThrown);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2923
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2924 // Notify listeners
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2925 popoto.result.resultListeners.forEach(function (listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2926 listener([]);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2927 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2928
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2929 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2930
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2931 // Execute query to get total result count
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2932 // But only if needed, if listeners have been added
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2933 if (popoto.result.resultCountListeners.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2934 popoto.logger.info("Results count ==> ");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2935 popoto.rest.post(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2936 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2937 "statements": [
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2938 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2939 "statement": popoto.query.generateResultCypherQueryCount()
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2940 }]
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2941 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2942 .done(function (data) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2943
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2944 if (data.errors && data.errors.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2945 popoto.logger.error("Cypher query error:" + JSON.stringify(data.errors));
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2946 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2947
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2948 var count = 0;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2949
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2950 if (data.results && data.results.length > 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2951 count = data.results[0].data[0].row[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2952 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2953
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2954 popoto.result.resultCountListeners.forEach(function (listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2955 listener(count);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2956 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2957
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2958 })
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2959 .fail(function (xhr, textStatus, errorThrown) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2960 popoto.logger.error(textStatus + ": error while accessing Neo4j server on URL:\"" + popoto.rest.CYPHER_URL + "\" defined in \"popoto.rest.CYPHER_URL\" property: " + errorThrown);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2961
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2962 popoto.result.resultCountListeners.forEach(function (listener) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2963 listener(0);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2964 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2965 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2966 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2967 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2968 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2969
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2970 // NODE LABEL PROVIDERS -----------------------------------------------------------------------------------------------------
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2971
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2972 popoto.provider = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2973 popoto.provider.linkProvider = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2974 popoto.provider.taxonomyProvider = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2975 popoto.provider.nodeProviders = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2976
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2977 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2978 * Get the text representation of a link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2979 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2980 * @param link the link to get the text representation.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2981 * @returns {string} the text representation of the link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2982 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2983 popoto.provider.getLinkTextValue = function (link) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2984 if (popoto.provider.linkProvider.hasOwnProperty("getLinkTextValue")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2985 return popoto.provider.linkProvider.getLinkTextValue(link);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2986 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2987 if (popoto.provider.DEFAULT_LINK_PROVIDER.hasOwnProperty("getLinkTextValue")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2988 return popoto.provider.DEFAULT_LINK_PROVIDER.getLinkTextValue(link);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2989 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2990 popoto.logger.error("No provider defined for getLinkTextValue");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2991 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2992 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2993 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2994
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2995 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2996 * Get the semantic text representation of a link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2997 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2998 * @param link the link to get the semantic text representation.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
2999 * @returns {string} the semantic text representation of the link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3000 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3001 popoto.provider.getLinkSemanticValue = function (link) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3002 if (popoto.provider.linkProvider.hasOwnProperty("getLinkSemanticValue")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3003 return popoto.provider.linkProvider.getLinkSemanticValue(link);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3004 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3005 if (popoto.provider.DEFAULT_LINK_PROVIDER.hasOwnProperty("getLinkSemanticValue")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3006 return popoto.provider.DEFAULT_LINK_PROVIDER.getLinkSemanticValue(link);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3007 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3008 popoto.logger.error("No provider defined for getLinkSemanticValue");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3009 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3010 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3011 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3012
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3013 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3014 * Label provider used by default if none have been defined for a label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3015 * This provider can be changed if needed to customize default behavior.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3016 * If some properties are not found in user customized providers, default values will be extracted from this provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3017 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3018 popoto.provider.DEFAULT_LINK_PROVIDER = Object.freeze(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3019 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3020 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3021 * Function used to return the text representation of a link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3022 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3023 * The default behavior is to return the internal relation name as text for relation links.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3024 * And return the target node text value for links between a node and its expanded values but only if text is not displayed on value node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3025 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3026 * @param link the link to represent as text.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3027 * @returns {string} the text representation of the link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3028 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3029 "getLinkTextValue": function (link) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3030 if (link.type === popoto.graph.link.LinkTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3031 // Links between node and list of values.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3032
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3033 if (popoto.provider.isTextDisplayed(link.target)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3034 // Don't display text on link if text is displayed on target node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3035 return "";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3036 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3037 // No text is displayed on target node then the text is displayed on link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3038 return popoto.provider.getTextValue(link.target);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3039 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3040
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3041 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3042
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3043 // Link
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3044 return link.label
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3045 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3046 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3047
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3048 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3049 * Function used to return a descriptive text representation of a link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3050 * This representation should be more complete than getLinkTextValue and can contain semantic data.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3051 * This function is used for example to generate the label in the query viewer.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3052 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3053 * The default behavior is to return the getLinkTextValue.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3054 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3055 * @param link the link to represent as text.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3056 * @returns {string} the text semantic representation of the link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3057 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3058 "getLinkSemanticValue": function (link) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3059 return popoto.provider.getLinkTextValue(link);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3060 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3061 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3062 popoto.provider.linkProvider = popoto.provider.DEFAULT_LINK_PROVIDER;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3063
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3064 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3065 * Get the text representation of a taxonomy.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3066 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3067 * @param label the label used for the taxonomy.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3068 * @returns {string} the text representation of the taxonomy.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3069 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3070 popoto.provider.getTaxonomyTextValue = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3071 if (popoto.provider.taxonomyProvider.hasOwnProperty("getTextValue")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3072 return popoto.provider.taxonomyProvider.getTextValue(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3073 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3074 if (popoto.provider.DEFAULT_TAXONOMY_PROVIDER.hasOwnProperty("getTextValue")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3075 return popoto.provider.DEFAULT_TAXONOMY_PROVIDER.getTextValue(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3076 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3077 popoto.logger.error("No provider defined for taxonomy getTextValue");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3078 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3079 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3080 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3081
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3082 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3083 * Label provider used by default if none have been defined for a label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3084 * This provider can be changed if needed to customize default behavior.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3085 * If some properties are not found in user customized providers, default values will be extracted from this provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3086 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3087 popoto.provider.DEFAULT_TAXONOMY_PROVIDER = Object.freeze(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3088 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3089 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3090 * Function used to return the text representation of a taxonomy.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3091 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3092 * The default behavior is to return the label without changes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3093 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3094 * @param label the label used to represent the taxonomy.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3095 * @returns {string} the text representation of the taxonomy.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3096 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3097 "getTextValue": function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3098 return label;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3099 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3100 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3101 popoto.provider.taxonomyProvider = popoto.provider.DEFAULT_TAXONOMY_PROVIDER;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3102
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3103 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3104 * Define the different type of rendering of a node for a given label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3105 * TEXT: default rendering type, the node will be displayed with an ellipse and a text in it.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3106 * IMAGE: the node is displayed as an image using the image tag in the svg graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3107 * In this case an image path is required.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3108 * SVG: the node is displayed using a list of svg path, each path can contain its own color.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3109 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3110 popoto.provider.NodeDisplayTypes = Object.freeze({TEXT: 0, IMAGE: 1, SVG: 2});
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3111
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3112 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3113 * Get the label provider for the given label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3114 * If no provider is defined for the label:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3115 * First search in parent provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3116 * Then if not found will create one from default provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3117 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3118 * @param label to retrieve the corresponding label provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3119 * @returns {object} corresponding label provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3120 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3121 popoto.provider.getProvider = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3122 if (label === undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3123 popoto.logger.error("Node label is undefined, no label provider can be found.");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3124 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3125 if (popoto.provider.nodeProviders.hasOwnProperty(label)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3126 return popoto.provider.nodeProviders[label];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3127 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3128 popoto.logger.debug("No direct provider found for label " + label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3129
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3130 // Search in all children list definitions to find the parent provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3131 for (var p in popoto.provider.nodeProviders) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3132 if (popoto.provider.nodeProviders.hasOwnProperty(p)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3133 var provider = popoto.provider.nodeProviders[p];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3134 if (provider.hasOwnProperty("children")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3135 if (provider["children"].indexOf(label) > -1) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3136 popoto.logger.debug("No provider is defined for label (" + label + "), parent (" + p + ") will be used");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3137 // A provider containing the required label in its children definition has been found it will be cloned.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3138
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3139 var newProvider = {"parent": p};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3140 for (var pr in provider) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3141 if (provider.hasOwnProperty(pr) && pr != "children" && pr != "parent") {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3142 newProvider[pr] = provider[pr];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3143 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3144 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3145
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3146 popoto.provider.nodeProviders[label] = newProvider;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3147 return popoto.provider.nodeProviders[label];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3148 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3149 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3150 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3151 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3152
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3153 popoto.logger.debug("No label provider defined for label (" + label + ") default one will be created from popoto.provider.DEFAULT_PROVIDER");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3154
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3155 popoto.provider.nodeProviders[label] = {};
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3156 // Clone default provider properties in new provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3157 for (var prop in popoto.provider.DEFAULT_PROVIDER) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3158 if (popoto.provider.DEFAULT_PROVIDER.hasOwnProperty(prop)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3159 popoto.provider.nodeProviders[label][prop] = popoto.provider.DEFAULT_PROVIDER[prop];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3160 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3161 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3162 return popoto.provider.nodeProviders[label];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3163 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3164 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3165 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3166
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3167 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3168 * Get the property or function defined in node label provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3169 * If the property is not found search is done in parents.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3170 * If not found in parent, property defined in popoto.provider.DEFAULT_PROVIDER is returned.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3171 * If not found in default provider, defaultValue is set and returned.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3172 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3173 * @param label node label to get the property in its provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3174 * @param name name of the property to retrieve.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3175 * @returns {*} node property defined in its label provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3176 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3177 popoto.provider.getProperty = function (label, name) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3178 var provider = popoto.provider.getProvider(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3179
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3180 if (!provider.hasOwnProperty(name)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3181 var providerIterator = provider;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3182
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3183 // Check parents
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3184 var isPropertyFound = false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3185 while (providerIterator.hasOwnProperty("parent") && !isPropertyFound) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3186 providerIterator = popoto.provider.getProvider(providerIterator.parent);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3187 if (providerIterator.hasOwnProperty(name)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3188
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3189 // Set attribute in child to optimize next call.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3190 provider[name] = providerIterator[name];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3191 isPropertyFound = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3192 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3193 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3194
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3195 if (!isPropertyFound) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3196 popoto.logger.debug("No \"" + name + "\" property found for node label provider (" + label + "), default value will be used");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3197 if (popoto.provider.DEFAULT_PROVIDER.hasOwnProperty(name)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3198 provider[name] = popoto.provider.DEFAULT_PROVIDER[name];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3199 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3200 popoto.logger.error("No default value for \"" + name + "\" property found for label provider (" + label + ")");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3201 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3202 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3203 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3204 return provider[name];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3205 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3206
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3207 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3208 * Return the "isSearchable" property for the node label provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3209 * Is Searchable defined whether the label can be used as graph query builder root.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3210 * If true the label can be displayed in the taxonomy filter.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3211 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3212 * @param label
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3213 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3214 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3215 popoto.provider.getIsSearchable = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3216 return popoto.provider.getProperty(label, "isSearchable");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3217 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3218
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3219 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3220 * Return the list of attributes defined in node label provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3221 * Parents return attributes are also returned.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3222 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3223 * @param label used to retrieve parent attributes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3224 * @returns {Array} list of return attributes for a node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3225 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3226 popoto.provider.getReturnAttributes = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3227 var provider = popoto.provider.getProvider(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3228 var attributes = {}; // Object is used as a Set to merge possible duplicate in parents
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3229
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3230 if (provider.hasOwnProperty("returnAttributes")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3231 for (var i = 0; i < provider.returnAttributes.length; i++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3232 if (provider.returnAttributes[i] === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3233 attributes[popoto.query.NEO4J_INTERNAL_ID.queryInternalName] = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3234 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3235 attributes[provider.returnAttributes[i]] = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3236 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3237 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3238 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3239
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3240 // Add parent attributes
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3241 while (provider.hasOwnProperty("parent")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3242 provider = popoto.provider.getProvider(provider.parent);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3243 if (provider.hasOwnProperty("returnAttributes")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3244 for (var j = 0; j < provider.returnAttributes.length; j++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3245 if (provider.returnAttributes[j] === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3246 attributes[popoto.query.NEO4J_INTERNAL_ID.queryInternalName] = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3247 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3248 attributes[provider.returnAttributes[j]] = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3249 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3250 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3251 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3252 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3253
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3254 // Add default provider attributes if any but not internal id as this id is added only if none has been found.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3255 if (popoto.provider.DEFAULT_PROVIDER.hasOwnProperty("returnAttributes")) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3256 for (var k = 0; k < popoto.provider.DEFAULT_PROVIDER.returnAttributes.length; k++) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3257 if (popoto.provider.DEFAULT_PROVIDER.returnAttributes[k] !== popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3258 attributes[popoto.provider.DEFAULT_PROVIDER.returnAttributes[k]] = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3259 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3260 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3261 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3262
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3263 // Add constraint attribute in the list
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3264 var constraintAttribute = popoto.provider.getConstraintAttribute(label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3265 if (constraintAttribute === popoto.query.NEO4J_INTERNAL_ID) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3266 attributes[popoto.query.NEO4J_INTERNAL_ID.queryInternalName] = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3267 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3268 attributes[constraintAttribute] = true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3269 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3270
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3271
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3272 // Add all in array
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3273 var attrList = [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3274 for (var attr in attributes) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3275 if (attributes.hasOwnProperty(attr)) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3276 if (attr == popoto.query.NEO4J_INTERNAL_ID.queryInternalName) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3277 attrList.push(popoto.query.NEO4J_INTERNAL_ID);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3278 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3279 attrList.push(attr);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3280 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3281 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3282 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3283
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3284 // If no attributes have been found internal ID is used
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3285 if (attrList.length <= 0) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3286 attrList.push(popoto.query.NEO4J_INTERNAL_ID);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3287 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3288 return attrList;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3289 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3290
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3291 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3292 * Return the attribute to use as constraint attribute for a node defined in its label provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3293 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3294 * @param label
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3295 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3296 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3297 popoto.provider.getConstraintAttribute = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3298 return popoto.provider.getProperty(label, "constraintAttribute");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3299 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3300
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3301 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3302 * Return a list of predefined constraint defined in the node label configuration.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3303 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3304 * @param label
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3305 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3306 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3307 popoto.provider.getPredefinedConstraints = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3308 return popoto.provider.getProperty(label, "getPredefinedConstraints")();
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3309 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3310
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3311
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3312 popoto.provider.getValueOrderByAttribute = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3313 return popoto.provider.getProperty(label, "valueOrderByAttribute");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3314 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3315
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3316 popoto.provider.isValueOrderAscending = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3317 return popoto.provider.getProperty(label, "isValueOrderAscending");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3318 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3319
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3320 popoto.provider.getResultOrderByAttribute = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3321 return popoto.provider.getProperty(label, "resultOrderByAttribute");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3322 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3323
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3324 popoto.provider.isResultOrderAscending = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3325 return popoto.provider.getProperty(label, "isResultOrderAscending");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3326 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3327
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3328 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3329 * Return the value of the getTextValue function defined in the label provider corresponding to the parameter node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3330 * If no "getTextValue" function is defined in the provider, search is done in parents.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3331 * If none is found in parent default provider method is used.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3332 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3333 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3334 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3335 popoto.provider.getTextValue = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3336 return popoto.provider.getProperty(node.label, "getTextValue")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3337 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3338
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3339
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3340 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3341 * Return the value of the getTextValue function defined in the label provider corresponding to the parameter node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3342 * If no "getTextValue" function is defined in the provider, search is done in parents.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3343 * If none is found in parent default provider method is used.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3344 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3345 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3346 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3347 popoto.provider.getTextValue = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3348 return popoto.provider.getProperty(node.label, "getTextValue")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3349 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3350
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3351 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3352 * Return the value of the getSemanticValue function defined in the label provider corresponding to the parameter node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3353 * The semantic value is a more detailed description of the node used for example in the query viewer.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3354 * If no "getTextValue" function is defined in the provider, search is done in parents.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3355 * If none is found in parent default provider method is used.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3356 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3357 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3358 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3359 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3360 popoto.provider.getSemanticValue = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3361 return popoto.provider.getProperty(node.label, "getSemanticValue")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3362 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3363
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3364 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3365 * Return a list of SVG paths objects, each defined by a "d" property containing the path and "f" property for the color.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3366 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3367 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3368 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3369 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3370 popoto.provider.getSVGPaths = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3371 return popoto.provider.getProperty(node.label, "getSVGPaths")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3372 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3373
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3374 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3375 * Check in label provider if text must be displayed with images nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3376 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3377 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3378 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3379 popoto.provider.isTextDisplayed = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3380 return popoto.provider.getProperty(node.label, "getIsTextDisplayed")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3381 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3382
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3383 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3384 * Return the getIsGroup property.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3385 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3386 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3387 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3388 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3389 popoto.provider.getIsGroup = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3390 return popoto.provider.getProperty(node.label, "getIsGroup")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3391 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3392
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3393 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3394 * Return the node display type.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3395 * can be TEXT, IMAGE, SVG or GROUP.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3396 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3397 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3398 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3399 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3400 popoto.provider.getNodeDisplayType = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3401 return popoto.provider.getProperty(node.label, "getDisplayType")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3402 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3403
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3404 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3405 * Return the file path of the image defined in the provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3406 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3407 * @param node the node to get the image path.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3408 * @returns {string} the path of the node image.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3409 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3410 popoto.provider.getImagePath = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3411 return popoto.provider.getProperty(node.label, "getImagePath")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3412 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3413
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3414 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3415 * Return the width size of the node image.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3416 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3417 * @param node the node to get the image width.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3418 * @returns {int} the image width.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3419 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3420 popoto.provider.getImageWidth = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3421 return popoto.provider.getProperty(node.label, "getImageWidth")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3422 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3423
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3424 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3425 * Return the height size of the node image.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3426 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3427 * @param node the node to get the image height.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3428 * @returns {int} the image height.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3429 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3430 popoto.provider.getImageHeight = function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3431 return popoto.provider.getProperty(node.label, "getImageHeight")(node);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3432 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3433
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3434 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3435 * Return the displayResults function defined in label parameter's provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3436 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3437 * @param label
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3438 * @returns {*}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3439 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3440 popoto.provider.getDisplayResultFunction = function (label) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3441 return popoto.provider.getProperty(label, "displayResults");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3442 };
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3443
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3444 /**
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3445 * Select the label if there is more than one.
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3446 *
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3447 * Discards the label with an underscore.
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3448 */
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3449 popoto.provider.getLabelFilter = function (nodeLabel) {
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3450 if (Array.isArray(nodeLabel)) {
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3451 // use last label
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3452 var label = nodeLabel[nodeLabel.length - 1];
3
aea1b2097f4f fix silly bug.
casties
parents: 1
diff changeset
3453 if (label.indexOf('_') != -1 && nodeLabel.length > 1) {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3454 // skip if wrong label
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3455 label = nodeLabel[nodeLabel.length - 2];
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3456 }
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3457 // replace array with string
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3458 nodeLabel = label;
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3459 }
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3460 return nodeLabel;
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3461 }
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3462
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3463 /**
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3464 * Label provider used by default if none have been defined for a label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3465 * This provider can be changed if needed to customize default behavior.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3466 * If some properties are not found in user customized providers, default values will be extracted from this provider.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3467 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3468 popoto.provider.DEFAULT_PROVIDER = Object.freeze(
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3469 {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3470 /**********************************************************************
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3471 * Label specific parameters:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3472 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3473 * These attributes are specific to a node label and will be used for every node having this label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3474 **********************************************************************/
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3475
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3476 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3477 * Defines whether this label can be used as root element of the graph query builder.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3478 * This property is also used to determine whether the label can be displayed in the taxonomy filter.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3479 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3480 * The default value is true.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3481 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3482 "isSearchable": true,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3483
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3484 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3485 * Defines the list of attribute to return for node of this label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3486 * All the attributes listed here will be added in generated cypher queries and available in result list and in node provider's functions.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3487 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3488 * The default value contains only the Neo4j internal id.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3489 * This id is used by default because it is a convenient way to identify a node when nothing is known about its attributes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3490 * But you should really consider using your application attributes instead, it is a bad practice to rely on this attribute.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3491 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3492 "returnAttributes": [popoto.query.NEO4J_INTERNAL_ID],
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3493
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3494 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3495 * Defines the attribute used to order the value displayed on node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3496 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3497 * Default value is "count" attribute.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3498 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3499 "valueOrderByAttribute": "count",
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3500
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3501 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3502 * Defines whether the value query order by is ascending, if false order by will be descending.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3503 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3504 * Default value is false (descending)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3505 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3506 "isValueOrderAscending": false,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3507
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3508 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3509 * Defines the attribute used to order the results.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3510 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3511 * Default value is "null" to disable order by.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3512 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3513 "resultOrderByAttribute": null,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3514
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3515 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3516 * Defines whether the result query order by is ascending, if false order by will be descending.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3517 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3518 * Default value is true (ascending)
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3519 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3520 "isResultOrderAscending": true,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3521
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3522 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3523 * Defines the attribute of the node to use in query constraint for nodes of this label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3524 * This attribute is used in the generated cypher query to build the constraints with selected values.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3525 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3526 * The default value is the Neo4j internal id.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3527 * This id is used by default because it is a convenient way to identify a node when nothing is known about its attributes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3528 * But you should really consider using your application attributes instead, it is a bad practice to rely on this attribute.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3529 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3530 "constraintAttribute": popoto.query.NEO4J_INTERNAL_ID,
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3531
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3532 /**
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3533 * Defines the attribute of the node to display as a text identifying the node.
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3534 *
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3535 * The default value is the Neo4j internal id.
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3536 */
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3537 "displayAttribute": popoto.query.NEO4J_INTERNAL_ID,
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3538
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3539 /**
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3540 * Return the list of predefined constraints to add for the given label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3541 * These constraints will be added in every generated Cypher query.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3542 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3543 * For example if the returned list contain ["$identifier.born > 1976"] for "Person" nodes everywhere in popoto.js the generated Cypher query will add the constraint
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3544 * "WHERE person.born > 1976"
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3545 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3546 * @returns {Array}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3547 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3548 "getPredefinedConstraints": function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3549 return [];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3550 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3551
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3552 /**********************************************************************
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3553 * Node specific parameters:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3554 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3555 * These attributes are specific to nodes (in graph or query viewer) for a given label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3556 * But they can be customized for nodes of the same label.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3557 * The parameters are defined by a function that will be called with the node as parameter.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3558 * In this function the node internal attributes can be used to customize the value to return.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3559 **********************************************************************/
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3560
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3561 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3562 * Function returning the display type of a node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3563 * This type defines how the node will be drawn in the graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3564 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3565 * The result must be one of the following values:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3566 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3567 * popoto.provider.NodeDisplayTypes.IMAGE
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3568 * In this case the node will be drawn as an image and "getImagePath" function is required to return the node image path.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3569 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3570 * popoto.provider.NodeDisplayTypes.SVG
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3571 * In this case the node will be drawn as SVG paths and "getSVGPaths"
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3572 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3573 * popoto.provider.NodeDisplayTypes.TEXT
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3574 * In this case the node will be drawn as a simple ellipse.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3575 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3576 * Default value is TEXT.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3577 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3578 * @param node the node to extract its type.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3579 * @returns {number} one value from popoto.provider.NodeDisplayTypes
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3580 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3581 "getDisplayType": function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3582 return popoto.provider.NodeDisplayTypes.TEXT;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3583 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3584
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3585 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3586 * Function defining whether the node is a group node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3587 * In this case no count are displayed and no value can be selected on the node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3588 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3589 * Default value is false.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3590 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3591 "getIsGroup": function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3592 return false;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3593 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3594
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3595 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3596 * Function defining whether the node text representation must be displayed on graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3597 * If true the value returned for getTextValue on node will be displayed on graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3598 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3599 * This text will be added in addition to the getDisplayType representation.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3600 * It can be displayed on all type of node display, images, SVG or text.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3601 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3602 * Default value is true
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3603 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3604 * @param node the node to display on graph.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3605 * @returns {boolean} true if text must be displayed on graph for the node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3606 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3607 "getIsTextDisplayed": function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3608 return true;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3609 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3610
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3611 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3612 * Function used to return the text representation of a node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3613 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3614 * The default behavior is to return the label of the node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3615 * or the value of constraint attribute of the node if it contains value.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3616 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3617 * The returned value is truncated using popoto.graph.node.NODE_MAX_CHARS property.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3618 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3619 * @param node the node to represent as text.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3620 * @returns {string} the text representation of the node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3621 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3622 "getTextValue": function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3623 var text;
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3624 var textAttr = popoto.provider.getProperty(node.label, "displayAttribute");
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3625 if (node.type === popoto.graph.node.NodeTypes.VALUE) {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3626 if (textAttr === popoto.query.NEO4J_INTERNAL_ID) {
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3627 text = "" + node.internalID;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3628 } else {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3629 text = "" + node.attributes[textAttr];
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3630 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3631 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3632 if (node.value === undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3633 text = node.label;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3634 } else {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3635 if (textAttr === popoto.query.NEO4J_INTERNAL_ID) {
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3636 text = "" + node.value.internalID;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3637 } else {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3638 text = "" + node.value.attributes[textAttr];
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3639 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3640 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3641 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3642 // Text is truncated to fill the ellipse
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3643 return text.substring(0, popoto.graph.node.NODE_MAX_CHARS);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3644 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3645
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3646 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3647 * Function used to return a descriptive text representation of a link.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3648 * This representation should be more complete than getTextValue and can contain semantic data.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3649 * This function is used for example to generate the label in the query viewer.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3650 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3651 * The default behavior is to return the getTextValue not truncated.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3652 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3653 * @param node the node to represent as text.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3654 * @returns {string} the text semantic representation of the node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3655 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3656 "getSemanticValue": function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3657 var text;
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3658 var textAttr = popoto.provider.getProperty(node.label, "displayAttribute");
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3659 if (node.type === popoto.graph.node.NodeTypes.VALUE) {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3660 if (textAttr === popoto.query.NEO4J_INTERNAL_ID) {
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3661 text = "" + node.internalID;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3662 } else {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3663 text = "" + node.attributes[textAttr];
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3664 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3665 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3666 if (node.value === undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3667 text = node.label;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3668 } else {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3669 if (textAttr === popoto.query.NEO4J_INTERNAL_ID) {
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3670 text = "" + node.value.internalID;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3671 } else {
1
db013b2f3e10 added displayAttribute to show on individual nodes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
3672 text = "" + node.value.attributes[textAttr];
0
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3673 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3674 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3675 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3676 return text;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3677 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3678
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3679 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3680 * Function returning the image file path to use for a node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3681 * This function is only used for popoto.provider.NodeDisplayTypes.IMAGE type nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3682 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3683 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3684 * @returns {string}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3685 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3686 "getImagePath": function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3687 if (node.type === popoto.graph.node.NodeTypes.VALUE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3688 return "css/image/node-yellow.png";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3689 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3690 if (node.value === undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3691 if (node.type === popoto.graph.node.NodeTypes.ROOT) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3692 return "css/image/node-blue.png";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3693 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3694 if (node.type === popoto.graph.node.NodeTypes.CHOOSE) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3695 return "css/image/node-green.png";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3696 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3697 if (node.type === popoto.graph.node.NodeTypes.GROUP) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3698 return "css/image/node-black.png";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3699 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3700 } else {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3701 return "css/image/node-orange.png";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3702 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3703 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3704 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3705
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3706 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3707 * Function returning the image width of the node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3708 * This function is only used for popoto.provider.NodeDisplayTypes.IMAGE type nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3709 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3710 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3711 * @returns {number}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3712 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3713 "getImageWidth": function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3714 return 125;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3715 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3716
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3717 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3718 * Function returning the image height of the node.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3719 * This function is only used for popoto.provider.NodeDisplayTypes.IMAGE type nodes.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3720 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3721 * @param node
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3722 * @returns {number}
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3723 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3724 "getImageHeight": function (node) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3725 return 125;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3726 },
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3727
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3728 /**********************************************************************
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3729 * Results specific parameters:
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3730 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3731 * These attributes are specific to result display.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3732 **********************************************************************/
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3733
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3734 /**
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3735 * Generate the result entry content using d3.js mechanisms.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3736 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3737 * The parameter of the function is the &lt;p&gt; selected with d3.js
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3738 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3739 * The default behavior is to generate a &lt;table&gt; containing all the return attributes in a &lt;th&gt; and their value in a &lt;td&gt;.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3740 *
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3741 * @param pElmt the &lt;p&gt; element generated in the result list.
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3742 */
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3743 "displayResults": function (pElmt) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3744 var result = pElmt.data()[0];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3745
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3746 var returnAttributes = popoto.provider.getReturnAttributes(result.label);
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3747
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3748 var table = pElmt.append("table").attr("class", "ppt-result-table");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3749
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3750 returnAttributes.forEach(function (attribute) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3751 var tr = table.append("tr");
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3752 tr.append("th").text(function () {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3753 return attribute + ":";
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3754 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3755 if (result.attributes[attribute] !== undefined) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3756 tr.append("td").text(function (result) {
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3757 return result.attributes[attribute];
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3758 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3759 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3760 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3761 }
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3762
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3763 });
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3764
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3765 return popoto;
3b8b5aa8ab65 first check-in
casties
parents:
diff changeset
3766 }();