Skip to content

Commit

Permalink
calculate margin in store instead
Browse files Browse the repository at this point in the history
  • Loading branch information
negar-binary committed May 23, 2019
1 parent 2682270 commit cf3f03e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/javascript/app/Modules/SmartChart/Containers/smart-chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ class Chart extends React.Component {
);

render() {
const granularity = this.props.granularity;
const duration = this.props.end_epoch - this.props.start_epoch;

const margin = granularity === 0 ? (Math.max(300, (30 * duration) / (60 * 60) || 0)) : 3 * granularity;

// load more ticks so we can draw one tick before and one tick after contract
const start_margin = ((this.props.start_epoch) - margin).toFixed(0);
const end_margin = (this.props.end_epoch + margin).toFixed(0);

return (
<SmartChart
barriers={this.props.barriers_array}
Expand All @@ -56,7 +47,7 @@ class Chart extends React.Component {
chartStatusListener={this.props.getChartStatus}
chartType={this.props.chart_type}
endEpoch={this.props.end_epoch}
endEpochMargin={end_margin}
margin={this.props.margin ? this.props.margin : null}
id={this.props.chart_id}
isMobile={this.props.is_mobile}
granularity={this.props.granularity}
Expand All @@ -66,7 +57,6 @@ class Chart extends React.Component {
settings={this.props.settings}
showLastDigitStats={this.props.should_show_last_digit_stats}
startEpoch={this.props.start_epoch}
startEpochMargin={start_margin}
scrollToEpoch={this.props.scroll_to_epoch}
scrollToEpochOffset={this.props.scroll_to_offset}
symbol={this.props.symbol}
Expand Down Expand Up @@ -105,6 +95,7 @@ Chart.propTypes = {
is_static_chart : PropTypes.bool,
is_title_enabled : PropTypes.bool,
is_trade_page : PropTypes.bool,
margin : PropTypes.number,
markers_array : PropTypes.array,
onMount : PropTypes.func,
onSymbolChange : PropTypes.func,
Expand Down Expand Up @@ -136,6 +127,7 @@ export default connect(
is_contract_mode : modules.smart_chart.is_contract_mode,
is_title_enabled : modules.smart_chart.is_title_enabled,
is_static_chart : modules.smart_chart.is_static_chart,
margin : modules.smart_chart.margin,
markers_array : modules.smart_chart.markers_array,
onMount : modules.smart_chart.onMount,
onUnmount : modules.smart_chart.onUnmount,
Expand Down
6 changes: 6 additions & 0 deletions src/javascript/app/Stores/Modules/Contract/contract-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default class ContractStore extends BaseStore {
SmartChartStore.updateGranularity(0);
SmartChartStore.updateChartType('mountain');
}
this.is_left_epoch_set = true;
SmartChartStore.setChartView(contract_info.purchase_time);
}
Expand All @@ -111,6 +112,8 @@ export default class ContractStore extends BaseStore {
createChartBarrier(SmartChartStore, contract_info);
createChartMarkers(SmartChartStore, contract_info);
SmartChartStore.updateMargin((end_time || contract_info.date_expiry) - date_start);
if (this.smart_chart.is_chart_ready) {
this.smart_chart.setIsChartLoading(false);
}
Expand Down Expand Up @@ -215,6 +218,9 @@ export default class ContractStore extends BaseStore {
createChartMarkers(this.smart_chart, this.replay_info);
this.handleDigits(this.replay_info);
this.smart_chart.updateMargin(
(getEndTime(this.replay_info) || this.replay_info.date_expiry) - this.replay_info.date_start);
this.waitForChartListener(this.smart_chart);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class SmartChartStore extends BaseStore {

@observable start_epoch;
@observable end_epoch;
@observable margin;

@observable scroll_to_left_epoch = null;
@observable scroll_to_left_epoch_offset = 0;
Expand Down Expand Up @@ -54,6 +55,14 @@ export default class SmartChartStore extends BaseStore {
this.granularity = granularity;
}

@action.bound
updateMargin(duration) {
this.margin = Math.floor(!this.granularity ?
(Math.max(300, (30 * duration) / (60 * 60) || 0))
:
3 * this.granularity);
}

@action.bound
updateEpochScrollToValue(epoch) {
this.scroll_to_left_epoch = epoch;
Expand Down

0 comments on commit cf3f03e

Please sign in to comment.