UNPKG

2.68 kBJavaScriptView Raw
1import graph from "../graph/graph";
2import tools from "../tools/tools";
3
4var toolbar = {};
5
6toolbar.TOOL_TAXONOMY = "Show/hide taxonomy panel";
7toolbar.TOOL_RELATION = "Show/hide relation";
8toolbar.TOOL_CENTER = "Center view";
9toolbar.TOOL_FULL_SCREEN = "Full screen";
10toolbar.TOOL_RESET = "Reset graph";
11toolbar.TOOL_SAVE = "Save graph";
12toolbar.TOOL_FIT_TEXT = "Fit text in nodes";
13
14toolbar.render = function (container) {
15 var toolbar = container
16 .append("div")
17 .attr("class", "ppt-toolbar");
18
19 if (tools.TOGGLE_VIEW_RELATION) {
20 toolbar.append("span")
21 .attr("id", "popoto-toggle-relation")
22 .attr("class", "ppt-icon ppt-menu relation")
23 .attr("title", toolbar.TOOL_RELATION)
24 .on("click", function () {
25 tools.toggleViewRelation();
26 });
27 }
28
29 if (tools.RESET_GRAPH) {
30 toolbar.append("span")
31 .attr("id", "popoto-reset-menu")
32 .attr("class", "ppt-icon ppt-menu reset")
33 .attr("title", toolbar.TOOL_RESET)
34 .on("click", function () {
35 graph.notifyListeners(graph.Events.GRAPH_RESET, []);
36 tools.reset();
37 });
38 }
39
40 if (tools.TOGGLE_TAXONOMY) {
41 toolbar.append("span")
42 .attr("id", "popoto-taxonomy-menu")
43 .attr("class", "ppt-icon ppt-menu taxonomy")
44 .attr("title", toolbar.TOOL_TAXONOMY)
45 .on("click", tools.toggleTaxonomy);
46 }
47
48 if (tools.CENTER_GRAPH) {
49 toolbar.append("span")
50 .attr("id", "popoto-center-menu")
51 .attr("class", "ppt-icon ppt-menu center")
52 .attr("title", toolbar.TOOL_CENTER)
53 .on("click", tools.center);
54 }
55
56 if (tools.TOGGLE_FULL_SCREEN) {
57 toolbar.append("span")
58 .attr("id", "popoto-fullscreen-menu")
59 .attr("class", "ppt-icon ppt-menu fullscreen")
60 .attr("title", toolbar.TOOL_FULL_SCREEN)
61 .on("click", tools.toggleFullScreen);
62 }
63
64 if (tools.SAVE_GRAPH) {
65 toolbar.append("span")
66 .attr("id", "popoto-save-menu")
67 .attr("class", "ppt-icon ppt-menu save")
68 .attr("title", toolbar.TOOL_SAVE)
69 .on("click", function () {
70 graph.notifyListeners(graph.Events.GRAPH_SAVE, [graph.getSchema()]);
71 });
72 }
73
74 if (tools.TOGGLE_FIT_TEXT) {
75 toolbar.append("span")
76 .attr("id", "popoto-fit-text-menu")
77 .attr("class", "ppt-icon ppt-menu fit-text")
78 .attr("title", toolbar.TOOL_FIT_TEXT)
79 .on("click", tools.toggleFitText);
80 }
81};
82
83export default toolbar