-
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.
- Create a macro that could be repurposed by the design system - Tidy up and refactor all the JavaScript - Don't include the annotations in the chart config from the back-end, and instead build this in the JavaScript to create the arrows - Fix missing annotations JS
- Loading branch information
Showing
9 changed files
with
315 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{% macro onsChart(params) %} | ||
<div data-highcharts-base-chart data-highcharts-type="{{ params.chartType }}" data-highcharts-theme="{{ params.theme }}" data-highcharts-title="{{ params.title }}"> | ||
<figure class="highcharts-figure" id="{{ params.domId }}"> | ||
<h2>{{ params.title }}</h2> | ||
<h3>{{ params.subtitle }}</h3> | ||
<div data-highcharts-chart data-highcharts-id="{{ params.uuid }}"></div> | ||
{% if params.caption %} | ||
<figcaption>{{ params.caption }}</figcaption> | ||
{% endif %} | ||
</figure> | ||
|
||
<!-- Set scripts to pass the config and annotations values as json to the javascript --> | ||
{% set config_scriptid = ["config--", params.uuid] | join %} | ||
{{ params.config|json_script(config_scriptid) }} | ||
|
||
{% if params.annotations_values %} | ||
{% set annotations_values_scriptid = ["annotations-values--", params.uuid] | join %} | ||
{{ params.annotations_values|json_script(annotations_values_scriptid) }} | ||
{% endif %} | ||
|
||
{% if params.download_title and (params.download_image or params.download_csv or params.download_excel) %} | ||
{% if params.download_title %}<h3>{{ params.download_title }}</h3>{% endif %} | ||
<ol> | ||
{% if params.download_excel %} | ||
<li><a href="{{ params.download_excel }}">Excel spreadsheet (XLSX format{% if params.download_excel_size %}, {{ params.download_excel_size }}{% endif %})</a></li> | ||
{% endif %} | ||
{% if params.download_csv %} | ||
<li><a href="{{ params.download_csv }}">Simple text file (CSV format{% if params.download_csv_size %}, {{ params.download_csv_size }}{% endif %})</a></li> | ||
{% endif %} | ||
{% if params.download_image %} | ||
<li><a href="{{ params.download_image }}">Image (PNG format{% if params.download_image_size %}, {{ params.download_image_size }}{% endif %})</a></li> | ||
{% endif %} | ||
</ol> | ||
{% endif %} | ||
</div> | ||
{% endmacro %} |
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,15 +1,27 @@ | ||
<div data-highcharts-base-chart data-highcharts-type="{{ object.highcharts_chart_type }}" data-highcharts-theme="{{ object.theme }}" data-highcharts-title="{{ object.title }}"> | ||
{% if not media_already_loaded and object.media %} | ||
{{ object.media }} | ||
{% endif %} | ||
<figure class="highcharts-figure" id="chart-figure--{{ object.uuid }}"> | ||
<h2>{{ object.title }}</h2> | ||
<h3>{{ object.subtitle }}</h3> | ||
<div data-highcharts-chart data-highcharts-id="{{ object.uuid }}"></div> | ||
{% if object.caption %} | ||
<figcaption>{{ object.caption|richtext }}</figcaption> | ||
{% endif %} | ||
</figure> | ||
{% set scriptid = ["config--", object.uuid] | join %} | ||
{{ config|json_script(scriptid) }} | ||
</div> | ||
{% from "templates/datavis/_macro.njk" import onsChart %} | ||
|
||
{% if not media_already_loaded and object.media %} | ||
{{ object.media }} | ||
{% endif %} | ||
|
||
{# fmt:off #} | ||
{{ | ||
onsChart({ | ||
"chartType": object.highcharts_chart_type, | ||
"theme": object.theme, | ||
"title": object.title, | ||
"subtitle": object.subtitle, | ||
"uuid": object.uuid, | ||
"caption": object.caption|richtext, | ||
"config": config, | ||
"annotations_values": annotations_values, | ||
"download_title": "Figure 1 data", | ||
"download_image": "xyz", | ||
"download_image_size": "18KB", | ||
"download_csv": "xyz", | ||
"download_csv_size": "25KB", | ||
"download_excel": "xyz", | ||
"download_excel_size": "25KB", | ||
}) | ||
}} | ||
{# fmt:on #} |
37 changes: 37 additions & 0 deletions
37
cms/static_src/javascript/components/bar-chart-plot-options.js
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import ChartConstants from './chart-constants'; | ||
|
||
class BarChartPlotOptions { | ||
static plotOptions() { | ||
return this.plotOptions; | ||
} | ||
|
||
constructor() { | ||
const constants = ChartConstants.constants(); | ||
this.plotOptions = { | ||
bar: { | ||
// Set the width of the bars to be 30px and the spacing between them to be 10px | ||
pointWidth: 30, // Fixed bar height | ||
groupPadding: 0, // No padding between groups | ||
pointPadding: 0, // No padding within groups | ||
borderWidth: 0, | ||
borderRadius: 0, | ||
spacing: [10, 0, 0, 0], // [top, right, bottom, left] spacing between bars | ||
// Set the data labels to be enabled and positioned outside the bars | ||
// We can add custom formatting on each chart to move the labels inside the bars if the bar is wide enough | ||
dataLabels: { | ||
enabled: true, | ||
inside: false, | ||
style: { | ||
textOutline: 'none', | ||
// there is no semibold font weight available in the design system fonts, so we use 400 instead | ||
fontWeight: '400', | ||
color: constants.labelColor, | ||
fontSize: constants.mobileFontSize, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
export default BarChartPlotOptions; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class ChartConstants { | ||
static constants() { | ||
const constants = { | ||
primaryTheme: [ | ||
'#206095', | ||
'#27a0cc', | ||
'#003c57', | ||
'#118c7b', | ||
'#a8bd3a', | ||
'#871a5b', | ||
'#f66068', | ||
'#746cb1', | ||
'#22d0b6', | ||
], | ||
// Alternate theme colours from https://service-manual.ons.gov.uk/data-visualisation/colours/using-colours-in-charts | ||
alternateTheme: ['#206095', '#27A0CC', '#871A5B', '#A8BD3A', '#F66068'], | ||
labelColor: '#414042', | ||
axisLabelColor: '#707071', | ||
gridLineColor: '#d9d9d9', | ||
zeroLineColor: '#b3b3b3', | ||
// Responsive font sizes | ||
mobileFontSize: '0.875rem', | ||
desktopFontSize: '1rem', | ||
}; | ||
|
||
return constants; | ||
} | ||
} | ||
|
||
export default ChartConstants; |
17 changes: 17 additions & 0 deletions
17
cms/static_src/javascript/components/column-chart-plot-options.js
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class ColumnChartPlotOptions { | ||
static plotOptions() { | ||
return this.plotOptions; | ||
} | ||
|
||
constructor() { | ||
this.plotOptions = { | ||
column: { | ||
groupPadding: 0.2, | ||
borderWidth: 0, | ||
borderRadius: 0, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
export default ColumnChartPlotOptions; |
Oops, something went wrong.