1 | $(function() { |
---|
2 | |
---|
3 | // Graph class |
---|
4 | |
---|
5 | function Graph(containerName) { |
---|
6 | var self = this; |
---|
7 | var _id; |
---|
8 | var _type; |
---|
9 | var _size; |
---|
10 | var _data; |
---|
11 | var _graphObject; |
---|
12 | var _title; |
---|
13 | this._container = document.getElementById(containerName); |
---|
14 | |
---|
15 | this.init = function(id, data, type, size, title) { |
---|
16 | // Draw the graph to the element |
---|
17 | _id = id; |
---|
18 | _data = data; |
---|
19 | _type = type; |
---|
20 | _size = size; |
---|
21 | if (title) _title = title; |
---|
22 | |
---|
23 | var canvas = document.createElement("canvas"); |
---|
24 | canvas.id = id; |
---|
25 | canvas.className = "graphDisplay"; |
---|
26 | canvas.width = _size[0]; |
---|
27 | canvas.height = size[1]; |
---|
28 | self._container.appendChild(canvas); |
---|
29 | |
---|
30 | switch (_type) { |
---|
31 | case "Pie": |
---|
32 | // Hardcoded data |
---|
33 | // Participant age |
---|
34 | _data = [5,7,9,4]; |
---|
35 | _graphObject = new RGraph.Pie(_id, _data); |
---|
36 | _graphObject.Set('chart.labels', ['20-30 (20 participants)', '30-40 (28 participants)', '40-50 (36 participants)', '50+ (16 participants)']); |
---|
37 | _graphObject.Set('chart.text.color', '#fff'); |
---|
38 | break; |
---|
39 | case "Bar": |
---|
40 | // Hardcoded data |
---|
41 | // Quality of control |
---|
42 | _data = [4,20,50,18,8]; |
---|
43 | _graphObject = new RGraph.Bar(_id, _data); |
---|
44 | _graphObject.Set('chart.labels', ['Bad','Subpar','Average','Above average','Good']); |
---|
45 | _graphObject.Set('chart.text.color', '#fff'); |
---|
46 | break; |
---|
47 | case "Radar": |
---|
48 | //Hardcoded data |
---|
49 | // Gameplay errors |
---|
50 | _data = [24,20,26,35,36,29,25,16]; |
---|
51 | _graphObject = new RGraph.Radar(_id, _data); |
---|
52 | _graphObject.Set('chart.labels',['Bram','Paula','Jules','Joel','Tyrone','Henk','Darcy','Frans']); |
---|
53 | _graphObject.Set('chart.text.color', '#000'); |
---|
54 | _graphObject.Set('chart.strokestyle','black'); |
---|
55 | |
---|
56 | break; |
---|
57 | case "Rose": |
---|
58 | _graphObject = new RGraph.Rose(_id, _data); |
---|
59 | _graphObject.Set('chart.text.color', '#000'); |
---|
60 | break; |
---|
61 | } |
---|
62 | |
---|
63 | // Set standard properties. |
---|
64 | _graphObject.Set('chart.shadow', false); |
---|
65 | _graphObject.Set('chart.colors', ['rgba(240,240,240,0.5)', 'rgba(240,240,240,0.5)', 'rgba(240,240,240,0.5)']); |
---|
66 | _graphObject.Set('chart.axis.color', 'rgba(240,240,240,0.5)'); |
---|
67 | _graphObject.Set('chart.strokestyle', 'rgba(240,240,240,1.0)'); |
---|
68 | if (title) { |
---|
69 | _graphObject.Set('chart.title', title); |
---|
70 | _graphObject.Set('chart.title.color', 'white'); |
---|
71 | } |
---|
72 | |
---|
73 | //enlarge click event |
---|
74 | if (canvas.id == "enlarged") { |
---|
75 | canvas.addEventListener("click", function(event) { |
---|
76 | self.closeLarge(self); |
---|
77 | }, true); |
---|
78 | canvas.className = "fullGraphDisplay"; |
---|
79 | } |
---|
80 | else { |
---|
81 | canvas.addEventListener("click", function(event) { |
---|
82 | self.enlarge(); |
---|
83 | }, true); |
---|
84 | } |
---|
85 | // Draw |
---|
86 | _graphObject.Draw(); |
---|
87 | } |
---|
88 | |
---|
89 | this.getId = function() { |
---|
90 | return _id; |
---|
91 | } |
---|
92 | this.getType = function() { |
---|
93 | return _type; |
---|
94 | } |
---|
95 | |
---|
96 | this.enlarge = function() { |
---|
97 | // Check if already enlarged? |
---|
98 | debugger; |
---|
99 | var present = document.getElementById("largeContainer"); |
---|
100 | if (present != null) return; |
---|
101 | |
---|
102 | var largeContainer = document.createElement("div"); |
---|
103 | largeContainer.className = "fullscreenGraphContainer"; // make css! |
---|
104 | largeContainer.id = "largeContainer"; |
---|
105 | |
---|
106 | // TESTING!!!! /////////////////////////////// |
---|
107 | $("#content").append(largeContainer); |
---|
108 | $(".basePanel").addClass("hidden"); |
---|
109 | |
---|
110 | // END TESTING ////////////////////////// |
---|
111 | /* |
---|
112 | $(".basePanel").append(largeContainer); |
---|
113 | */ |
---|
114 | var largeGraph = new Graph("largeContainer"); |
---|
115 | largeGraph.init("enlarged", _data, _type, [900,550], _title); |
---|
116 | var clearDiv = document.createElement("div"); |
---|
117 | $(clearDiv).css("float", "left").css("clear", "both"); |
---|
118 | largeGraph._container.appendChild(clearDiv); |
---|
119 | } |
---|
120 | |
---|
121 | this.closeLarge = function(graph) { |
---|
122 | debugger; |
---|
123 | self._container.parentNode.removeChild(self._container); |
---|
124 | $(".basePanel").removeClass('hidden'); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | window.Graph = Graph; |
---|
129 | |
---|
130 | }); |
---|