Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend axis tickformat/hoverformat configuration #1

Closed
wants to merge 1 commit into from

Conversation

apalchys
Copy link
Owner

This PR extends tickformat and hoverformat for date axes and allow to configure date format for specific zoom level by passing configuration object.
Use case: sometimes it is really needed to change date format only at some zoom level without changing default behavior for other zoom levels.

Supported zoom levels:
millisecond, second, minute, hour, day, week, month, year.

If some level is not defined, then default formatter will be used.

Example of usage:

xaxis: {
    tickformat: {
        millisecond: "%H:%M:%S.%L ms",
        second: "%H:%M:%S s",
        minute: "%H:%M m",
        hour: "%H:%M h",
        day: "%e %b d",
        week: "%b %d w",
        month: "%b %y M",
        year: "%Y Y"
    }
}

@apalchys apalchys changed the title Extend tickformat/hoverformat configuration Extend axis tickformat/hoverformat configuration Aug 10, 2017
@etpinard
Copy link

That's interesting. Thanks for exploring this avenue @apalchys !

I'm not a fan of making tickformat a valType: 'any' attribute, I would prefer adding a separate attribute e.g. tickformatstops or tickstops. Moreover, we should make sure this new attributes has a meaning for other axis types (linear, log and category). Maybe something like:

tickstops: [{
  range: [0, 10],  // or maybe `span: 10` would be best?
  value; 'tickformat string' || [/* array of tick values for this range */]
}, {
  range: [0, 1],
  value: // ...
}, {
  // ...
}]

@apalchys
Copy link
Owner Author

apalchys commented Aug 11, 2017

@etpinard thanks. it seems i got your idea.
So, what do you think about implementing the following API:

tickformatstops: [{
  span:  number | string,
  value: string
}

I suggest to make value string only for now. Here are examples how it will work for different axis types:

//linear
tickformatstops: [{
  span: 10,
  value: '.2%'
}, {
  span: 100,
  value: '.1%'
}]

//date.
tickformatstops: [{
  span: 'year',
  value: '%Y year'
}, {
  span: 86400000, // in ms
  value: '%e %b'
}]

//log
tickformatstops: [{
  span: 1,
  value: '.1'
}, {
  span: 2,
  value: '.0'
}]

//category
tickformatstops: [{
  span: 6,  //number of visible ticks ?
  value: '.1'
}]

@etpinard
Copy link

@apalchys would you mind reposting your #1 (comment) in plotly#1946 so that other devs can chip in on this topic?

Thanks!

alexcjohnson pushed a commit that referenced this pull request Oct 9, 2017
@apalchys apalchys closed this Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants