override flat property

parent 80286d55
...@@ -43,6 +43,14 @@ const getData = async (indicator) => { ...@@ -43,6 +43,14 @@ const getData = async (indicator) => {
return data; return data;
} }
Object.defineProperty(Array.prototype, 'flat', {
value: function(depth = 1) {
return this.reduce(function (flat, toFlatten) {
return flat.concat((Array.isArray(toFlatten) && (depth>1)) ? toFlatten.flat(depth-1) : toFlatten);
}, []);
}
});
function makeIndicatorGraph() { function makeIndicatorGraph() {
let data = [], let data = [],
...@@ -73,7 +81,6 @@ function makeIndicatorGraph() { ...@@ -73,7 +81,6 @@ function makeIndicatorGraph() {
updateData; updateData;
function chart(selection) { function chart(selection) {
// get data ranges using values from displayName // get data ranges using values from displayName
minDate = d3.min(data[0].values, d => { minDate = d3.min(data[0].values, d => {
return d[displayName]; return d[displayName];
...@@ -162,7 +169,9 @@ function makeIndicatorGraph() { ...@@ -162,7 +169,9 @@ function makeIndicatorGraph() {
// Calculate min and max values of data to define chart y-axis domain // Calculate min and max values of data to define chart y-axis domain
//let minDomain = d3.min(data.map(d => d.values).flat().map(d => d.value)); //let minDomain = d3.min(data.map(d => d.values).flat().map(d => d.value));
//console.log("data: ", data.map(d => d.values));
let maxDomain = d3.max(data.map(d => d.values).flat().map(d => d.value)); let maxDomain = d3.max(data.map(d => d.values).flat().map(d => d.value));
yLine.domain([0, maxDomain]).nice(); yLine.domain([0, maxDomain]).nice();
//yLine.domain([0, d3.max(data[0].values, d => d.value)]).nice(); //yLine.domain([0, d3.max(data[0].values, d => d.value)]).nice();
...@@ -249,7 +258,7 @@ function makeIndicatorGraph() { ...@@ -249,7 +258,7 @@ function makeIndicatorGraph() {
return d[displayName]; return d[displayName];
}); });
maxDate = d3.timeDay.offset(maxDate, 15) // get next month to get correct x-axis alignment maxDate = d3.timeDay.offset(maxDate, 15) // get next month to get correct x-axis alignment
// update axes' domain // update axes' domain
xLine.domain([minDate, maxDate]) xLine.domain([minDate, maxDate])
//.nice() //.nice()
...@@ -568,4 +577,4 @@ function makeIndicatorGraph() { ...@@ -568,4 +577,4 @@ function makeIndicatorGraph() {
}; };
return chart; return chart;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment