Skip to content

Commit 7037f11

Browse files
committed
chore: bump deps and fix example
1 parent c2fc3cb commit 7037f11

File tree

8 files changed

+1977
-1767
lines changed

8 files changed

+1977
-1767
lines changed

dist/justgage.js

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@
252252
// show full donut gauge
253253
donut: kvLookup("donut", config, dataset, false),
254254

255+
// differential : bool
256+
// show gauge with 0 at 12 o'clock
257+
differential: kvLookup("differential", config, dataset, false),
258+
255259
// relativeGaugeSize : bool
256260
// whether gauge size should follow changes in container element size
257261
relativeGaugeSize: kvLookup("relativeGaugeSize", config, dataset, false),
@@ -470,24 +474,24 @@
470474

471475
// parameters
472476
obj.params = {
473-
canvasW: canvasW,
474-
canvasH: canvasH,
475-
widgetW: widgetW,
476-
widgetH: widgetH,
477-
dx: dx,
478-
dy: dy,
479-
valueFontSize: valueFontSize,
480-
valueX: valueX,
481-
valueY: valueY,
482-
labelFontSize: labelFontSize,
483-
labelX: labelX,
484-
labelY: labelY,
485-
minFontSize: minFontSize,
486-
minX: minX,
487-
minY: minY,
488-
maxFontSize: maxFontSize,
489-
maxX: maxX,
490-
maxY: maxY,
477+
canvasW,
478+
canvasH,
479+
widgetW,
480+
widgetH,
481+
dx,
482+
dy,
483+
valueFontSize,
484+
valueX,
485+
valueY,
486+
labelFontSize,
487+
labelX,
488+
labelY,
489+
minFontSize,
490+
minX,
491+
minY,
492+
maxFontSize,
493+
maxX,
494+
maxY,
491495
};
492496

493497
// var clear
@@ -499,7 +503,7 @@
499503
* @param {Number} value display value
500504
* @returns SVG path string for gauge level
501505
*/
502-
obj.canvas.customAttributes.pki = function (value) {
506+
obj.canvas.customAttributes.pki = function (value, isDiff) {
503507
let min = obj.config.min;
504508
let max = obj.config.max;
505509
const w = obj.params.widgetW;
@@ -509,9 +513,9 @@
509513
const gws = obj.config.gaugeWidthScale;
510514
const donut = obj.config.donut;
511515

512-
let alpha, Ro, Ri, Cx, Cy, Xo, Yo, Xi, Yi, path;
516+
let alpha, Ro, Ri, Cx, Cy, So, Si, Xo, Yo, Xi, Yi, path;
513517

514-
if (min < 0) {
518+
if (min < 0 && !isDiff) {
515519
max -= min;
516520
value -= min;
517521
min = 0;
@@ -544,7 +548,37 @@
544548
path += "Z ";
545549

546550
return {
547-
path: path,
551+
path,
552+
};
553+
} else if (isDiff) {
554+
// At the moment only works with min = -max
555+
// otherwise would need to work out the zero point
556+
// Which of course is possible, but haven't done it yet
557+
alpha = (1 - (value - min) / (max - min)) * Math.PI;
558+
Ro = w / 2 - w / 10;
559+
Ri = Ro - (w / 6.666666666666667) * gws;
560+
561+
Cx = w / 2 + dx;
562+
Cy = h / 1.25 + dy;
563+
564+
Xo = Cx + Ro * Math.cos(alpha);
565+
Yo = Cy - Ro * Math.sin(alpha);
566+
Xi = Cx + Ri * Math.cos(alpha);
567+
Yi = Cy - Ri * Math.sin(alpha);
568+
569+
So = value < 0 ? 1 : 0;
570+
Si = value < 0 ? 0 : 1;
571+
572+
path = "M" + Cx + "," + (Cy - Ri) + " ";
573+
path += "L" + Cx + "," + (Cy - Ro) + " ";
574+
path += "A" + Ro + "," + Ro + " 0 0 " + Si + " " + Xo + "," + Yo + " ";
575+
path += "L" + Xi + "," + Yi + " ";
576+
path +=
577+
"A" + Ri + "," + Ri + " 0 0 " + So + " " + Cx + "," + (Cy - Ri) + " ";
578+
path += "Z ";
579+
580+
return {
581+
path,
548582
};
549583
} else {
550584
alpha = (1 - (value - min) / (max - min)) * Math.PI;
@@ -572,7 +606,7 @@
572606
path += "Z ";
573607

574608
return {
575-
path: path,
609+
path,
576610
};
577611
}
578612
};
@@ -660,7 +694,7 @@
660694
path += "Z ";
661695

662696
return {
663-
path: path,
697+
path,
664698
};
665699
} else {
666700
alpha = (1 - (value - min) / (max - min)) * Math.PI;
@@ -691,7 +725,7 @@
691725
path += "Z ";
692726

693727
return {
694-
path: path,
728+
path,
695729
};
696730
}
697731
};
@@ -713,8 +747,12 @@
713747
obj.config.noGradient,
714748
obj.config.customSectors
715749
),
716-
pki: [obj.config.min],
750+
pki: [
751+
obj.config.differential ? 0 : obj.config.min,
752+
obj.config.differential,
753+
],
717754
});
755+
718756
if (obj.config.donut) {
719757
obj.level.transform(
720758
"r" +
@@ -955,9 +993,10 @@
955993
if (obj.config.reverse) {
956994
rvl = obj.config.max * 1 + obj.config.min * 1 - obj.config.value * 1;
957995
}
996+
958997
obj.level.animate(
959998
{
960-
pki: [rvl],
999+
pki: [rvl, obj.config.differential],
9611000
},
9621001
obj.config.startAnimationTime,
9631002
obj.config.startAnimationType,
@@ -1148,7 +1187,7 @@
11481187

11491188
obj.level.animate(
11501189
{
1151-
pki: [rvl],
1190+
pki: [rvl, obj.config.differential],
11521191
fill: color,
11531192
},
11541193
obj.config.refreshAnimationTime,

dist/justgage.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/justgage.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/differential.html

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,62 @@
1-
<div id="gauge"></div>
1+
<!doctype html>
2+
<html>
23

3-
<!-- Raphael must be included before justgage -->
4-
<script type="text/javascript" src="./raphael.min.js"></script>
5-
<script type="text/javascript" src="./justgage.js"></script>
6-
7-
<script>
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Differential</title>
7+
<meta name="viewport" content="width=device-width">
8+
<style>
9+
.container {
10+
width: 600px;
11+
margin: 100px auto;
12+
text-align: center;
13+
}
814

9-
var gauge = new JustGage({
10-
id: "gauge", // the id of the html element
11-
value: 20,
12-
min: -50,
13-
max: 50,
14-
label: "Amps",
15-
decimals: 2,
16-
gaugeWidthScale: 0.6,
17-
differential: true,
18-
pointer: true,
19-
pointerOptions: {
20-
toplength: -30,
21-
bottomlength: 10,
22-
bottomwidth: 10,
23-
color: '#8e8e93',
24-
stroke: '#ffffff',
25-
stroke_width: 2,
26-
stroke_linecap: 'round'
15+
.gauge {
16+
width: 250px;
17+
height: 250px;
18+
display: inline-block;
2719
}
28-
});
20+
</style>
21+
</head>
22+
23+
<body>
24+
<div class="container">
25+
<div id="gauge"></div>
26+
</div>
27+
<script src="../raphael.min.js"></script>
28+
<script src="../justgage.js"></script>
29+
<script>
30+
document.addEventListener("DOMContentLoaded", function (event) {
31+
32+
var gauge = new JustGage({
33+
id: "gauge", // the id of the html element
34+
value: 20,
35+
min: -50,
36+
max: 50,
37+
label: "Amps",
38+
decimals: 2,
39+
gaugeWidthScale: 0.6,
40+
differential: true,
41+
pointer: true,
42+
pointerOptions: {
43+
toplength: -30,
44+
bottomlength: 10,
45+
bottomwidth: 10,
46+
color: '#8e8e93',
47+
stroke: '#ffffff',
48+
stroke_width: 2,
49+
stroke_linecap: 'round'
50+
}
51+
});
52+
53+
// update the value randomly
54+
setInterval(() => {
55+
gauge.refresh(Math.random() * 100 - 50);
56+
}, 5000)
2957

30-
// update the value randomly
31-
setInterval(() => {
32-
gauge.refresh(Math.random() * 100 - 50);
33-
}, 5000)
58+
});
59+
</script>
60+
</body>
3461

35-
</script>
62+
</html>

0 commit comments

Comments
 (0)