Skip to content

Commit

Permalink
Merge pull request #262 from ONSvisual/220-bar-chart-x-axis-tick-form…
Browse files Browse the repository at this point in the history
…at-should-be-set-from-the-config

All axis tick formats now read from configs
  • Loading branch information
MikeLister authored Oct 10, 2024
2 parents f118d2a + 2f87013 commit d859cc6
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions area-stacked/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config = {
"md": "%Y",
"lg": "%Y"
},
"yAxisTickFormat": ".0%",
"dateFormat": "%Y",
"xAxisLabel": "x axis label",
"yAxisLabel": "y axis label",
Expand Down
3 changes: 2 additions & 1 deletion area-stacked/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ function drawGraphic() {
svg
.append('g')
.attr('class', 'y axis numeric')
.call(d3.axisLeft(y).tickFormat(d3.format('.0%')));
.call(d3.axisLeft(y)
.tickFormat(d3.format(config.essential.yAxisTickFormat)));

//This does the x-axis label
addAxisLabel({
Expand Down
1 change: 1 addition & 0 deletions comet-clustered/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ config = {
"accessibleSummary":
"The chart canvas is hidden from screen readers. The main message is summarised by the chart title and the data behind the chart is available to download below.",
"numberFormat": ".1f",
"xAxisNumberFormat": ".0f",
"numberSuffix": "",
"xAxisLabel": "£ billion",
// "xDomain": "auto",
Expand Down
4 changes: 3 additions & 1 deletion comet-clustered/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ function drawGraphic() {
});

//set up xAxis generator
let xAxis = d3.axisBottom(x).ticks(config.optional.xAxisTicks[size]);
let xAxis = d3.axisBottom(x)
.ticks(config.optional.xAxisTicks[size])
.tickFormat(d3.format(config.essential.xAxisNumberFormat));

let divs = graphic.selectAll('div.categoryLabels').data(groups).join('div');

Expand Down
1 change: 1 addition & 0 deletions comet-plot/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config = {
"accessibleSummary":
"Here is the screenreader text describing the chart.",
"numberFormat": ".0f",
"xAxisNumberFormat": ".0f",
"xAxisLabel": "x axis label",
"xDomain": [0, 100],
// either auto or a custom domain as an array e.g [0,100]
Expand Down
4 changes: 3 additions & 1 deletion comet-plot/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ function drawGraphic() {
});

//set up xAxis generator
let xAxis = d3.axisBottom(x).ticks(config.optional.xAxisTicks[size]);
let xAxis = d3.axisBottom(x)
.ticks(config.optional.xAxisTicks[size])
.tickFormat(d3.format(config.essential.xAxisNumberFormat));

divs = graphic.selectAll('div.categoryLabels').data(groups).join('div');

Expand Down
Binary file removed dot-plot-with-ci-sm/fallback.png
Binary file not shown.
3 changes: 2 additions & 1 deletion dot-plot/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ config = {
"colour_palette": ["#A09FA0", "#206095"],
"sourceText": "Office for National Statistics",
"accessibleSummary":
"CHere is the screenreader text describing the chart.",
"Here is the screenreader text describing the chart.",
"xAxisNumberFormat": ".0f",
"xAxisLabel": "x axis label",
"xDomain": "auto"
// either auto or a custom domain as an array e.g [0,100]
Expand Down
3 changes: 2 additions & 1 deletion dot-plot/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function drawGraphic() {
let xAxis = d3
.axisBottom(x)
.tickSize(-height)
.ticks(config.optional.xAxisTicks[size]);
.ticks(config.optional.xAxisTicks[size])
.tickFormat(d3.format(config.essential.xAxisNumberFormat));

// Set up the legend
let legenditem = d3
Expand Down
1 change: 1 addition & 0 deletions population-pyramid-static-with-comparison/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ config = {
// this is the lighter palette for reference lines ["#9A86E9", "#3fb0b3"]
"comparison_colour_palette": ["#5c5185", "#306970"],
"legend": ["Area name", "England and Wales"],
"xAxisNumberFormat": ".1%",
"xAxisLabel": "Percentage",
"yAxisLabel": "Age"
},
Expand Down
4 changes: 2 additions & 2 deletions population-pyramid-static-with-comparison/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xLeft)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand All @@ -157,7 +157,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xRight)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand Down
1 change: 1 addition & 0 deletions population-pyramid-static/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ config = {
"colour_palette": ["#6749A6", "#2EA1A4"],
// this is the darker palette when there are no comparison lines ["#6749A6","#2EA1A4"]
"legend": ["Variable name"],
"xAxisNumberFormat": ".1%",
"xAxisLabel": "Percentage",
"yAxisLabel": "Age"
},
Expand Down
4 changes: 2 additions & 2 deletions population-pyramid-static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xLeft)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand All @@ -119,7 +119,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xRight)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand Down
1 change: 1 addition & 0 deletions population-pyramid-with-comparison-toggle/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ config = {
// this is the lighter palette for reference lines ["#9A86E9", "#3fb0b3"]
"comparison_colour_palette": ["#5c5185", "#306970"],
"legend": ["Area name", "Selected comparison"],
"xAxisNumberFormat": ".1%",
"xAxisLabel": "Percentage",
"yAxisLabel": "Age"
},
Expand Down
4 changes: 2 additions & 2 deletions population-pyramid-with-comparison-toggle/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xLeft)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand All @@ -243,7 +243,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xRight)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ config = {
// this is the lighter palette for reference lines ["#9A86E9", "#3fb0b3"]
"comparison_colour_palette": ["#5c5185", "#306970"],
"legend": ["Selected area", "2011"],
"xAxisNumberFormat": ".1%",
"xAxisLabel": "Percentage",
"yAxisLabel": "Age"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xLeft)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand All @@ -283,7 +283,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xRight)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand Down
1 change: 1 addition & 0 deletions population-pyramid-with-dropdown/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ config = {
// this is the lighter palette for reference lines ["#9A86E9", "#3fb0b3"]
"comparison_colour_palette": ["#5c5185", "#306970"],
"legend": ["Selected area", "England and Wales"],
"xAxisNumberFormat": ".1%",
"xAxisLabel": "Percentage",
"yAxisLabel": "Age"
},
Expand Down
4 changes: 2 additions & 2 deletions population-pyramid-with-dropdown/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xLeft)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand All @@ -242,7 +242,7 @@ function drawGraphic() {
.call(
d3
.axisBottom(xRight)
.tickFormat(d3.format('.1%'))
.tickFormat(d3.format(config.essential.xAxisNumberFormat))
.ticks(config.optional.xAxisTicks[size])
.tickSize(-height)
)
Expand Down
2 changes: 1 addition & 1 deletion range-plot/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function drawGraphic() {
//set up xAxis generator
let xAxis = d3.axisBottom(x)
.ticks(config.optional.xAxisTicks[size])
.tickFormat(d => d3.format(config.essential.xAxisTickFormat)(d));
.tickFormat(d3.format(config.essential.xAxisTickFormat));

divs = graphic.selectAll('div.categoryLabels').data(groups).join('div');

Expand Down

0 comments on commit d859cc6

Please sign in to comment.