Skip to content

Commit

Permalink
Additional fix for issue Mikhus#99 (linear gauge fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhus committed Jan 10, 2017
1 parent df0be3e commit aac8d58
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 13 deletions.
141 changes: 139 additions & 2 deletions examples/issue-99.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
</head>
<body>

<canvas id="gauge"></canvas>
<canvas id="radial-gauge"></canvas>
<canvas id="linear-gauge"></canvas>

<script>
var gauge = new RadialGauge({
"renderTo": 'gauge',
"renderTo": 'radial-gauge',
"width": 201,
"height": 200,
"minValue": -7,
Expand Down Expand Up @@ -150,6 +151,142 @@
"animationTarget": "needle",
"useMinPath": false,
}).draw();

var gauge = new LinearGauge({
"renderTo": 'linear-gauge',
"width": 400,
"height": 120,
"minValue": -7,
"maxValue": 107,
"value": 0,
"units": false,
"exactTicks": true,
"majorTicks": [
-7,
0,
20,
80,
100,
107
],
"minorTicks": 0,
"strokeTicks": true,
"animatedValue": false,
"animateOnInit": false,
"title": false,
"borders": true,
"numbersMargin": 1,
"valueInt": 3,
"valueDec": 2,
"majorTicksInt": 1,
"majorTicksDec": 0,
"animation": true,
"animationDuration": 500,
"animationRule": "cycle",
"colorPlate": "#fff",
"colorPlateEnd": "",
"colorMajorTicks": "#444",
"colorMinorTicks": "#666",
"colorTitle": "#888",
"colorUnits": "#888",
"colorNumbers": "#444",
"colorNeedle": "rgba(240,128,128,1)",
"colorNeedleEnd": "rgba(255,160,122,.9)",
"colorValueText": "#444",
"colorValueTextShadow": "rgba(0,0,0,0.3)",
"colorBorderShadow": "rgba(0,0,0,0.5)",
"colorBorderOuter": "#ddd",
"colorBorderOuterEnd": "#aaa",
"colorBorderMiddle": "#eee",
"colorBorderMiddleEnd": "#f0f0f0",
"colorBorderInner": "#fafafa",
"colorBorderInnerEnd": "#ccc",
"colorValueBoxRect": "#888",
"colorValueBoxRectEnd": "#666",
"colorValueBoxBackground": "#babab2",
"colorValueBoxShadow": "rgba(0,0,0,1)",
"colorNeedleShadowUp": "rgba(2,255,255,0.2)",
"colorNeedleShadowDown": "rgba(188,143,143,0.45)",
"colorBarStroke": "#222",
"colorBar": "#ccc",
"colorBarProgress": "#888",
"colorBarShadow": "#000",
"fontNumbers": "Arial",
"fontTitle": "Arial",
"fontUnits": "Arial",
"fontValue": "Arial",
"fontNumbersSize": 20,
"fontTitleSize": 24,
"fontUnitsSize": 22,
"fontValueSize": 26,
"fontNumbersStyle": "normal",
"fontTitleStyle": "normal",
"fontUnitsStyle": "normal",
"fontValueStyle": "normal",
"fontNumbersWeight": "normal",
"fontTitleWeight": "normal",
"fontUnitsWeight": "normal",
"fontValueWeight": "normal",
"needle": true,
"needleShadow": true,
"needleType": "arrow",
"needleStart": 5,
"needleEnd": 85,
"needleWidth": 4,
"borderOuterWidth": 3,
"borderMiddleWidth": 3,
"borderInnerWidth": 3,
"borderShadowWidth": 3,
"valueBox": true,
"valueBoxStroke": 5,
"valueBoxWidth": 0,
"valueText": "",
"valueTextShadow": true,
"valueBoxBorderRadius": 2.5,
"highlights": [
{
"from": -7,
"to": 0,
"color": "#FF0000"
},
{
"from": 0,
"to": 20,
"color": "#FFF000"
},
{
"from": 20,
"to": 80,
"color": "#00FF00"
},
{
"from": 80,
"to": 100,
"color": "#FFF000"
},
{
"from": 100,
"to": 107,
"color": "#FF0000"
}
],
"highlightsWidth": 15,
"barWidth": 0,
"barStrokeWidth": 0,
"barProgress": true,
"barShadow": 0,
"ticksAngle": 270,
"startAngle": 45,
"colorNeedleCircleOuter": "#f0f0f0",
"colorNeedleCircleOuterEnd": "#ccc",
"colorNeedleCircleInner": "#e8e8e8",
"colorNeedleCircleInnerEnd": "#f5f5f5",
"needleCircleSize": 10,
"needleCircleInner": true,
"needleCircleOuter": true,
"animationTarget": "needle",
"useMinPath": false,
}).draw();
</script>


Expand Down
2 changes: 1 addition & 1 deletion gauge.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gauge.min.js.map

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions lib/LinearGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,20 +762,23 @@ function drawLinearMinorTicks(context, options) {
let ticks = [];
let i = options.minValue;
let minTicks = Math.abs(options.minorTicks) || 0;
let valuePerNonExactTick = minTicks ? (options.maxValue - options.minValue) /
let valuePerNonExactTick = minTicks ?
(options.maxValue - options.minValue) /
(minTicks * (options.majorTicks.length - 1)) : 0;

if (options.exactTicks) {
let delta = (options.majorTicks[0] % minTicks) || 0;
if (minTicks) {
if (options.exactTicks) {
let delta = (options.majorTicks[0] % minTicks) || 0;

for (; i < options.maxValue; i += minTicks) {
ticks.push(delta + i);
for (; i < options.maxValue; i += minTicks) {
ticks.push(delta + i);
}
}
}

else {
for (; i < options.maxValue; i += valuePerNonExactTick) {
ticks.push(i);
else {
for (; i < options.maxValue; i += valuePerNonExactTick) {
ticks.push(i);
}
}
}

Expand Down

0 comments on commit aac8d58

Please sign in to comment.