From 5ab470ec5fa32637188ae28fd09bf60541df597e Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 22 Mar 2021 22:21:03 +0300 Subject: [PATCH] [SSE] Add sparklines --- .../main/app/controller/Toolbar.js | 23 ++++++++++ .../main/app/template/Toolbar.template | 1 + .../main/app/view/Toolbar.js | 45 ++++++++++++++++++- apps/spreadsheeteditor/main/locale/en.json | 2 + 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 0b2c0fdd0..8e267602f 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -79,6 +79,7 @@ define([ 'Toolbar': { 'change:compact': this.onClickChangeCompact.bind(me), 'add:chart' : this.onSelectChart, + 'add:spark' : this.onSelectSpark, 'insert:textart': this.onInsertTextart, 'change:scalespn': this.onClickChangeScaleInMenu.bind(me), 'click:customscale': this.onScaleClick.bind(me), @@ -1130,6 +1131,28 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.toolbar); }, + onSelectSpark: function(type) { + if (!this.editMode) return; + var me = this, + info = me.api.asc_getCellInfo(), + seltype = info.asc_getSelectionType(); + + if (me.api) { + if (seltype==Asc.c_oAscSelectionType.RangeCells || seltype==Asc.c_oAscSelectionType.RangeCol || + seltype==Asc.c_oAscSelectionType.RangeRow || seltype==Asc.c_oAscSelectionType.RangeMax) { + var sparkLineInfo = info.asc_getSparklineInfo(); + if (!!sparkLineInfo) { + var props = new Asc.sparklineGroup(); + props.asc_setType(type); + this.api.asc_setSparklineGroup(sparkLineInfo.asc_getId(), props); + } else { + // add sparkline + } + } + } + Common.NotificationCenter.trigger('edit:complete', this.toolbar); + }, + onInsertTextart: function (data) { if (this.api) { this.toolbar.fireEvent('inserttextart', this.toolbar); diff --git a/apps/spreadsheeteditor/main/app/template/Toolbar.template b/apps/spreadsheeteditor/main/app/template/Toolbar.template index 1b359be7d..55a1bf9a0 100644 --- a/apps/spreadsheeteditor/main/app/template/Toolbar.template +++ b/apps/spreadsheeteditor/main/app/template/Toolbar.template @@ -130,6 +130,7 @@ +
diff --git a/apps/spreadsheeteditor/main/app/view/Toolbar.js b/apps/spreadsheeteditor/main/app/view/Toolbar.js index 78b16ee8f..3dd82ee5e 100644 --- a/apps/spreadsheeteditor/main/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/view/Toolbar.js @@ -722,6 +722,15 @@ define([ menu : true }); + me.btnInsertSparkline = new Common.UI.Button({ + id : 'tlbtn-insertsparkline', + cls : 'btn-toolbar x-huge icon-top', + iconCls : 'toolbar__icon btn-insert-sparkline', + lock : [_set.editCell, _set.selChart, _set.selChartText, _set.selImage, _set.selShape, _set.selSlicer, _set.multiselect, _set.lostConnect, _set.coAuth, _set.coAuthText, _set.editPivot], + caption : me.capInsertSpark, + menu : true + }); + me.btnInsertShape = new Common.UI.Button({ id : 'tlbtn-insertshape', cls : 'btn-toolbar x-huge icon-top', @@ -1461,7 +1470,7 @@ define([ me.btnInsertText, me.btnInsertTextArt, me.btnSortUp, me.btnSortDown, me.btnSetAutofilter, me.btnClearAutofilter, me.btnTableTemplate, me.btnPercentStyle, me.btnCurrencyStyle, me.btnDecDecimal, me.btnAddCell, me.btnDeleteCell, me.btnCondFormat, me.cmbNumberFormat, me.btnBorders, me.btnInsertImage, me.btnInsertHyperlink, - me.btnInsertChart, me.btnColorSchemas, + me.btnInsertChart, me.btnColorSchemas, me.btnInsertSparkline, me.btnCopy, me.btnPaste, me.listStyles, me.btnPrint, /*me.btnSave,*/ me.btnClearStyle, me.btnCopyStyle, me.btnPageMargins, me.btnPageSize, me.btnPageOrient, me.btnPrintArea, me.btnPrintTitles, me.btnImgAlign, me.btnImgBackward, me.btnImgForward, me.btnImgGroup, me.btnScale @@ -1661,6 +1670,7 @@ define([ _injectComponent('#slot-btn-colorschemas', this.btnColorSchemas); _injectComponent('#slot-btn-search', this.btnSearch); _injectComponent('#slot-btn-inschart', this.btnInsertChart); + _injectComponent('#slot-btn-inssparkline', this.btnInsertSparkline); _injectComponent('#slot-field-styles', this.listStyles); _injectComponent('#slot-btn-chart', this.btnEditChart); _injectComponent('#slot-btn-chart-data', this.btnEditChartData); @@ -1720,6 +1730,7 @@ define([ _updateHint(this.btnInsertTable, this.tipInsertTable); _updateHint(this.btnInsertImage, this.tipInsertImage); _updateHint(this.btnInsertChart, this.tipInsertChartSpark); + _updateHint(this.btnInsertSparkline, this.tipInsertSpark); _updateHint(this.btnInsertText, this.tipInsertText); _updateHint(this.btnInsertTextArt, this.tipInsertTextart); _updateHint(this.btnInsertHyperlink, this.tipInsertHyperlink + Common.Utils.String.platformKey('Ctrl+K')); @@ -1919,6 +1930,34 @@ define([ this.btnInsertChart.menu.on('show:before', onShowBefore); } + if ( this.btnInsertSparkline ) { + this.btnInsertSparkline.setMenu(new Common.UI.Menu({ + style: 'width: 166px;padding: 5px 0 10px;', + items: [ + { template: _.template('') } + ] + })); + + var onShowBefore = function(menu) { + var picker = new Common.UI.DataView({ + el: $('#id-toolbar-menu-insertspark'), + parentMenu: menu, + showLast: false, + restoreHeight: 50, + // groups: new Common.UI.DataViewGroupStore(Common.define.chartData.getSparkGroupData()), + store: new Common.UI.DataViewStore(Common.define.chartData.getSparkData()), + itemTemplate: _.template('
\">
') + }); + picker.on('item:click', function (picker, item, record, e) { + if (record) + me.fireEvent('add:spark', [record.get('type')]); + if (e.type !== 'click') menu.hide(); + }); + menu.off('show:before', onShowBefore); + }; + this.btnInsertSparkline.menu.on('show:before', onShowBefore); + } + if (this.btnInsertTextArt) { var onShowBeforeTextArt = function (menu) { var collection = SSE.getCollection('Common.Collections.TextArt'); @@ -2648,6 +2687,8 @@ define([ tipEditChartData: 'Select Data', tipEditChartType: 'Change Chart Type', textAutoColor: 'Automatic', - textItems: 'Items' + textItems: 'Items', + tipInsertSpark: 'Insert sparkline', + capInsertSpark: 'Sparkline' }, SSE.Views.Toolbar || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index a22d4868f..e7e814122 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -3257,6 +3257,8 @@ "SSE.Views.Toolbar.txtTime": "Time", "SSE.Views.Toolbar.txtUnmerge": "Unmerge Cells", "SSE.Views.Toolbar.txtYen": "¥ Yen", + "SSE.Views.Toolbar.tipInsertSpark": "Insert sparkline", + "SSE.Views.Toolbar.capInsertSpark": "Sparkline", "SSE.Views.Top10FilterDialog.textType": "Show", "SSE.Views.Top10FilterDialog.txtBottom": "Bottom", "SSE.Views.Top10FilterDialog.txtBy": "by",