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

provide some way to pre-filter splits & ticks #305

Closed
leeoniya opened this issue Sep 16, 2020 · 0 comments
Closed

provide some way to pre-filter splits & ticks #305

leeoniya opened this issue Sep 16, 2020 · 0 comments

Comments

@leeoniya
Copy link
Owner

leeoniya commented Sep 16, 2020

context: #304 (comment)

axis.values currently serves 2 purposes: tick formatting and tick filtering (in the case of log axes). it's possible to want to customize just the former without having to re-implement the latter. would be useful to have some intermediate step between the splits gen and the values gen. same maybe for gridlines.

something like:

{
axes: [
  {
    filter: (self, splits, ...) => valuesSplits,
    grid: {
      filter: (self, splits, ...) => linesSplits,
    }
}

another option would be to use the same strategy as scale ranging and simply expose the filters as static utility functions which can be used inside of custom axis.values:

e.g. uPlot.filtLog10():

uPlot/src/opts.js

Lines 435 to 457 in e2285cc

const RE_ALL = /./;
const RE_12357 = /[12357]/;
const RE_125 = /[125]/;
const RE_1 = /1/;
export function logAxisVals(self, splits, axisIdx, foundSpace, foundIncr) {
let axis = self.axes[axisIdx];
let scaleKey = axis.scale;
let valToPos = self.valToPos;
let minSpace = axis.space(); // TOFIX: only works for static space:
let _10 = valToPos(10, scaleKey);
let re = (
valToPos(9, scaleKey) - _10 >= minSpace ? RE_ALL :
valToPos(7, scaleKey) - _10 >= minSpace ? RE_12357 :
valToPos(5, scaleKey) - _10 >= minSpace ? RE_125 :
RE_1
);
return splits.map(v => re.test(v) ? fmtNum(v) : "");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant