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

Allow for ability of line and area charts to interpolate between points #2

Open
SamGRosen opened this issue Jun 29, 2021 · 0 comments

Comments

@SamGRosen
Copy link
Member

SamGRosen commented Jun 29, 2021

Currently when drawing lines and area charts, the interpolation between points is a line, as that is the default behavior when drawing lines with WebGL. Interpolating between the points non-linearly has value. This could be accomplished potentially by adding a check to the line case in VertexCalculator._calculateForMark. Knowledge of the previous mark would be necessary for interpolation but this is already done when calculating area charts. The case for lines would likely look something like this:

if (this.track.mark === "line") {
  let toReturn;
  if(this.track.interpolation === "linear" || !this.track.interpolation) { // default
    toReturn = this._getVertexForDot(mark);
  } else if(this.track.interpolation === "basis") {
    toReturn = this._getVerticesForInterpolatedLine(mark, "basis")
  }
 this.lastMark = mark;
 return toReturn;
}
...
_getVerticesForInterpolatedLine(mark, interpolationType) {
  const interpolateFunc = getInterpolationFunctionBetweenPoints(
     this._mapToGPUSpace([mark.x, mark.y]), 
     this._mapToGPUSpace([this.lastMark.x, this.lastMark.y]), 
     interpolationType
  ); // takes t in [0, 1] where t = 0 -> mark.xy and t -> 1 this.lastMark.xy
  let vertices = []
  for(let i = 0; i < NUM_POINTS_FOR_INTERPOLATION; i++) {
    vertices.push(...interpolateFunc(i / NUM_POINTS_FOR_INTERPOLATION));
  }
  return vertices;
}

Be sure to add an example using the interpolation and record the expected output for future integration tests.

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

No branches or pull requests

1 participant