Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Callback function to allow color setting on the chart ticks. #917

Open
wants to merge 1 commit into from

2 participants

@fmsf

Allow the user to set a function callback for the tick colors. The callback function will be: function(value, axis_direction).

I don't know if calling "$.isFunction(axis.options.tickColor)" in the middle of a loop is a good call (as it won't change during the loop). But wanted to avoid polluting the code. And this function should always process fast.

@fmsf fmsf Allow the user to set a function callback for the tick colors. The ca…
…llback function will be: function(value, axis_direction)
7a5231e
@fmsf

The use case for this was to have different tick colors on specific intervals. Like when using days: have a darker tick on 00:00 and lighter on the other ones

@aaronaverill

I would like to see $.isFunction(color) support across bar fill as well, similar to this request:

#847

It is probably reasonable to do this for any color in the options. If it's a string, use CSS, if it's an array, use a gradient, if it's a function, call the function (then apply recursively).

@fmsf is it possible for you to make the code changes for bar fill color to allow a function? This is really the feature I am after. We will need a slightly different context for the bar color fill context.

I also need to color pie slices individually :)

@dnschnur dnschnur referenced this pull request from a commit
@dnschnur dnschnur Axis and tick color options now make more sense.
The axis color now controls the color of the axis line, instead of its
ticks and labels, while the tickColor controls the tick color. This
makes a little more sense and provides the minor feature of being able
to change the axis line color separately from that of its ticks.  Pull
request #917 ought to be easier to merge now, too.
3cd7a51
@dnschnur dnschnur referenced this pull request from a commit in dnschnur/flot
@dnschnur dnschnur Axis and tick color options now make more sense.
The axis color now controls the color of the axis line, instead of its
ticks and labels, while the tickColor controls the tick color. This
makes a little more sense and provides the minor feature of being able
to change the axis line color separately from that of its ticks.  Pull
request #917 ought to be easier to merge now, too.
5fd5c83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 30, 2012
  1. @fmsf

    Allow the user to set a function callback for the tick colors. The ca…

    fmsf authored
    …llback function will be: function(value, axis_direction)
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 3 deletions.
  1. +6 −3 jquery.flot.js
View
9 jquery.flot.js
@@ -1597,9 +1597,9 @@ Licensed under the MIT license.
ctx.stroke();
}
- // draw ticks
- ctx.beginPath();
+ // draw ticks
for (i = 0; i < axis.ticks.length; ++i) {
+ ctx.beginPath();
var v = axis.ticks[i].v;
xoff = yoff = 0;
@@ -1633,11 +1633,14 @@ Licensed under the MIT license.
y = Math.floor(y) + 0.5;
}
+ if ($.isFunction(axis.options.tickColor)){
+ ctx.strokeStyle = axis.options.tickColor(v, axis.direction);
+ }
ctx.moveTo(x, y);
ctx.lineTo(x + xoff, y + yoff);
+ ctx.stroke();
}
- ctx.stroke();
}
Something went wrong with that request. Please try again.