Skip to content

Instantly share code, notes, and snippets.

@eikhunter
Created August 21, 2019 12:44
Show Gist options
  • Save eikhunter/982a4a56d6f062ec1a12fa3ca3481e3c to your computer and use it in GitHub Desktop.
Save eikhunter/982a4a56d6f062ec1a12fa3ca3481e3c to your computer and use it in GitHub Desktop.
const DATA_POINTS_ON_SCREEN = 6;
const WIDTH = Math.round((DATA.length / DATA_POINTS_ON_SCREEN) * Dimensions.get('window').width);
calculateXPosition = (index: number): number => {
const linearScale = scaleLinear()
.domain([0, DATA.length])
.range([0, WIDTH]);
return linearScale(index);
}
_updateDataPointOnGraph = (event) => {
const { pinIndex } = this.state;
const scrollPos = event.nativeEvent.contentOffset.x;
const index = pinIndex + 1;
if (scrollPos > this.calculateXPosition(index)) {
this.setState({ pinIndex: this.state.pinIndex + 1 });
} if (scrollPos < this.calculateXPosition(index) && scrollPos < this.calculateXPosition(index - 1)) {
this.setState({ pinIndex: this.state.pinIndex - 1 });
}
}
@eikhunter
Copy link
Author

const DIMENSION_WIDTH * ((data.length - DATA_POINTS_ON_SCREEN) / (DATA_POINTS_ON_SCREEN - 1) + 1);

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