Fix graph oom issue

https://github.com/rancher/rancher/issues/18929
This commit is contained in:
loganhz 2019-03-15 09:09:12 +08:00
parent 7e650bc59b
commit d51a820fc8
2 changed files with 37 additions and 24 deletions

View File

@ -154,10 +154,10 @@ export default Component.extend(ThrottledResize, {
set(this, 'chart', chart); set(this, 'chart', chart);
chart.showLoading(LOADING_PARAMS); chart.showLoading(LOADING_PARAMS);
this.draw(false); this.draw();
}, },
draw(update = true) { draw() {
const chart = get(this, 'chart'); const chart = get(this, 'chart');
if ( !chart ) { if ( !chart ) {
@ -248,16 +248,8 @@ export default Component.extend(ThrottledResize, {
option.yAxis.max = minMax; option.yAxis.max = minMax;
} }
let newOptions;
if ( update ) {
newOptions = { series };
} else {
newOptions = option;
}
chart.clear(); chart.clear();
chart.setOption(newOptions, true); chart.setOption(option, true);
chart.hideLoading(); chart.hideLoading();
}, },

View File

@ -8,23 +8,44 @@ export default Component.extend({
layout, layout,
rows: null, rows: null,
graphs: null, graphs: null,
loading: null, loading: null,
noGraphs: null, noGraphs: null,
noDataLabel: 'metricsAction.noData', noDataLabel: 'metricsAction.noData',
currentGraphs: null,
graphsDidChange: observer('graphs', function() { graphsDidChange: observer('graphs', function() {
let out = []; let out = [];
const graphs = (get(this, 'graphs') || []); const graphs = (get(this, 'graphs') || []);
const newGrahps = graphs.map((graph) => get(graph, 'graph.title') || '').join(',');
const changed = newGrahps !== get(this, 'currentGraphs');
graphs.forEach((graph, index) => { set(this, 'currentGraphs', newGrahps);
if (index % 3 === 0) {
out.pushObject([graph]); if ( changed ) {
} else { graphs.forEach((graph, index) => {
get(out, 'lastObject').pushObject(graph); if (index % 3 === 0) {
} out.pushObject([graph]);
}); } else {
set(this, 'rows', out); get(out, 'lastObject').pushObject(graph);
}
});
set(this, 'rows', out);
} else {
let rowIndex = -1;
const currentRows = get(this, 'rows') || [];
graphs.forEach((graph, index) => {
let colIndex = index % 3;
if ( colIndex === 0 ) {
rowIndex++;
}
let row = currentRows.objectAt(rowIndex) || [];
set(row.objectAt(colIndex), 'series', get(graph, 'series') );
});
}
}), }),
}); });