Skip to content

Commit

Permalink
calculate max value for zoom graph
Browse files Browse the repository at this point in the history
  • Loading branch information
raptox committed Feb 29, 2020
1 parent 7649bce commit 0c7c50c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions app/components/ViewParsed.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default class ViewParsed extends Component {
balanceZoomPageSize: 30,
balanceZoomData: {},
balanceZoomEnd: false,
balanceZoomStart: true
balanceZoomStart: true,
balanceZoomMaxValue: 0
};
}

Expand Down Expand Up @@ -273,7 +274,10 @@ export default class ViewParsed extends Component {
],
yAxes: [
{
stacked: true
stacked: true,
ticks: {
suggestedMax: this.state.balanceZoomMaxValue
}
}
]
}
Expand Down Expand Up @@ -431,6 +435,26 @@ export default class ViewParsed extends Component {
if (file) {
fs.readFile(file[0], (err, data) => {
this.setState({ parsedContent: JSON.parse(data) });

// calculate max value for graph scaling
if (this.state.parsedContent.balanceData.datasets.length) {
let maxValues = [];
this.state.parsedContent.balanceData.datasets[0].data.forEach(
(data, index) => {
let tempMaxValue = data;
this.state.parsedContent.balanceData.datasets.forEach(
(dataset, yindex) => {
if (yindex === 0) return;
tempMaxValue += dataset.data[index];
}
);
maxValues.push(tempMaxValue);
}
);
console.log(Math.max(...maxValues));
this.setState({ balanceZoomMaxValue: Math.max(...maxValues) });
}

this.unZoomBalanceData();
});
}
Expand Down

0 comments on commit 0c7c50c

Please sign in to comment.