Skip to content

Commit

Permalink
Merge pull request #127 from nzzdev/release-3.1.8
Browse files Browse the repository at this point in the history
Release 3.1.8
  • Loading branch information
philipkueng authored Oct 31, 2019
2 parents 9ba3a31 + cdab700 commit e989315
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 223 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Q Table [![Build Status](https://travis-ci.com/nzzdev/Q-table.svg?token=g43MZxbtUcZ6QyxqUoJM&branch=dev)](https://travis-ci.com/nzzdev/Q-table) [![Greenkeeper badge](https://badges.greenkeeper.io/nzzdev/Q-table.svg?token=70f2c40b32fd66edccfe705c14e1443e8e403768fadc870f4f22f749877c522b&ts=1549974271422)](https://greenkeeper.io/)

**Maintainer**: [manuelroth](https://github.com/manuelroth)
**Maintainer**: [philipkueng](https://github.com/philipkueng)

Q Table is one tool of the Q toolbox to create tables.
Test it in the [demo](https://editor.q.tools).
Expand Down
24 changes: 19 additions & 5 deletions helpers/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ const Array2D = require("array2d");
const appendFootnoteAnnotationsToTableData = require("./footnotes.js")
.appendFootnoteAnnotationsToTableData;

const fourPerEmSpace = "\u2005";
const enDash = "\u2013";

const formatLocale = d3.format.formatLocale({
decimal: ",",
thousands: " ", // this is a viertelgeviert U+2005
thousands: fourPerEmSpace,
minus: enDash,
grouping: [3]
});

Expand All @@ -32,12 +36,16 @@ function getColumnsType(data) {

Array2D.eachColumn(table, column => {
let columnEmpty = column.every(cell => {
return cell === null || cell === "" || cell === "-";
return cell === null || cell === "" || cell === "-" || cell === "–";
});
let isColumnNumeric = column.every(cell => {
return (
!columnEmpty &&
(isNumeric(cell) || cell === null || cell === "" || cell === "-")
(isNumeric(cell) ||
cell === null ||
cell === "" ||
cell === "-" ||
cell === "–")
);
});
columns.push({ isNumeric: isColumnNumeric });
Expand Down Expand Up @@ -68,8 +76,14 @@ function getTableData(data, footnotes, options) {
let value = cell;
if (columns[columnIndex].isNumeric) {
type = "numeric";
// do not format the header row, empty cells or a hyphen(-)
if (rowIndex > 0 && cell !== null && cell !== "" && cell != "-") {
// do not format the header row, empty cells, a hyphen(-) or a en dash (–)
if (
rowIndex > 0 &&
cell !== null &&
cell !== "" &&
cell != "-" &&
cell != enDash
) {
if (Math.abs(parseFloat(cell)) >= 10000) {
value = formatGrouping(cell);
} else {
Expand Down
Loading

0 comments on commit e989315

Please sign in to comment.