From 66b75928b3954e4a62500205e193f3c17d29c7ff Mon Sep 17 00:00:00 2001 From: junjie Date: Mon, 31 Jan 2022 12:07:10 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20S2=E6=98=8E=E7=BB=86=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 2 +- .../canvas/custom-component/UserView.vue | 18 +- .../views/chart/chart/common/common_table.js | 10 + .../src/views/chart/chart/table/table-info.js | 59 +++ .../chart/components/ChartComponentS2.vue | 362 ++++++++++++++++++ frontend/src/views/chart/view/ChartEdit.vue | 12 +- 6 files changed, 459 insertions(+), 4 deletions(-) create mode 100644 frontend/src/views/chart/chart/common/common_table.js create mode 100644 frontend/src/views/chart/chart/table/table-info.js create mode 100644 frontend/src/views/chart/components/ChartComponentS2.vue diff --git a/frontend/package.json b/frontend/package.json index 3da6eec8cd..5d9f2444c6 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,7 +14,7 @@ }, "dependencies": { "@antv/g2plot": "^2.3.32", - "@antv/s2": "^1.6.0", + "@antv/s2": "^1.7.0", "@riophae/vue-treeselect": "0.4.0", "@tinymce/tinymce-vue": "^3.2.8", "axios": "^0.21.1", diff --git a/frontend/src/components/canvas/custom-component/UserView.vue b/frontend/src/components/canvas/custom-component/UserView.vue index 611338e0e1..d03de10662 100644 --- a/frontend/src/components/canvas/custom-component/UserView.vue +++ b/frontend/src/components/canvas/custom-component/UserView.vue @@ -37,6 +37,16 @@ @onChartClick="chartClick" @onJumpClick="jumpClick" /> + { + columns.push(ele.dataeaseName) + + meta.push({ + field: ele.dataeaseName, + name: ele.name + }) + }) + + // data config + const s2DataConfig = { + fields: { + columns: columns + }, + meta: meta, + data: tableData + } + + // options + const s2Options = { + width: containerDom.offsetWidth, + height: containerDom.offsetHeight, + // showSeriesNumber: true + style: { + cellCfg: { + width: 500 + } + } + } + + // 开始渲染 + if (s2) { + s2.destroy() + } + s2 = new TableSheet(containerDom, s2DataConfig, s2Options) + + // theme + const customTheme = getCustomTheme(chart) + s2.setThemeCfg({ theme: customTheme }) + + return s2 +} diff --git a/frontend/src/views/chart/components/ChartComponentS2.vue b/frontend/src/views/chart/components/ChartComponentS2.vue new file mode 100644 index 0000000000..4421891aaf --- /dev/null +++ b/frontend/src/views/chart/components/ChartComponentS2.vue @@ -0,0 +1,362 @@ + + + + + diff --git a/frontend/src/views/chart/view/ChartEdit.vue b/frontend/src/views/chart/view/ChartEdit.vue index f32461c88f..9675393638 100644 --- a/frontend/src/views/chart/view/ChartEdit.vue +++ b/frontend/src/views/chart/view/ChartEdit.vue @@ -769,8 +769,16 @@ class="chart-class" @onChartClick="chartClick" /> + Date: Mon, 31 Jan 2022 14:34:31 +0800 Subject: [PATCH 2/4] feat: S2 --- frontend/src/lang/en.js | 6 ++- frontend/src/lang/tw.js | 6 ++- frontend/src/lang/zh.js | 6 ++- frontend/src/views/chart/chart/chart.js | 2 + .../shape-attr/SizeSelectorAntV.vue | 38 +++++++++++++------ frontend/src/views/chart/view/ChartEdit.vue | 2 +- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index c1a0036c7a..3135ae9403 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -1016,7 +1016,11 @@ export default { filter_exp: 'Filter Value', filter_type: 'Filter Type', filter_value_can_not_str: 'Value type can not input string', - enum_value_can_not_null: 'Enum Value can not empty.' + enum_value_can_not_null: 'Enum Value can not empty.', + table_config: 'Table Config', + table_column_width_config: 'Column Width', + table_column_adapt: 'Adapt', + table_column_custom: 'Custom' }, dataset: { sheet_warn: 'There are multiple sheet pages, and the first one is extracted by default', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 622f135d37..39d208e5fc 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -1016,7 +1016,11 @@ export default { filter_exp: '過濾值', filter_type: '過濾方式', filter_value_can_not_str: '數值類型字段過濾值不能包含文本', - enum_value_can_not_null: '字段枚舉值不能為空' + enum_value_can_not_null: '字段枚舉值不能為空', + table_config: '表格配置', + table_column_width_config: '列寬調整', + table_column_adapt: '自適應', + table_column_custom: '自定義' }, dataset: { sheet_warn: '有多個 Sheet 頁,默認抽取第一個', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 79869971c1..32bfd2af3e 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -1018,7 +1018,11 @@ export default { filter_exp: '过滤值', filter_type: '过滤方式', filter_value_can_not_str: '数值类型字段过滤值不能包含文本', - enum_value_can_not_null: '字段枚举值不能为空' + enum_value_can_not_null: '字段枚举值不能为空', + table_config: '表格配置', + table_column_width_config: '列宽调整', + table_column_adapt: '自适应', + table_column_custom: '自定义' }, dataset: { sheet_warn: '有多个 Sheet 页,默认抽取第一个', diff --git a/frontend/src/views/chart/chart/chart.js b/frontend/src/views/chart/chart/chart.js index e0f36d1f81..9356fd684b 100644 --- a/frontend/src/views/chart/chart/chart.js +++ b/frontend/src/views/chart/chart/chart.js @@ -31,6 +31,8 @@ export const DEFAULT_SIZE = { tableTitleHeight: 36, tableItemHeight: 36, tablePageSize: '20', + tableColumnMode: 'adapt', + tableColumnWidth: 100, gaugeMin: 0, gaugeMax: 100, gaugeStartAngle: 225, diff --git a/frontend/src/views/chart/components/shape-attr/SizeSelectorAntV.vue b/frontend/src/views/chart/components/shape-attr/SizeSelectorAntV.vue index ad36ad6972..b2b58c76b7 100644 --- a/frontend/src/views/chart/components/shape-attr/SizeSelectorAntV.vue +++ b/frontend/src/views/chart/components/shape-attr/SizeSelectorAntV.vue @@ -81,6 +81,16 @@ + + + + + @@ -92,20 +102,19 @@ - + - + - - - - + + + {{ $t('chart.table_column_adapt') }} + {{ $t('chart.table_column_custom') }} + + + + @@ -322,6 +331,9 @@ export default { this.sizeForm.liquidWaveCount = this.sizeForm.liquidWaveCount ? this.sizeForm.liquidWaveCount : DEFAULT_SIZE.liquidWaveCount this.sizeForm.tablePageSize = this.sizeForm.tablePageSize ? this.sizeForm.tablePageSize : DEFAULT_SIZE.tablePageSize + + this.sizeForm.tableColumnMode = this.sizeForm.tableColumnMode ? this.sizeForm.tableColumnMode : DEFAULT_SIZE.tableColumnMode + this.sizeForm.tableColumnWidth = this.sizeForm.tableColumnWidth ? this.sizeForm.tableColumnWidth : DEFAULT_SIZE.tableColumnWidth } } }, @@ -361,7 +373,9 @@ export default { .el-select-dropdown__item{ padding: 0 20px; } - span{font-size: 12px} +span{ + font-size: 12px +} .el-form-item{ margin-bottom: 6px; diff --git a/frontend/src/views/chart/view/ChartEdit.vue b/frontend/src/views/chart/view/ChartEdit.vue index 9675393638..73c15a2f72 100644 --- a/frontend/src/views/chart/view/ChartEdit.vue +++ b/frontend/src/views/chart/view/ChartEdit.vue @@ -565,7 +565,7 @@ Date: Tue, 1 Feb 2022 15:30:09 +0800 Subject: [PATCH 3/4] feat: S2 --- .../views/chart/chart/common/common_table.js | 27 ++++++++ .../src/views/chart/chart/table/table-info.js | 61 +++++++++++++++++-- .../chart/components/ChartComponentS2.vue | 12 +++- 3 files changed, 91 insertions(+), 9 deletions(-) diff --git a/frontend/src/views/chart/chart/common/common_table.js b/frontend/src/views/chart/chart/common/common_table.js index e38cbcf94a..81214b36a2 100644 --- a/frontend/src/views/chart/chart/common/common_table.js +++ b/frontend/src/views/chart/chart/common/common_table.js @@ -8,3 +8,30 @@ export function getCustomTheme(chart) { theme.background = background return theme } + +export function getSize(chart) { + const size = {} + let customAttr = {} + if (chart.customAttr) { + customAttr = JSON.parse(chart.customAttr) + // size + if (customAttr.size) { + const s = JSON.parse(JSON.stringify(customAttr.size)) + size.colCfg = { + height: s.tableTitleHeight + } + size.cellCfg = { + height: s.tableItemHeight + } + if (!s.tableColumnMode || s.tableColumnMode === 'adapt') { + delete size.cellCfg.width + size.layoutWidthType = 'compact' + } else { + delete size.layoutWidthType + size.cellCfg.width = s.tableColumnWidth + } + } + } + + return size +} diff --git a/frontend/src/views/chart/chart/table/table-info.js b/frontend/src/views/chart/chart/table/table-info.js index 15fce23ebf..080a4aaf33 100644 --- a/frontend/src/views/chart/chart/table/table-info.js +++ b/frontend/src/views/chart/chart/table/table-info.js @@ -1,5 +1,5 @@ import { TableSheet } from '@antv/s2' -import { getCustomTheme } from '@/views/chart/chart/common/common_table' +import { getCustomTheme, getSize } from '@/views/chart/chart/common/common_table' export function baseTableInfo(s2, container, chart, action, tableData) { const containerDom = document.getElementById(container) @@ -38,11 +38,60 @@ export function baseTableInfo(s2, container, chart, action, tableData) { width: containerDom.offsetWidth, height: containerDom.offsetHeight, // showSeriesNumber: true - style: { - cellCfg: { - width: 500 - } - } + style: getSize(chart) + } + + // 开始渲染 + if (s2) { + s2.destroy() + } + s2 = new TableSheet(containerDom, s2DataConfig, s2Options) + + // theme + const customTheme = getCustomTheme(chart) + s2.setThemeCfg({ theme: customTheme }) + + return s2 +} + +export function baseTableNormal(s2, container, chart, action, tableData) { + const containerDom = document.getElementById(container) + + // data + const fields = chart.data.fields + if (!fields || fields.length === 0) { + if (s2) { + s2.destroy() + } + return + } + + const columns = [] + const meta = [] + fields.forEach(ele => { + columns.push(ele.dataeaseName) + + meta.push({ + field: ele.dataeaseName, + name: ele.name + }) + }) + + // data config + const s2DataConfig = { + fields: { + columns: columns + }, + meta: meta, + data: tableData + } + + // options + const s2Options = { + width: containerDom.offsetWidth, + height: containerDom.offsetHeight, + // showSeriesNumber: true + style: getSize(chart) } // 开始渲染 diff --git a/frontend/src/views/chart/components/ChartComponentS2.vue b/frontend/src/views/chart/components/ChartComponentS2.vue index 4421891aaf..25e68cee82 100644 --- a/frontend/src/views/chart/components/ChartComponentS2.vue +++ b/frontend/src/views/chart/components/ChartComponentS2.vue @@ -5,7 +5,8 @@

{{ chart.title }}

-
+
+
{{ $t('chart.total') }} @@ -33,7 +34,7 @@ import { uuid } from 'vue-uuid' import ViewTrackBar from '@/components/canvas/components/Editor/ViewTrackBar' import { hexColorToRGBA } from '@/views/chart/chart/util' -import { baseTableInfo } from '@/views/chart/chart/table/table-info' +import { baseTableInfo, baseTableNormal } from '@/views/chart/chart/table/table-info' export default { name: 'ChartComponentS2', @@ -186,6 +187,8 @@ export default { } if (chart.type === 'table-info') { this.myChart = baseTableInfo(this.myChart, this.chartId, chart, this.antVAction, this.tableData) + } else if (chart.type === 'table-normal') { + this.myChart = baseTableNormal(this.myChart, this.chartId, chart, this.antVAction, this.tableData) } else { if (this.myChart) { this.antVRenderStatus = false @@ -336,9 +339,12 @@ export default {