diff --git a/helpers/data.js b/helpers/data.js index 40b89750..b205aea0 100644 --- a/helpers/data.js +++ b/helpers/data.js @@ -35,6 +35,7 @@ function getColumnsType(data) { const table = clone(data).slice(1); Array2D.eachColumn(table, column => { + let withFormating = false; let columnEmpty = column.every(cell => { return cell === null || cell === "" || cell === "-" || cell === "–"; }); @@ -48,7 +49,11 @@ function getColumnsType(data) { cell === "–") ); }); - columns.push({ isNumeric: isColumnNumeric }); + if (isColumnNumeric) { + const numbersOfColumn = column.map(number => isNumeric(number) ? parseFloat(number) : null); + withFormating = Math.max(...numbersOfColumn) >= 10000 || Math.min(...numbersOfColumn) <= -10000 + } + columns.push({ isNumeric: isColumnNumeric, withFormating }); }); return columns; } @@ -84,7 +89,7 @@ function getTableData(data, footnotes, options) { cell != "-" && cell != enDash ) { - if (Math.abs(parseFloat(cell)) >= 10000) { + if (columns[columnIndex].withFormating) { value = formatGrouping(cell); } else { value = formatNoGrouping(cell); diff --git a/package-lock.json b/package-lock.json index 2b02580f..596ea5a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "q-table", - "version": "3.1.8", + "version": "3.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -966,17 +966,17 @@ "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" }, "autoprefixer": { - "version": "9.7.0", - "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.7.0.tgz", - "integrity": "sha512-j2IRvaCfrUxIiZun9ba4mhJ2omhw4OY88/yVzLO+lHhGBumAAK72PgM6gkbSN8iregPOn1ZlxGkmZh2CQ7X4AQ==", + "version": "9.7.1", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.7.1.tgz", + "integrity": "sha512-w3b5y1PXWlhYulevrTJ0lizkQ5CyqfeU6BIRDbuhsMupstHQOeb1Ur80tcB1zxSu7AwyY/qCQ7Vvqklh31ZBFw==", "dev": true, "requires": { "browserslist": "^4.7.2", - "caniuse-lite": "^1.0.30001004", + "caniuse-lite": "^1.0.30001006", "chalk": "^2.4.2", "normalize-range": "^0.1.2", "num2fraction": "^1.2.2", - "postcss": "^7.0.19", + "postcss": "^7.0.21", "postcss-value-parser": "^4.0.2" }, "dependencies": { @@ -992,21 +992,21 @@ } }, "caniuse-lite": { - "version": "1.0.30001004", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001004.tgz", - "integrity": "sha512-3nfOR4O8Wa2RWoYfJkMtwRVOsK96TQ+eq57wd0iKaEWl8dwG4hKZ/g0MVBfCvysFvMLi9fQGR/DvozMdkEPl3g==", + "version": "1.0.30001008", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001008.tgz", + "integrity": "sha512-b8DJyb+VVXZGRgJUa30cbk8gKHZ3LOZTBLaUEEVr2P4xpmFigOCc62CO4uzquW641Ouq1Rm9N+rWLWdSYDaDIw==", "dev": true }, "electron-to-chromium": { - "version": "1.3.295", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.295.tgz", - "integrity": "sha512-KxlGE9GcZTv7xGwYJGMEABHJq2JuTMNF7jD8NwHk6sBY226mW+Dyp9kZmA2Od9tKHMCS7ltPnqFg+zq3jTWN7Q==", + "version": "1.3.304", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.304.tgz", + "integrity": "sha512-a5mqa13jCdBc+Crgk3Gyr7vpXCiFWfFq23YDCEmrPYeiDOQKZDVE6EX/Q4Xdv97n3XkcjiSBDOY0IS19yP2yeA==", "dev": true }, "node-releases": { - "version": "1.1.38", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.38.tgz", - "integrity": "sha512-/5NZAaOyTj134Oy5Cp/J8mso8OD/D9CSuL+6TOXXsTKO8yjc5e4up75SRPCganCjwFKMj2jbp5tR0dViVdox7g==", + "version": "1.1.39", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.39.tgz", + "integrity": "sha512-8MRC/ErwNCHOlAFycy9OPca46fQYUjbJRDcZTHVWIGXIjYLM73k70vv3WkYutVnM4cCo4hE0MqBVVZjP6vjISA==", "dev": true, "requires": { "semver": "^6.3.0" @@ -3462,9 +3462,9 @@ "dev": true }, "jsdom": { - "version": "15.2.0", - "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-15.2.0.tgz", - "integrity": "sha512-+hRyEfjRPFwTYMmSQ3/f7U9nP8ZNZmbkmUek760ZpxnCPWJIhaaLRuUSvpJ36fZKCGENxLwxClzwpOpnXNfChQ==", + "version": "15.2.1", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-15.2.1.tgz", + "integrity": "sha512-fAl1W0/7T2G5vURSyxBzrJ1LSdQn6Tr5UX/xD4PXDx/PDgwygedfW6El/KIj3xJ7FU61TTYnc/l/B7P49Eqt6g==", "dev": true, "requires": { "abab": "^2.0.0", @@ -3477,7 +3477,7 @@ "domexception": "^1.0.1", "escodegen": "^1.11.1", "html-encoding-sniffer": "^1.0.2", - "nwsapi": "^2.1.4", + "nwsapi": "^2.2.0", "parse5": "5.1.0", "pn": "^1.1.0", "request": "^2.88.0", @@ -3890,9 +3890,9 @@ } }, "nwsapi": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.1.4.tgz", - "integrity": "sha512-iGfd9Y6SFdTNldEy2L0GUhcarIutFmk+MPWIn9dmj8NMIup03G08uUF2KGbbmv/Ux4RT0VZJoP/sVbWA6d/VIw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.0.tgz", + "integrity": "sha512-h2AatdwYH+JHiZpv7pt/gSX1XoRGb7L/qSIeuqA6GwYoF9w1vP1cw42TO0aI2pNyshRK5893hNSl+1//vHK7hQ==", "dev": true }, "oauth-sign": { @@ -4153,9 +4153,9 @@ "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, "postcss": { - "version": "7.0.20", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.20.tgz", - "integrity": "sha512-VOdO3a5nHVftPSEbG1zaG320b4mH5KAflH+pIeVAF5/hlw6YumELSgHZQBekjg29Oj4qw7XAyp9tIEBpeNWcyg==", + "version": "7.0.21", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.21.tgz", + "integrity": "sha512-uIFtJElxJo29QC753JzhidoAhvp/e/Exezkdhfmt8AymWT6/5B7W1WmponYWkHk2eg6sONyTch0A3nkMPun3SQ==", "dev": true, "requires": { "chalk": "^2.4.2", @@ -4692,21 +4692,29 @@ } }, "request-promise-core": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.2.tgz", - "integrity": "sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.3.tgz", + "integrity": "sha512-QIs2+ArIGQVp5ZYbWD5ZLCY29D5CfWizP8eWnm8FoGD1TX61veauETVQbrV60662V0oFBkrDOuaBI8XgtuyYAQ==", "dev": true, "requires": { - "lodash": "^4.17.11" + "lodash": "^4.17.15" + }, + "dependencies": { + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true + } } }, "request-promise-native": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.7.tgz", - "integrity": "sha512-rIMnbBdgNViL37nZ1b3L/VfPOpSi0TqVDQPAvO6U14lMzOLrt5nilxCQqtDKhZeDiW0/hkCXGoQjhgJd/tCh6w==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.8.tgz", + "integrity": "sha512-dapwLGqkHtwL5AEbfenuzjTYg35Jd6KPytsC2/TLkVMz8rm+tNt72MGUWT1RP/aYawMpN6HqbNGBQaRcBtjQMQ==", "dev": true, "requires": { - "request-promise-core": "1.1.2", + "request-promise-core": "1.1.3", "stealthy-require": "^1.1.1", "tough-cookie": "^2.3.3" }, @@ -4817,9 +4825,9 @@ "dev": true }, "sass": { - "version": "1.23.1", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.23.1.tgz", - "integrity": "sha512-zQzJ3UETUWOMd/pJJGH/zvRsBVO97m11RcpfUhcQUHEXf0yHUBgOIE/Nw8aK0m1XyVJPeq228iIK7gVxsJ/Puw==", + "version": "1.23.3", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.23.3.tgz", + "integrity": "sha512-1DKRZxJMOh4Bme16AbWTyYeJAjTlrvw2+fWshHHaepeJfGq2soFZTnt0YhWit+bohtDu4LdyPoEj6VFD4APHog==", "dev": true, "requires": { "chokidar": ">=2.0.0 <4.0.0" @@ -5393,9 +5401,9 @@ "dev": true }, "uglify-js": { - "version": "3.6.4", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.4.tgz", - "integrity": "sha512-9Yc2i881pF4BPGhjteCXQNaXx1DCwm3dtOyBaG2hitHjLWOczw/ki8vD1bqyT3u6K0Ms/FpCShkmfg+FtlOfYA==", + "version": "3.6.7", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.7.tgz", + "integrity": "sha512-4sXQDzmdnoXiO+xvmTzQsfIiwrjUCSA95rSP4SEd8tDb51W2TiDOlL76Hl+Kw0Ie42PSItCW8/t6pBNCF2R48A==", "requires": { "commander": "~2.20.3", "source-map": "~0.6.1" diff --git a/package.json b/package.json index 726ca1fe..f63fc6d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "q-table", - "version": "3.1.8", + "version": "3.2.0", "description": "", "main": "index.js", "scripts": { @@ -20,17 +20,17 @@ "clone": "^2.1.2", "d3-format": "^1.4.1", "nunjucks": "^3.2.0", - "uglify-js": "^3.6.4" + "uglify-js": "^3.6.7" }, "devDependencies": { "@hapi/code": "^5.3.1", "@hapi/lab": "^19.1.0", - "autoprefixer": "^9.7.0", + "autoprefixer": "^9.7.1", "cssnano": "^4.1.10", "html-minifier": "^4.0.0", - "jsdom": "^15.2.0", - "postcss": "^7.0.20", + "jsdom": "^15.2.1", + "postcss": "^7.0.21", "postcss-import": "^12.0.1", - "sass": "^1.23.1" + "sass": "^1.23.3" } } diff --git a/resources/fixtures/data/formatted-numbers-mixed.json b/resources/fixtures/data/formatted-numbers-mixed.json new file mode 100644 index 00000000..a5c176c1 --- /dev/null +++ b/resources/fixtures/data/formatted-numbers-mixed.json @@ -0,0 +1,22 @@ +{ + "title": "FIXTURE: four column numeric card layout for small mixed", + "subtitle": "Subtitle", + "data": { + "table": [ + ["Kennzahlen", "2016", "2017"], + ["Umsatz", "12000", "100"], + ["Betriebsergebnis Ebit", "79123", "2000"], + ["Ebit-Marge (%)", "12332", "300"], + ["Konzernergebnis", "12331", "4000"], + ["Cashflow aus Geschäftstätigkeit", "99999", "10000"] + ], + "metaData": { + "cells": [] + } + }, + "sources": [], + "options": { + "cardLayout": false, + "cardLayoutIfSmall": true + } +} diff --git a/resources/fixtures/data/formatted-numbers-negative.json b/resources/fixtures/data/formatted-numbers-negative.json new file mode 100644 index 00000000..2dcdfa90 --- /dev/null +++ b/resources/fixtures/data/formatted-numbers-negative.json @@ -0,0 +1,22 @@ +{ + "title": "FIXTURE: four column numeric card layout for small negative", + "subtitle": "Subtitle", + "data": { + "table": [ + ["Kennzahlen", "2016", "2017"], + ["Umsatz", "12000", "-10000"], + ["Betriebsergebnis Ebit", "79123", "12333"], + ["Ebit-Marge (%)", "12332", "32147"], + ["Konzernergebnis", "12331", "10000"], + ["Cashflow aus Geschäftstätigkeit", "99999", "12312"] + ], + "metaData": { + "cells": [] + } + }, + "sources": [], + "options": { + "cardLayout": false, + "cardLayoutIfSmall": true + } +} diff --git a/routes/fixtures/data.js b/routes/fixtures/data.js index 0ec8c43a..3e54e5d7 100644 --- a/routes/fixtures/data.js +++ b/routes/fixtures/data.js @@ -30,7 +30,9 @@ const fixtureData = [ require(`${fixtureDataDirectory}/cardlayout-mobile.json`), require(`${fixtureDataDirectory}/lots-of-data.json`), require(`${fixtureDataDirectory}/special-characters.json`), - require(`${fixtureDataDirectory}/formatted-numbers.json`) + require(`${fixtureDataDirectory}/formatted-numbers.json`), + require(`${fixtureDataDirectory}/formatted-numbers-mixed.json`), + require(`${fixtureDataDirectory}/formatted-numbers-negative.json`) ]; module.exports = { diff --git a/tasks/updateFixtureData.js b/tasks/updateFixtureData.js index fe69795d..86859813 100644 --- a/tasks/updateFixtureData.js +++ b/tasks/updateFixtureData.js @@ -110,6 +110,18 @@ const fixtureData = [ [ `${fixtureDataDirectory}/lots-of-data.json`, require(`${fixtureDataDirectory}/lots-of-data.json`) + ], + [ + `${fixtureDataDirectory}/formatted-number.json`, + require(`${fixtureDataDirectory}/formatted-number.json`) + ], + [ + `${fixtureDataDirectory}/formatted-number-mixed.json`, + require(`${fixtureDataDirectory}/formatted-number-mixed.json`) + ], + [ + `${fixtureDataDirectory}/formatted-number-negative.json`, + require(`${fixtureDataDirectory}/formatted-number-negative.json`) ] ]; diff --git a/test/dom-tests.js b/test/dom-tests.js index f2ee75ae..b1376a24 100644 --- a/test/dom-tests.js +++ b/test/dom-tests.js @@ -126,6 +126,44 @@ lab.experiment("cell values", () => { } ); }); + + it("should display < -10000 show formatted", async () => { + const response = await server.inject({ + url: "/rendering-info/web?_id=someid", + method: "POST", + payload: { + item: require("../resources/fixtures/data/formatted-numbers-negative.json"), + toolRuntimeConfig: {} + } + }); + + return elements(response.result.markup, ".q-table__cell--numeric").then( + elements => { + elements.forEach(element => { + expect(element.innerHTML.includes(" ")).to.be.equals(true); + }); + } + ); + }); + + it("should display > 1000 when column contains >10000", async () => { + const response = await server.inject({ + url: "/rendering-info/web?_id=someid", + method: "POST", + payload: { + item: require("../resources/fixtures/data/formatted-numbers-mixed.json"), + toolRuntimeConfig: {} + } + }); + + return elements(response.result.markup, ".q-table__cell--numeric").then( + elements => { + elements.forEach(element => { + expect(element.innerHTML.includes(" ")).to.be.equals(true); + }); + } + ); + }); }); lab.experiment("cardlayout", () => { @@ -225,7 +263,7 @@ lab.experiment("cardlayout on mobile", () => { lab.experiment("minibars", () => { it("shows the same markup for positive minibars", async () => { - const workingMinibarsMarkup = `

FIXTURE: minibars with negative values

State by state breakdown
20162017+/- %
Auftragseingang10 37510 989
–6
Umsatz968310 178
–5
Ebit-Mage (%)11,711,7
-
Cashflow aus Geschäftstätigkeite929810
–13
Quelle: The Centers for Disease Control and Prevention
`; + const workingMinibarsMarkup = `

FIXTURE: minibars with negative values

State by state breakdown
20162017+/- %
Auftragseingang10 37510 989
–6
Umsatz9 68310 178
–5
Ebit-Mage (%)11,711,7
-
Cashflow aus Geschäftstätigkeite929810
–13
Quelle: The Centers for Disease Control and Prevention
`; const response = await server.inject({ url: "/rendering-info/web?_id=someid", @@ -252,7 +290,7 @@ lab.experiment("minibars", () => { }); it("shows the same markup for negative minibars", async () => { - const workingMinibarsMarkup = `

FIXTURE: minibars with negative values

State by state breakdown
20162017+/- %
Auftragseingang10 37510 989
–6
Umsatz968310 178
–5
Ebit-Mage (%)11,711,7
-
Cashflow aus Geschäftstätigkeite929810
–13
Quelle: The Centers for Disease Control and Prevention
`; + const workingMinibarsMarkup = `

FIXTURE: minibars with negative values

State by state breakdown
20162017+/- %
Auftragseingang10 37510 989
–6
Umsatz9 68310 178
–5
Ebit-Mage (%)11,711,7
-
Cashflow aus Geschäftstätigkeite929810
–13
Quelle: The Centers for Disease Control and Prevention
`; const response = await server.inject({ url: "/rendering-info/web?_id=someid", @@ -279,7 +317,7 @@ lab.experiment("minibars", () => { }); it("shows the same markup for mixed minibars", async () => { - const workingMinibarsMarkup = `

FIXTURE: minibars with positive and negative values

State by state breakdown
20162017+/- %
Auftragseingang10 37510 989
6
Umsatz968310 178
5
Ebit-Mage (%)11,711,7
-
Cashflow aus Geschäftstätigkeite929810
–13
Quelle: The Centers for Disease Control and Prevention
`; + const workingMinibarsMarkup = `

FIXTURE: minibars with positive and negative values

State by state breakdown
20162017+/- %
Auftragseingang10 37510 989
6
Umsatz9 68310 178
5
Ebit-Mage (%)11,711,7
-
Cashflow aus Geschäftstätigkeite929810
–13
Quelle: The Centers for Disease Control and Prevention
`; const response = await server.inject({ url: "/rendering-info/web?_id=someid", method: "POST", diff --git a/test/e2e-tests.js b/test/e2e-tests.js index 6fb83f0c..d56578bb 100644 --- a/test/e2e-tests.js +++ b/test/e2e-tests.js @@ -164,9 +164,9 @@ lab.experiment("dynamic schema endpoint", () => { }); lab.experiment("fixture data endpoint", () => { - it("returns 29 fixture data items for /fixtures/data", async () => { + it("returns 31 fixture data items for /fixtures/data", async () => { const response = await server.inject("/fixtures/data"); expect(response.statusCode).to.be.equal(200); - expect(response.result.length).to.be.equal(29); + expect(response.result.length).to.be.equal(31); }); });