Published
Edited
Jun 16, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mapCancer = {
const m = new Map();
// map.set(key, value) – stores the value by the key.

let i = 0;
for (const obj of datCancerF) {
i++;
m.set(obj.SA2_code, obj);
// if (i < 10) console.log(i, obj, obj.SA2_code, dataMap.get(obj.SA2_code));
}
return m;
}
Insert cell
Insert cell
Insert cell
exampleDataItem = mapCancer.get("11001")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
datCensus2016 = FileAttachment("2016Census_G01_AUS_SA2.csv").csv()
Insert cell
Insert cell
datCensus2011 = FileAttachment("2011Census_B01_AUST_SA2_short.csv").csv()
Insert cell
Insert cell
Insert cell
// Create census map with new 5-code id:
mapCensus = {
const m = new Map(); // <-- m.set(key, value) – stores the value by the key.

for (const obj of datCensus2011) {
const id = toID(obj.region_id);
m.set(id, obj);
}
return m;
}
Insert cell
// -- returns 5 number census ID from 9 number: clunky & unreliable!
function toID(s) {
return s.slice(0, 1) + s.slice(5, 9);
}
Insert cell
TEST = toID("101011001")
Insert cell
Insert cell
Insert cell
TEST_geoData = geoData.features
Insert cell
TEST_geoDataP = geoData.features[0].properties
Insert cell
TEST_features = geoData.features[0].properties.SA2_5DIG16
Insert cell
TEST_coordinates = geoData.features[0].geometry.coordinates
Insert cell
TEST_area = d3.polygonArea(...TEST_coordinates)
// const pCent = d3.polygonCentroid(poly)
// const pArea = d3.polygonArea(poly);
Insert cell
Insert cell
// -- geoData Map!
// Create geoData map with new 5-code id:
geoMap = {
const m = new Map(); // m.set(key, value) – stores the value by the key.

const max = 10;
let i = 0;
for (const obj of geoData.features) {
// console.log("o:", obj);
// console.log("o.p:", obj.properties);
// console.log("o.p:", obj);
const id5 = obj.properties.SA2_5DIG16;
if (obj.geometry !== null) {
const poly = obj.geometry.coordinates[0];
const area = d3.polygonArea(poly);
const cent = d3.polygonCentroid(poly);
// -- throw some output for checking -->
if (i < 10) {
console.log("o.p.id5:", id5, area, cent); // <-- works!
}
obj.id5 = id5;
obj.area = area;
obj.cent = cent;
}
m.set(id5, obj);
i++;
// if (i > 10) return;
}
return m;
}
Insert cell
areaMax = [...geoMap.entries()].reduce((max, e) => {
console.log("e1:", e[1], "max:", max);
if (e[1] === undefined || e[1].area === undefined) {
return max;
} else {
return e[1].area > max ? e[1].area : max;
}
}, -9999)
Insert cell
[...geoMap.entries()]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
TEST_d3area = {
const poly = [
[148.55128637200673, -36.10400631381554],
[148.55495737756803, -36.145674384801225],
[148.62225914619205, -36.165440008217516],
[148.62531831749314, -36.10293790173898],
[148.69935026297952, -36.07676180586336],
[148.69262008611713, -36.12270352515527],
[148.73238931303132, -36.131785027805996],
[148.78745439645095, -36.1974923705142],
[148.80703309277794, -36.17719254105963]
];

const pArea = d3.polygonArea(poly);
return pArea;
}
Insert cell
Insert cell
Insert cell
getCol()
Insert cell
k = () => `rgb(255, 128, 64)`
Insert cell
z = k()
Insert cell
Insert cell
Insert cell
dE = d3.extent([0, 32, 33, 34, 56, 100])
Insert cell
Insert cell
dSLin = {
// let dS = d3.scaleLinear([32, 36]);
let dS = d3.scaleLinear(dE);
console.log("dSLin:", dS);
return dS;
}
Insert cell
Insert cell
dSLin(0.975)
Insert cell
Insert cell
dSSeq = {
// let dS = d3.scaleLinear([32, 36]);
let dS = d3.scaleSequential(dE);
console.log("dSSeq:", dS);
return dS;
}
Insert cell
dSSeq(0.975)
Insert cell
Insert cell
cB = d3.scaleSequential().domain(dE).interpolator(d3.interpolatePuRd)
Insert cell
aColour = cB(0.5)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { gaussian } from "@jsndyks/useful-functions-basic"
Insert cell
import { makeRandomGenerator } from "@forresto/random-seed"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more