rgraph-rails 5.00 → 6.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish-geml.yaml +46 -0
- data/.gitignore +1 -0
- data/README.md +4 -5
- data/lib/rgraph-rails/version.rb +1 -1
- data/rgraph-rails.gemspec +4 -4
- data/vendor/assets/javascripts/RGraph.activity.js +1691 -0
- data/vendor/assets/javascripts/RGraph.bar.js +4253 -236
- data/vendor/assets/javascripts/RGraph.bipolar.js +3958 -162
- data/vendor/assets/javascripts/RGraph.common.annotate.js +414 -35
- data/vendor/assets/javascripts/RGraph.common.context.js +635 -30
- data/vendor/assets/javascripts/RGraph.common.core.js +10485 -419
- data/vendor/assets/javascripts/RGraph.common.csv.js +508 -27
- data/vendor/assets/javascripts/RGraph.common.dynamic.js +1693 -90
- data/vendor/assets/javascripts/RGraph.common.effects.js +1629 -89
- data/vendor/assets/javascripts/RGraph.common.key.js +1003 -53
- data/vendor/assets/javascripts/RGraph.common.moment.js +5670 -0
- data/vendor/assets/javascripts/RGraph.common.sheets.js +541 -31
- data/vendor/assets/javascripts/RGraph.common.sheets.php +351 -0
- data/vendor/assets/javascripts/RGraph.common.starburst.js +382 -0
- data/vendor/assets/javascripts/RGraph.common.table.js +386 -0
- data/vendor/assets/javascripts/RGraph.common.tooltips.js +1433 -32
- data/vendor/assets/javascripts/RGraph.drawing.background.js +660 -35
- data/vendor/assets/javascripts/RGraph.drawing.circle.js +618 -34
- data/vendor/assets/javascripts/RGraph.drawing.image.js +857 -52
- data/vendor/assets/javascripts/RGraph.drawing.line.js +712 -0
- data/vendor/assets/javascripts/RGraph.drawing.marker1.js +760 -38
- data/vendor/assets/javascripts/RGraph.drawing.marker2.js +740 -37
- data/vendor/assets/javascripts/RGraph.drawing.marker3.js +573 -36
- data/vendor/assets/javascripts/RGraph.drawing.poly.js +667 -36
- data/vendor/assets/javascripts/RGraph.drawing.rect.js +638 -34
- data/vendor/assets/javascripts/RGraph.drawing.text.js +672 -37
- data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +653 -52
- data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +714 -51
- data/vendor/assets/javascripts/RGraph.fuel.js +1149 -59
- data/vendor/assets/javascripts/RGraph.funnel.js +1277 -56
- data/vendor/assets/javascripts/RGraph.gantt.js +1646 -82
- data/vendor/assets/javascripts/RGraph.gauge.js +1773 -89
- data/vendor/assets/javascripts/RGraph.hbar.js +3869 -159
- data/vendor/assets/javascripts/RGraph.horseshoe.js +970 -0
- data/vendor/assets/javascripts/RGraph.hprogress.js +1829 -81
- data/vendor/assets/javascripts/RGraph.line.js +5293 -244
- data/vendor/assets/javascripts/RGraph.meter.js +1570 -77
- data/vendor/assets/javascripts/RGraph.modaldialog.js +300 -19
- data/vendor/assets/javascripts/RGraph.odo.js +1553 -68
- data/vendor/assets/javascripts/RGraph.pie.js +3273 -129
- data/vendor/assets/javascripts/RGraph.radar.js +2333 -108
- data/vendor/assets/javascripts/RGraph.rose.js +2685 -114
- data/vendor/assets/javascripts/RGraph.rscatter.js +1920 -80
- data/vendor/assets/javascripts/RGraph.scatter.js +4215 -171
- data/vendor/assets/javascripts/RGraph.segmented.js +1006 -0
- data/vendor/assets/javascripts/RGraph.semicircularprogress.js +1980 -59
- data/vendor/assets/javascripts/RGraph.svg.activity.js +1696 -0
- data/vendor/assets/javascripts/RGraph.svg.bar.js +2575 -77
- data/vendor/assets/javascripts/RGraph.svg.bipolar.js +3533 -106
- data/vendor/assets/javascripts/RGraph.svg.common.ajax.js +240 -21
- data/vendor/assets/javascripts/RGraph.svg.common.core.js +7105 -299
- data/vendor/assets/javascripts/RGraph.svg.common.csv.js +408 -28
- data/vendor/assets/javascripts/RGraph.svg.common.fx.js +1291 -68
- data/vendor/assets/javascripts/RGraph.svg.common.key.js +451 -20
- data/vendor/assets/javascripts/RGraph.svg.common.sheets.js +543 -31
- data/vendor/assets/javascripts/RGraph.svg.common.table.js +391 -0
- data/vendor/assets/javascripts/RGraph.svg.common.tooltips.js +1072 -23
- data/vendor/assets/javascripts/RGraph.svg.funnel.js +1151 -32
- data/vendor/assets/javascripts/RGraph.svg.gauge.js +1429 -34
- data/vendor/assets/javascripts/RGraph.svg.hbar.js +2692 -65
- data/vendor/assets/javascripts/RGraph.svg.horseshoe.js +969 -0
- data/vendor/assets/javascripts/RGraph.svg.line.js +2855 -86
- data/vendor/assets/javascripts/RGraph.svg.pie.js +1630 -58
- data/vendor/assets/javascripts/RGraph.svg.radar.js +1772 -58
- data/vendor/assets/javascripts/RGraph.svg.rose.js +2419 -83
- data/vendor/assets/javascripts/RGraph.svg.scatter.js +2280 -65
- data/vendor/assets/javascripts/RGraph.svg.segmented.js +930 -0
- data/vendor/assets/javascripts/RGraph.svg.semicircularprogress.js +1612 -29
- data/vendor/assets/javascripts/RGraph.svg.waterfall.js +1525 -50
- data/vendor/assets/javascripts/RGraph.thermometer.js +1411 -64
- data/vendor/assets/javascripts/RGraph.vprogress.js +1915 -81
- data/vendor/assets/javascripts/RGraph.waterfall.js +1896 -89
- data/vendor/assets/javascripts/financial-data.js +1067 -0
- metadata +37 -16
- data/.travis.yml +0 -11
- data/vendor/assets/javascripts/RGraph.common.deprecated.js +0 -35
- data/vendor/assets/javascripts/RGraph.common.resizing.js +0 -38
- data/vendor/assets/javascripts/RGraph.common.zoom.js +0 -15
- data/vendor/assets/javascripts/RGraph.cornergauge.js +0 -71
@@ -1,35 +1,1430 @@
|
|
1
|
+
'version:2023-09-16 (6.14)';
|
2
|
+
//
|
3
|
+
// o--------------------------------------------------------------------------------o
|
4
|
+
// | This file is part of the RGraph package - you can learn more at: |
|
5
|
+
// | |
|
6
|
+
// | https://www.rgraph.net |
|
7
|
+
// | |
|
8
|
+
// | RGraph is licensed under the Open Source MIT license. That means that it's |
|
9
|
+
// | totally free to use and there are no restrictions on what you can do with it! |
|
10
|
+
// o--------------------------------------------------------------------------------o
|
1
11
|
|
2
|
-
RGraph=window.RGraph||{isRGraph:true};
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
{
|
8
|
-
|
9
|
-
{
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
{
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
this.
|
27
|
-
|
28
|
-
|
29
|
-
{
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
12
|
+
RGraph = window.RGraph || {isrgraph:true,isRGraph:true,rgraph:true};
|
13
|
+
RGraph.SVG = RGraph.SVG || {};
|
14
|
+
|
15
|
+
// Module pattern
|
16
|
+
(function (win, doc, undefined)
|
17
|
+
{
|
18
|
+
RGraph.SVG.Gauge = function (conf)
|
19
|
+
{
|
20
|
+
//
|
21
|
+
// A setter that the constructor uses (at the end)
|
22
|
+
// to set all of the properties
|
23
|
+
//
|
24
|
+
// @param string name The name of the property to set
|
25
|
+
// @param string value The value to set the property to
|
26
|
+
//
|
27
|
+
this.set = function (name, value)
|
28
|
+
{
|
29
|
+
if (arguments.length === 1 && typeof name === 'object') {
|
30
|
+
for (i in arguments[0]) {
|
31
|
+
if (typeof i === 'string') {
|
32
|
+
|
33
|
+
name = ret.name;
|
34
|
+
value = ret.value;
|
35
|
+
|
36
|
+
this.set(name, value);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
} else {
|
40
|
+
|
41
|
+
var ret = RGraph.SVG.commonSetter({
|
42
|
+
object: this,
|
43
|
+
name: name,
|
44
|
+
value: value
|
45
|
+
});
|
46
|
+
|
47
|
+
name = ret.name;
|
48
|
+
value = ret.value;
|
49
|
+
|
50
|
+
this.properties[name] = value;
|
51
|
+
|
52
|
+
// If setting the colors, update the originalColors
|
53
|
+
// property too
|
54
|
+
//
|
55
|
+
// NB Don't need to do this for this chart type
|
56
|
+
//if (name === 'colors') {
|
57
|
+
// this.originalColors = RGraph.SVG.arrayClone(value);
|
58
|
+
// this.colorsParsed = false;
|
59
|
+
//}
|
60
|
+
}
|
61
|
+
|
62
|
+
return this;
|
63
|
+
};
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
//
|
73
|
+
// A getter.
|
74
|
+
//
|
75
|
+
// @param name string The name of the property to get
|
76
|
+
//
|
77
|
+
this.get = function (name)
|
78
|
+
{
|
79
|
+
return this.properties[name];
|
80
|
+
};
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
this.type = 'gauge';
|
89
|
+
this.innerMin = RGraph.SVG.stringsToNumbers(conf.innerMin);
|
90
|
+
this.innerMax = RGraph.SVG.stringsToNumbers(conf.innerMax);
|
91
|
+
this.outerMin = RGraph.SVG.stringsToNumbers(conf.outerMin);
|
92
|
+
this.outerMax = RGraph.SVG.stringsToNumbers(conf.outerMax);
|
93
|
+
this.value = RGraph.SVG.stringsToNumbers(conf.value);
|
94
|
+
this.angleStart = 0 - RGraph.SVG.TRIG.HALFPI - (RGraph.SVG.TRIG.HALFPI / 2);
|
95
|
+
this.angleEnd = 0 + RGraph.SVG.TRIG.HALFPI + (RGraph.SVG.TRIG.HALFPI / 2);
|
96
|
+
this.angleSpan = this.angleEnd - this.angleStart;
|
97
|
+
this.id = conf.id;
|
98
|
+
this.uid = RGraph.SVG.createUID();
|
99
|
+
this.container = document.getElementById(this.id);
|
100
|
+
this.layers = {}; // MUST be before the SVG tag is created!
|
101
|
+
this.svg = RGraph.SVG.createSVG({
|
102
|
+
object: this,
|
103
|
+
container: this.container
|
104
|
+
});
|
105
|
+
this.isRGraph = true;
|
106
|
+
this.isrgraph = true;
|
107
|
+
this.rgraph = true;
|
108
|
+
this.width = Number(this.svg.getAttribute('width'));
|
109
|
+
this.height = Number(this.svg.getAttribute('height'));
|
110
|
+
|
111
|
+
this.colorsParsed = false;
|
112
|
+
this.originalColors = {};
|
113
|
+
this.gradientCounter = 1;
|
114
|
+
this.nodes = {};
|
115
|
+
this.shadowNodes = [];
|
116
|
+
this.firstDraw = true; // After the first draw this will be false
|
117
|
+
|
118
|
+
// Some bounds checking for the value
|
119
|
+
if (this.value > this.innerMax) this.value = this.innerMax;
|
120
|
+
if (this.value < this.innerMin) this.value = this.innerMin;
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
// Add this object to the ObjectRegistry
|
129
|
+
RGraph.SVG.OR.add(this);
|
130
|
+
|
131
|
+
// Set the DIV container to be inline-block
|
132
|
+
this.container.style.display = 'inline-block';
|
133
|
+
|
134
|
+
this.properties =
|
135
|
+
{
|
136
|
+
centerx: null,
|
137
|
+
centery: null,
|
138
|
+
radius: null,
|
139
|
+
|
140
|
+
marginLeft: 35,
|
141
|
+
marginRight: 35,
|
142
|
+
marginTop: 35,
|
143
|
+
marginBottom: 35,
|
144
|
+
rmargin: null, // This is set below
|
145
|
+
|
146
|
+
backgroundFill: 'Gradient(white:#FEFEFE:#E6E6E6:#dedede)',
|
147
|
+
backgroundStroke: '#ddd',
|
148
|
+
backgroundGrid: true,
|
149
|
+
backgroundGridColor: '#ddd',
|
150
|
+
|
151
|
+
linewidth: 1,
|
152
|
+
colors: ['black','black'],
|
153
|
+
innerGap: 5,
|
154
|
+
|
155
|
+
tickmarksOuterSize: 3,
|
156
|
+
tickmarksInnerSize: 3,
|
157
|
+
tickmarksCount: 10,
|
158
|
+
|
159
|
+
textColor: 'black',
|
160
|
+
textFont: 'Arial, Verdana, sans-serif',
|
161
|
+
textSize: 12 ,
|
162
|
+
textBold: false,
|
163
|
+
textItalic: false,
|
164
|
+
text: null,
|
165
|
+
|
166
|
+
labelsIngraph: true,
|
167
|
+
labelsIngraphFont: null,
|
168
|
+
labelsIngraphSize: null,
|
169
|
+
labelsIngraphBold: null,
|
170
|
+
labelsIngraphItalic: null,
|
171
|
+
labelsIngraphColor: null,
|
172
|
+
labelsIngraphUnitsPre: '',
|
173
|
+
labelsIngraphUnitsPost: '',
|
174
|
+
labelsIngraphThousand: ',',
|
175
|
+
labelsIngraphPoint: '.',
|
176
|
+
labelsIngraphFormatter: null,
|
177
|
+
labelsIngraphDecimals: 0,
|
178
|
+
labelsIngraphPadding: 3,
|
179
|
+
labelsIngraphBackground: 'Gradient(#ddd:#eee)',
|
180
|
+
labelsIngraphRounded: 2,
|
181
|
+
|
182
|
+
scaleInnerFont: null,
|
183
|
+
scaleInnerSize: null,
|
184
|
+
scaleInnerBold: null,
|
185
|
+
scaleInnerItalic: null,
|
186
|
+
scaleInnerColor: null,
|
187
|
+
scaleInnerUnitsPre: '',
|
188
|
+
scaleInnerUnitsPost: '',
|
189
|
+
scaleInnerPoint: '.',
|
190
|
+
scaleInnerThousand: ',',
|
191
|
+
scaleInnerDecimals: 0,
|
192
|
+
scaleInnerFormatter: null,
|
193
|
+
scaleInnerLabelsCount: 10,
|
194
|
+
scaleInnerRound: false,
|
195
|
+
|
196
|
+
scaleOuter: true,
|
197
|
+
scaleOuterFont: null,
|
198
|
+
scaleOuterSize: null,
|
199
|
+
scaleOuterBold: null,
|
200
|
+
scaleOuterItalic: null,
|
201
|
+
scaleOuterColor: null,
|
202
|
+
scaleOuterUnitsPre: '',
|
203
|
+
scaleOuterUnitsPost: '',
|
204
|
+
scaleOuterPoint: '.',
|
205
|
+
scaleOuterThousand: ',',
|
206
|
+
scaleOuterDecimals: 0,
|
207
|
+
scaleOuterFormatter: null,
|
208
|
+
scaleOuterLabelsCount: 10,
|
209
|
+
scaleOuterRound: false,
|
210
|
+
|
211
|
+
shadow: false,
|
212
|
+
shadowOffsetx: 2,
|
213
|
+
shadowOffsety: 2,
|
214
|
+
shadowColor: 'rgba(0,0,0,0.25)',
|
215
|
+
shadowBlur: 2,
|
216
|
+
|
217
|
+
title: '',
|
218
|
+
titleX: null,
|
219
|
+
titleY: null,
|
220
|
+
titleHalign: 'center',
|
221
|
+
titleValign: 'bottom',
|
222
|
+
titleSize: null,
|
223
|
+
titleColor: null,
|
224
|
+
titleFont: null,
|
225
|
+
titleBold: null,
|
226
|
+
titleItalic: null,
|
227
|
+
|
228
|
+
titleSubtitle: null,
|
229
|
+
titleSubtitleSize: null,
|
230
|
+
titleSubtitleColor: '#aaa',
|
231
|
+
titleSubtitleFont: null,
|
232
|
+
titleSubtitleBold: null,
|
233
|
+
titleSubtitleItalic: null,
|
234
|
+
|
235
|
+
needleColor: '#666',
|
236
|
+
|
237
|
+
centerpinRadius: 15,
|
238
|
+
|
239
|
+
adjustable: false
|
240
|
+
};
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
//
|
246
|
+
// Copy the global object properties to this instance
|
247
|
+
//
|
248
|
+
RGraph.SVG.getGlobals(this);
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
//
|
255
|
+
// "Decorate" the object with the generic effects if the effects library has been included
|
256
|
+
//
|
257
|
+
if (RGraph.SVG.FX && typeof RGraph.SVG.FX.decorate === 'function') {
|
258
|
+
RGraph.SVG.FX.decorate(this);
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
// Add the responsive function to the object
|
266
|
+
this.responsive = RGraph.SVG.responsive;
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
var properties = this.properties;
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
//
|
282
|
+
// The draw method draws the Bar chart
|
283
|
+
//
|
284
|
+
this.draw = function ()
|
285
|
+
{
|
286
|
+
// Fire the beforedraw event
|
287
|
+
RGraph.SVG.fireCustomEvent(this, 'onbeforedraw');
|
288
|
+
|
289
|
+
|
290
|
+
// Reset this to prevent it from growing
|
291
|
+
this.nodes = {};
|
292
|
+
|
293
|
+
// Should be the first thing that's done inthe.draw() function
|
294
|
+
// except for the onbeforedraw event
|
295
|
+
this.width = Number(this.svg.getAttribute('width'));
|
296
|
+
this.height = Number(this.svg.getAttribute('height'));
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
// Create the defs tag if necessary
|
301
|
+
RGraph.SVG.createDefs(this);
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
// Add these
|
306
|
+
this.graphWidth = this.width - properties.marginLeft - properties.marginRight;
|
307
|
+
this.graphHeight = this.height - properties.marginTop - properties.marginBottom;
|
308
|
+
|
309
|
+
// If a title is specified then adjust the centery down
|
310
|
+
//
|
311
|
+
// NO LONGER NECESSARY NOW THAT THE drawTitle() FUNCTION HAS BEEN
|
312
|
+
// REWRITTEN
|
313
|
+
//
|
314
|
+
//if (properties.title.length > 0) {
|
315
|
+
// this.graphHeight -= properties.marginTop;
|
316
|
+
//}
|
317
|
+
|
318
|
+
// Work out the center point
|
319
|
+
this.centerx = (this.graphWidth / 2) + properties.marginLeft;
|
320
|
+
this.centery = (this.graphHeight / 2) + properties.marginTop;
|
321
|
+
this.radius = Math.min(this.graphWidth / 2, this.graphHeight / 2);
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
// Allow the user to override the calculated centerx/y/radius
|
328
|
+
this.centerx = typeof properties.centerx === 'number' ? properties.centerx : this.centerx;
|
329
|
+
this.centery = typeof properties.centery === 'number' ? properties.centery : this.centery;
|
330
|
+
this.radius = typeof properties.radius === 'number' ? properties.radius : this.radius;
|
331
|
+
|
332
|
+
// Allow the centerx/centery/radius to be a plus/minus
|
333
|
+
if (typeof properties.radius === 'string' && properties.radius.match(/^\+|-\d+$/) ) this.radius += parseFloat(properties.radius);
|
334
|
+
if (typeof properties.centerx === 'string' && properties.centerx.match(/^\+|-\d+$/) ) this.centery += parseFloat(properties.centerx);
|
335
|
+
if (typeof properties.centery === 'string' && properties.centery.match(/^\+|-\d+$/) ) this.centerx += parseFloat(properties.centery);
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
// Parse the colors for gradients
|
341
|
+
RGraph.SVG.resetColorsToOriginalValues({object:this});
|
342
|
+
this.parseColors();
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
// Change the rmargin if it wasnt set manually
|
348
|
+
if (properties.rmargin === null) {
|
349
|
+
if (properties.scaleOuter) {
|
350
|
+
properties.rmargin = 40;
|
351
|
+
} else {
|
352
|
+
properties.rmargin = 25;
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
// Draw the meter
|
362
|
+
this.drawMeter();
|
363
|
+
|
364
|
+
|
365
|
+
// Draw the needle
|
366
|
+
this.drawNeedle();
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
// Draw the ingraph label
|
371
|
+
if (properties.labelsIngraph) {
|
372
|
+
this.drawIngraph();
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
// Draw the title and subtitle
|
378
|
+
RGraph.SVG.drawTitle(this);
|
379
|
+
|
380
|
+
|
381
|
+
// Ajusting
|
382
|
+
if (properties.adjustable) {
|
383
|
+
|
384
|
+
this.adjusting_mousedown = false;
|
385
|
+
var obj = this;
|
386
|
+
|
387
|
+
var func = function (e)
|
388
|
+
{
|
389
|
+
var div = e.currentTarget,
|
390
|
+
mouseX = e.offsetX,
|
391
|
+
mouseY = e.offsetY;
|
392
|
+
|
393
|
+
if (RGraph.SVG.ISFF) {
|
394
|
+
mouseX = e.pageX - e.currentTarget.offsetLeft;
|
395
|
+
mouseY = e.pageY - e.currentTarget.offsetTop;
|
396
|
+
}
|
397
|
+
|
398
|
+
var radius = RGraph.SVG.TRIG.getHypLength({
|
399
|
+
x1: mouseX,
|
400
|
+
y1: mouseY,
|
401
|
+
x2: obj.centerx,
|
402
|
+
y2: obj.centery,
|
403
|
+
object: obj
|
404
|
+
});
|
405
|
+
|
406
|
+
if (radius > obj.radius) {
|
407
|
+
return;
|
408
|
+
}
|
409
|
+
|
410
|
+
var value = obj.getValue(e);
|
411
|
+
|
412
|
+
obj.value = value;
|
413
|
+
obj.drawNeedle();
|
414
|
+
};
|
415
|
+
|
416
|
+
// Create a reference so that code thats inside
|
417
|
+
// the event listeners can easily access the
|
418
|
+
// object
|
419
|
+
|
420
|
+
this.container.addEventListener('mousedown', function (e)
|
421
|
+
{
|
422
|
+
obj.adjusting_mousedown = true;
|
423
|
+
func(e);
|
424
|
+
|
425
|
+
// Fire the beforedraw event
|
426
|
+
RGraph.SVG.fireCustomEvent(obj, 'onadjustbegin');
|
427
|
+
|
428
|
+
}, false);
|
429
|
+
|
430
|
+
this.container.addEventListener('mousemove', function (e)
|
431
|
+
{
|
432
|
+
if (obj.adjusting_mousedown) {
|
433
|
+
func(e);
|
434
|
+
|
435
|
+
// Fire the beforedraw event
|
436
|
+
RGraph.SVG.fireCustomEvent(obj, 'onadjust');
|
437
|
+
}
|
438
|
+
}, false);
|
439
|
+
|
440
|
+
window.addEventListener('mouseup', function (e)
|
441
|
+
{
|
442
|
+
obj.adjusting_mousedown = false;
|
443
|
+
|
444
|
+
// Fire the beforedraw event
|
445
|
+
RGraph.SVG.fireCustomEvent(obj, 'onadjustend');
|
446
|
+
}, false);
|
447
|
+
}
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
|
456
|
+
//
|
457
|
+
// Allow the addition of custom text via the
|
458
|
+
// text: property.
|
459
|
+
//
|
460
|
+
RGraph.SVG.addCustomText(this);
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
//
|
476
|
+
// Fire the onfirstdraw event
|
477
|
+
//
|
478
|
+
if (this.firstDraw) {
|
479
|
+
this.firstDraw = false;
|
480
|
+
RGraph.SVG.fireCustomEvent(this, 'onfirstdraw');
|
481
|
+
}
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
// Fire the draw event
|
486
|
+
RGraph.SVG.fireCustomEvent(this, 'ondraw');
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
//
|
495
|
+
// Install any inline responsive configuration. This
|
496
|
+
// should be last in the draw function - even after
|
497
|
+
// the draw events.
|
498
|
+
//
|
499
|
+
RGraph.SVG.installInlineResponsive(this);
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
return this;
|
511
|
+
};
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
|
520
|
+
//
|
521
|
+
// New create() shortcut function
|
522
|
+
// For example:
|
523
|
+
// this.create('rect,x:0,y:0,width:100,height:100'[,parent]);
|
524
|
+
//
|
525
|
+
// @param str string The tag definition to parse and create
|
526
|
+
// @param object The (optional) parent element
|
527
|
+
// @return object The new tag
|
528
|
+
//
|
529
|
+
this.create = function (str)
|
530
|
+
{
|
531
|
+
var def = RGraph.SVG.create.parseStr(this, str);
|
532
|
+
def.svg = this.svg;
|
533
|
+
|
534
|
+
// By default the parent is the SVG tag - but if
|
535
|
+
// requested then change it to the tag that has
|
536
|
+
// been given
|
537
|
+
if (arguments[1]) {
|
538
|
+
def.parent = arguments[1];
|
539
|
+
}
|
540
|
+
|
541
|
+
return RGraph.SVG.create(def);
|
542
|
+
};
|
543
|
+
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
// Generate the inner scale
|
552
|
+
this.drawMeter = function ()
|
553
|
+
{
|
554
|
+
// Generate the Inner scale
|
555
|
+
this.scaleInner = RGraph.SVG.getScale({
|
556
|
+
object: this,
|
557
|
+
numlabels: properties.scaleInnerLabelsCount,
|
558
|
+
unitsPre: properties.scaleInnerUnitsPre,
|
559
|
+
unitsPost: properties.scaleInnerUnitsPost,
|
560
|
+
max: this.innerMax,
|
561
|
+
min: this.innerMin,
|
562
|
+
point: properties.scaleInnerPoint,
|
563
|
+
round: properties.scaleInnerRound,
|
564
|
+
thousand: properties.scaleInnerThousand,
|
565
|
+
decimals: properties.scaleInnerDecimals,
|
566
|
+
strict: true,
|
567
|
+
formatter: properties.scaleInnerFormatter
|
568
|
+
});
|
569
|
+
|
570
|
+
// Generate the outer scale
|
571
|
+
this.scaleOuter = RGraph.SVG.getScale({
|
572
|
+
object: this,
|
573
|
+
numlabels: properties.scaleOuterLabelsCount,
|
574
|
+
unitsPre: properties.scaleOuterUnitsPre,
|
575
|
+
unitsPost: properties.scaleOuterUnitsPost,
|
576
|
+
max: this.outerMax,
|
577
|
+
min: this.outerMin,
|
578
|
+
point: properties.scaleOuterPoint,
|
579
|
+
round: properties.scaleOuterRound,
|
580
|
+
thousand: properties.scaleOuterThousand,
|
581
|
+
decimals: properties.scaleOuterDecimals,
|
582
|
+
strict: true,
|
583
|
+
formatter: properties.scaleOuterFormatter
|
584
|
+
});
|
585
|
+
|
586
|
+
// If a shadow is requested - define it
|
587
|
+
if (properties.shadow) {
|
588
|
+
RGraph.SVG.setShadow({
|
589
|
+
object: this,
|
590
|
+
offsetx: properties.shadowOffsetx,
|
591
|
+
offsety: properties.shadowOffsety,
|
592
|
+
blur: properties.shadowBlur,
|
593
|
+
color: properties.shadowColor,
|
594
|
+
id: 'dropShadow'
|
595
|
+
});
|
596
|
+
}
|
597
|
+
|
598
|
+
|
599
|
+
// Draw the background circle
|
600
|
+
this.nodes.background = RGraph.SVG.create({
|
601
|
+
svg: this.svg,
|
602
|
+
type: 'circle',
|
603
|
+
parent: this.svg.all,
|
604
|
+
attr: {
|
605
|
+
cx: this.centerx,
|
606
|
+
cy: this.centery,
|
607
|
+
r: this.radius,
|
608
|
+
stroke: properties.backgroundStroke,
|
609
|
+
fill: properties.backgroundFill,
|
610
|
+
filter: properties.shadow ? 'url(#dropShadow)' : ''
|
611
|
+
}
|
612
|
+
});
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
//
|
632
|
+
// Draw the gray background grid lines
|
633
|
+
//
|
634
|
+
if (properties.backgroundGrid) {
|
635
|
+
(function (obj)
|
636
|
+
{
|
637
|
+
for(var i=0; i<=properties.scaleInnerLabelsCount; ++i) {
|
638
|
+
|
639
|
+
var numticks = properties.tickmarksCount,
|
640
|
+
gap = obj.angleSpan / numticks;
|
641
|
+
|
642
|
+
// Draw the background grid lines
|
643
|
+
var endPoint = RGraph.SVG.TRIG.getRadiusEndPoint({
|
644
|
+
angle: obj.angleStart + (i * gap) - RGraph.SVG.TRIG.HALFPI,
|
645
|
+
radius: obj.radius - properties.rmargin - properties.innerGap
|
646
|
+
});
|
647
|
+
|
648
|
+
RGraph.SVG.create({
|
649
|
+
svg: obj.svg,
|
650
|
+
type: 'path',
|
651
|
+
parent: obj.svg.all,
|
652
|
+
attr: {
|
653
|
+
d: 'M{1} {2} L{3} {4}'.format(
|
654
|
+
obj.centerx + endPoint[0], obj.centery + endPoint[1],
|
655
|
+
obj.centerx, obj.centery
|
656
|
+
),
|
657
|
+
stroke: properties.backgroundGridColor,
|
658
|
+
fill: 'transparent',
|
659
|
+
'stroke-width': 1,
|
660
|
+
'stroke-linecap': 'square'
|
661
|
+
}
|
662
|
+
});
|
663
|
+
}
|
664
|
+
})(this);
|
665
|
+
}
|
666
|
+
|
667
|
+
|
668
|
+
|
669
|
+
|
670
|
+
|
671
|
+
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
|
676
|
+
// Create the axis groups
|
677
|
+
this.nodes.innerAxisGroup = RGraph.SVG.create({
|
678
|
+
svg: this.svg,
|
679
|
+
type: 'g',
|
680
|
+
parent: this.svg.all,
|
681
|
+
attr: {
|
682
|
+
id: 'innerAxisGroup',
|
683
|
+
}
|
684
|
+
});
|
685
|
+
|
686
|
+
|
687
|
+
this.nodes.outerAxisGroup = RGraph.SVG.create({
|
688
|
+
svg: this.svg,
|
689
|
+
type: 'g',
|
690
|
+
parent: this.svg.all,
|
691
|
+
attr: {
|
692
|
+
id: 'outerAxisGroup',
|
693
|
+
}
|
694
|
+
});
|
695
|
+
|
696
|
+
|
697
|
+
|
698
|
+
|
699
|
+
//
|
700
|
+
// Draw the circular lines
|
701
|
+
//
|
702
|
+
var innerPath = RGraph.SVG.TRIG.getArcPath3({
|
703
|
+
cx: this.centerx,
|
704
|
+
cy: this.centery,
|
705
|
+
r: this.radius - properties.innerGap - properties.rmargin,
|
706
|
+
start: this.angleStart,
|
707
|
+
end: this.angleEnd,
|
708
|
+
anticlockwise: false,
|
709
|
+
lineto: false
|
710
|
+
});
|
711
|
+
|
712
|
+
var inner = RGraph.SVG.create({
|
713
|
+
svg: this.svg,
|
714
|
+
type: 'path',
|
715
|
+
parent: this.nodes.innerAxisGroup,
|
716
|
+
attr: {
|
717
|
+
d: innerPath,
|
718
|
+
stroke: properties.colors[1],
|
719
|
+
fill: 'transparent',
|
720
|
+
'stroke-width': properties.linewidth
|
721
|
+
}
|
722
|
+
});
|
723
|
+
|
724
|
+
|
725
|
+
|
726
|
+
|
727
|
+
|
728
|
+
|
729
|
+
|
730
|
+
|
731
|
+
|
732
|
+
|
733
|
+
|
734
|
+
|
735
|
+
|
736
|
+
|
737
|
+
// Draw the outer partial circle
|
738
|
+
var outerPath = RGraph.SVG.TRIG.getArcPath3({
|
739
|
+
cx: this.centerx,
|
740
|
+
cy: this.centery,
|
741
|
+
r: this.radius - properties.rmargin,
|
742
|
+
start: this.angleStart,
|
743
|
+
end: this.angleEnd,
|
744
|
+
anticlockwise: false,
|
745
|
+
lineto: false
|
746
|
+
});
|
747
|
+
|
748
|
+
var outer = RGraph.SVG.create({
|
749
|
+
svg: this.svg,
|
750
|
+
type: 'path',
|
751
|
+
parent: this.nodes.outerAxisGroup,
|
752
|
+
attr: {
|
753
|
+
d: outerPath,
|
754
|
+
stroke: properties.colors[0],
|
755
|
+
fill: 'transparent',
|
756
|
+
'stroke-width': properties.linewidth
|
757
|
+
}
|
758
|
+
});
|
759
|
+
|
760
|
+
// Store references to the circles
|
761
|
+
this.nodes.outerAxis = outerPath;
|
762
|
+
this.nodes.innerAxis = innerPath;
|
763
|
+
|
764
|
+
|
765
|
+
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
|
770
|
+
|
771
|
+
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
|
776
|
+
|
777
|
+
|
778
|
+
|
779
|
+
|
780
|
+
var numticks = properties.tickmarksCount,
|
781
|
+
gap = this.angleSpan / numticks,
|
782
|
+
numlabels = properties.tickmarksCount;
|
783
|
+
|
784
|
+
|
785
|
+
|
786
|
+
//
|
787
|
+
// Get the text configurations
|
788
|
+
//
|
789
|
+
var textConfOuter = RGraph.SVG.getTextConf({
|
790
|
+
object: this,
|
791
|
+
prefix: 'scaleOuter'
|
792
|
+
});
|
793
|
+
|
794
|
+
var textConfInner = RGraph.SVG.getTextConf({
|
795
|
+
object: this,
|
796
|
+
prefix: 'scaleInner'
|
797
|
+
});
|
798
|
+
|
799
|
+
|
800
|
+
for (var i=0; i<=properties.scaleOuterLabelsCount; ++i) {
|
801
|
+
|
802
|
+
if (properties.scaleOuter) {
|
803
|
+
|
804
|
+
// Draw the OUTER tickmarks
|
805
|
+
var path_a = RGraph.SVG.TRIG.getArcPath3({
|
806
|
+
cx: this.centerx,
|
807
|
+
cy: this.centery,
|
808
|
+
r: this.radius - properties.rmargin,
|
809
|
+
start: this.angleStart + (i * gap),
|
810
|
+
end: this.angleStart + (i * gap),
|
811
|
+
anticlockwise: false,
|
812
|
+
lineto: false
|
813
|
+
});
|
814
|
+
|
815
|
+
var path_b = RGraph.SVG.TRIG.getArcPath3({
|
816
|
+
cx: this.centerx,
|
817
|
+
cy: this.centery,
|
818
|
+
r: this.radius + properties.tickmarksOuterSize - properties.rmargin,
|
819
|
+
start: this.angleStart + (i * gap),
|
820
|
+
end: this.angleStart + (i * gap),
|
821
|
+
anticlockwise: false,
|
822
|
+
lineto: true
|
823
|
+
});
|
824
|
+
|
825
|
+
RGraph.SVG.create({
|
826
|
+
svg: this.svg,
|
827
|
+
type: 'path',
|
828
|
+
parent: this.nodes.outerAxisGroup,
|
829
|
+
attr: {
|
830
|
+
d: path_a + ' ' + path_b,
|
831
|
+
stroke: properties.colors[0],
|
832
|
+
fill: 'transparent',
|
833
|
+
'stroke-width': properties.linewidth,
|
834
|
+
'stroke-linecap': 'square'
|
835
|
+
}
|
836
|
+
});
|
837
|
+
|
838
|
+
//
|
839
|
+
// Determine the correct gap for the outer labels#
|
840
|
+
//
|
841
|
+
var outerLabelGap = (this.angleEnd - this.angleStart) / properties.scaleOuterLabelsCount;
|
842
|
+
|
843
|
+
// Calculate the coordinates for the text label
|
844
|
+
var coords = RGraph.SVG.TRIG.toCartesian({
|
845
|
+
cx: this.centerx,
|
846
|
+
cy: this.centery,
|
847
|
+
r: this.radius + properties.tickmarksOuterSize + 10 - properties.rmargin,
|
848
|
+
angle: this.angleStart - RGraph.SVG.TRIG.HALFPI + (i * outerLabelGap)
|
849
|
+
});
|
850
|
+
|
851
|
+
var halign = (coords.x > this.centerx ? 'left' : 'right');
|
852
|
+
|
853
|
+
if (i / numlabels === 0.5) {
|
854
|
+
halign = 'center';
|
855
|
+
}
|
856
|
+
|
857
|
+
var zerolabel = RGraph.SVG.numberFormat({
|
858
|
+
object: this,
|
859
|
+
prepend: properties.scaleOuterUnitsPre,
|
860
|
+
append: properties.scaleOuterUnitsPost,
|
861
|
+
num: this.outerMin.toFixed(properties.scaleOuterDecimals),
|
862
|
+
point: properties.scaleOuterPoint,
|
863
|
+
thousand: properties.scaleOuterThousand
|
864
|
+
});
|
865
|
+
|
866
|
+
if (typeof properties.scaleOuterFormatter === 'function') {
|
867
|
+
zerolabel = (properties.scaleOuterFormatter)(zerolabel);
|
868
|
+
}
|
869
|
+
|
870
|
+
// Add an outer text label
|
871
|
+
var textnode = RGraph.SVG.text({
|
872
|
+
object: this,
|
873
|
+
svg: this.svg,
|
874
|
+
parent: this.nodes.outerAxisGroup,
|
875
|
+
tag: 'scale.outer',
|
876
|
+
text: (i === 0 ? zerolabel : this.scaleOuter.labels[i - 1]),
|
877
|
+
x: coords.x,
|
878
|
+
y: coords.y,
|
879
|
+
halign: halign,
|
880
|
+
valign: 'center',
|
881
|
+
padding: 2,
|
882
|
+
|
883
|
+
size: textConfOuter.size,
|
884
|
+
color: textConfOuter.color,
|
885
|
+
bold: textConfOuter.bold,
|
886
|
+
italic: textConfOuter.italic,
|
887
|
+
font: textConfOuter.font
|
888
|
+
});
|
889
|
+
|
890
|
+
textnode.style.pointerEvents = 'none';
|
891
|
+
|
892
|
+
} else {
|
893
|
+
|
894
|
+
|
895
|
+
|
896
|
+
// Close the circles
|
897
|
+
|
898
|
+
|
899
|
+
|
900
|
+
var path_a = RGraph.SVG.TRIG.getArcPath3({
|
901
|
+
cx: this.centerx,
|
902
|
+
cy: this.centery,
|
903
|
+
r: this.radius - properties.rmargin,
|
904
|
+
start: this.angleStart,
|
905
|
+
end: this.angleStart,
|
906
|
+
anticlockwise: false,
|
907
|
+
lineto: false
|
908
|
+
});
|
909
|
+
|
910
|
+
var path_b = RGraph.SVG.TRIG.getArcPath3({
|
911
|
+
cx: this.centerx,
|
912
|
+
cy: this.centery,
|
913
|
+
r: this.radius - properties.innerGap - properties.rmargin,
|
914
|
+
start: this.angleStart,
|
915
|
+
end: this.angleStart,
|
916
|
+
anticlockwise: false,
|
917
|
+
lineto: true
|
918
|
+
});
|
919
|
+
|
920
|
+
RGraph.SVG.create({
|
921
|
+
svg: this.svg,
|
922
|
+
type: 'path',
|
923
|
+
parent: this.nodes.innerAxisGroup,
|
924
|
+
attr: {
|
925
|
+
d: path_a + path_b,
|
926
|
+
stroke: properties.colors[1],
|
927
|
+
fill: 'transparent',
|
928
|
+
'stroke-width': properties.linewidth,
|
929
|
+
'stroke-linecap': 'square'
|
930
|
+
}
|
931
|
+
});
|
932
|
+
|
933
|
+
|
934
|
+
|
935
|
+
|
936
|
+
|
937
|
+
|
938
|
+
var path_a = RGraph.SVG.TRIG.getArcPath3({
|
939
|
+
cx: this.centerx,
|
940
|
+
cy: this.centery,
|
941
|
+
r: this.radius - properties.rmargin,
|
942
|
+
start: this.angleEnd,
|
943
|
+
end: this.angleEnd,
|
944
|
+
anticlockwise: false,
|
945
|
+
lineto: false
|
946
|
+
});
|
947
|
+
|
948
|
+
var path_b = RGraph.SVG.TRIG.getArcPath3({
|
949
|
+
cx: this.centerx,
|
950
|
+
cy: this.centery,
|
951
|
+
r: this.radius - properties.innerGap - properties.rmargin,
|
952
|
+
start: this.angleEnd,
|
953
|
+
end: this.angleEnd,
|
954
|
+
anticlockwise: false,
|
955
|
+
lineto: true
|
956
|
+
});
|
957
|
+
|
958
|
+
RGraph.SVG.create({
|
959
|
+
svg: this.svg,
|
960
|
+
type: 'path',
|
961
|
+
parent: this.nodes.innerAxisGroup,
|
962
|
+
attr: {
|
963
|
+
d: path_a + path_b,
|
964
|
+
stroke: properties.colors[1],
|
965
|
+
fill: 'transparent',
|
966
|
+
'stroke-width': properties.linewidth,
|
967
|
+
'stroke-linecap': 'square'
|
968
|
+
}
|
969
|
+
});
|
970
|
+
}
|
971
|
+
}
|
972
|
+
|
973
|
+
|
974
|
+
|
975
|
+
|
976
|
+
// Draw the inner labels
|
977
|
+
for(var i=0; i<=properties.scaleInnerLabelsCount; ++i) {
|
978
|
+
|
979
|
+
|
980
|
+
|
981
|
+
|
982
|
+
|
983
|
+
|
984
|
+
|
985
|
+
// Draw the INNER tickmarks
|
986
|
+
|
987
|
+
|
988
|
+
|
989
|
+
|
990
|
+
var path_a = RGraph.SVG.TRIG.getArcPath3({
|
991
|
+
cx: this.centerx,
|
992
|
+
cy: this.centery,
|
993
|
+
r: this.radius - properties.rmargin - properties.innerGap,
|
994
|
+
start: this.angleStart + (i * gap),
|
995
|
+
end: this.angleStart + (i * gap),
|
996
|
+
anticlockwise: false,
|
997
|
+
lineto: false
|
998
|
+
});
|
999
|
+
|
1000
|
+
var path_b = RGraph.SVG.TRIG.getArcPath3({
|
1001
|
+
cx: this.centerx,
|
1002
|
+
cy: this.centery,
|
1003
|
+
r: this.radius - properties.innerGap - properties.tickmarksOuterSize - properties.rmargin,
|
1004
|
+
start: this.angleStart + (i * gap),
|
1005
|
+
end: this.angleStart + (i * gap),
|
1006
|
+
anticlockwise: false,
|
1007
|
+
lineto: true
|
1008
|
+
});
|
1009
|
+
|
1010
|
+
RGraph.SVG.create({
|
1011
|
+
svg: this.svg,
|
1012
|
+
type: 'path',
|
1013
|
+
parent: this.nodes.innerAxisGroup,
|
1014
|
+
attr: {
|
1015
|
+
d: path_a + ' ' + path_b,
|
1016
|
+
stroke: properties.colors[1],
|
1017
|
+
fill: 'transparent',
|
1018
|
+
'stroke-width': properties.linewidth,
|
1019
|
+
'stroke-linecap': 'square'
|
1020
|
+
}
|
1021
|
+
});
|
1022
|
+
|
1023
|
+
|
1024
|
+
//
|
1025
|
+
// Determine the correct gap for the outer labels#
|
1026
|
+
//
|
1027
|
+
var innerLabelGap = (this.angleEnd - this.angleStart) / properties.scaleInnerLabelsCount;
|
1028
|
+
|
1029
|
+
|
1030
|
+
// Calculate the coordinates for the text label
|
1031
|
+
var coords = RGraph.SVG.TRIG.toCartesian({
|
1032
|
+
cx: this.centerx,
|
1033
|
+
cy: this.centery,
|
1034
|
+
r: this.radius - properties.innerGap - properties.tickmarksInnerSize - 10 - properties.rmargin,
|
1035
|
+
angle: this.angleStart - RGraph.SVG.TRIG.HALFPI + (i * innerLabelGap)
|
1036
|
+
});
|
1037
|
+
|
1038
|
+
var halign = (coords.x > this.centerx ? 'right' : 'left');
|
1039
|
+
|
1040
|
+
|
1041
|
+
var zerolabel = RGraph.SVG.numberFormat({
|
1042
|
+
object: this,
|
1043
|
+
prepend: properties.scaleInnerUnitsPre,
|
1044
|
+
append: properties.scaleInnerUnitsPost,
|
1045
|
+
num: this.innerMin.toFixed(properties.scaleInnerDecimals),
|
1046
|
+
point: properties.scaleInnerPoint,
|
1047
|
+
thousand: properties.scaleInnerThousand
|
1048
|
+
});
|
1049
|
+
|
1050
|
+
if (typeof properties.scaleInnerFormatter === 'function') {
|
1051
|
+
zerolabel = (properties.scaleInnerFormatter)(zerolabel);
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
// Change the horizontal alignment for the center label
|
1055
|
+
if (
|
1056
|
+
coords.x > (this.centerx - 2)
|
1057
|
+
&& coords.x < (this.centerx + 2)
|
1058
|
+
) {
|
1059
|
+
halign = 'center';
|
1060
|
+
}
|
1061
|
+
|
1062
|
+
// Add an inner text label
|
1063
|
+
RGraph.SVG.text({
|
1064
|
+
object: this,
|
1065
|
+
svg: this.svg,
|
1066
|
+
parent: this.nodes.innerAxisGroup,
|
1067
|
+
tag: 'scale.inner',
|
1068
|
+
|
1069
|
+
text: (i === 0 ? zerolabel : this.scaleInner.labels[i - 1]),
|
1070
|
+
|
1071
|
+
x: coords.x,
|
1072
|
+
y: coords.y,
|
1073
|
+
halign: halign,
|
1074
|
+
valign: 'center',
|
1075
|
+
padding: 2,
|
1076
|
+
|
1077
|
+
size: textConfInner.size,
|
1078
|
+
color: textConfInner.color,
|
1079
|
+
bold: textConfInner.bold,
|
1080
|
+
italic: textConfInner.italic,
|
1081
|
+
font: textConfInner.font
|
1082
|
+
});
|
1083
|
+
}
|
1084
|
+
};
|
1085
|
+
|
1086
|
+
|
1087
|
+
|
1088
|
+
|
1089
|
+
|
1090
|
+
|
1091
|
+
|
1092
|
+
|
1093
|
+
// Draws the label that sits below the needle,
|
1094
|
+
// inside the meter
|
1095
|
+
this.drawIngraph = function ()
|
1096
|
+
{
|
1097
|
+
// If the group already exists remove it
|
1098
|
+
if (this.nodes.labelsIngraphGroup) {
|
1099
|
+
this.nodes.labelsIngraphGroup.parentNode.removeChild(this.nodes.labelsIngraphGroup);
|
1100
|
+
}
|
1101
|
+
|
1102
|
+
this.nodes.labelsIngraphGroup = RGraph.SVG.create({
|
1103
|
+
svg: this.svg,
|
1104
|
+
type: 'g',
|
1105
|
+
parent: this.svg.all,
|
1106
|
+
attr: {
|
1107
|
+
id: 'labelsIngraphGroup',
|
1108
|
+
}
|
1109
|
+
});
|
1110
|
+
|
1111
|
+
// Get the text configuration
|
1112
|
+
var textConf = RGraph.SVG.getTextConf({
|
1113
|
+
object: this,
|
1114
|
+
prefix: 'labelsIngraph'
|
1115
|
+
});
|
1116
|
+
|
1117
|
+
this.nodes.labelsIngraph = RGraph.SVG.text({
|
1118
|
+
object: this,
|
1119
|
+
parent: this.nodes.labelsIngraphGroup,
|
1120
|
+
text: RGraph.SVG.numberFormat({
|
1121
|
+
prepend: properties.labelsIngraphUnitsPre,
|
1122
|
+
append: properties.labelsIngraphUnitsPost,
|
1123
|
+
point: properties.labelsIngraphPoint,
|
1124
|
+
thousand: properties.labelsIngraphThousand,
|
1125
|
+
formatter: properties.labelsIngraphFormatter,
|
1126
|
+
num: this.value.toFixed(properties.labelsIngraphDecimals)
|
1127
|
+
}),
|
1128
|
+
x: this.centerx,
|
1129
|
+
y: this.centery + this.radius - properties.rmargin - 30,
|
1130
|
+
background: properties.labelsIngraphBackground,
|
1131
|
+
backgroundRounded: properties.labelsIngraphRounded,
|
1132
|
+
padding: properties.labelsIngraphPadding,
|
1133
|
+
halign: 'center',
|
1134
|
+
valign: 'center',
|
1135
|
+
|
1136
|
+
size: textConf.size,
|
1137
|
+
bold: textConf.bold,
|
1138
|
+
italic: textConf.italic,
|
1139
|
+
font: textConf.font,
|
1140
|
+
color: textConf.color
|
1141
|
+
});
|
1142
|
+
|
1143
|
+
// Add a border to the rect
|
1144
|
+
var rect = this.nodes.labelsIngraph.previousSibling;
|
1145
|
+
|
1146
|
+
rect.setAttribute('stroke', '#aaa');
|
1147
|
+
|
1148
|
+
// Prevent clicks on the label from affecting the rest of the
|
1149
|
+
// chart if adjusting is enabled
|
1150
|
+
var func = function (e) {e.stopPropagation();};
|
1151
|
+
|
1152
|
+
rect.addEventListener('mousedown', func, false);
|
1153
|
+
this.nodes.labelsIngraph.addEventListener('mousedown', func, false);
|
1154
|
+
};
|
1155
|
+
|
1156
|
+
|
1157
|
+
|
1158
|
+
|
1159
|
+
|
1160
|
+
|
1161
|
+
|
1162
|
+
|
1163
|
+
// Draws the needle of the meter.
|
1164
|
+
//
|
1165
|
+
// This function is used by the adkusting feature to redraw just
|
1166
|
+
// the needle instead of redrawing the whole chart
|
1167
|
+
//
|
1168
|
+
this.drawNeedle = function ()
|
1169
|
+
{
|
1170
|
+
// Remove any pre-existing needle
|
1171
|
+
if (this.nodes.needleGroup) {
|
1172
|
+
this.nodes.needleGroup.parentNode.removeChild(this.nodes.needleGroup);
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
|
1176
|
+
|
1177
|
+
this.nodes.needleGroup = RGraph.SVG.create({
|
1178
|
+
svg: this.svg,
|
1179
|
+
type: 'g',
|
1180
|
+
parent: this.svg.all,
|
1181
|
+
attr: {
|
1182
|
+
id: 'needle-group',
|
1183
|
+
fill: properties.needleColor,
|
1184
|
+
stroke: properties.needleColor
|
1185
|
+
}
|
1186
|
+
});
|
1187
|
+
|
1188
|
+
|
1189
|
+
|
1190
|
+
|
1191
|
+
|
1192
|
+
// Calculate the end coords of the needle
|
1193
|
+
var angle = (this.value - this.innerMin) / (this.innerMax - this.innerMin) * this.angleSpan;
|
1194
|
+
angle += RGraph.SVG.TRIG.HALFPI + (RGraph.SVG.TRIG.HALFPI / 2);
|
1195
|
+
|
1196
|
+
// These are the coords of the tip of the needle
|
1197
|
+
var coords = RGraph.SVG.TRIG.toCartesian({
|
1198
|
+
cx: this.centerx,
|
1199
|
+
cy: this.centery,
|
1200
|
+
r: this.radius - 60,
|
1201
|
+
angle: angle
|
1202
|
+
});
|
1203
|
+
|
1204
|
+
// These are the coords of the left of the needle
|
1205
|
+
var coords2 = RGraph.SVG.TRIG.toCartesian({
|
1206
|
+
cx: this.centerx,
|
1207
|
+
cy: this.centery,
|
1208
|
+
r: properties.centerpinRadius,
|
1209
|
+
angle: angle - RGraph.SVG.TRIG.HALFPI
|
1210
|
+
});
|
1211
|
+
|
1212
|
+
// These are the coords of the right of the needle
|
1213
|
+
var coords3 = RGraph.SVG.TRIG.toCartesian({
|
1214
|
+
cx: this.centerx,
|
1215
|
+
cy: this.centery,
|
1216
|
+
r: properties.centerpinRadius,
|
1217
|
+
angle: angle + RGraph.SVG.TRIG.HALFPI
|
1218
|
+
});
|
1219
|
+
|
1220
|
+
// Now draw the needle
|
1221
|
+
RGraph.SVG.create({
|
1222
|
+
svg: this.svg,
|
1223
|
+
type: 'path',
|
1224
|
+
parent: this.nodes.needleGroup,
|
1225
|
+
attr: {
|
1226
|
+
'stroke-width': 1,
|
1227
|
+
'stroke-linecap': "round",
|
1228
|
+
d: 'M{1} {2} L{3} {4} L{5} {6} z'.format(
|
1229
|
+
coords.x,
|
1230
|
+
coords.y,
|
1231
|
+
coords2.x,
|
1232
|
+
coords2.y,
|
1233
|
+
coords3.x,
|
1234
|
+
coords3.y
|
1235
|
+
|
1236
|
+
)
|
1237
|
+
}
|
1238
|
+
});
|
1239
|
+
|
1240
|
+
// Draw a center circle
|
1241
|
+
RGraph.SVG.create({
|
1242
|
+
svg: this.svg,
|
1243
|
+
type: 'circle',
|
1244
|
+
parent: this.nodes.needleGroup,
|
1245
|
+
attr: {
|
1246
|
+
cx:this.centerx,
|
1247
|
+
cy: this.centery,
|
1248
|
+
r: properties.centerpinRadius
|
1249
|
+
}
|
1250
|
+
});
|
1251
|
+
|
1252
|
+
|
1253
|
+
|
1254
|
+
|
1255
|
+
// Update the ingraph label if it's enabled
|
1256
|
+
if (properties.labelsIngraph) {
|
1257
|
+
this.drawIngraph();
|
1258
|
+
}
|
1259
|
+
};
|
1260
|
+
|
1261
|
+
|
1262
|
+
|
1263
|
+
|
1264
|
+
|
1265
|
+
|
1266
|
+
|
1267
|
+
|
1268
|
+
|
1269
|
+
|
1270
|
+
|
1271
|
+
|
1272
|
+
|
1273
|
+
|
1274
|
+
|
1275
|
+
|
1276
|
+
|
1277
|
+
//
|
1278
|
+
// This allows for easy specification of gradients
|
1279
|
+
//
|
1280
|
+
this.parseColors = function ()
|
1281
|
+
{
|
1282
|
+
// Save the original colors so that they can be restored when the canvas is reset
|
1283
|
+
if (!Object.keys(this.originalColors).length) {
|
1284
|
+
this.originalColors = {
|
1285
|
+
colors: RGraph.SVG.arrayClone(properties.colors),
|
1286
|
+
backgroundFill: RGraph.SVG.arrayClone(properties.backgroundFill),
|
1287
|
+
backgroundStroke: RGraph.SVG.arrayClone(properties.backgroundStroke),
|
1288
|
+
labelsIngraphBackground: RGraph.SVG.arrayClone(properties.labelsIngraphBackground)
|
1289
|
+
}
|
1290
|
+
}
|
1291
|
+
|
1292
|
+
// backgroundFill
|
1293
|
+
properties.backgroundFill = RGraph.SVG.parseColorLinear({
|
1294
|
+
object: this,
|
1295
|
+
color: properties.backgroundFill,
|
1296
|
+
start: properties.marginTop,
|
1297
|
+
end: this.height - properties.marginBottom,
|
1298
|
+
direction: 'vertical'
|
1299
|
+
});
|
1300
|
+
|
1301
|
+
// backgroundStroke
|
1302
|
+
properties.backgroundStroke = RGraph.SVG.parseColorLinear({
|
1303
|
+
object: this,
|
1304
|
+
color: properties.backgroundStroke,
|
1305
|
+
start: properties.marginTop,
|
1306
|
+
end: this.height - properties.marginBottom,
|
1307
|
+
direction: 'vertical'
|
1308
|
+
});
|
1309
|
+
|
1310
|
+
// labelsIngraphBackground
|
1311
|
+
properties.labelsIngraphBackground = RGraph.SVG.parseColorLinear({
|
1312
|
+
object: this,
|
1313
|
+
color: properties.labelsIngraphBackground,
|
1314
|
+
direction: 'vertical',
|
1315
|
+
gradientUnits: 'objectBoundingBox'
|
1316
|
+
});
|
1317
|
+
};
|
1318
|
+
|
1319
|
+
|
1320
|
+
|
1321
|
+
|
1322
|
+
|
1323
|
+
|
1324
|
+
|
1325
|
+
|
1326
|
+
// Returns the value of a click
|
1327
|
+
//
|
1328
|
+
// @param e object The event object
|
1329
|
+
this.getValue = function (e)
|
1330
|
+
{
|
1331
|
+
var mouseX = e.offsetX,
|
1332
|
+
mouseY = e.offsetY;
|
1333
|
+
|
1334
|
+
if (RGraph.SVG.ISFF) {
|
1335
|
+
mouseX = e.pageX - e.currentTarget.offsetLeft;
|
1336
|
+
mouseY = e.pageY - e.currentTarget.offsetTop;
|
1337
|
+
}
|
1338
|
+
|
1339
|
+
var angle = RGraph.SVG.TRIG.getAngleByXY({
|
1340
|
+
cx: this.centerx,
|
1341
|
+
cy: this.centery,
|
1342
|
+
x: mouseX,
|
1343
|
+
y: mouseY
|
1344
|
+
});
|
1345
|
+
|
1346
|
+
if (mouseX < this.centerx) {
|
1347
|
+
angle = angle - RGraph.SVG.TRIG.TWOPI;
|
1348
|
+
}
|
1349
|
+
|
1350
|
+
var value = ((angle - this.angleStart) / (this.angleEnd - this.angleStart));
|
1351
|
+
value = value * (this.innerMax - this.innerMin);
|
1352
|
+
value = value + this.innerMin;
|
1353
|
+
|
1354
|
+
if (value < this.innerMin) value = this.innerMin;
|
1355
|
+
if (value > this.innerMax) value = this.innerMax;
|
1356
|
+
|
1357
|
+
return value;
|
1358
|
+
};
|
1359
|
+
|
1360
|
+
|
1361
|
+
|
1362
|
+
|
1363
|
+
|
1364
|
+
|
1365
|
+
|
1366
|
+
|
1367
|
+
//
|
1368
|
+
// Using a function to add events makes it easier to facilitate method
|
1369
|
+
// chaining
|
1370
|
+
//
|
1371
|
+
// @param string type The type of even to add
|
1372
|
+
// @param function func
|
1373
|
+
//
|
1374
|
+
this.on = function (type, func)
|
1375
|
+
{
|
1376
|
+
if (type.substr(0,2) !== 'on') {
|
1377
|
+
type = 'on' + type;
|
1378
|
+
}
|
1379
|
+
|
1380
|
+
RGraph.SVG.addCustomEventListener(this, type, func);
|
1381
|
+
|
1382
|
+
return this;
|
1383
|
+
};
|
1384
|
+
|
1385
|
+
|
1386
|
+
|
1387
|
+
|
1388
|
+
|
1389
|
+
|
1390
|
+
|
1391
|
+
|
1392
|
+
//
|
1393
|
+
// Used in chaining. Runs a function there and then - not waiting for
|
1394
|
+
// the events to fire (eg the onbeforedraw event)
|
1395
|
+
//
|
1396
|
+
// @param function func The function to execute
|
1397
|
+
//
|
1398
|
+
this.exec = function (func)
|
1399
|
+
{
|
1400
|
+
func(this);
|
1401
|
+
|
1402
|
+
return this;
|
1403
|
+
};
|
1404
|
+
|
1405
|
+
|
1406
|
+
|
1407
|
+
|
1408
|
+
|
1409
|
+
|
1410
|
+
|
1411
|
+
|
1412
|
+
//
|
1413
|
+
// Set the options that the user has provided
|
1414
|
+
//
|
1415
|
+
for (i in conf.options) {
|
1416
|
+
if (typeof i === 'string') {
|
1417
|
+
this.set(i, conf.options[i]);
|
1418
|
+
}
|
1419
|
+
}
|
1420
|
+
};
|
1421
|
+
|
1422
|
+
|
1423
|
+
|
1424
|
+
return this;
|
1425
|
+
|
1426
|
+
|
1427
|
+
|
1428
|
+
|
1429
|
+
// End module pattern
|
1430
|
+
})(window, document);
|