-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove coloured boxes * Put everything into cards * improve visuals portfolio view * Make buttons more visible * Improve visuals sector view * Improve visuals company * Style * Style table * Set mode to light
- Loading branch information
Showing
13 changed files
with
507 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,118 @@ | ||
import * as d3 from 'd3'; | ||
|
||
export function tabulateIntoIncludedTable(data, id, opts) { | ||
// set options | ||
opts = typeof opts === 'undefined' ? {} : opts; | ||
var columnsText = typeof opts.columnsText === 'undefined' ? [1, 6] : opts.columnsText, | ||
columnsNumeric = typeof opts.columnsNumeric === 'undefined' ? [2, 5] : opts.columnsNumeric, | ||
columnsPercent = typeof opts.columnsPercent === 'undefined' ? [3] : opts.columnsPercent, | ||
columnsShortText = typeof opts.columnsShortText === 'undefined' ? [4] : opts.columnsShortText, | ||
columnValueBreakdown = | ||
typeof opts.columnValueBreakdown === 'undefined' ? 5 : opts.columnValueBreakdown, | ||
columnToMergeHeaderWithContent = | ||
typeof opts.columnToMergeHeaderWithContent === 'undefined' | ||
? 5 | ||
: opts.columnToMergeHeaderWithContent, | ||
columnToMergeHeaderNoContent = | ||
typeof opts.columnToMergeHeaderNoContent === 'undefined' | ||
? 6 | ||
: opts.columnToMergeHeaderNoContent; | ||
|
||
// set options | ||
opts = (typeof opts === 'undefined') ? {} : opts; | ||
var columnsText = (typeof opts.columnsText === 'undefined') ? [1, 6] : opts.columnsText, | ||
columnsNumeric = (typeof opts.columnsNumeric === 'undefined') ? [2, 5] : opts.columnsNumeric, | ||
columnsPercent = (typeof opts.columnsPercent === 'undefined') ? [3] : opts.columnsPercent, | ||
columnsShortText = (typeof opts.columnsShortText === 'undefined') ? [4] : opts.columnsShortText, | ||
columnValueBreakdown = (typeof opts.columnValueBreakdown === 'undefined') ? 5 : opts.columnValueBreakdown, | ||
columnToMergeHeaderWithContent = (typeof opts.columnToMergeHeaderWithContent === 'undefined') ? 5 : opts.columnToMergeHeaderWithContent, | ||
columnToMergeHeaderNoContent = (typeof opts.columnToMergeHeaderNoContent === 'undefined') ? 6 : opts.columnToMergeHeaderNoContent; | ||
|
||
var columns = Object.keys(data[0]); | ||
d3.select(id).selectAll("table").remove(); | ||
|
||
var idDiv = d3.select(id) | ||
.attr("class","d3chart included_table") | ||
.style("width","800px"); | ||
|
||
var table = idDiv.append("table"), | ||
thead = table.append("thead"), | ||
tbody = table.append("tbody"); | ||
|
||
thead.append("tr") | ||
.selectAll("th") | ||
.data(columns) | ||
.enter() | ||
.append("th") | ||
.text(function(column) { return column; }) | ||
.style("text-align", "center") | ||
; | ||
|
||
if (!(columnToMergeHeaderWithContent == null) && !(columnToMergeHeaderNoContent == null)) { | ||
table.selectAll("thead th:nth-child(" + columnToMergeHeaderWithContent + ")").attr("colspan", 2); | ||
table.selectAll("thead th:nth-child(" + columnToMergeHeaderNoContent + ")").remove(); | ||
} | ||
|
||
var rows = tbody.selectAll("tr") | ||
.data(data) | ||
.enter() | ||
.append("tr"); | ||
|
||
var cells = rows.selectAll("td") | ||
.data(row => { | ||
return columns.map(column => { | ||
return { value: row[column] }; | ||
}); | ||
}) | ||
.enter() | ||
.append("td") | ||
.html(d => d.value) | ||
.attr("border","none") | ||
.style("text-align", "left") | ||
; | ||
|
||
columnsText.forEach(col => leftAlignBody(col)); | ||
columnsNumeric.forEach(col => {formatMillionsBody(col); rightAlignBody(col)}); | ||
columnsPercent.forEach(col => {formatFractionIntoPercentage(col); rightAlignBody(col)}); | ||
columnsShortText.forEach(col => centerAlignBody(col)); | ||
|
||
|
||
|
||
function formatMillionsBody(column) { | ||
table.selectAll("tbody td:nth-child(" + column + ")").html(d => formatMillions(d.value)); | ||
} | ||
|
||
function formatMillions(num) { | ||
if (num == null) { | ||
return num; | ||
} else if (num < 0.01e6 && num > -0.01e6) { | ||
return num >= 0 ? "<0.01" : ">-0.01"; | ||
} else { | ||
return d3.format(",.2f")(num / 1e6); | ||
} | ||
} | ||
|
||
function formatFractionIntoPercentage(column) { | ||
table.selectAll("tbody td:nth-child(" + column + ")").html(d => (d.value == null) ? d.value : d3.format(".0%")(d.value)); | ||
} | ||
|
||
function leftAlignBody(column) { | ||
table.selectAll("tbody td:nth-child(" + column + ")").style("text-align", "left"); | ||
} | ||
|
||
function rightAlignBody(column) { | ||
table.selectAll("tbody td:nth-child(" + column + ")").style("text-align", "right"); | ||
} | ||
|
||
function centerAlignBody(column) { | ||
table.selectAll("tbody td:nth-child(" + column + ")").style("text-align", "center"); | ||
} | ||
|
||
// Add grids in chosen places | ||
table.selectAll("tbody tr:nth-child(" + data.length + ")").attr("class", "summary_row"); | ||
|
||
if (!(columnValueBreakdown == null)) { | ||
table.selectAll("thead th:nth-child(" + columnValueBreakdown + ")").attr("class", "column_left_border"); | ||
table.selectAll("tbody td:nth-child(" + columnValueBreakdown + ")").attr("class", "column_left_border"); | ||
} | ||
|
||
return table; | ||
} | ||
var columns = Object.keys(data[0]); | ||
d3.select(id).selectAll('table').remove(); | ||
|
||
var idDiv = d3.select(id).attr('class', 'd3chart included_table').style('width', '800px'); | ||
|
||
var table = idDiv.append('table'), | ||
thead = table.append('thead'), | ||
tbody = table.append('tbody'); | ||
|
||
thead | ||
.append('tr') | ||
.selectAll('th') | ||
.data(columns) | ||
.enter() | ||
.append('th') | ||
.text(function (column) { | ||
return column; | ||
}) | ||
.style('text-align', 'center'); | ||
|
||
if (!(columnToMergeHeaderWithContent == null) && !(columnToMergeHeaderNoContent == null)) { | ||
table | ||
.selectAll('thead th:nth-child(' + columnToMergeHeaderWithContent + ')') | ||
.attr('colspan', 2); | ||
table.selectAll('thead th:nth-child(' + columnToMergeHeaderNoContent + ')').remove(); | ||
} | ||
|
||
var rows = tbody.selectAll('tr').data(data).enter().append('tr'); | ||
|
||
var cells = rows | ||
.selectAll('td') | ||
.data((row) => { | ||
return columns.map((column) => { | ||
return { value: row[column] }; | ||
}); | ||
}) | ||
.enter() | ||
.append('td') | ||
.html((d) => d.value) | ||
.attr('border', 'none') | ||
.style('text-align', 'left'); | ||
columnsText.forEach((col) => leftAlignBody(col)); | ||
columnsNumeric.forEach((col) => { | ||
formatMillionsBody(col); | ||
rightAlignBody(col); | ||
}); | ||
columnsPercent.forEach((col) => { | ||
formatFractionIntoPercentage(col); | ||
rightAlignBody(col); | ||
}); | ||
columnsShortText.forEach((col) => centerAlignBody(col)); | ||
|
||
function formatMillionsBody(column) { | ||
table.selectAll('tbody td:nth-child(' + column + ')').html((d) => formatMillions(d.value)); | ||
} | ||
|
||
function formatMillions(num) { | ||
if (num == null) { | ||
return num; | ||
} else if (num < 0.01e6 && num > -0.01e6) { | ||
return num >= 0 ? '<0.01' : '>-0.01'; | ||
} else { | ||
return d3.format(',.2f')(num / 1e6); | ||
} | ||
} | ||
|
||
function formatFractionIntoPercentage(column) { | ||
table | ||
.selectAll('tbody td:nth-child(' + column + ')') | ||
.html((d) => (d.value == null ? d.value : d3.format('.0%')(d.value))); | ||
} | ||
|
||
function leftAlignBody(column) { | ||
table.selectAll('tbody td:nth-child(' + column + ')').style('text-align', 'left'); | ||
} | ||
|
||
function rightAlignBody(column) { | ||
table.selectAll('tbody td:nth-child(' + column + ')').style('text-align', 'right'); | ||
} | ||
|
||
function centerAlignBody(column) { | ||
table.selectAll('tbody td:nth-child(' + column + ')').style('text-align', 'center'); | ||
} | ||
|
||
// Add grids in chosen places | ||
table.selectAll('tbody tr:nth-child(' + data.length + ')').attr('class', 'summary_row'); | ||
|
||
if (!(columnValueBreakdown == null)) { | ||
table | ||
.selectAll('thead th:nth-child(' + columnValueBreakdown + ')') | ||
.attr('class', 'column_left_border'); | ||
table | ||
.selectAll('tbody td:nth-child(' + columnValueBreakdown + ')') | ||
.attr('class', 'column_left_border'); | ||
} | ||
|
||
return table; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.