Created
February 10, 2014 19:56
-
-
Save muhqu/8923013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.peity.register('alarmline', $.extend({},$.fn.peity.defaults.line,{ | |
alarmColour: '#a00' | |
}), function (opts) { | |
$.fn.peity.graphers.line.apply(this, [opts]); | |
var values = this.values(); | |
if (values.length == 1) values.push(values[0]); | |
var min = Math.min.apply(Math, values.concat([opts.min])); | |
var max = Math.max.apply(Math, values.concat([opts.max])); | |
var canvas = this.canvas; | |
var context = this.context; | |
var width = canvas.width; | |
var height = canvas.height - opts.strokeWidth; | |
var yQuotient = height / (max - min); | |
if (opts.alarm) { | |
context.beginPath(); | |
var alarm_y = height - (yQuotient * (opts.alarm - min)) + opts.strokeWidth / 2; | |
context.moveTo(0, alarm_y); | |
context.lineTo(width, alarm_y); | |
context.lineWidth = opts.strokeWidth * (window.devicePixelRatio||1); | |
context.strokeStyle = opts.alarmColour; | |
context.stroke(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment