annotate popoto_dev/src/js/popoto.js @ 23:80010fb9dbce

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