Skip to content

Commit

Permalink
Fix for issue #2 and some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
naikus committed Oct 28, 2016
1 parent 391d9ed commit db7837c
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 128 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ var Gauge = window.Gauge;

// Create a new Gauge
var cpuGauge = Gauge(document.getElementById("cpuSpeed"), {
min: 0
max: 100,
// custom label renderer
label: function(value) {
return Math.round(value) + "/" + this.max;
},
value: 50,
});

Expand All @@ -67,6 +70,7 @@ cpuGauge.setValueAnimated(90, 1);
| ```dialEndAngle``` | The angle in degrees to end the dial. This MUST be less than dialStartAngle (```45```) |
| ```radius``` | The radius of the gauge (```400```) |
| ```max``` | The maximum value for the gauge (```100```) |
| ```label``` | Optional function that returns a string label that will be rendered in the center. This function will be passed the current value |
| ```showValue``` | Whether to show the value at the center of the gauge (```true```) |


Expand Down
15 changes: 9 additions & 6 deletions dist/gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
currentIteration = 1,
iterations = 60 * duration,
start = options.start || 0,
end = options.end || 100,
end = options.end,
change = end - start,
step = options.step,
easing = options.easing || function easeInOutCubic(pos) {
Expand Down Expand Up @@ -168,9 +168,9 @@
value = normalize(opts.value || 0, limit),
radius = opts.radius || 400,
displayValue = opts.showValue === false ? false : true,
valueLabelRender = typeof opts.label === "function" ? opts.label : defaultLabelRenderer,
startAngle = typeof(opts.dialStartAngle) === "undefined" ? 135 : opts.dialStartAngle,
endAngle = typeof(opts.dialEndAngle) === "undefined" ? 45 : opts.dialEndAngle,
valueLabelRender = typeof (opts.label) === "function" ? opts.label : defaultLabelRenderer,
startAngle = typeof (opts.dialStartAngle) === "undefined" ? 135 : opts.dialStartAngle,
endAngle = typeof (opts.dialEndAngle) === "undefined" ? 45 : opts.dialEndAngle,
gaugeTextElem,
gaugeValuePath,
instance;
Expand Down Expand Up @@ -241,12 +241,15 @@
limit = max;
},
setValue: function(val) {
value = normalize(val);
value = normalize(val, limit);
updateGauge(value);
},
setValueAnimated: function(val, duration) {
var oldVal = value;
value = normalize(val);
value = normalize(val, limit);
if(oldVal === value) {
return;
}
Animation({
start: oldVal || 0,
end: value,
Expand Down
2 changes: 1 addition & 1 deletion dist/gauge.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
display: block;
float: left;
padding: 10px;
overflow: hidden;
}
.gauge-container > .gauge > .dial {
stroke: #334455;
Expand Down
227 changes: 114 additions & 113 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
text-align: center;
overflow: auto;
padding: 20px 0;
overflow: hidden;
}
.example > .display {
padding-left: 20%;
}

pre {
Expand All @@ -45,12 +45,12 @@
font-size: 6em;
}

@media only screen and (min-device-width: 600px) {
@media only screen and (min-device-width: 768px) {
.example > .code {
width: 70%;
width: 65%;
}
.example > .display {
width: 30%;
width: 35%;
}
.example > .code {
float: left;
Expand All @@ -77,20 +77,21 @@ <h4>Minimalistic, zero dependency animated gauge widget</h4>
<div class="example">
<div class="code">
<pre>
<code class="html">&lt;div id="gauge1" class="gauge-container"&gt;&lt;/div&gt;</code>
<code class="javascript">
var gauge1 = Gauge(
document.getElementById("gauge1"),
{
max: 100,
dialStartAngle: -90,
dialEndAngle: -90.001,
value: 100,
label: function(value) {
return Math.round(value) + "/" + this.max;
}
}
);</code>
<code class="html">&lt;div id="gauge1" class="gauge-container"&gt;&lt;/div&gt;</code>
<code class="javascript">
var gauge1 = Gauge(
document.getElementById("gauge1"),
{
max: 100,
dialStartAngle: -90,
dialEndAngle: -90.001,
value: 100,
label: function(value) {
return Math.round(value) + "/" + this.max;
}
}
);
</code>
</pre>
</div>
<div class="display">
Expand All @@ -103,20 +104,20 @@ <h4>Minimalistic, zero dependency animated gauge widget</h4>
<div class="example">
<div class="code">
<pre>
<code class="html">
&lt;div id="gauge2" class="gauge-container two"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge2 = Gauge(
document.getElementById("gauge2"),
{
max: 100,
dialStartAngle: 180,
dialEndAngle: 0,
value: 50
}
);
</code>
<code class="html">
&lt;div id="gauge2" class="gauge-container two"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge2 = Gauge(
document.getElementById("gauge2"),
{
max: 100,
dialStartAngle: 180,
dialEndAngle: 0,
value: 50
}
);
</code>
</pre>
</div>
<div class="display">
Expand All @@ -130,71 +131,71 @@ <h4>Minimalistic, zero dependency animated gauge widget</h4>
<div class="example">
<div class="code">
<pre>
<code class="html">
&lt;div id="gauge3" class="gauge-container three"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge3 = Gauge(
document.getElementById("gauge3"),
{
max: 100,
value: 50
}
);
</code>
</pre>
</div>
<div class="display">
<div id="gauge3" class="gauge-container three"></div>
</div>
</div>



<div class="example">
<div class="code">
<pre>
<code class="html">
&lt;div id="gauge4" class="gauge-container four"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge4 = Gauge(
document.getElementById("gauge4"),
{
max: 100,
dialStartAngle: 180,
dialEndAngle: -90,
value: 50
}
);
</code>
</pre>
</div>
<div class="display">
<div id="gauge4" class="gauge-container four"></div>
</div>
</div>




<div class="example">
<div class="code">
<pre>
<code class="html">
&lt;div id="gauge5" class="gauge-container five"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge5 = Gauge(
document.getElementById("gauge5"),
{
max: 200,
dialStartAngle: 0,
dialEndAngle: -180,
value: 50
}
);
</code>
<code class="html">
&lt;div id="gauge3" class="gauge-container three"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge3 = Gauge(
document.getElementById("gauge3"),
{
max: 100,
value: 50
}
);
</code>
</pre>
</div>
<div class="display">
<div id="gauge3" class="gauge-container three"></div>
</div>
</div>



<div class="example">
<div class="code">
<pre>
<code class="html">
&lt;div id="gauge4" class="gauge-container four"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge4 = Gauge(
document.getElementById("gauge4"),
{
max: 100,
dialStartAngle: 180,
dialEndAngle: -90,
value: 50
}
);
</code>
</pre>
</div>
<div class="display">
<div id="gauge4" class="gauge-container four"></div>
</div>
</div>




<div class="example">
<div class="code">
<pre>
<code class="html">
&lt;div id="gauge5" class="gauge-container five"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge5 = Gauge(
document.getElementById("gauge5"),
{
max: 200,
dialStartAngle: 0,
dialEndAngle: -180,
value: 50
}
);
</code>
</pre>
</div>
<div class="display">
Expand All @@ -208,22 +209,22 @@ <h4>Minimalistic, zero dependency animated gauge widget</h4>
<div class="example">
<div class="code">
<pre>
<code class="html">
&lt;div id="gauge6" class="gauge-container six"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge6 = Gauge(
document.getElementById("gauge6"),
{
max: 100,
dialStartAngle: 90.01,
dialEndAngle: 89.99,
radius: 150,
displayValue: false,
value: 50,
}
);
</code>
<code class="html">
&lt;div id="gauge6" class="gauge-container six"&gt;&lt;/div&gt;
</code>
<code class="javascript">
var gauge6 = Gauge(
document.getElementById("gauge6"),
{
max: 100,
dialStartAngle: 90.01,
dialEndAngle: 89.99,
radius: 150,
displayValue: false,
value: 50,
}
);
</code>
</pre>
</div>
<div class="display">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svg-gauge",
"version": "1.0.0",
"version": "1.0.1",
"description": "Minimal SVG animated gauge with zero dependencies",
"main": "index.js",
"directories": {
Expand Down
15 changes: 9 additions & 6 deletions src/gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
currentIteration = 1,
iterations = 60 * duration,
start = options.start || 0,
end = options.end || 100,
end = options.end,
change = end - start,
step = options.step,
easing = options.easing || function easeInOutCubic(pos) {
Expand Down Expand Up @@ -168,9 +168,9 @@
value = normalize(opts.value || 0, limit),
radius = opts.radius || 400,
displayValue = opts.showValue === false ? false : true,
valueLabelRender = typeof opts.label === "function" ? opts.label : defaultLabelRenderer,
startAngle = typeof(opts.dialStartAngle) === "undefined" ? 135 : opts.dialStartAngle,
endAngle = typeof(opts.dialEndAngle) === "undefined" ? 45 : opts.dialEndAngle,
valueLabelRender = typeof (opts.label) === "function" ? opts.label : defaultLabelRenderer,
startAngle = typeof (opts.dialStartAngle) === "undefined" ? 135 : opts.dialStartAngle,
endAngle = typeof (opts.dialEndAngle) === "undefined" ? 45 : opts.dialEndAngle,
gaugeTextElem,
gaugeValuePath,
instance;
Expand Down Expand Up @@ -241,12 +241,15 @@
limit = max;
},
setValue: function(val) {
value = normalize(val);
value = normalize(val, limit);
updateGauge(value);
},
setValueAnimated: function(val, duration) {
var oldVal = value;
value = normalize(val);
value = normalize(val, limit);
if(oldVal === value) {
return;
}
Animation({
start: oldVal || 0,
end: value,
Expand Down

0 comments on commit db7837c

Please sign in to comment.