531 lines
22 KiB
JavaScript
531 lines
22 KiB
JavaScript
/*
|
|
*
|
|
* (c) Copyright Ascensio System SIA 2010-2020
|
|
*
|
|
* This program is a free software product. You can redistribute it and/or
|
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
* version 3 as published by the Free Software Foundation. In accordance with
|
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
|
* of any third-party rights.
|
|
*
|
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
*
|
|
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
|
* street, Riga, Latvia, EU, LV-1050.
|
|
*
|
|
* The interactive user interfaces in modified source and object code versions
|
|
* of the Program must display Appropriate Legal Notices, as required under
|
|
* Section 5 of the GNU AGPL version 3.
|
|
*
|
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
|
* grant you any rights under trademark law for use of our trademarks.
|
|
*
|
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
|
* well as technical writing content are licensed under the terms of the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* ChartDataDialog.js
|
|
*
|
|
* Created by Julia Radzhabova on 06.07.2020
|
|
* Copyright (c) 2020 Ascensio System SIA. All rights reserved.
|
|
*
|
|
*/
|
|
|
|
define([
|
|
'common/main/lib/util/utils',
|
|
'common/main/lib/component/MetricSpinner',
|
|
'common/main/lib/component/ComboBox',
|
|
'common/main/lib/component/ListView',
|
|
'common/main/lib/view/AdvancedSettingsWindow'
|
|
], function () { 'use strict';
|
|
|
|
SSE.Views.ChartDataDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
|
|
options: {
|
|
contentWidth: 370,
|
|
height: 490
|
|
},
|
|
|
|
initialize : function(options) {
|
|
var me = this;
|
|
|
|
_.extend(this.options, {
|
|
title: this.textTitle,
|
|
template: [
|
|
'<div class="box" style="height:' + (me.options.height - 85) + 'px;">',
|
|
'<div class="content-panel" style="padding: 0 10px;"><div class="inner-content">',
|
|
'<div class="settings-panel active">',
|
|
'<table cols="1" style="width: 100%;">',
|
|
'<tr>',
|
|
'<td>',
|
|
'<label class="input-label">', me.textDataRange, '</label>',
|
|
'</td>',
|
|
'</tr>',
|
|
'<tr>',
|
|
'<td class="padding-small" width="200">',
|
|
'<div id="chart-dlg-txt-range" class="input-row" style=""></div>',
|
|
'</td>',
|
|
'</tr>',
|
|
'<tr>',
|
|
'<td class="padding-small">',
|
|
'<label class="input-label">', me.textSeries, '</label>',
|
|
'<div id="chart-dlg-series-list" class="" style="width:100%; height: 93px;"></div>',
|
|
'</td>',
|
|
'</tr>',
|
|
'<tr>',
|
|
'<td class="padding-large">',
|
|
'<button type="button" class="btn btn-text-default auto" id="chart-dlg-btn-add" style="min-width: 70px;margin-right:5px;">', me.textAdd, '</button>',
|
|
'<button type="button" class="btn btn-text-default auto" id="chart-dlg-btn-edit" style="min-width: 70px;margin-right:5px;">', me.textEdit, '</button>',
|
|
'<button type="button" class="btn btn-text-default auto" id="chart-dlg-btn-delete" style="min-width: 70px;margin-right:5px;">', me.textDelete, '</button>',
|
|
'<div style="display: inline-block; float: right;">',
|
|
'<div id="chart-dlg-btn-up" style="display: inline-block;border: 1px solid #cfcfcf;border-radius: 1px;margin-right: 2px;"></div>',
|
|
'<div id="chart-dlg-btn-down" style="display: inline-block;border: 1px solid #cfcfcf;border-radius: 1px;"></div>',
|
|
'</div>',
|
|
'</td>',
|
|
'</tr>',
|
|
'<tr>',
|
|
'<td class="padding-large">',
|
|
'<button type="button" class="btn btn-text-default auto" id="chart-dlg-btn-switch" style="min-width: 70px;margin-right:5px;">', me.textSwitch, '</button>',
|
|
'</td>',
|
|
'</tr>',
|
|
'<tr>',
|
|
'<td class="padding-small">',
|
|
'<label class="input-label">', me.textCategory, '</label>',
|
|
'<div id="chart-dlg-category-list" class="" style="width:100%; height: 93px;"></div>',
|
|
'</td>',
|
|
'</tr>',
|
|
'<tr>',
|
|
'<td class="padding-small">',
|
|
'<button type="button" class="btn btn-text-default auto" id="chart-dlg-btn-category-edit" style="min-width: 70px;margin-right:5px;">', me.textEdit, '</button>',
|
|
'</td>',
|
|
'</tr>',
|
|
'</table>',
|
|
'</div></div>',
|
|
'</div>',
|
|
'</div>',
|
|
'<div class="separator horizontal"></div>'
|
|
].join('')
|
|
}, options);
|
|
|
|
this.handler = options.handler;
|
|
|
|
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
|
|
|
|
this._noApply = true;
|
|
this._changedProps = null;
|
|
|
|
this.api = this.options.api;
|
|
this.chartSettings = this.options.chartSettings;
|
|
this.dataRangeValid = '';
|
|
this.currentChartType = Asc.c_oAscChartTypeSettings.barNormal;
|
|
},
|
|
|
|
render: function() {
|
|
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
|
|
var me = this;
|
|
|
|
this.txtDataRange = new Common.UI.InputFieldBtn({
|
|
el : $('#chart-dlg-txt-range'),
|
|
name : 'range',
|
|
style : 'width: 100%;',
|
|
btnHint : this.textSelectData,
|
|
allowBlank : true
|
|
// validateOnChange: true
|
|
});
|
|
this.txtDataRange.on('button:click', _.bind(this.onSelectData, this));
|
|
this.txtDataRange.on('changed:after', function(input, newValue, oldValue, e) {
|
|
if (newValue == oldValue) return;
|
|
me.changeChartRange(newValue);
|
|
});
|
|
|
|
// Chart data
|
|
this.seriesList = new Common.UI.ListView({
|
|
el: $('#chart-dlg-series-list', this.$window),
|
|
store: new Common.UI.DataViewStore(),
|
|
emptyText: '',
|
|
scrollAlwaysVisible: true
|
|
});
|
|
this.seriesList.onKeyDown = _.bind(this.onListKeyDown, this, 'series');
|
|
this.seriesList.on('item:select', _.bind(this.onSelectSeries, this));
|
|
this.seriesList.store.comparator = function(rec) {
|
|
return rec.get("order");
|
|
};
|
|
|
|
this.btnAdd = new Common.UI.Button({
|
|
el: $('#chart-dlg-btn-add')
|
|
});
|
|
this.btnAdd.on('click', _.bind(this.onAddSeries, this, false));
|
|
|
|
this.btnDelete = new Common.UI.Button({
|
|
el: $('#chart-dlg-btn-delete')
|
|
});
|
|
this.btnDelete.on('click', _.bind(this.onDeleteSeries, this));
|
|
|
|
this.btnEdit = new Common.UI.Button({
|
|
el: $('#chart-dlg-btn-edit')
|
|
});
|
|
this.btnEdit.on('click', _.bind(this.onEditSeries, this, false));
|
|
|
|
this.btnUp = new Common.UI.Button({
|
|
parentEl: $('#chart-dlg-btn-up'),
|
|
cls: 'btn-toolbar',
|
|
iconCls: 'caret-up',
|
|
hint: this.textUp
|
|
});
|
|
this.btnUp.on('click', _.bind(this.onMoveClick, this, true));
|
|
|
|
this.btnDown = new Common.UI.Button({
|
|
parentEl: $('#chart-dlg-btn-down'),
|
|
cls: 'btn-toolbar',
|
|
iconCls: 'caret-down',
|
|
hint: this.textDown
|
|
});
|
|
this.btnDown.on('click', _.bind(this.onMoveClick, this, false));
|
|
|
|
this.btnSwitch = new Common.UI.Button({
|
|
el: $('#chart-dlg-btn-switch')
|
|
});
|
|
this.btnSwitch.on('click', _.bind(this.onSwitch, this));
|
|
|
|
this.categoryList = new Common.UI.ListView({
|
|
el: $('#chart-dlg-category-list', this.$window),
|
|
store: new Common.UI.DataViewStore(),
|
|
emptyText: '',
|
|
scrollAlwaysVisible: true
|
|
});
|
|
|
|
this.btnEditCategory = new Common.UI.Button({
|
|
el: $('#chart-dlg-btn-category-edit')
|
|
});
|
|
this.btnEditCategory.on('click', _.bind(this.onEditCategory, this, false));
|
|
|
|
this.afterRender();
|
|
},
|
|
|
|
afterRender: function() {
|
|
this._setDefaults(this.chartSettings);
|
|
},
|
|
|
|
show: function() {
|
|
Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments);
|
|
|
|
var me = this;
|
|
_.delay(function(){
|
|
me.txtDataRange.cmpEl.find('input').focus();
|
|
},50);
|
|
},
|
|
|
|
close: function () {
|
|
this.api.asc_onCloseChartFrame();
|
|
Common.Views.AdvancedSettingsWindow.prototype.close.apply(this, arguments);
|
|
},
|
|
|
|
_setDefaults: function (props) {
|
|
var me = this;
|
|
if (props ){
|
|
this.chartSettings = props;
|
|
|
|
this.currentChartType = props.getType();
|
|
|
|
var value = props.getRange();
|
|
this.txtDataRange.setValue((value) ? value : '');
|
|
this.dataRangeValid = value;
|
|
|
|
this.txtDataRange.validation = function(value) {
|
|
if (_.isEmpty(value)) {
|
|
return true;
|
|
}
|
|
|
|
var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Chart, value, false);
|
|
return (isvalid==Asc.c_oAscError.ID.DataRangeError) ? (me.textError + ' ' + me.textInvalidRange) : true;
|
|
};
|
|
|
|
this.updateSeriesList(props.getSeries(), 0);
|
|
this.updateCategoryList(props.getCatValues());
|
|
}
|
|
this.updateButtons();
|
|
},
|
|
|
|
getSettings: function () {
|
|
return { chartSettings: this.chartSettings};
|
|
},
|
|
|
|
onDlgBtnClick: function(event) {
|
|
var me = this;
|
|
var state = (typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event;
|
|
if (state == 'ok') {
|
|
if (!this.isRangeValid()) return;
|
|
this.handler && this.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined);
|
|
}
|
|
|
|
this.close();
|
|
},
|
|
|
|
onPrimary: function() {
|
|
this.onDlgBtnClick('ok');
|
|
return false;
|
|
},
|
|
|
|
isRangeValid: function() {
|
|
var isvalid;
|
|
if (!_.isEmpty(this.txtDataRange.getValue())) {
|
|
//change validation!!
|
|
isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Chart, this.txtDataRange.getValue(), true, this.dataDirect===0, this.currentChartType);
|
|
if (isvalid == Asc.c_oAscError.ID.No)
|
|
return true;
|
|
} else
|
|
return true;
|
|
|
|
if (isvalid == Asc.c_oAscError.ID.StockChartError) {
|
|
Common.UI.warning({msg: this.errorStockChart});
|
|
} else if (isvalid == Asc.c_oAscError.ID.MaxDataSeriesError) {
|
|
Common.UI.warning({msg: this.errorMaxRows});
|
|
} else if (isvalid == Asc.c_oAscError.ID.MaxDataPointsError)
|
|
Common.UI.warning({msg: this.errorMaxPoints});
|
|
else {
|
|
Common.UI.warning({msg: this.textInvalidRange});
|
|
}
|
|
return false;
|
|
},
|
|
|
|
changeChartRange: function(settings) {
|
|
var me = this;
|
|
if (me.isRangeValid(settings)) {
|
|
me.dataRangeValid = settings;
|
|
me.txtDataRange.checkValidate();
|
|
me.chartSettings.putRange(me.dataRangeValid);
|
|
|
|
me.updateSeriesList(me.chartSettings.getSeries(), 0);
|
|
me.updateCategoryList(me.chartSettings.getCatValues());
|
|
me.updateButtons();
|
|
}
|
|
},
|
|
|
|
onSelectData: function(input) {
|
|
var me = this;
|
|
if (me.api) {
|
|
var handlerDlg = function(dlg, result) {
|
|
if (result == 'ok') {
|
|
input.setValue(dlg.getSettings());
|
|
me.changeChartRange(dlg.getSettings());
|
|
}
|
|
};
|
|
|
|
var win = new SSE.Views.CellRangeDialog({
|
|
handler: handlerDlg
|
|
}).on('close', function() {
|
|
me.show();
|
|
});
|
|
|
|
var xy = me.$window.offset();
|
|
me.hide();
|
|
win.show(xy.left + 160, xy.top + 125);
|
|
win.setSettings({
|
|
api : me.api,
|
|
range : (!_.isEmpty(me.txtDataRange.getValue()) && (me.txtDataRange.checkValidate()==true)) ? me.txtDataRange.getValue() : me.dataRangeValid,
|
|
type : Asc.c_oAscSelectionDialogType.Chart
|
|
});
|
|
}
|
|
},
|
|
|
|
onListKeyDown: function (type, e, data) {
|
|
var record = null, listView = this.seriesList;
|
|
|
|
if (listView.disabled) return;
|
|
if (_.isUndefined(undefined)) data = e;
|
|
|
|
if (data.keyCode==Common.UI.Keys.DELETE && !this.btnDelete.isDisabled()) {
|
|
// this.onDeleteSeries();
|
|
} else {
|
|
Common.UI.DataView.prototype.onKeyDown.call(listView, e, data);
|
|
}
|
|
},
|
|
|
|
onSelectSeries: function(lisvView, itemView, record) {
|
|
this.updateMoveButtons();
|
|
},
|
|
|
|
updateButtons: function() {
|
|
this.btnEdit.setDisabled(this.seriesList.store.length<1);
|
|
this.btnDelete.setDisabled(this.seriesList.store.length<1);
|
|
this.btnSwitch.setDisabled(this.seriesList.store.length<1 || !this.chartSettings.getRange());
|
|
this.updateMoveButtons();
|
|
},
|
|
|
|
updateMoveButtons: function() {
|
|
var rec = this.seriesList.getSelectedRec(),
|
|
index = rec ? this.seriesList.store.indexOf(rec) : -1;
|
|
this.btnUp.setDisabled(index<1);
|
|
this.btnDown.setDisabled(index<0 || index==this.seriesList.store.length-1);
|
|
},
|
|
|
|
onAddSeries: function() {
|
|
var rec = (this.seriesList.store.length>0) ? this.seriesList.store.at(this.seriesList.store.length-1) : null,
|
|
isScatter = false,
|
|
me = this;
|
|
rec && (isScatter = rec.get('series').asc_IsScatter());
|
|
// me.setStartPointHistory();
|
|
var series;
|
|
if (isScatter) {
|
|
series = me.chartSettings.addScatterSeries();
|
|
} else {
|
|
series = me.chartSettings.addSeries();
|
|
}
|
|
var handlerDlg = function(dlg, result) {
|
|
if (result == 'ok') {
|
|
me.updateSeriesList(me.chartSettings.getSeries(), me.seriesList.store.length-1);
|
|
me.updateButtons();
|
|
}
|
|
};
|
|
this.changeDataRange(1, {series: series, isScatter: isScatter}, handlerDlg);
|
|
},
|
|
|
|
onDeleteSeries: function() {
|
|
var rec = this.seriesList.getSelectedRec();
|
|
if (rec) {
|
|
var order = rec.get('order');
|
|
// this.chartSettings.deleteSeries(rec.get('index'));
|
|
this.updateSeriesList(this.chartSettings.getSeries(), order);
|
|
}
|
|
this.updateButtons();
|
|
},
|
|
|
|
onEditSeries: function() {
|
|
var rec = this.seriesList.getSelectedRec();
|
|
if (rec) {
|
|
var series = rec.get('series'),
|
|
isScatter = series.asc_IsScatter(),
|
|
me = this;
|
|
var handlerDlg = function(dlg, result) {
|
|
if (result == 'ok') {
|
|
rec.set('value', series.asc_getSeriesName());
|
|
}
|
|
};
|
|
// me.setStartPointHistory();
|
|
this.changeDataRange(1, {series: series, isScatter: isScatter }, handlerDlg);
|
|
}
|
|
},
|
|
|
|
onEditCategory: function() {
|
|
var me = this;
|
|
var handlerDlg = function(dlg, result) {
|
|
if (result == 'ok') {
|
|
me.updateCategoryList(me.chartSettings.getCatValues());
|
|
}
|
|
};
|
|
// me.setStartPointHistory();
|
|
this.changeDataRange(0, {category: '', values: this.chartSettings.getCatValues()}, handlerDlg);
|
|
},
|
|
|
|
changeDataRange: function(type, props, handlerDlg) {
|
|
var me = this;
|
|
var win = new SSE.Views.ChartDataRangeDialog({
|
|
type: type, //series
|
|
isScatter: !!props.isScatter,
|
|
handler: handlerDlg
|
|
}).on('close', function() {
|
|
me.show();
|
|
// me.setEndPointHistory(); when cancel
|
|
});
|
|
|
|
var xy = me.$window.offset();
|
|
me.hide();
|
|
win.show(xy.left + 160, xy.top + 125);
|
|
win.setSettings({
|
|
api : me.api,
|
|
props : props,
|
|
chartSettings: me.chartSettings
|
|
});
|
|
},
|
|
|
|
onMoveClick: function(up) {
|
|
var store = this.seriesList.store,
|
|
length = store.length,
|
|
rec = this.seriesList.getSelectedRec();
|
|
if (rec) {
|
|
var index = store.indexOf(rec),
|
|
order = rec.get('order'),
|
|
newindex = up ? Math.max(0, index-1) : Math.min(length-1, index+1),
|
|
newrec = store.at(newindex),
|
|
neworder = newrec.get('order');
|
|
store.add(store.remove(rec), {at: newindex});
|
|
rec.set('order', neworder);
|
|
newrec.set('order', order);
|
|
// this.chartSettings.changeSeriesOrder(rec.get('index'), neworder, newrec.get('index'), order);
|
|
this.seriesList.selectRecord(rec);
|
|
this.seriesList.scrollToRecord(rec);
|
|
}
|
|
this.updateMoveButtons();
|
|
},
|
|
|
|
updateSeriesList: function(series, index) {
|
|
this.btnEditCategory.setDisabled(series && series.length>0 ? series[0].asc_IsScatter() : false);
|
|
|
|
var arr = [];
|
|
var store = this.seriesList.store;
|
|
for (var i = 0, len = series.length; i < len; i++)
|
|
{
|
|
var item = series[i],
|
|
rec = new Common.UI.DataViewModel();
|
|
rec.set({
|
|
value: item.asc_getSeriesName(),
|
|
index: item.asc_getIdx(),
|
|
order: item.asc_getOrder(),
|
|
series: item
|
|
});
|
|
arr.push(rec);
|
|
}
|
|
store.reset(arr);
|
|
(len>0) && this.seriesList.selectByIndex(Math.min(index || 0, store.length-1));
|
|
},
|
|
|
|
updateCategoryList: function(categories) {
|
|
var arr = [];
|
|
var store = this.categoryList.store;
|
|
for (var i = 0, len = categories.length; i < len; i++)
|
|
{
|
|
var item = categories[i],
|
|
rec = new Common.UI.DataViewModel();
|
|
rec.set({
|
|
value: item
|
|
});
|
|
arr.push(rec);
|
|
}
|
|
store.reset(arr);
|
|
(len>0) && this.categoryList.selectByIndex(0);
|
|
},
|
|
|
|
onSwitch: function() {
|
|
this.chartSettings.switchRowCol();
|
|
this.updateSeriesList(this.chartSettings.getSeries(), 0);
|
|
this.updateCategoryList(this.chartSettings.getCatValues());
|
|
this.updateButtons();
|
|
},
|
|
|
|
textTitle: 'Chart Data',
|
|
txtEmpty: 'This field is required',
|
|
textInvalidRange: 'Invalid cells range',
|
|
textError: 'ERROR!',
|
|
textSelectData: 'Select data',
|
|
errorMaxRows: 'The maximum number of data series per chart is 255.',
|
|
errorStockChart: 'Incorrect row order. To build a stock chart place the data on the sheet in the following order:<br> opening price, max price, min price, closing price.',
|
|
errorMaxPoints: 'The maximum number of points in series per chart is 4096.',
|
|
textSeries: 'Legend Entries (Series)',
|
|
textAdd: 'Add',
|
|
textEdit: 'Edit',
|
|
textDelete: 'Remove',
|
|
textSwitch: 'Switch Row/Column',
|
|
textCategory: 'Horizontal (Category) Axis Labels',
|
|
textUp: 'Up',
|
|
textDown: 'Down',
|
|
textData: 'Data'
|
|
}, SSE.Views.ChartDataDialog || {}))
|
|
});
|