Skip to content

Commit

Permalink
Merge pull request #8671 from cfpb/sc-legend-fixes
Browse files Browse the repository at this point in the history
Fix simple legend to allow for any number of data classes
  • Loading branch information
wpears authored Dec 4, 2024
2 parents a8e941d + f0641fc commit ab05c98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 5 additions & 6 deletions cfgov/unprocessed/css/on-demand/simple-chart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,14 @@
width: 100%;
height: 60px;
margin-top: -5px;
margin-bottom: 66px;

// Mobile only.
@include respond-to-max($bp-xs-max) {
margin-top: -8px;
margin-bottom: -6px;
}

.legend-grid {
display: grid;
}

.legend-title {
Expand All @@ -243,8 +245,6 @@

.legend-color,
.legend-label {
float: left;
width: 19.75%;
text-align: center;
}
.legend-label {
Expand All @@ -254,8 +254,7 @@
.legend-color {
height: 15px;
border: 1px solid var(--gray-60);
width: 19.5%;
&:not(:nth-child(2)) {
&:not(:first-child) {
border-left: none;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ function updateTilemapLegend(node, data, legendTitle) {
labels[i].innerText = '\xa0';
}
}
colors.forEach((v) => legend.appendChild(v));
labels.forEach((v) => legend.appendChild(v));
const grid = document.createElement('div');
grid.className = 'legend-grid';
grid.style.gridTemplateColumns = `repeat(${classes.length}, 1fr)`;
legend.appendChild(grid);

colors.forEach((v) => grid.appendChild(v));
labels.forEach((v) => grid.appendChild(v));
legend.style.display = 'block';
}

/**
Expand Down Expand Up @@ -236,10 +242,6 @@ function init(chartNode, target, data, dataAttributes) {
const tilemapOptions = makeTilemapOptions(data, dataAttributes);
const chart = Highmaps.mapChart(target, tilemapOptions);

const legend = target.parentNode.getElementsByClassName(
'o-simple-chart__tilemap-legend',
)[0];
legend.style.display = 'block';
updateTilemapLegend(target, tilemapOptions, yAxisLabel);

/**
Expand Down

0 comments on commit ab05c98

Please sign in to comment.