Skip to content

Instantly share code, notes, and snippets.

@muhqu
Created February 10, 2014 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muhqu/8923013 to your computer and use it in GitHub Desktop.
Save muhqu/8923013 to your computer and use it in GitHub Desktop.
$.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