Skip to content

Commit

Permalink
Style dashboard (#75)
Browse files Browse the repository at this point in the history
* 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
MonikaFu authored Nov 28, 2024
1 parent fe20513 commit 405971b
Show file tree
Hide file tree
Showing 13 changed files with 507 additions and 436 deletions.
2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en" class="dark">
<html lang="en" class="light">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
Expand Down
46 changes: 23 additions & 23 deletions src/css/plot_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ div.d3chart .chart_source {

div.d3chart svg {
/* border: 1px dashed; */
background-color: white;
background-color: #d9e2e8;
}

div.d3chart > * {
Expand All @@ -140,7 +140,7 @@ div.d3chart > * {

div.d3chart div.d3tooltip {
opacity: 0.9;
background-color: white;
background-color: #d9e2e8;
color: black;
border-radius: 4px;
padding: 10px;
Expand Down Expand Up @@ -171,67 +171,67 @@ div.d3chart.WaffleChart {
}

div.d3chart .axis {
font-size: 0.9em;
font-size: 0.8em;
}

/* axis color */
div.d3chart path.domain {
stroke: #c0c0c0;
stroke: #99b1c1;
}

div.d3chart .tick line {
stroke: #c0c0c0;
stroke: #99b1c1;
}

/* d3 data_table styling */

div.d3chart.data_table table,
div.d3chart.data_table th,
div.d3chart.data_table td {
border-collapse: collapse;
padding: 8px;
border-bottom: 1px solid #aaa;
border-bottom: none !important;
text-align: center;
font-size: 1em;
border-collapse: collapse;
padding: 8px;
border-bottom: 1px solid #aaa;
border-bottom: none !important;
text-align: center;
font-size: 1em;
}

div.d3chart.data_table table tr {
background-color: #fff !important;
background-color: #fff !important;
}

div.d3chart.data_table table tr:hover {
background-color: #f5f5f5 !important;
background-color: #f5f5f5 !important;
}

div.d3chart.included_table {
margin: auto;
}

div.d3chart.included_table table thead tr {
border-top: none !important;
border-bottom: 2px solid #ccc !important;
border-top: none !important;
border-bottom: 2px solid #99b1c1 !important;
}

div.d3chart.included_table table,
div.d3chart.included_table th,
div.d3chart.included_table td,
div.d3chart.included_table tr {
border-collapse: collapse;
padding: 10px !important;
border-bottom: none !important;
border-top: none !important;
font-size: 1em;
border-collapse: collapse;
padding: 10px !important;
border-bottom: none !important;
border-top: none !important;
font-size: 1em;
}

div.d3chart.included_table table tr.summary_row {
border-top: 1px solid #ccc !important;
border-bottom: none !important;
border-top: 1px solid #99b1c1 !important;
border-bottom: none !important;
}

div.d3chart.included_table table td.column_left_border,
div.d3chart.included_table table th.column_left_border {
border-left: 1px solid #ccc !important;
border-left: 1px solid #99b1c1 !important;
}

/* sectors color palette */
Expand Down
6 changes: 4 additions & 2 deletions src/js/company_bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class company_bubble {
const marginTop = 40;
const marginRight = 60;
const marginBottom = 80;
const marginLeft = 80;
const marginLeft = 85;
let size = height - marginTop - marginBottom;

// Chart parameters
Expand All @@ -43,7 +43,7 @@ export class company_bubble {
let xtitle = 'Current capacity in low-carbon technologies',
xsubtitle = '(as % of sector production capacity)',
ytitle = 'Planned new capacity in low-carbon technologies',
ysubtitle = '(as a % of the scenario* target for YEAR)',
ysubtitle = '(as a % of the scenario target for YEAR)',
xtooltip = xtitle,
ytooltip = ytitle,
ztooltip = 'Weight in portfolio (% of AUM)',
Expand Down Expand Up @@ -106,6 +106,7 @@ export class company_bubble {

svg.select('.xaxis').call(xaxis).selectAll('.domain').attr('stroke', axis_color);
svg.select('.xaxis').selectAll('.tick').selectAll('line').attr('stroke', axis_color);
svg.select('.xaxis').selectAll('text').style('font-size', '1.2em');

svg
.append('text')
Expand Down Expand Up @@ -164,6 +165,7 @@ export class company_bubble {

svg.select('.yaxis').call(yaxis).selectAll('.domain').attr('stroke', axis_color);
svg.select('.yaxis').selectAll('.tick').selectAll('line').attr('stroke', axis_color);
svg.select('.yaxis').selectAll('text').style('font-size', '1.2em');

// Mid lines
svg
Expand Down
214 changes: 114 additions & 100 deletions src/js/included_table.js
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;
}
2 changes: 1 addition & 1 deletion src/js/pie_exploded.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class PieExploded {
.attr('class', (d) => (d.data.exploded ? d.data.key : 'non-PACTA'))
.attr('d', arc)
.attr('fill', (d) => (d.data.exploded ? color(d.data.key) : greys(d.data.key)))
.attr('stroke', 'white')
.attr('stroke', '#d9e2e8')
.style('stroke-width', '2px')
.style('opacity', 1)
.on('mouseover', mouseover)
Expand Down
Loading

0 comments on commit 405971b

Please sign in to comment.