1 | import * as d3 from "d3";
|
2 | import {version} from "../dist/package";
|
3 | import dataModel from "./datamodel/dataModel";
|
4 | import cypherviewer from "./cypherviewer/cypherviewer";
|
5 | import graph from "./graph/graph";
|
6 | import logger from "./logger/logger";
|
7 | import provider from "./provider/provider";
|
8 | import queryviewer from "./queryviewer/queryviewer";
|
9 | import runner from "./runner/runner";
|
10 | import result from "./result/result";
|
11 | import taxonomy from "./taxonomy/taxonomy";
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export function start(startParam) {
|
20 | logger.info("Popoto " + version + " start on " + startParam);
|
21 |
|
22 | graph.mainLabel = startParam;
|
23 |
|
24 | checkHtmlComponents();
|
25 |
|
26 | if (taxonomy.isActive) {
|
27 | taxonomy.createTaxonomyPanel();
|
28 | }
|
29 |
|
30 | if (graph.isActive) {
|
31 | graph.createGraphArea();
|
32 | graph.createForceLayout();
|
33 |
|
34 | if (typeof startParam === 'string' || startParam instanceof String) {
|
35 | var labelSchema = provider.node.getSchema(startParam);
|
36 | if (labelSchema !== undefined) {
|
37 | graph.addSchema(labelSchema);
|
38 | } else {
|
39 | graph.addRootNode(startParam);
|
40 | }
|
41 | } else {
|
42 | graph.loadSchema(startParam);
|
43 | }
|
44 | }
|
45 |
|
46 | if (queryviewer.isActive) {
|
47 | queryviewer.createQueryArea();
|
48 | }
|
49 |
|
50 | if (cypherviewer.isActive) {
|
51 | cypherviewer.createQueryArea();
|
52 | }
|
53 |
|
54 | if (graph.USE_VORONOI_LAYOUT === true) {
|
55 | graph.voronoi.extent([[-popoto.graph.getSVGWidth(), -popoto.graph.getSVGWidth()], [popoto.graph.getSVGWidth() * 2, popoto.graph.getSVGHeight() * 2]]);
|
56 | }
|
57 |
|
58 | update();
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function checkHtmlComponents() {
|
65 | var graphHTMLContainer = d3.select("#" + graph.containerId);
|
66 | var taxonomyHTMLContainer = d3.select("#" + taxonomy.containerId);
|
67 | var queryHTMLContainer = d3.select("#" + queryviewer.containerId);
|
68 | var cypherHTMLContainer = d3.select("#" + cypherviewer.containerId);
|
69 | var resultsHTMLContainer = d3.select("#" + result.containerId);
|
70 |
|
71 | if (graphHTMLContainer.empty()) {
|
72 | logger.debug("The page doesn't contain a container with ID = \"" + graph.containerId + "\" no graph area will be generated. This ID is defined in graph.containerId property.");
|
73 | graph.isActive = false;
|
74 | } else {
|
75 | graph.isActive = true;
|
76 | }
|
77 |
|
78 | if (taxonomyHTMLContainer.empty()) {
|
79 | logger.debug("The page doesn't contain a container with ID = \"" + taxonomy.containerId + "\" no taxonomy filter will be generated. This ID is defined in taxonomy.containerId property.");
|
80 | taxonomy.isActive = false;
|
81 | } else {
|
82 | taxonomy.isActive = true;
|
83 | }
|
84 |
|
85 | if (queryHTMLContainer.empty()) {
|
86 | logger.debug("The page doesn't contain a container with ID = \"" + queryviewer.containerId + "\" no query viewer will be generated. This ID is defined in queryviewer.containerId property.");
|
87 | queryviewer.isActive = false;
|
88 | } else {
|
89 | queryviewer.isActive = true;
|
90 | }
|
91 |
|
92 | if (cypherHTMLContainer.empty()) {
|
93 | logger.debug("The page doesn't contain a container with ID = \"" + cypherviewer.containerId + "\" no cypher query viewer will be generated. This ID is defined in cypherviewer.containerId property.");
|
94 | cypherviewer.isActive = false;
|
95 | } else {
|
96 | cypherviewer.isActive = true;
|
97 | }
|
98 |
|
99 | if (resultsHTMLContainer.empty()) {
|
100 | logger.debug("The page doesn't contain a container with ID = \"" + result.containerId + "\" no result area will be generated. This ID is defined in result.containerId property.");
|
101 | result.isActive = false;
|
102 | } else {
|
103 | result.isActive = true;
|
104 | }
|
105 | }
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | export function update() {
|
111 | updateGraph();
|
112 |
|
113 |
|
114 | var root = dataModel.getRootNode();
|
115 |
|
116 | if (!root || root.label === undefined) {
|
117 | return;
|
118 | }
|
119 |
|
120 | if (queryviewer.isActive) {
|
121 | queryviewer.updateQuery();
|
122 | }
|
123 | if (cypherviewer.isActive) {
|
124 | cypherviewer.updateQuery();
|
125 | }
|
126 |
|
127 |
|
128 |
|
129 | if (result.isActive || result.resultListeners.length > 0 || result.resultCountListeners.length > 0 || result.graphResultListeners.length > 0) {
|
130 | result.updateResults();
|
131 | }
|
132 | }
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | export function updateGraph() {
|
138 | if (graph.isActive) {
|
139 |
|
140 |
|
141 |
|
142 | graph.link.updateLinks();
|
143 | graph.node.updateNodes();
|
144 |
|
145 |
|
146 | graph.force.nodes(dataModel.nodes);
|
147 | graph.force.force("link").links(dataModel.links);
|
148 | graph.force.alpha(1).restart();
|
149 | }
|
150 | } |
\ | No newline at end of file |