Published
Edited
May 27, 2021
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
Insert cell
layers = evaluate_layers(show_datapoints, show_boxplot)
Insert cell
evaluate_layers = function(display_datapoints, display_boxplot) {
const layers = [];
if (display_datapoints == "On") {layers.push(vl.markPoint() .encode(
vl.x().fieldN("sampleName"),
vl.y().fieldQ(target),
vl.color().fieldN("sampleName"),
vl.shape().fieldN("organisation"),
vl.tooltip([
vl.fieldN("sampleName"),
{"field": target, "aggregate": "mean", "type": "quantitative"},
]),
))}
if (display_boxplot == "On") {layers.push(vl.markBoxplot() .encode(
vl.x().fieldN("sampleName"),
vl.y().fieldQ(target).scale({zero: false}),
vl.color().fieldN("sampleName"),
vl.shape().fieldN("organisation"),
vl.tooltip([
vl.fieldN("sampleName"),
vl.fieldQ(target),
]),
))}
return layers
}
Insert cell
filtered_data = full_data.filter(function(obj) {
return (obj.Weighting == weighting && obj.Distribution == distribution);
})
Insert cell
full_data = [].concat(...array_of_full_datasets)
Insert cell
array_of_full_datasets = add_metadata_to_datasets(array_of_datasets, array_of_metadata)
Insert cell
function add_metadata_to_datasets(arr_datasets, arr_metadata) {
const new_datasets = [];
for (var i = 0; i < arr_datasets.length; i++) {
const dataset = arr_datasets[i];
const dataset2 = [];
const metadata = arr_metadata[i];
for (var j = 0; j < dataset.length; j++) {
const object = dataset[j];
for (const key in metadata) {
object[key] = metadata[key]
}
dataset2.push(object);
}
new_datasets.push(dataset2);
}
return new_datasets;
}
Insert cell
array_of_metadata = Promise.all(meta_promises)
Insert cell
array_of_datasets = Promise.all(promises)
Insert cell
meta_promises = dataset_ids.map(id => {
const url = api_url + id + "/versions/latest/metadata";
return fetch_metadata(url) })
Insert cell
promises = dataset_ids.map(id => {
const url = api_url + id + "/versions/latest/data";
return fetch_dataset_to_array(url, {}) })
Insert cell
function fetch_metadata(dataset_url) {
return fetch(dataset_url).then(response_dataset => {
if (!response_dataset.ok) throw new Error(response_dataset.status);
return response_dataset.json();}
);
}
Insert cell
function fetch_dataset_to_array(dataset_url, query_options) {
return fetch(dataset_url, query_options).then(response_dataset => {
if (!response_dataset.ok) throw new Error(response_dataset.status);
return response_dataset.json();}).then(json => json.results.map(x => x.data));
}
Insert cell
dataset_ids = [
"e7afa026-f4b0-4914-96e6-f34e064c74a5",
"d858218e-dd47-4b06-9641-e3fdde6e0efb",
"c91d0b9e-d5b8-4707-8382-033b8e41841e",
"5b4f2b06-11bb-4036-b5b7-c120d87bdef0"
]
Insert cell
api_url = "https://data.acenano.douglasconnect.com/datasets/"
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell
import {Select, Range, Toggle, Table} from "@observablehq/inputs"
Insert cell
import {render_data_table, table_styles, displayImage, displayCaution} from '@info474/utilities'
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