Skip to content

Commit

Permalink
Merge pull request #1 from troutowicz/master
Browse files Browse the repository at this point in the history
Fixes issue #2
  • Loading branch information
jasonroman committed Dec 7, 2014
2 parents 51aacb2 + 9f0c19b commit dba880a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions jquery.flot.barnumbers.enhanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,23 @@
{
"use strict";

// default each series to have the bar numbers feature turned off
var options = {
bars: {
numbers: {
show: false,
threshold: false,
yOffset: 0,
xOffset: 0
}
}
};

function processOptions(plot, options)
{
var barnumbers = options.series.bars.numbers;

barnumbers.show = barnumbers.show || false;
barnumbers.threshold = barnumbers.threshold || false;
barnumbers.xOffset = barnumbers.xOffset || 0;
barnumbers.yOffset = barnumbers.yOffset || 0;
}

/**
* Draw the bar values on the bars
*
Expand All @@ -60,10 +65,13 @@
$.each(plot.getData(), function(index, series)
{
var xAlign, yAlign, horizontalShift, i;

// shortcut all of the barnumbers-specific options
var barnumbers = series.bars.numbers;

// make sure this series should show the bar numbers
if (!barnumbers.show) {
return false;
}

// if user-specified function for xAlign, set that
if ($.isFunction(barnumbers.xAlign)) {
xAlign = barnumbers.xAlign;
Expand Down Expand Up @@ -97,11 +105,6 @@
// handles horizontal bar shift for stacked bars using the proper access
horizontalShift = (series.bars.horizontal) ? 0 : 1;

// make sure this series should show the bar numbers
if (!barnumbers.show) {
return false;
}

// variable shortcuts
var points = series.datapoints.points;
var ctx = plot.getCanvas().getContext('2d');
Expand Down Expand Up @@ -192,6 +195,7 @@
*/
function init(plot)
{
plot.hooks.processOptions.push(processOptions);
plot.hooks.draw.push(draw);
}

Expand Down

0 comments on commit dba880a

Please sign in to comment.