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

Improved load-on-pan events #690

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/lib/charts/CandleStickChartPanToLoadMore.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class CandleStickChartPanToLoadMore extends React.Component {
const { data: prevData, ema26, ema12, macdCalculator, smaVolume50 } = this.state;
const { data: inputData } = this.props;


if (inputData.length === prevData.length) return;

const rowsToDownload = end - Math.ceil(start);
Expand Down Expand Up @@ -169,7 +168,7 @@ class CandleStickChartPanToLoadMore extends React.Component {
seriesName="MSFT"
data={data}
xScale={xScale} xAccessor={xAccessor} displayXAccessor={displayXAccessor}
onLoadMore={this.handleDownloadMore}>
onLoadBefore={this.handleDownloadMore}>
<Chart id={1} height={400}
yExtents={[d => [d.high, d.low], ema26.accessor(), ema12.accessor()]}
padding={{ top: 10, bottom: 20 }}>
Expand Down
108 changes: 90 additions & 18 deletions src/lib/ChartCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,31 @@ class ChartCanvas extends Component {
this.clearThreeCanvas();

const { fullData } = this;

const firstItem = head(fullData);
const scale_start = head(xScale.domain());
const data_start = xAccessor(firstItem);

const lastItem = last(fullData);
const scale_end = last(xScale.domain());
const data_end = xAccessor(lastItem);

const start = head(xScale.domain());
const end = xAccessor(firstItem);
const { onLoadMore } = this.props;
const {
onLoadMore,
onLoad,
onLoadAfter,
onLoadBefore,
} = this.props;

this.setState(state, () => {
if (start < end) {
onLoadMore(start, end);
if (scale_start < data_start) {
onLoadMore(scale_start, data_start); // deprecated
onLoadBefore(scale_start, data_start);
onLoad(scale_start, data_start);
}
if (data_end < scale_end) {
onLoadAfter(data_end, scale_end);
onLoad(data_end, scale_end);
}
});
}
Expand Down Expand Up @@ -617,10 +633,19 @@ class ChartCanvas extends Component {
this.clearThreeCanvas();

const firstItem = head(fullData);
const scale_start = head(xScale.domain());
const data_start = xAccessor(firstItem);

const start = head(xScale.domain());
const end = xAccessor(firstItem);
const { onLoadMore } = this.props;
const lastItem = last(fullData);
const scale_end = last(xScale.domain());
const data_end = xAccessor(lastItem);

const {
onLoadMore,
onLoad,
onLoadAfter,
onLoadBefore,
} = this.props;

this.mutableState = {
mouseXY: mouseXY,
Expand All @@ -643,8 +668,14 @@ class ChartCanvas extends Component {
plotData,
chartConfig,
}, () => {
if (start < end) {
onLoadMore(start, end);
if (scale_start < data_start) {
onLoadMore(scale_start, data_start); // deprecated
onLoadBefore(scale_start, data_start);
onLoad(scale_start, data_start);
}
if (data_end < scale_end) {
onLoadAfter(data_end, scale_end);
onLoad(data_end, scale_end);
}
});
}
Expand All @@ -655,16 +686,34 @@ class ChartCanvas extends Component {
const { xAccessor } = this.state;
const { fullData } = this;
const firstItem = head(fullData);
const start = head(xScale.domain());
const end = xAccessor(firstItem);
const { onLoadMore } = this.props;
const scale_start = head(xScale.domain());
const data_start = xAccessor(firstItem);

const lastItem = last(fullData);
const scale_end = last(xScale.domain());
const data_end = xAccessor(lastItem);

const {
onLoadMore,
onLoad,
onLoadAfter,
onLoadBefore,
} = this.props;

this.setState({
xScale,
plotData,
chartConfig,
}, () => {
if (start < end) onLoadMore(start, end);
if (scale_start < data_start) {
onLoadMore(scale_start, data_start); // deprecated
onLoadBefore(scale_start, data_start);
onLoad(scale_start, data_start);
}
if (data_end < scale_end) {
onLoadAfter(data_end, scale_end);
onLoad(data_end, scale_end);
}
});
}
yAxisZoom(chartId, newDomain) {
Expand Down Expand Up @@ -809,11 +858,20 @@ class ChartCanvas extends Component {
const { fullData } = this;

const firstItem = head(fullData);
const start = head(xScale.domain());
const end = xAccessor(firstItem);
const scale_start = head(xScale.domain());
const data_start = xAccessor(firstItem);
// console.log(start, end, start < end ? "Load more" : "I have it");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code should not be pushed to GitHub.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dude, this repo is dead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and the comment isn't even part of the PR 😂


const { onLoadMore } = this.props;
const lastItem = last(fullData);
const scale_end = last(xScale.domain());
const data_end = xAccessor(lastItem);

const {
onLoadMore,
onLoad,
onLoadAfter,
onLoadBefore,
} = this.props;

this.clearThreeCanvas();

Expand All @@ -822,7 +880,15 @@ class ChartCanvas extends Component {
plotData,
chartConfig,
}, () => {
if (start < end) onLoadMore(start, end);
if (scale_start < data_start) {
onLoadMore(scale_start, data_start); // deprecated
onLoadBefore(scale_start, data_start);
onLoad(scale_start, data_start);
}
if (data_end < scale_end) {
onLoadAfter(data_end, scale_end);
onLoad(data_end, scale_end);
}
});
});
}
Expand Down Expand Up @@ -1164,6 +1230,9 @@ ChartCanvas.propTypes = {
defaultFocus: PropTypes.bool,
zoomMultiplier: PropTypes.number,
onLoadMore: PropTypes.func,
onLoad: PropTypes.func,
onLoadAfter: PropTypes.func,
onLoadBefore: PropTypes.func,
displayXAccessor: function(props, propName/* , componentName */) {
if (isNotDefined(props[propName])) {
console.warn("`displayXAccessor` is not defined,"
Expand Down Expand Up @@ -1198,6 +1267,9 @@ ChartCanvas.defaultProps = {
useCrossHairStyleCursor: true,
defaultFocus: true,
onLoadMore: noop,
onLoad: noop,
onLoadBefore: noop,
onLoadAfter: noop,
onSelect: noop,
mouseMoveEvent: true,
panEvent: true,
Expand Down