Skip to content

Commit

Permalink
Merge pull request #139 from ONSvisual/Code-fixes
Browse files Browse the repository at this point in the history
Code fixes
  • Loading branch information
MikeLister authored Sep 20, 2023
2 parents bd46f8c + 4d5122c commit 3eca52c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions line-chart-with-area/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ config = {
// "lineCurveType": "curveCardinal", // Cardinal spline curve
// "lineCurveType": "curveCatmullRom" // Catmull-Rom spline curve
// "lineCurveType": "curveMonotoneX" // Monotone spline curve

"xDomain": "auto",
"yDomain": [0,7],
// either "auto" or an array for the x domain e.g. [0,2000]
"xAxisTickFormat": {
Expand All @@ -50,13 +50,13 @@ config = {
},
"margin": {
"sm": {
"top": 15,
"top": 30,
"right": 30,
"bottom": 50,
"left": 30
},
"md": {
"top": 15,
"top": 30,
"right": 100,
"bottom": 50,
"left": 30
Expand Down
10 changes: 9 additions & 1 deletion line-chart-with-area/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

let graphic = d3.select('#graphic');
//console.log(`Graphic selected: ${graphic}`);
let legend = d3.selectAll('#legend')
let pymChild = null;

function drawGraphic() {
Expand Down Expand Up @@ -34,6 +35,7 @@ function drawGraphic() {
// Remove any existing chart elements
graphic.selectAll('*').remove();
//console.log(`Removed existing chart elements`);
legend.selectAll('*').remove();

// Get categories from the keys used in the stack generator
// const categories = Object.keys(graphic_data[0]).filter((k) => k !== 'date');
Expand All @@ -56,14 +58,20 @@ function drawGraphic() {

let x;



if (xDataType == 'date') {
x = d3.scaleTime()
.domain(d3.extent(graphic_data, (d) => d.date))
.range([0, width]);
} else {
} else if (config.essential.xDomain == "auto"){
x = d3.scaleLinear()
.domain(d3.extent(graphic_data, (d) => +d.date))
.range([0, width]);
} else {
x = d3.scaleLinear()
.domain(config.essential.xDomain)
.range([0, width]);
}
//console.log(`x defined`);

Expand Down
2 changes: 1 addition & 1 deletion scatter-plot/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ config={
"accessibleSummary":"Here is the screenreader text describing the chart.",
"xDomain":"auto",
"yDomain":"auto",
// either "auto" or an array for the x domain e.g. [0,100]
// either "auto" or an array for the x/y domain e.g. [0,100]
"xAxisLabel":"x axis label",
"yAxisLabel":"y axis label",
"xAxisFormat":".0%",
Expand Down
4 changes: 2 additions & 2 deletions scatter-plot/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ legenditem
}


if(config.essential.xDomain=="auto"){
if(config.essential.yDomain=="auto"){
y.domain([0, d3.max(graphic_data,function(d){return d.yvalue})]);
}else{
y.domain(config.essential.xDomain)
y.domain(config.essential.yDomain)
}

svg
Expand Down

0 comments on commit 3eca52c

Please sign in to comment.