Skip to content

Conversation

markruys
Copy link

@markruys markruys commented Sep 6, 2016

When you want to specify which ticks you want to show up on the horizontal axis, you typically use a callback function in options.xAxes[].ticks. As shown in https://jsfiddle.net/xuf1qwtp/, this goes wrong for larger sets of values: only a single label gets drawn. The pull requests fixes this.

@etimberg
Copy link
Member

etimberg commented Sep 6, 2016

I think this is a step in the right direction. One case that might not be handled well is if the callback does not hide labels at regular intervals. I was recently looking at overhauling the auto skip code to work for vertical axes and in doing so I thought about writing the auto skip to actually check if the text was going to overlap and only hiding the label if it would.

@simonbrunel @zachpanz88 what are your thoughts on merging this as a stop-gap? I almost think we should iterate a bit per my notes above.

@markruys
Copy link
Author

markruys commented Sep 7, 2016

I think the fix does work well for the case the labels are spread irregularly. This is because skipRatio will be set to false (assuming you do have enough space to position the labels), hence the shouldSkip won't get set.

I confirmed code like in https://jsfiddle.net/xuf1qwtp/ with

var options = {
  scales: {
    xAxes: [{
      ticks: {
        callback: function(value, i) {
          return Math.random() < number_of_items_on_xaxis / number_of_items ? value : null;
        },
      }
    }],
  },

and it works.

@etimberg
Copy link
Member

Closing as out of date

@etimberg etimberg closed this Feb 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants