Compare commits

...

4 commits

Author SHA1 Message Date
Julia Radzhabova 8e6ef9be94 Revert "[DE] Clear chart styles on start loading"
This reverts commit 0dbe14e9fc.
2022-02-16 15:07:42 +03:00
Julia Radzhabova 0dbe14e9fc [DE] Clear chart styles on start loading 2022-02-16 13:42:57 +03:00
Julia Radzhabova 15977a76e1 [DE] Draw chart style when it's received 2022-02-15 21:08:46 +03:00
Julia Radzhabova 7ba1009581 [DE] Chart styles loading optimization 2022-02-15 20:05:28 +03:00

View file

@ -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,81 @@ define([
this.fireEvent('editcomplete', this); this.fireEvent('editcomplete', this);
}, },
selectCurrentChartStyle: function() {
if (!this.cmbChartStyle || this._state.beginPreviewStyles) return;
this.cmbChartStyle.suspendEvents();
var rec = this.cmbChartStyle.menuPicker.store.findWhere({data: this._state.ChartStyle});
if (!rec && (this._state.previewStylesCount===this.cmbChartStyle.menuPicker.store.length || this._state.drawCurrentStyle)) {
rec = this.cmbChartStyle.menuPicker.store.at(0);
}
this.cmbChartStyle.menuPicker.selectRecord(rec);
this.cmbChartStyle.resumeEvents();
if (rec) {
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(), true);
this._state.currentStyleFound = true;
this._state.drawCurrentStyle = false;
}
},
onBeginChartStylesPreview: function(count){
this._state.beginPreviewStyles = true;
this._state.currentStyleFound = false;
this._state.drawCurrentStyle = false;
this._state.previewStylesCount = count;
},
onEndChartStylesPreview: function(){
if (this.cmbChartStyle) {
if (this.cmbChartStyle.menuPicker.store.length>0) {
!this._state.currentStyleFound && 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){
var name = item.asc_getName();
stylearray.push({
imageUrl: item.asc_getImage(),
data : name,
tip : me.textStyle + ' ' + item.asc_getName()
});
if (name===me._state.ChartStyle)
me._state.drawCurrentStyle = true;
});
if (this._state.beginPreviewStyles) {
this._state.beginPreviewStyles = false;
stylesStore.reset(stylearray);
if (this._state.ChartStyle===null)
this._state.drawCurrentStyle = true;
} else {
stylesStore.add(stylearray);
}
}
!this._state.currentStyleFound && this._state.drawCurrentStyle && (stylesStore.length>2) && this.selectCurrentChartStyle();
}
},
_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 +525,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) {