ridge-speedometer
HTML
<body ng-app="demoApp">
<div>
<ridge-speedometer x-val="33" />
</div>
<div>
<ridge-speedometer x-val="88" x-conf="{backgroundColor: 'white', markerColor: 'black', smallTickColor: 'gray', smallTickIncrement: 2, largeTickColor: 'black'}" />
</div>
</body>
JavaScript
var module = angular.module( 'ridge-speedometer', [] ).directive( 'ridgeSpeedometer', [ '$timeout', function( $timeout ){
return {
restrict: 'EAC',
scope: { targetVal: '=val', conf: '=', label: '@' },
template: '<canvas>HTML Canvas not supported by your browser</canvas><div class="ridge-speedometer-label" style="text-align: center">{{label}}</div>',
link: function( scope, el ){
scope.val = 0;
var conf = setupConf( scope.conf );
if( isNaN( scope.targetVal ) ){
scope.targetVal = conf.min;
}
else if( scope.targetVal < conf.min){
scope.targetVal = conf.min;
}
else if( scope.targetVal > conf.max ){
scope.targetVal = conf.max;
}
if( conf.size )
angular.element(el).find('canvas').attr( 'width', conf.size).attr( 'height', Math.floor( conf.size/2) );
function draw() {
var canvas = angular.element(el).find('canvas')[0],
options = null;
// Canvas good?
if (canvas !== null && canvas.getContext) {
options = buildOptionsAsJSON(canvas, scope.val, conf );
// Clear canvas
clearCanvas(options);
// Draw the styled edge
drawEdgeArcs(options, "outer");
drawEdgeArcs(options, "inner");
// Draw thw background
drawBackground(options);
// Draw tick marks
drawTickMarks(options, "large");
drawTickMarks(options, "small");
// Draw labels on markers
drawTextMarkers(options);
// Draw speeometer colour arc
drawGaugeColourArc(options);
// Draw the needle and base
drawNeedle(options);
} else {
alert("HTML Canvas not supported by your browser!");
}
// Give the imppression of an "active" needle even if
// our values are staying the same
if( scope.val == scope.targetVal ){
if( conf.wobble )
scope.val = scope.val + 1;
}
else if ( scope.val < scope.targetVal ){
if( scope.val+10 < scope.targetVal )
scope.val = scope.val + 5;
else
scope.val =...