Skip to content

Commit

Permalink
Merge pull request #174 from nzzdev/release-6.1.3
Browse files Browse the repository at this point in the history
Release 6.1.3
  • Loading branch information
dnlbln authored Aug 10, 2022
2 parents 1b514a6 + 3b60111 commit 4258e63
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 39 deletions.
29 changes: 15 additions & 14 deletions dist/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,21 +955,22 @@ function getColumnsType(data) {
}
return columns;
}
/**
* TODO:
* This is quite a rough function.
* Will fail under mixed values.
* Need better to logic.
*/
function isColumnNumeric(column) {
// If we find one cell that is numeric then it is a numeric column.
// Loop through all cells and if one cell is not numeric
for (let i = 0; i < column.length; i++) {
const value = column[i];
if (isNumeric(value)) {
return true;
// TODO
// The question should we accept a string as an exception for a numeric column or force the user to
// keep it null or empty?
if (value === null || value === '-') {
continue;
}
// If we detect any non numeric value then this column is not numeric anymore.
if (!isNumeric(value)) {
return false;
}
}
return false;
return true;
}
function formatTableData(data, footnotes, options) {
const columns = getColumnsType(data);
Expand Down Expand Up @@ -1211,14 +1212,14 @@ function getMinibarNumbersWithType(data, selectedColumnIndex) {
const row = data[i];
const cell = row[selectedColumnIndex];
let value = parseFloat(cell || '');
const type = getTypeOfValue(value);
if (isNaN(value)) {
minibarsWithType.items.push({
value: null,
type
type: "empty" /* MINIBAR_TYPE.EMPTY */
});
}
else {
const type = getTypeOfValue(value);
minibarsWithType.numbers.push(value);
minibarsWithType.items.push({
value,
Expand Down Expand Up @@ -1295,8 +1296,8 @@ function getTypeOfValue(value) {
return "empty" /* MINIBAR_TYPE.EMPTY */;
}
function getMinibarType(numbers) {
const allPositive = numbers.every(number => number > 0);
const allNegative = numbers.every(number => number < 0);
const allPositive = numbers.every(number => number >= 0);
const allNegative = numbers.every(number => number <= 0);
if (allPositive) {
return "positive" /* MINIBAR_TYPE.POSITIVE */;
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "q-table",
"version": "6.1.2",
"version": "6.1.3",
"description": "",
"main": "index.js",
"type": "module",
Expand Down
37 changes: 31 additions & 6 deletions resources/fixtures/data/minibars-negative.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,36 @@
"title": "FIXTURE: minibars with negative values",
"data": {
"table": [
["", "2016", "2017", "+/- %"],
["Auftragseingang", "10375", "10989", "-6"],
["Umsatz", "9683", "10178", "-5"],
["Ebit-Mage (%)", "11.7", "11.7", "-"],
["Cashflow aus Geschäftstätigkeite", "929", "810", "-13"]
[
"",
"2016",
"2017",
"+/- %"
],
[
"Auftragseingang",
"10375",
"10989",
"-6"
],
[
"Umsatz",
"9683",
"10178",
"-5"
],
[
"Ebit-Mage (%)",
"11.7",
"11.7",
"-"
],
[
"Cashflow aus Geschäftstätigkeite",
"929",
"810",
"-13"
]
],
"metaData": {
"cells": []
Expand Down Expand Up @@ -38,4 +63,4 @@
},
"tool": "table",
"subtitle": "State by state breakdown"
}
}
5 changes: 2 additions & 3 deletions src/components/minibar/MinibarValue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
}
function getCellClass() {
let classes = `q-table__cell q-table__cell--${
cell.type
} ${cell.classes.join(" ")} `;
let classes = `q-table__cell q-table__cell--${cell.type} ${cell.classes.join(" ")} `;
if (
item.options.minibar.selectedColumn === colIndex &&
!item.options.initWithCardLayout
Expand Down
22 changes: 12 additions & 10 deletions src/helpers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,25 @@ function getColumnsType(data: QTableDataRaw): ColumnType[] {
return columns;
}

/**
* TODO:
* This is quite a rough function.
* Will fail under mixed values.
* Need better to logic.
*/
function isColumnNumeric(column: (string|null)[]): boolean {
// If we find one cell that is numeric then it is a numeric column.
// Loop through all cells and if one cell is not numeric
for (let i = 0 ; i < column.length; i++) {
const value = column[i];

if (isNumeric(value)) {
return true;
// TODO
// The question should we accept a string as an exception for a numeric column or force the user to
// keep it null or empty?
if (value === null || value === '-') {
continue;
}

// If we detect any non numeric value then this column is not numeric anymore.
if (!isNumeric(value)) {
return false;
}
}

return false;
return true;
}

export function formatTableData(data: QTableDataRaw, footnotes: StructuredFootnote[], options: QTableConfigOptions): QTableDataFormatted[][] {
Expand Down
9 changes: 5 additions & 4 deletions src/helpers/minibars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ export function getMinibarNumbersWithType(data: QTableDataRaw, selectedColumnInd
const row = data[i];
const cell = row[selectedColumnIndex];
let value = parseFloat(cell || '');
const type = getTypeOfValue(value);


if (isNaN(value)) {
minibarsWithType.items.push({
value: null,
type
type: MINIBAR_TYPE.EMPTY
});
} else {
const type = getTypeOfValue(value);
minibarsWithType.numbers.push(value);

minibarsWithType.items.push({
Expand Down Expand Up @@ -145,8 +146,8 @@ function getTypeOfValue(value: number):MINIBAR_TYPE {
}

function getMinibarType(numbers: number[]): MINIBAR_TYPE {
const allPositive = numbers.every(number => number > 0);
const allNegative = numbers.every(number => number < 0);
const allPositive = numbers.every(number => number >= 0);
const allNegative = numbers.every(number => number <= 0);

if (allPositive) {
return MINIBAR_TYPE.POSITIVE;
Expand Down

0 comments on commit 4258e63

Please sign in to comment.