rgraph-rails 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rgraph-rails/version.rb +3 -0
- data/lib/rgraph-rails.rb +8 -0
- data/license.txt +19 -0
- data/rgraph-rails.gemspec +26 -0
- data/vendor/assets/images/bg.png +0 -0
- data/vendor/assets/images/bullet.png +0 -0
- data/vendor/assets/images/facebook-large.png +0 -0
- data/vendor/assets/images/google-plus-large.png +0 -0
- data/vendor/assets/images/logo.png +0 -0
- data/vendor/assets/images/meter-image-sd-needle.png +0 -0
- data/vendor/assets/images/meter-image-sd.png +0 -0
- data/vendor/assets/images/meter-sketch-needle.png +0 -0
- data/vendor/assets/images/meter-sketch.png +0 -0
- data/vendor/assets/images/odometer-background.png +0 -0
- data/vendor/assets/images/rgraph.jpg +0 -0
- data/vendor/assets/images/title.png +0 -0
- data/vendor/assets/images/twitter-large.png +0 -0
- data/vendor/assets/javascripts/RGraph.bar.js +3246 -0
- data/vendor/assets/javascripts/RGraph.bipolar.js +2003 -0
- data/vendor/assets/javascripts/RGraph.common.annotate.js +399 -0
- data/vendor/assets/javascripts/RGraph.common.context.js +600 -0
- data/vendor/assets/javascripts/RGraph.common.core.js +4751 -0
- data/vendor/assets/javascripts/RGraph.common.csv.js +275 -0
- data/vendor/assets/javascripts/RGraph.common.deprecated.js +454 -0
- data/vendor/assets/javascripts/RGraph.common.dynamic.js +1194 -0
- data/vendor/assets/javascripts/RGraph.common.effects.js +1524 -0
- data/vendor/assets/javascripts/RGraph.common.key.js +735 -0
- data/vendor/assets/javascripts/RGraph.common.resizing.js +550 -0
- data/vendor/assets/javascripts/RGraph.common.tooltips.js +605 -0
- data/vendor/assets/javascripts/RGraph.common.zoom.js +223 -0
- data/vendor/assets/javascripts/RGraph.drawing.background.js +636 -0
- data/vendor/assets/javascripts/RGraph.drawing.circle.js +579 -0
- data/vendor/assets/javascripts/RGraph.drawing.image.js +810 -0
- data/vendor/assets/javascripts/RGraph.drawing.marker1.js +710 -0
- data/vendor/assets/javascripts/RGraph.drawing.marker2.js +672 -0
- data/vendor/assets/javascripts/RGraph.drawing.marker3.js +568 -0
- data/vendor/assets/javascripts/RGraph.drawing.poly.js +623 -0
- data/vendor/assets/javascripts/RGraph.drawing.rect.js +603 -0
- data/vendor/assets/javascripts/RGraph.drawing.text.js +648 -0
- data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +815 -0
- data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +860 -0
- data/vendor/assets/javascripts/RGraph.fuel.js +965 -0
- data/vendor/assets/javascripts/RGraph.funnel.js +988 -0
- data/vendor/assets/javascripts/RGraph.gantt.js +1242 -0
- data/vendor/assets/javascripts/RGraph.gauge.js +1391 -0
- data/vendor/assets/javascripts/RGraph.hbar.js +1794 -0
- data/vendor/assets/javascripts/RGraph.hprogress.js +1307 -0
- data/vendor/assets/javascripts/RGraph.line.js +3940 -0
- data/vendor/assets/javascripts/RGraph.meter.js +1242 -0
- data/vendor/assets/javascripts/RGraph.modaldialog.js +292 -0
- data/vendor/assets/javascripts/RGraph.odo.js +1265 -0
- data/vendor/assets/javascripts/RGraph.pie.js +1979 -0
- data/vendor/assets/javascripts/RGraph.radar.js +1840 -0
- data/vendor/assets/javascripts/RGraph.rose.js +1860 -0
- data/vendor/assets/javascripts/RGraph.rscatter.js +1332 -0
- data/vendor/assets/javascripts/RGraph.scatter.js +3029 -0
- data/vendor/assets/javascripts/RGraph.thermometer.js +1131 -0
- data/vendor/assets/javascripts/RGraph.vprogress.js +1326 -0
- data/vendor/assets/javascripts/RGraph.waterfall.js +1252 -0
- data/vendor/assets/javascripts/financial-data.js +1067 -0
- data/vendor/assets/stylesheets/ModalDialog.css +90 -0
- data/vendor/assets/stylesheets/animations.css +3347 -0
- data/vendor/assets/stylesheets/website.css +402 -0
- metadata +175 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// version: 2015-11-02
|
|
2
|
+
/**
|
|
3
|
+
* o--------------------------------------------------------------------------------o
|
|
4
|
+
* | This file is part of the RGraph package - you can learn more at: |
|
|
5
|
+
* | |
|
|
6
|
+
* | http://www.rgraph.net |
|
|
7
|
+
* | |
|
|
8
|
+
* | RGraph is dual licensed under the Open Source GPL (General Public License) |
|
|
9
|
+
* | v2.0 license and a commercial license which means that you're not bound by |
|
|
10
|
+
* | the terms of the GPL. The commercial license is just �99 (GBP) and you can |
|
|
11
|
+
* | read about it here: |
|
|
12
|
+
* | http://www.rgraph.net/license |
|
|
13
|
+
* o--------------------------------------------------------------------------------o
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
RGraph = window.RGraph || {isRGraph: true};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// Module pattern
|
|
20
|
+
(function (win, doc, undefined)
|
|
21
|
+
{
|
|
22
|
+
var RG = RGraph,
|
|
23
|
+
ua = navigator.userAgent,
|
|
24
|
+
ma = Math;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A zoom in function
|
|
31
|
+
*
|
|
32
|
+
* @param e object The event object
|
|
33
|
+
*/
|
|
34
|
+
RG.zoom =
|
|
35
|
+
RG.Zoom = function (e)
|
|
36
|
+
{
|
|
37
|
+
e = RGraph.fixEventObject(e);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Triggered from a context menu
|
|
42
|
+
*/
|
|
43
|
+
if (e && e.target && e.target.__canvas__) {
|
|
44
|
+
var canvas = e.target.__canvas__;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* This is here to facilitate zooming by just a single left click
|
|
48
|
+
*/
|
|
49
|
+
} else if (e && e.target && e.target.__object__) {
|
|
50
|
+
var canvas = e.target.__object__.canvas;
|
|
51
|
+
e.stopPropagation(); // Hmmmm
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Fallback for MSIE9
|
|
55
|
+
if (!canvas) {
|
|
56
|
+
var registry_canvas = RGraph.Registry.get('chart.contextmenu').__canvas__;
|
|
57
|
+
if (registry_canvas) {
|
|
58
|
+
var canvas = registry_canvas;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var obj = canvas.__object__;
|
|
63
|
+
var context = obj.context;
|
|
64
|
+
var dataurl = canvas.toDataURL();
|
|
65
|
+
var tmp = canvas;
|
|
66
|
+
var coords = RG.getCanvasXY(canvas);
|
|
67
|
+
var factor = obj.Get('chart.zoom.factor') - 1;
|
|
68
|
+
|
|
69
|
+
var x = coords[0];
|
|
70
|
+
var y = coords[1];
|
|
71
|
+
|
|
72
|
+
var img = document.createElement('img');
|
|
73
|
+
img.className = 'RGraph_zoomed_canvas';
|
|
74
|
+
img.style.border = '1px solid #ccc';
|
|
75
|
+
img.style.width = canvas.width + 'px';
|
|
76
|
+
img.style.height = canvas.height + 'px';
|
|
77
|
+
img.style.position = 'absolute';
|
|
78
|
+
img.style.left = x + 'px';
|
|
79
|
+
img.style.top = y + 'px';
|
|
80
|
+
img.style.backgroundColor = 'white';
|
|
81
|
+
img.style.opacity = obj.Get('chart.zoom.fade.in') ? 0 : 1;
|
|
82
|
+
img.style.zIndex = 99;
|
|
83
|
+
img.src = dataurl;
|
|
84
|
+
document.body.appendChild(img);
|
|
85
|
+
|
|
86
|
+
//RGraph.Registry.Set('chart.zoomedimage', img);
|
|
87
|
+
// Store the zoomed image in a global var - NOT the registry
|
|
88
|
+
RGraph.zoom_image = img;
|
|
89
|
+
RGraph.zoom_image.obj = obj;
|
|
90
|
+
|
|
91
|
+
// Image onclick should not hide the image
|
|
92
|
+
img.onclick = function (e)
|
|
93
|
+
{
|
|
94
|
+
e = RGraph.fixEventObject(e);
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//setTimeout(function (){document.body.onclick = RGraph.HideZoomedCanvas;}, 1);
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
var width = parseInt(canvas.width);
|
|
103
|
+
var height = parseInt(canvas.height);
|
|
104
|
+
var frames = obj.Get('chart.zoom.frames');
|
|
105
|
+
var delay = obj.Get('chart.zoom.delay');
|
|
106
|
+
|
|
107
|
+
// Increase the width over 10 frames - center
|
|
108
|
+
if (obj.Get('chart.zoom.hdir') == 'center') {
|
|
109
|
+
|
|
110
|
+
for (var i=1; i<=frames; ++i) {
|
|
111
|
+
var newWidth = width * factor * (i/frames) + width;
|
|
112
|
+
var rightHandEdge = x + canvas.width;
|
|
113
|
+
var newLeft = (x + (canvas.width / 2)) - (newWidth / 2);
|
|
114
|
+
|
|
115
|
+
setTimeout("RGraph.zoom_image.style.width = '" + String(newWidth) + "px'; RGraph.zoom_image.style.left = '" + newLeft + "px'", i * delay);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Left
|
|
119
|
+
} else if (obj.Get('chart.zoom.hdir') == 'left') {
|
|
120
|
+
for (var i=1; i<=frames; ++i) {
|
|
121
|
+
var newWidth = width * factor * (i/frames) + width;
|
|
122
|
+
var rightHandEdge = x + canvas.width;
|
|
123
|
+
var newLeft = rightHandEdge - newWidth;
|
|
124
|
+
|
|
125
|
+
setTimeout("RGraph.zoom_image.style.width = '" + String(newWidth) + "px'; RGraph.zoom_image.style.left = '" + newLeft + "px'", i * delay);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Right (default)
|
|
129
|
+
} else {
|
|
130
|
+
for (var i=1; i<=frames; ++i) {
|
|
131
|
+
var newWidth = width * factor * (i/frames) + width;
|
|
132
|
+
setTimeout("RGraph.zoom_image.style.width = '" + String(newWidth) + "px'", i * delay);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Increase the height over 10 frames - up
|
|
137
|
+
if (obj.Get('chart.zoom.vdir') == 'up') {
|
|
138
|
+
for (var i=1; i<=frames; ++i) {
|
|
139
|
+
var newHeight = (height * factor * (i/frames)) + height;
|
|
140
|
+
var bottomEdge = y + canvas.height;
|
|
141
|
+
var newTop = bottomEdge - newHeight;
|
|
142
|
+
|
|
143
|
+
setTimeout("RGraph.zoom_image.style.height = '" + String(newHeight) + "px'; RGraph.zoom_image.style.top = '" + newTop + "px'", i * delay);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// center
|
|
147
|
+
} else if (obj.Get('chart.zoom.vdir') == 'center') {
|
|
148
|
+
for (var i=1; i<=frames; ++i) {
|
|
149
|
+
var newHeight = (height * factor * (i/frames)) + height;
|
|
150
|
+
var bottomEdge = (y + (canvas.height / 2)) + (newHeight / 2);
|
|
151
|
+
var newTop = bottomEdge - newHeight;
|
|
152
|
+
|
|
153
|
+
setTimeout("RGraph.zoom_image.style.height = '" + String(newHeight) + "px'; RGraph.zoom_image.style.top = '" + newTop + "px'", i * delay);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Down (default
|
|
157
|
+
} else {
|
|
158
|
+
for (var i=1; i<=frames; ++i) {
|
|
159
|
+
setTimeout("RGraph.zoom_image.style.height = '" + String(height * factor * (i/frames) + height) + "px'", i * delay);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// If enabled, increase the opactity over the requested number of frames
|
|
164
|
+
if (obj.Get('chart.zoom.fade.in')) {
|
|
165
|
+
for (var i=1; i<=frames; ++i) {
|
|
166
|
+
setTimeout("RGraph.zoom_image.style.opacity = " + Number(i / frames), i * (delay / 2));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// If stipulated, produce a shadow
|
|
171
|
+
if (obj.Get('chart.zoom.shadow')) {
|
|
172
|
+
for (var i=1; i<=frames; ++i) {
|
|
173
|
+
setTimeout("RGraph.zoom_image.style.boxShadow = 'rgba(128,128,128," + Number(i / frames) / 2 + ") 0 0 25px'", i * delay);
|
|
174
|
+
setTimeout("RGraph.zoom_image.style.MozBoxShadow = 'rgba(128,128,128," + Number(i / frames) / 2 + ") 0 0 25px'", i * delay);
|
|
175
|
+
setTimeout("RGraph.zoom_image.style.WebkitBoxShadow = 'rgba(128,128,128," + Number(i / frames) / 2 + ") 0 0 25px'", i * delay);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Create the background. As of March 2013 this is always done
|
|
183
|
+
*/
|
|
184
|
+
var div = document.createElement('DIV');
|
|
185
|
+
div.style.backgroundColor = 'white';
|
|
186
|
+
div.style.opacity = 0;
|
|
187
|
+
div.style.position = 'fixed';
|
|
188
|
+
div.style.top = 0;
|
|
189
|
+
div.style.left = 0;
|
|
190
|
+
div.style.width = (screen.width + 100) + 'px';
|
|
191
|
+
div.style.height = (screen.height + 100) + 'px';
|
|
192
|
+
div.style.zIndex = 98;
|
|
193
|
+
|
|
194
|
+
// Hides the zoomed caboodle
|
|
195
|
+
div.onclick =
|
|
196
|
+
div.oncontextmenu = function (e)
|
|
197
|
+
{
|
|
198
|
+
return RG.hideZoomedCanvas(e);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
div.origHeight = div.style.height;
|
|
202
|
+
|
|
203
|
+
document.body.appendChild(div);
|
|
204
|
+
|
|
205
|
+
RG.zoom_background = div;
|
|
206
|
+
|
|
207
|
+
// If the window is resized, hide the zoom
|
|
208
|
+
//window.onresize = RGraph.HideZoomedCanvas;
|
|
209
|
+
|
|
210
|
+
for (var i=1; i<=frames; ++i) {
|
|
211
|
+
setTimeout("RGraph.zoom_background.style.opacity = " + (Number(i / frames) * 0.8), i * (delay / 2));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Fire the onzoom event
|
|
216
|
+
*/
|
|
217
|
+
RG.fireCustomEvent(obj, 'onzoom');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
// End module pattern
|
|
223
|
+
})(window, document);
|
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
// version: 2015-11-02
|
|
2
|
+
/**
|
|
3
|
+
* o--------------------------------------------------------------------------------o
|
|
4
|
+
* | This file is part of the RGraph package - you can learn more at: |
|
|
5
|
+
* | |
|
|
6
|
+
* | http://www.rgraph.net |
|
|
7
|
+
* | |
|
|
8
|
+
* | RGraph is dual licensed under the Open Source GPL (General Public License) |
|
|
9
|
+
* | v2.0 license and a commercial license which means that you're not bound by |
|
|
10
|
+
* | the terms of the GPL. The commercial license is just �99 (GBP) and you can |
|
|
11
|
+
* | read about it here: |
|
|
12
|
+
* | http://www.rgraph.net/license |
|
|
13
|
+
* o--------------------------------------------------------------------------------o
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Having this here means that the RGraph libraries can be included in any order, instead of you having
|
|
18
|
+
* to include the common core library first.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// Define the RGraph global variable
|
|
22
|
+
RGraph = window.RGraph || {isRGraph: true};
|
|
23
|
+
RGraph.Drawing = RGraph.Drawing || {};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The constructor. This function sets up the object. It only takes the ID (the HTML attribute) of the canvas as the
|
|
27
|
+
* first argument - the gutters are set as properties.
|
|
28
|
+
*
|
|
29
|
+
* @param string id The canvas tag ID
|
|
30
|
+
*/
|
|
31
|
+
RGraph.Drawing.Background = function (conf)
|
|
32
|
+
{
|
|
33
|
+
/**
|
|
34
|
+
* Allow for object config style
|
|
35
|
+
*/
|
|
36
|
+
if ( typeof conf === 'object'
|
|
37
|
+
&& typeof conf.id === 'string') {
|
|
38
|
+
|
|
39
|
+
var id = conf.id
|
|
40
|
+
var canvas = document.getElementById(id);
|
|
41
|
+
|
|
42
|
+
var parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor)
|
|
43
|
+
|
|
44
|
+
} else {
|
|
45
|
+
|
|
46
|
+
var id = conf;
|
|
47
|
+
var canvas = document.getElementById(id);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
this.id = id;
|
|
54
|
+
this.canvas = document.getElementById(this.id);
|
|
55
|
+
this.context = this.canvas.getContext('2d');
|
|
56
|
+
this.canvas.__object__ = this;
|
|
57
|
+
this.original_colors = [];
|
|
58
|
+
this.firstDraw = true; // After the first draw this will be false
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* This defines the type of this shape
|
|
63
|
+
*/
|
|
64
|
+
this.type = 'drawing.background';
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* This facilitates easy object identification, and should always be true
|
|
69
|
+
*/
|
|
70
|
+
this.isRGraph = true;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* This adds a uid to the object that you can use for identification purposes
|
|
75
|
+
*/
|
|
76
|
+
this.uid = RGraph.CreateUID();
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* This adds a UID to the canvas for identification purposes
|
|
81
|
+
*/
|
|
82
|
+
this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.createUID();
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Some example background properties
|
|
89
|
+
*/
|
|
90
|
+
this.properties =
|
|
91
|
+
{
|
|
92
|
+
'chart.background.barcolor1': 'rgba(0,0,0,0)',
|
|
93
|
+
'chart.background.barcolor2': 'rgba(0,0,0,0)',
|
|
94
|
+
'chart.background.grid': true,
|
|
95
|
+
'chart.background.grid.color': '#ddd',
|
|
96
|
+
'chart.background.grid.width': 1,
|
|
97
|
+
'chart.background.grid.vlines': true,
|
|
98
|
+
'chart.background.grid.hlines': true,
|
|
99
|
+
'chart.background.grid.border': true,
|
|
100
|
+
'chart.background.grid.autofit':true,
|
|
101
|
+
'chart.background.grid.autofit.numhlines': 5,
|
|
102
|
+
'chart.background.grid.autofit.numvlines': 20,
|
|
103
|
+
'chart.background.grid.dashed': false,
|
|
104
|
+
'chart.background.grid.dotted': false,
|
|
105
|
+
|
|
106
|
+
'chart.background.image': null,
|
|
107
|
+
'chart.background.image.stretch': true,
|
|
108
|
+
'chart.background.image.x': null,
|
|
109
|
+
'chart.background.image.y': null,
|
|
110
|
+
'chart.background.image.w': null,
|
|
111
|
+
'chart.background.image.h': null,
|
|
112
|
+
'chart.background.image.align': null,
|
|
113
|
+
'chart.background.color': null,
|
|
114
|
+
|
|
115
|
+
'chart.gutter.left': 25,
|
|
116
|
+
'chart.gutter.right': 25,
|
|
117
|
+
'chart.gutter.top': 25,
|
|
118
|
+
'chart.gutter.bottom': 25,
|
|
119
|
+
|
|
120
|
+
'chart.text.color': 'black', // Gradients aren't supported for this color
|
|
121
|
+
'chart.text.size': 12,
|
|
122
|
+
'chart.text.font': 'Arial',
|
|
123
|
+
|
|
124
|
+
'chart.events.click': null,
|
|
125
|
+
'chart.events.mousemove': null,
|
|
126
|
+
|
|
127
|
+
'chart.tooltips': null,
|
|
128
|
+
'chart.tooltips.highlight': true,
|
|
129
|
+
'chart.tooltips.event': 'onclick',
|
|
130
|
+
|
|
131
|
+
'chart.highlight.stroke': 'rgba(0,0,0,0)',
|
|
132
|
+
'chart.highlight.fill': 'rgba(255,255,255,0.7)',
|
|
133
|
+
|
|
134
|
+
'chart.linewidth': 1,
|
|
135
|
+
|
|
136
|
+
'chart.title': '',
|
|
137
|
+
'chart.title.size': null,
|
|
138
|
+
'chart.title.font': null,
|
|
139
|
+
'chart.title.background': null, // Gradients aren't supported for this color
|
|
140
|
+
'chart.title.hpos': null,
|
|
141
|
+
'chart.title.vpos': null,
|
|
142
|
+
'chart.title.bold': true,
|
|
143
|
+
'chart.title.color': 'black',
|
|
144
|
+
'chart.title.x': null,
|
|
145
|
+
'chart.title.y': null,
|
|
146
|
+
'chart.title.halign': null,
|
|
147
|
+
'chart.title.valign': null,
|
|
148
|
+
|
|
149
|
+
'chart.title.xaxis': '',
|
|
150
|
+
'chart.title.xaxis.bold': true,
|
|
151
|
+
'chart.title.xaxis.size': null,
|
|
152
|
+
'chart.title.xaxis.font': null,
|
|
153
|
+
'chart.title.xaxis.x': null,
|
|
154
|
+
'chart.title.xaxis.y': null,
|
|
155
|
+
'chart.title.xaxis.pos': null,
|
|
156
|
+
|
|
157
|
+
'chart.title.yaxis': '',
|
|
158
|
+
'chart.title.yaxis.bold': true,
|
|
159
|
+
'chart.title.yaxis.size': null,
|
|
160
|
+
'chart.title.yaxis.font': null,
|
|
161
|
+
'chart.title.yaxis.color': 'black', // Gradients aren't supported for this color
|
|
162
|
+
'chart.title.yaxis.x': null,
|
|
163
|
+
'chart.title.yaxis.y': null,
|
|
164
|
+
'chart.title.yaxis.pos': null,
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A simple check that the browser has canvas support
|
|
169
|
+
*/
|
|
170
|
+
if (!this.canvas) {
|
|
171
|
+
alert('[DRAWING.BACKGROUND] No canvas support');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Create the dollar object so that functions can be added to them
|
|
179
|
+
*/
|
|
180
|
+
this.$0 = {};
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
|
|
186
|
+
* done already
|
|
187
|
+
*/
|
|
188
|
+
if (!this.canvas.__rgraph_aa_translated__) {
|
|
189
|
+
this.context.translate(0.5,0.5);
|
|
190
|
+
|
|
191
|
+
this.canvas.__rgraph_aa_translated__ = true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
// Short variable names
|
|
198
|
+
var RG = RGraph,
|
|
199
|
+
ca = this.canvas,
|
|
200
|
+
co = ca.getContext('2d'),
|
|
201
|
+
prop = this.properties,
|
|
202
|
+
pa = RG.Path,
|
|
203
|
+
pa2 = RG.path2,
|
|
204
|
+
win = window,
|
|
205
|
+
doc = document,
|
|
206
|
+
ma = Math
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* "Decorate" the object with the generic effects if the effects library has been included
|
|
212
|
+
*/
|
|
213
|
+
if (RG.Effects && typeof RG.Effects.decorate === 'function') {
|
|
214
|
+
RG.Effects.decorate(this);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* A setter method for setting graph properties. It can be used like this: obj.Set('chart.strokestyle', '#666');
|
|
222
|
+
*
|
|
223
|
+
* @param name string The name of the property to set OR it can be a map
|
|
224
|
+
* of name/value settings like what you set in the constructor
|
|
225
|
+
*/
|
|
226
|
+
this.set =
|
|
227
|
+
this.Set = function (name)
|
|
228
|
+
{
|
|
229
|
+
var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* the number of arguments is only one and it's an
|
|
233
|
+
* object - parse it for configuration data and return.
|
|
234
|
+
*/
|
|
235
|
+
if (arguments.length === 1 && typeof name === 'object') {
|
|
236
|
+
RG.parseObjectStyleConfig(this, name);
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* This should be done first - prepend the property name with "chart." if necessary
|
|
246
|
+
*/
|
|
247
|
+
if (name.substr(0,6) != 'chart.') {
|
|
248
|
+
name = 'chart.' + name;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
// Convert uppercase letters to dot+lower case letter
|
|
254
|
+
name = name.replace(/([A-Z])/g, function (str)
|
|
255
|
+
{
|
|
256
|
+
return '.' + String(RegExp.$1).toLowerCase();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
prop[name] = value;
|
|
261
|
+
|
|
262
|
+
return this;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* A getter method for retrieving graph properties. It can be used like this: obj.Get('chart.strokestyle');
|
|
270
|
+
*
|
|
271
|
+
* @param name string The name of the property to get
|
|
272
|
+
*/
|
|
273
|
+
this.get =
|
|
274
|
+
this.Get = function (name)
|
|
275
|
+
{
|
|
276
|
+
/**
|
|
277
|
+
* This should be done first - prepend the property name with "chart." if necessary
|
|
278
|
+
*/
|
|
279
|
+
if (name.substr(0,6) != 'chart.') {
|
|
280
|
+
name = 'chart.' + name;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Convert uppercase letters to dot+lower case letter
|
|
284
|
+
name = name.replace(/([A-Z])/g, function (str)
|
|
285
|
+
{
|
|
286
|
+
return '.' + String(RegExp.$1).toLowerCase()
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
return prop[name.toLowerCase()];
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Draws the circle
|
|
297
|
+
*/
|
|
298
|
+
this.draw =
|
|
299
|
+
this.Draw = function ()
|
|
300
|
+
{
|
|
301
|
+
/**
|
|
302
|
+
* Fire the onbeforedraw event
|
|
303
|
+
*/
|
|
304
|
+
RG.FireCustomEvent(this, 'onbeforedraw');
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Parse the colors. This allows for simple gradient syntax
|
|
309
|
+
*/
|
|
310
|
+
if (!this.colorsParsed) {
|
|
311
|
+
|
|
312
|
+
this.parseColors();
|
|
313
|
+
|
|
314
|
+
// Don't want to do this again
|
|
315
|
+
this.colorsParsed = true;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
/***********************
|
|
320
|
+
* DRAW BACKGROUND HERE *
|
|
321
|
+
***********************/
|
|
322
|
+
this.gutterLeft = prop['chart.gutter.left'];
|
|
323
|
+
this.gutterRight = prop['chart.gutter.right'];
|
|
324
|
+
this.gutterTop = prop['chart.gutter.top'];
|
|
325
|
+
this.gutterBottom = prop['chart.gutter.bottom'];
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Set the shadow
|
|
329
|
+
*/
|
|
330
|
+
RG.drawBackgroundImage(this);
|
|
331
|
+
RG.Background.draw(this);
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* This installs the event listeners
|
|
335
|
+
*/
|
|
336
|
+
RG.InstallEventListeners(this);
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Fire the onfirstdraw event
|
|
341
|
+
*/
|
|
342
|
+
if (this.firstDraw) {
|
|
343
|
+
RG.fireCustomEvent(this, 'onfirstdraw');
|
|
344
|
+
this.firstDraw = false;
|
|
345
|
+
this.firstDrawFunc();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Fire the ondraw event
|
|
352
|
+
*/
|
|
353
|
+
RG.FireCustomEvent(this, 'ondraw');
|
|
354
|
+
|
|
355
|
+
return this;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Used in chaining. Runs a function there and then - not waiting for
|
|
362
|
+
* the events to fire (eg the onbeforedraw event)
|
|
363
|
+
*
|
|
364
|
+
* @param function func The function to execute
|
|
365
|
+
*/
|
|
366
|
+
this.exec = function (func)
|
|
367
|
+
{
|
|
368
|
+
func(this);
|
|
369
|
+
|
|
370
|
+
return this;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* The getObjectByXY() worker method
|
|
378
|
+
*/
|
|
379
|
+
this.getObjectByXY = function (e)
|
|
380
|
+
{
|
|
381
|
+
if (this.getShape(e)) {
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Not used by the class during creating the shape, but is used by event handlers
|
|
391
|
+
* to get the coordinates (if any) of the selected bar
|
|
392
|
+
*
|
|
393
|
+
* @param object e The event object
|
|
394
|
+
* @param object OPTIONAL You can pass in the bar object instead of the
|
|
395
|
+
* function using "this"
|
|
396
|
+
*/
|
|
397
|
+
this.getShape = function (e)
|
|
398
|
+
{
|
|
399
|
+
var mouseXY = RGraph.getMouseXY(e);
|
|
400
|
+
var mouseX = mouseXY[0];
|
|
401
|
+
var mouseY = mouseXY[1];
|
|
402
|
+
|
|
403
|
+
if (
|
|
404
|
+
mouseX >= this.gutterLeft
|
|
405
|
+
&& mouseX <= (ca.width - this.gutterRight)
|
|
406
|
+
&& mouseY >= this.gutterTop
|
|
407
|
+
&& mouseY <= (ca.height - this.gutterBottom)
|
|
408
|
+
) {
|
|
409
|
+
|
|
410
|
+
var tooltip = prop['chart.tooltips'] ? prop['chart.tooltips'][0] : null
|
|
411
|
+
|
|
412
|
+
return {
|
|
413
|
+
0: this, 1: 0 /* the index */, 2: tooltip,
|
|
414
|
+
'object': this,'index': 0, 'tooltip': tooltip
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return null;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* This function positions a tooltip when it is displayed
|
|
426
|
+
*
|
|
427
|
+
* @param obj object The chart object
|
|
428
|
+
* @param int x The X coordinate specified for the tooltip
|
|
429
|
+
* @param int y The Y coordinate specified for the tooltip
|
|
430
|
+
* @param objec tooltip The tooltips DIV element
|
|
431
|
+
*/
|
|
432
|
+
this.positionTooltip = function (obj, x, y, tooltip, idx)
|
|
433
|
+
{
|
|
434
|
+
var canvasXY = RG.getCanvasXY(obj.canvas);
|
|
435
|
+
var width = tooltip.offsetWidth;
|
|
436
|
+
var height = tooltip.offsetHeight;
|
|
437
|
+
var tooltipX = RG.getCanvasXY(obj.canvas)[0] + ((obj.canvas.width - this.gutterLeft - this.gutterRight) / 2) + this.gutterLeft;
|
|
438
|
+
var tooltipY = RG.getCanvasXY(obj.canvas)[1] + ((obj.canvas.height - this.gutterTop - this.gutterBottom) / 2) + this.gutterTop;
|
|
439
|
+
|
|
440
|
+
// Set the top position
|
|
441
|
+
tooltip.style.left = 0;
|
|
442
|
+
tooltip.style.top = tooltipY - height - 7 + 'px';
|
|
443
|
+
|
|
444
|
+
// By default any overflow is hidden
|
|
445
|
+
tooltip.style.overflow = '';
|
|
446
|
+
|
|
447
|
+
// The arrow
|
|
448
|
+
var img = new Image();
|
|
449
|
+
img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAFCAYAAACjKgd3AAAARUlEQVQYV2NkQAN79+797+RkhC4M5+/bd47B2dmZEVkBCgcmgcsgbAaA9GA1BCSBbhAuA/AagmwQPgMIGgIzCD0M0AMMAEFVIAa6UQgcAAAAAElFTkSuQmCC';
|
|
450
|
+
img.style.position = 'absolute';
|
|
451
|
+
img.id = '__rgraph_tooltip_pointer__';
|
|
452
|
+
img.style.top = (tooltip.offsetHeight - 2) + 'px';
|
|
453
|
+
tooltip.appendChild(img);
|
|
454
|
+
|
|
455
|
+
// Reposition the tooltip if at the edges:
|
|
456
|
+
|
|
457
|
+
// LEFT edge
|
|
458
|
+
if ( (tooltipX - (width / 2)) < 10) {
|
|
459
|
+
tooltip.style.left = (tooltipX - (width * 0.1)) + 'px';
|
|
460
|
+
img.style.left = ((width * 0.1) - 8.5) + 'px';
|
|
461
|
+
|
|
462
|
+
// RIGHT EDGE
|
|
463
|
+
} else if ( (tooltipX + (width / 2)) > doc.body.offsetWidth) {
|
|
464
|
+
tooltip.style.left = (tooltipX - (width * 0.9)) + 'px';
|
|
465
|
+
img.style.left = ((width * 0.9) - 8.5) + 'px';
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
// CENTERED
|
|
469
|
+
} else {
|
|
470
|
+
tooltip.style.left = (tooltipX - (width * 0.5)) + 'px';
|
|
471
|
+
img.style.left = ((width * 0.5) - 8.5) + 'px';
|
|
472
|
+
}
|
|
473
|
+
//tooltip.style.left = (canvasXY[0] + this.centerx - (width * 0.1)) + 'px';
|
|
474
|
+
//img.style.left = ((width * 0.1) - 8.5) + 'px';
|
|
475
|
+
|
|
476
|
+
// RIGHT edge
|
|
477
|
+
//} else if ((canvasXY[0] + obj.canvas.width + (width / 2)) > doc.body.offsetWidth) {
|
|
478
|
+
// tooltip.style.left = canvasXY[0] + this.centerx - (width * 0.9) + 'px';
|
|
479
|
+
// img.style.left = ((width * 0.9) - 8.5) + 'px';
|
|
480
|
+
|
|
481
|
+
// Default positioning - CENTERED
|
|
482
|
+
//} else {
|
|
483
|
+
// tooltip.style.left = (canvasXY[0] + obj.gutterLeft ((obj.canvas.width - obj.gutterLeft - obj.gutterRight) / 2) - (width * 0.5)) + 'px';
|
|
484
|
+
// img.style.left = ((width * 0.5) - 8.5) + 'px';
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Each object type has its own Highlight() function which highlights the appropriate shape
|
|
492
|
+
*
|
|
493
|
+
* @param object shape The shape to highlight
|
|
494
|
+
*/
|
|
495
|
+
this.highlight =
|
|
496
|
+
this.Highlight = function (shape)
|
|
497
|
+
{
|
|
498
|
+
if (prop['chart.tooltips.highlight']) {
|
|
499
|
+
pa(co, ['b',
|
|
500
|
+
'r', prop['chart.gutter.left'],
|
|
501
|
+
prop['chart.gutter.top'],
|
|
502
|
+
ca.width - prop['chart.gutter.left'] - prop['chart.gutter.right'],
|
|
503
|
+
ca.height - prop['chart.gutter.top'] - prop['chart.gutter.bottom'],
|
|
504
|
+
'f',prop['chart.highlight.fill'],'s',prop['chart.highlight.stroke']]);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* This allows for easy specification of gradients
|
|
513
|
+
*/
|
|
514
|
+
this.parseColors = function ()
|
|
515
|
+
{
|
|
516
|
+
|
|
517
|
+
// Save the original colors so that they can be restored when the canvas is reset
|
|
518
|
+
if (this.original_colors.length === 0) {
|
|
519
|
+
this.original_colors['chart.strokestyle'] = RG.arrayClone(prop['chart.strokestyle']);
|
|
520
|
+
this.original_colors['chart.highlight.stroke'] = RG.arrayClone(prop['chart.highlight.stroke']);
|
|
521
|
+
this.original_colors['chart.highlight.fill'] = RG.arrayClone(prop['chart.highlight.fill']);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Parse various properties for colors
|
|
530
|
+
*/
|
|
531
|
+
prop['chart.strokestyle'] = this.parseSingleColorForGradient(prop['chart.strokestyle']);
|
|
532
|
+
prop['chart.highlight.stroke'] = this.parseSingleColorForGradient(prop['chart.highlight.stroke']);
|
|
533
|
+
prop['chart.highlight.fill'] = this.parseSingleColorForGradient(prop['chart.highlight.fill']);
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Use this function to reset the object to the post-constructor state. Eg reset colors if
|
|
541
|
+
* need be etc
|
|
542
|
+
*/
|
|
543
|
+
this.reset = function ()
|
|
544
|
+
{
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* This parses a single color value
|
|
552
|
+
*/
|
|
553
|
+
this.parseSingleColorForGradient = function (color)
|
|
554
|
+
{
|
|
555
|
+
if (!color) {
|
|
556
|
+
return color;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (typeof color === 'string' && color.match(/^gradient\((.*)\)$/i)) {
|
|
560
|
+
|
|
561
|
+
var parts = RegExp.$1.split(':');
|
|
562
|
+
|
|
563
|
+
// Create the gradient
|
|
564
|
+
var grad = co.createLinearGradient(this.gutterLeft, this.gutterTop, ca.width - this.gutterRight, ca.height - this.gutterRight);
|
|
565
|
+
|
|
566
|
+
var diff = 1 / (parts.length - 1);
|
|
567
|
+
|
|
568
|
+
//grad.addColorStop(0, RG.trim(parts[0]));
|
|
569
|
+
|
|
570
|
+
for (var j=0; j<parts.length; j+=1) {
|
|
571
|
+
grad.addColorStop(j * diff, RG.trim(parts[j]));
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return grad ? grad : color;
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Using a function to add events makes it easier to facilitate method chaining
|
|
583
|
+
*
|
|
584
|
+
* @param string type The type of even to add
|
|
585
|
+
* @param function func
|
|
586
|
+
*/
|
|
587
|
+
this.on = function (type, func)
|
|
588
|
+
{
|
|
589
|
+
if (type.substr(0,2) !== 'on') {
|
|
590
|
+
type = 'on' + type;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
this[type] = func;
|
|
594
|
+
|
|
595
|
+
return this;
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* This function runs once only
|
|
603
|
+
* (put at the end of the file (before any effects))
|
|
604
|
+
*/
|
|
605
|
+
this.firstDrawFunc = function ()
|
|
606
|
+
{
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
RG.att(ca);
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Objects are now always registered so that the chart is redrawn if need be.
|
|
623
|
+
*/
|
|
624
|
+
RG.Register(this);
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* This is the 'end' of the constructor so if the first argument
|
|
631
|
+
* contains configuration data - handle that.
|
|
632
|
+
*/
|
|
633
|
+
if (parseConfObjectForOptions) {
|
|
634
|
+
RG.parseObjectStyleConfig(this, conf.options);
|
|
635
|
+
}
|
|
636
|
+
};
|