From df19e50897093a6ed152aa97a2dc46acd6f5d330 Mon Sep 17 00:00:00 2001 From: Zhonglu Date: Wed, 13 May 2020 11:17:51 -0400 Subject: [PATCH] Fix multi series data issue on bar, line and area chart --- Dockerfile | 2 +- README.md | 6 +- build_release/start.bat | 2 +- build_release/start.sh | 2 +- docs/change-logs.md | 5 + docs/installation.md | 2 +- pom.xml | 2 +- .../java/com/shzlw/poli/util/Constants.java | 2 +- version | 2 +- web-app/package-lock.json | 73 ++----- web-app/package.json | 2 +- web-app/src/api/EchartsApi.js | 206 ++++++++++-------- 12 files changed, 155 insertions(+), 151 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1359db25..5944b825 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ FROM openjdk:8-jre-alpine WORKDIR /app -COPY --from=builder /app/src/target/poli-0.12.0.jar /app/poli-0.12.0.jar +COPY --from=builder /app/src/target/poli-0.12.1.jar /app/poli-0.12.1.jar COPY --from=builder /app/src/db/poli.db /app/db/poli.db COPY --from=builder /app/src/build_release/start.sh /app/start.sh COPY --from=builder /app/src/config/poli.docker.properties /app/config/poli.properties diff --git a/README.md b/README.md index 5791aab0..7e5741c3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # **Poli(魄力)** -[![Version](https://img.shields.io/badge/Version-0.12.0-0065FF.svg)](#) +[![Version](https://img.shields.io/badge/Version-0.12.1-0065FF.svg)](#) [![license: MIT](https://img.shields.io/badge/license-MIT-FF5630.svg)](https://opensource.org/licenses/MIT) [![Download](https://img.shields.io/github/downloads/shzlw/poli/total.svg?color=6554C0)](https://github.com/shzlw/poli/releases) [![Docker Pulls](https://img.shields.io/docker/pulls/zhonglu/poli.svg)](https://cloud.docker.com/u/zhonglu/repository/docker/zhonglu/poli) @@ -56,13 +56,13 @@ Auto refresh, drill through, fullscreen, embeds, color themes + more features in Windows/Linux ```sh -java -jar poli-0.12.0.jar +java -jar poli-0.12.1.jar ``` Docker ```sh -docker run -d -p 6688:6688 --name poli zhonglu/poli:0.12.0 +docker run -d -p 6688:6688 --name poli zhonglu/poli:0.12.1 ``` Check [installation guide](https://shzlw.github.io/poli/#/installation) for more details. diff --git a/build_release/start.bat b/build_release/start.bat index 485a4e53..0eb816e5 100644 --- a/build_release/start.bat +++ b/build_release/start.bat @@ -1 +1 @@ -java -jar poli-0.12.0.jar --spring.config.name=application,poli \ No newline at end of file +java -jar poli-0.12.1.jar --spring.config.name=application,poli \ No newline at end of file diff --git a/build_release/start.sh b/build_release/start.sh index 044b64d7..ca5be500 100644 --- a/build_release/start.sh +++ b/build_release/start.sh @@ -1,4 +1,4 @@ #!/bin/sh set -e -java -jar poli-0.12.0.jar --spring.config.name=application,poli +java -jar poli-0.12.1.jar --spring.config.name=application,poli diff --git a/docs/change-logs.md b/docs/change-logs.md index 0016d52f..05f53e8d 100644 --- a/docs/change-logs.md +++ b/docs/change-logs.md @@ -1,5 +1,10 @@ # Change Logs +## v0.12.1 + +### Bug Fixes +- Fix the issue that bar, line and area chart display wrong data when multi series option is checked in the chart option. + ## v0.12.0 ### Upgrade Steps diff --git a/docs/installation.md b/docs/installation.md index e287c0d8..d65685ae 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -96,7 +96,7 @@ 1. Pull and run the Poli image. ```bash - docker run -d -p 6688:6688 --name poli zhonglu/poli:0.12.0 + docker run -d -p 6688:6688 --name poli zhonglu/poli:0.12.1 ``` 2. Add JDBC drivers. diff --git a/pom.xml b/pom.xml index 2e798890..c8e8cde5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.shzlw.poli poli jar - 0.12.0 + 0.12.1 Poli The SQL BI tool diff --git a/src/main/java/com/shzlw/poli/util/Constants.java b/src/main/java/com/shzlw/poli/util/Constants.java index 21afb7e4..2b05e36f 100644 --- a/src/main/java/com/shzlw/poli/util/Constants.java +++ b/src/main/java/com/shzlw/poli/util/Constants.java @@ -4,7 +4,7 @@ public final class Constants { private Constants() {} - public static final String CURRENT_VERSION = "0.12.0"; + public static final String CURRENT_VERSION = "0.12.1"; public static final String SUCCESS = "success"; public static final String GOOD = ""; diff --git a/version b/version index 17779611..317d6af1 100755 --- a/version +++ b/version @@ -1,4 +1,4 @@ #!/bin/sh -VERSION=0.12.0 +VERSION=0.12.1 echo $VERSION diff --git a/web-app/package-lock.json b/web-app/package-lock.json index 7d0b5d2c..c8dc69fe 100644 --- a/web-app/package-lock.json +++ b/web-app/package-lock.json @@ -1,6 +1,6 @@ { "name": "poli-web-app", - "version": "0.12.0", + "version": "0.12.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -7203,8 +7203,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -7222,13 +7221,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7241,18 +7238,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -7355,8 +7349,7 @@ }, "inherits": { "version": "2.0.4", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -7366,7 +7359,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7379,20 +7371,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "1.2.5", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.9.0", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7409,7 +7398,6 @@ "mkdirp": { "version": "0.5.3", "bundled": true, - "optional": true, "requires": { "minimist": "^1.2.5" } @@ -7465,8 +7453,7 @@ }, "npm-normalize-package-bin": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "npm-packlist": { "version": "1.4.8", @@ -7491,8 +7478,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -7502,7 +7488,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -7571,8 +7556,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -7602,7 +7586,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7620,7 +7603,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7659,13 +7641,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.1.1", - "bundled": true, - "optional": true + "bundled": true } } } @@ -13686,8 +13666,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -13724,8 +13703,7 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", @@ -13734,8 +13712,7 @@ }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -13838,8 +13815,7 @@ }, "inherits": { "version": "2.0.4", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -13849,7 +13825,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -13875,7 +13850,6 @@ "minipass": { "version": "2.9.0", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -13892,7 +13866,6 @@ "mkdirp": { "version": "0.5.3", "bundled": true, - "optional": true, "requires": { "minimist": "^1.2.5" } @@ -13985,7 +13958,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -14054,8 +14026,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -14085,7 +14056,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -14103,7 +14073,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -14142,13 +14111,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.1.1", - "bundled": true, - "optional": true + "bundled": true } } }, diff --git a/web-app/package.json b/web-app/package.json index 710ab9ee..e08cd95a 100644 --- a/web-app/package.json +++ b/web-app/package.json @@ -1,6 +1,6 @@ { "name": "poli-web-app", - "version": "0.12.0", + "version": "0.12.1", "private": true, "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.28", diff --git a/web-app/src/api/EchartsApi.js b/web-app/src/api/EchartsApi.js index de7788f5..32ab7f1a 100644 --- a/web-app/src/api/EchartsApi.js +++ b/web-app/src/api/EchartsApi.js @@ -207,43 +207,41 @@ const getBarOption = (data, config, title) => { colorPlatte = 'default' } = config; - const legendData = new Set(); - const xAxisData = hasMultiSeries ? new Set() : []; - const seriesData = []; const type = 'bar'; - - for (let i = 0; i < data.length; i++) { - const row = data[i]; - if (hasMultiSeries) { - const xAxisVal = row[xAxis]; - const legendVal = row[legend]; - const yAxisVal = row[yAxis]; - xAxisData.add(xAxisVal); - legendData.add(legendVal); - const index = seriesData.findIndex(s => s.name === legendVal); - if (index === -1) { - const series = { - name: legendVal, - type: type, - data: [yAxisVal] - }; - - if (isStacked) { - series.stack = title || 'Empty'; - } - seriesData.push(series); - } else { - seriesData[index].data.push(yAxisVal); + const seriesData = []; + + if (hasMultiSeries) { + const { + legendList, + xAxisList, + grid + } = dataListToGrid(data, xAxis, yAxis, legend); + + // From grid to series list. + for (let i = 0; i < legendList.length; i++) { + const series = { + name: legendList[i], + type: type, + data: [] + }; + if (isStacked) { + series.stack = title || 'Empty'; + } + for (let j = 0; j < xAxisList.length; j++) { + series.data.push(grid[i][j]); } - } else { + seriesData.push(series); + } + + return getBarOptionTemplate(colorPlatte, legendList, xAxisList, seriesData, config); + } else { + const xAxisData = []; + for (let i = 0; i < data.length; i++) { + const row = data[i]; xAxisData.push(row[xAxis]); seriesData.push(row[yAxis]); } - } - if (hasMultiSeries) { - return getBarOptionTemplate(colorPlatte, Array.from(legendData), Array.from(xAxisData), seriesData, config); - } else { const series = { data: seriesData, type: type @@ -307,40 +305,39 @@ const getLineOption = (data, config) => { colorPlatte = 'default' } = config; - const legendData = new Set(); - const xAxisData = hasMultiSeries ? new Set() : []; const seriesData = []; const type = 'line'; - - for (let i = 0; i < data.length; i++) { - const row = data[i]; - if (hasMultiSeries) { - const xAxisVal = row[xAxis]; - const legendVal = row[legend]; - const yAxisVal = row[yAxis]; - xAxisData.add(xAxisVal); - legendData.add(legendVal); - const index = seriesData.findIndex(s => s.name === legendVal); - if (index === -1) { - const series = { - name: legendVal, - type: type, - data: [yAxisVal], - smooth: isSmooth - }; - seriesData.push(series); - } else { - seriesData[index].data.push(yAxisVal); + + if (hasMultiSeries) { + const { + legendList, + xAxisList, + grid + } = dataListToGrid(data, xAxis, yAxis, legend); + + // From grid to series list. + for (let i = 0; i < legendList.length; i++) { + const series = { + name: legendList[i], + type: type, + data: [], + smooth: isSmooth + }; + for (let j = 0; j < xAxisList.length; j++) { + series.data.push(grid[i][j]); } - } else { + seriesData.push(series); + } + + return getLineOptionTemplate(colorPlatte, legendList, xAxisList, seriesData, config); + } else { + const xAxisData = []; + for (let i = 0; i < data.length; i++) { + const row = data[i]; xAxisData.push(row[xAxis]); seriesData.push(row[yAxis]); } - } - if (hasMultiSeries) { - return getLineOptionTemplate(colorPlatte, Array.from(legendData), Array.from(xAxisData), seriesData, config); - } else { const series = { data: seriesData, type: type, @@ -404,41 +401,39 @@ const getAreaOption = (data, config) => { colorPlatte = 'default' } = config; - const legendData = new Set(); - const xAxisData = hasMultiSeries ? new Set() : []; const seriesData = []; const type = 'line'; - - for (let i = 0; i < data.length; i++) { - const row = data[i]; - if (hasMultiSeries) { - const xAxisVal = row[xAxis]; - const legendVal = row[legend]; - const yAxisVal = row[yAxis]; - xAxisData.add(xAxisVal); - legendData.add(legendVal); - const index = seriesData.findIndex(s => s.name === legendVal); - if (index === -1) { - const series = { - name: legendVal, - type: type, - data: [yAxisVal], - areaStyle: {}, - smooth: isSmooth - }; - seriesData.push(series); - } else { - seriesData[index].data.push(yAxisVal); + + if (hasMultiSeries) { + const { + legendList, + xAxisList, + grid + } = dataListToGrid(data, xAxis, yAxis, legend); + + // From grid to series list. + for (let i = 0; i < legendList.length; i++) { + const series = { + name: legendList[i], + type: type, + data: [], + areaStyle: {}, + smooth: isSmooth + }; + for (let j = 0; j < xAxisList.length; j++) { + series.data.push(grid[i][j]); } - } else { - xAxisData.push(row[xAxis]); - seriesData.push(row[yAxis]); + seriesData.push(series); } - } - if (hasMultiSeries) { - return getAreaOptionTemplate(colorPlatte, Array.from(legendData), Array.from(xAxisData), seriesData, config); + return getAreaOptionTemplate(colorPlatte, legendList, xAxisList, seriesData, config); } else { + const xAxisData = []; + for (let i = 0; i < data.length; i++) { + const row = data[i]; + xAxisData.push(row[xAxis]); + seriesData.push(row[yAxis]); + } const series = { data: seriesData, type: type, @@ -747,3 +742,40 @@ const getTimeLineOptionTemplate = (seriesData) => { ] } }; + + +const dataListToGrid = (dataList = [], xAxis, yAxis, legend) => { + const legendData = new Set(); + const xAxisData = new Set(); + + for (let i = 0; i < dataList.length; i++) { + const row = dataList[i]; + const xAxisVal = row[xAxis]; + const legendVal = row[legend]; + xAxisData.add(xAxisVal); + legendData.add(legendVal); + } + + const legendList = Array.from(legendData); + const xAxisList = Array.from(xAxisData); + + // Row: legend, Column: xAxis + const grid = new Array(legendList.length); + for (let i = 0; i < grid.length; i++) { + grid[i] = new Array(xAxisList.length); + } + + // Empty element in the grid is undefined. + for (let i = 0; i < dataList.length; i++) { + const row = dataList[i]; + const x = legendList.findIndex(val => val === row[legend]); + const y = xAxisList.findIndex(val => val === row[xAxis]); + grid[x][y] = row[yAxis]; + } + + return { + legendList, + xAxisList, + grid + }; +} \ No newline at end of file