[DE] Chart styles loading optimization
This commit is contained in:
parent
6320fc1aae
commit
7ba1009581
|
|
@ -75,7 +75,10 @@ define([
|
||||||
ChartStyle: 1,
|
ChartStyle: 1,
|
||||||
ChartType: -1,
|
ChartType: -1,
|
||||||
SeveralCharts: false,
|
SeveralCharts: false,
|
||||||
DisabledControls: false
|
DisabledControls: false,
|
||||||
|
beginPreviewStyles: true,
|
||||||
|
previewStylesCount: -1,
|
||||||
|
currentStyleFound: false
|
||||||
};
|
};
|
||||||
this.lockedControls = [];
|
this.lockedControls = [];
|
||||||
this._locked = false;
|
this._locked = false;
|
||||||
|
|
@ -102,6 +105,9 @@ define([
|
||||||
if (this.api) {
|
if (this.api) {
|
||||||
this.api.asc_registerCallback('asc_onImgWrapStyleChanged', _.bind(this._ChartWrapStyleChanged, this));
|
this.api.asc_registerCallback('asc_onImgWrapStyleChanged', _.bind(this._ChartWrapStyleChanged, this));
|
||||||
this.api.asc_registerCallback('asc_onUpdateChartStyles', _.bind(this._onUpdateChartStyles, this));
|
this.api.asc_registerCallback('asc_onUpdateChartStyles', _.bind(this._onUpdateChartStyles, this));
|
||||||
|
this.api.asc_registerCallback('asc_onBeginChartStylesPreview', _.bind(this.onBeginChartStylesPreview, this));
|
||||||
|
this.api.asc_registerCallback('asc_onAddChartStylesPreview', _.bind(this.onAddChartStylesPreview, this));
|
||||||
|
this.api.asc_registerCallback('asc_onEndChartStylesPreview', _.bind(this.onEndChartStylesPreview, this));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -149,9 +155,9 @@ define([
|
||||||
} else
|
} else
|
||||||
this.btnChartType.setIconCls('svgicon');
|
this.btnChartType.setIconCls('svgicon');
|
||||||
this.ShowCombinedProps(type);
|
this.ShowCombinedProps(type);
|
||||||
!(type===null || type==Asc.c_oAscChartTypeSettings.comboBarLine || type==Asc.c_oAscChartTypeSettings.comboBarLineSecondary ||
|
|
||||||
type==Asc.c_oAscChartTypeSettings.comboAreaBar || type==Asc.c_oAscChartTypeSettings.comboCustom) && this.updateChartStyles(this.api.asc_getChartPreviews(type));
|
|
||||||
this._state.ChartType = type;
|
this._state.ChartType = type;
|
||||||
|
!(type===null || type==Asc.c_oAscChartTypeSettings.comboBarLine || type==Asc.c_oAscChartTypeSettings.comboBarLineSecondary ||
|
||||||
|
type==Asc.c_oAscChartTypeSettings.comboAreaBar || type==Asc.c_oAscChartTypeSettings.comboCustom) && this.updateChartStyles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,18 +171,9 @@ define([
|
||||||
} else {
|
} else {
|
||||||
value = this.chartProps.getStyle();
|
value = this.chartProps.getStyle();
|
||||||
if (this._state.ChartStyle !== value || this._isChartStylesChanged) {
|
if (this._state.ChartStyle !== value || this._isChartStylesChanged) {
|
||||||
this.cmbChartStyle.suspendEvents();
|
|
||||||
var rec = this.cmbChartStyle.menuPicker.store.findWhere({data: value});
|
|
||||||
this.cmbChartStyle.menuPicker.selectRecord(rec);
|
|
||||||
this.cmbChartStyle.resumeEvents();
|
|
||||||
|
|
||||||
if (this._isChartStylesChanged) {
|
|
||||||
if (rec)
|
|
||||||
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(), true);
|
|
||||||
else
|
|
||||||
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true);
|
|
||||||
}
|
|
||||||
this._state.ChartStyle = value;
|
this._state.ChartStyle = value;
|
||||||
|
this._state.currentStyleFound = false;
|
||||||
|
this.selectCurrentChartStyle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._isChartStylesChanged = false;
|
this._isChartStylesChanged = false;
|
||||||
|
|
@ -427,14 +424,70 @@ define([
|
||||||
this.fireEvent('editcomplete', this);
|
this.fireEvent('editcomplete', this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
selectCurrentChartStyle: function() {
|
||||||
|
if (!this.cmbChartStyle || this._state.beginPreviewStyles || this._state.previewStylesCount!==this.cmbChartStyle.menuPicker.store.length) return;
|
||||||
|
|
||||||
|
this.cmbChartStyle.suspendEvents();
|
||||||
|
var rec = this.cmbChartStyle.menuPicker.store.findWhere({data: this._state.ChartStyle});
|
||||||
|
if (!rec) {
|
||||||
|
rec = this.cmbChartStyle.menuPicker.store.at(0);
|
||||||
|
}
|
||||||
|
this.cmbChartStyle.menuPicker.selectRecord(rec);
|
||||||
|
this.cmbChartStyle.resumeEvents();
|
||||||
|
|
||||||
|
rec && this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(), true);
|
||||||
|
this._state.currentStyleFound = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
onBeginChartStylesPreview: function(count){
|
||||||
|
this._state.beginPreviewStyles = true;
|
||||||
|
this._state.currentStyleFound = false;
|
||||||
|
this._state.previewStylesCount = count;
|
||||||
|
},
|
||||||
|
|
||||||
|
onEndChartStylesPreview: function(){
|
||||||
|
if (this.cmbChartStyle) {
|
||||||
|
if (this.cmbChartStyle.menuPicker.store.length>0) {
|
||||||
|
this.selectCurrentChartStyle();
|
||||||
|
this.cmbChartStyle.menuPicker.scroller.update({alwaysVisibleY: true});
|
||||||
|
} else {
|
||||||
|
this.cmbChartStyle.menuPicker.store.reset();
|
||||||
|
this.cmbChartStyle.clearComboView();
|
||||||
|
}
|
||||||
|
this.cmbChartStyle.setDisabled(this.cmbChartStyle.menuPicker.store.length<1 || this._locked);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onAddChartStylesPreview: function(styles){
|
||||||
|
var me = this;
|
||||||
|
if (styles && styles.length>0){
|
||||||
|
var stylesStore = this.cmbChartStyle.menuPicker.store;
|
||||||
|
if (stylesStore) {
|
||||||
|
var stylearray = [];
|
||||||
|
_.each(styles, function(item, index){
|
||||||
|
stylearray.push({
|
||||||
|
imageUrl: item.asc_getImage(),
|
||||||
|
data : item.asc_getName(),
|
||||||
|
tip : me.textStyle + ' ' + item.asc_getName()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (this._state.beginPreviewStyles) {
|
||||||
|
this._state.beginPreviewStyles = false;
|
||||||
|
stylesStore.reset(stylearray);
|
||||||
|
} else
|
||||||
|
stylesStore.add(stylearray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_onUpdateChartStyles: function() {
|
_onUpdateChartStyles: function() {
|
||||||
if (this.api && this._state.ChartType!==null && this._state.ChartType>-1 &&
|
if (this.api && this._state.ChartType!==null && this._state.ChartType>-1 &&
|
||||||
!(this._state.ChartType==Asc.c_oAscChartTypeSettings.comboBarLine || this._state.ChartType==Asc.c_oAscChartTypeSettings.comboBarLineSecondary ||
|
!(this._state.ChartType==Asc.c_oAscChartTypeSettings.comboBarLine || this._state.ChartType==Asc.c_oAscChartTypeSettings.comboBarLineSecondary ||
|
||||||
this._state.ChartType==Asc.c_oAscChartTypeSettings.comboAreaBar || this._state.ChartType==Asc.c_oAscChartTypeSettings.comboCustom))
|
this._state.ChartType==Asc.c_oAscChartTypeSettings.comboAreaBar || this._state.ChartType==Asc.c_oAscChartTypeSettings.comboCustom))
|
||||||
this.updateChartStyles(this.api.asc_getChartPreviews(this._state.ChartType));
|
this.updateChartStyles();
|
||||||
},
|
},
|
||||||
|
|
||||||
updateChartStyles: function(styles) {
|
updateChartStyles: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
this._isChartStylesChanged = true;
|
this._isChartStylesChanged = true;
|
||||||
|
|
||||||
|
|
@ -461,34 +514,7 @@ define([
|
||||||
});
|
});
|
||||||
this.lockedControls.push(this.cmbChartStyle);
|
this.lockedControls.push(this.cmbChartStyle);
|
||||||
}
|
}
|
||||||
|
this.api.asc_generateChartPreviews(this._state.ChartType);
|
||||||
if (styles && styles.length>0){
|
|
||||||
var stylesStore = this.cmbChartStyle.menuPicker.store;
|
|
||||||
if (stylesStore) {
|
|
||||||
var count = stylesStore.length;
|
|
||||||
if (count>0 && count==styles.length) {
|
|
||||||
var data = stylesStore.models;
|
|
||||||
_.each(styles, function(style, index){
|
|
||||||
data[index].set('imageUrl', style.asc_getImage());
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var stylearray = [],
|
|
||||||
selectedIdx = -1;
|
|
||||||
_.each(styles, function(item, index){
|
|
||||||
stylearray.push({
|
|
||||||
imageUrl: item.asc_getImage(),
|
|
||||||
data : item.asc_getName(),
|
|
||||||
tip : me.textStyle + ' ' + item.asc_getName()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
stylesStore.reset(stylearray, {silent: false});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.cmbChartStyle.menuPicker.store.reset();
|
|
||||||
this.cmbChartStyle.clearComboView();
|
|
||||||
}
|
|
||||||
this.cmbChartStyle.setDisabled(!styles || styles.length<1 || this._locked);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
ShowCombinedProps: function(type) {
|
ShowCombinedProps: function(type) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue