Added further optimazation

This commit is contained in:
kunkliricsi 2020-11-22 09:56:32 +01:00
parent 3cdaa2dc35
commit d75e9d378d
2 changed files with 70 additions and 49 deletions

View File

@ -57,6 +57,9 @@ class Dashboard extends Component {
componentWillUnmount() { componentWillUnmount() {
this.context.removeHandler(C.update_all_method_name, this.updateSeries); this.context.removeHandler(C.update_all_method_name, this.updateSeries);
this.context.removeHandler(C.update_method_name, this.updateSeries); this.context.removeHandler(C.update_method_name, this.updateSeries);
if (this.updateTimer) {
clearTimeout(this.updateTimer);
}
} }
getItemsWithStatus(iterate, status) { getItemsWithStatus(iterate, status) {
@ -125,7 +128,7 @@ class Dashboard extends Component {
barDevicePoints[d.id] = Array(3).fill(0); barDevicePoints[d.id] = Array(3).fill(0);
} }
const processMethod = (items, index) => { const processHeatmapItem = (items, index) => {
const p = items[index]; const p = items[index];
if (p.date > minuteAgo) { if (p.date > minuteAgo) {
var seconds = Math.floor((p.date.getTime() - minuteAgo.getTime()) / 1000); var seconds = Math.floor((p.date.getTime() - minuteAgo.getTime()) / 1000);
@ -164,7 +167,7 @@ class Dashboard extends Component {
} }
} }
const finishMethod = () => { const onFinished = () => {
const minuteHeatmapSeries = []; const minuteHeatmapSeries = [];
var i = 0; var i = 0;
@ -236,20 +239,23 @@ class Dashboard extends Component {
return categories; return categories;
} }
this.setState({ const toUpdate = [
heatmapSecondsSeries: minuteHeatmapSeries, { heatmapSecondsSeries: minuteHeatmapSeries },
heatmapMinutesSeries: hourHeatmapSeries, { heatmapMinutesSeries: hourHeatmapSeries },
barSeries: barSeries, { barSeries: barSeries },
barCategories: getBarCategories(), { barCategories: getBarCategories() },
lineSeries: lineSeries, { lineSeries: lineSeries }
];
//Set states must be done separately otherwise ApexChart's UI update freezes the page.
this.performTask(toUpdate, 2, 300, (list, index) => {
this.setState(list[index]);
},
() => {
this.updateTimer = setTimeout(this.updateDynamic, 1000);
}); });
setTimeout(this.updateDynamic, 1000);
} }
const processHeatmapItem = processMethod.bind(this);
const onFinished = finishMethod.bind(this)
this.performTask(this.context.heatmapPoints, Math.ceil(this.context.heatmapPoints.length / 50), 20, this.performTask(this.context.heatmapPoints, Math.ceil(this.context.heatmapPoints.length / 50), 20,
processHeatmapItem, onFinished); processHeatmapItem, onFinished);
} }

View File

@ -8,6 +8,21 @@ export class HeatmapChart extends Component {
this.state = { this.state = {
options: { options: {
chart: {
animations: {
enabled: true,
easing: 'linear',
speed: 250,
animateGradually: {
enabled: false,
speed: 250,
},
dynamicAnimation: {
enabled: true,
speed: 250
}
}
},
dataLabels: { dataLabels: {
enabled: false enabled: false
}, },