Published
Edited
Mar 31, 2022
2 forks
4 stars
Insert cell
Insert cell
record_urls
Insert cell
Insert cell
function get_linked_art(urls) {
const data = Promise.all(
urls.map(async (url) => {
return await (await fetch(url)).json()})
)
return data;
}
Insert cell
Insert cell
linked_art = get_linked_art(record_urls)
Insert cell
Insert cell
lajs = import("https://cdn.skypack.dev/@thegetty/linkedart.js");
Insert cell
Insert cell
art_data = linked_art.map(l => {
return {"title": lajs.getPrimaryName(l),
"artist": lajs.getFieldValuesByClassifications(l.produced_by, "referred_to_by","https://data.getty.edu/museum/ontology/linked-data/tms/object/producer-description")[0],
"materials": lajs.getMaterialStatements(l)[0],
// "type": lajs.getWorkTypes(l),
"type": lajs.getValueByClassification(lajs.normalizeFieldToArray(l, 'referred_to_by'), "http://vocab.getty.edu/aat/300435443"),
"dimensions": lajs.getDimensionsDescriptions(l)[0],
"begin": lajs.getProductionTimespans(l)[0].begin_of_the_begin,
"end": lajs.getProductionTimespans(l)[0].end_of_the_end,
"image": lajs.getDigitalImages(l)[0],
"cultures": lajs.getCultures(l)[0]} })
Insert cell
Insert cell
import { aq, op } from '@uwdata/arquero'
Insert cell
Insert cell
viewof artdf = aq.from(art_data).view()
Insert cell
Insert cell
viewof artdf_clean = artdf
// Use .spread() to separate the dimension column into width and height attributes
.spread({ dimensions: d => op.split(d.dimensions, /\s×\s|\s/) }, { drop: false, limit: 2 , as: ["width", "height"]})
.derive({
width: d => op.parse_float(d.width), // Turn width into a number
height: d => op.parse_float(d.height), // Turn height into a number
begin: d => op.parse_date(d.begin), // Turn begin into a date
end: d => op.parse_date(d.end) // Turn end into a date
})
.view()
Insert cell
Insert cell
viewof group_culture = artdf_clean
.groupby("cultures") // Group data by culture
.count() // Count the number of rows with each culture
.orderby(aq.desc("count")) // Put the table in descending numerical order
.view()
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.barY(group_culture, {x: "cultures", y: "count", fill:"cultures", sort: {x: "y", reverse: true}})
]
})
Insert cell
Insert cell
viewof group_material = artdf_clean
.groupby("materials") // Group data by materials
.count() // Count the number of rows with each material
.orderby(aq.desc("count")) // Put the table in descending numerical order
.view()
Insert cell
Plot.plot({
marginBottom: 200,
x: {
tickRotate: -45,
label: null
},
marks: [
Plot.barY(group_material, {x: "materials", y: "count", fill:"materials", sort: {x: "y", reverse: true}})
]
})
Insert cell
Insert cell
viewof better_categories = artdf_clean
.spread({ dimensions: d => op.split(d.materials, /,?\s/) }, { drop: false, limit: 1 , as: ["material_cat"]})
.view()
Insert cell
Insert cell
viewof group_material_cat = better_categories.groupby("material_cat").count().orderby(aq.desc("count")).view()
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.barY(group_material_cat, {x: "material_cat", y: "count", fill:"material_cat", sort: {x: "y", reverse: true}})
]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(artdf_clean, {x: "width", y: "height", stroke:"type"})
]
})
Insert cell
Insert cell
import {boxY, boxX} from '@observablehq/plot-box'
Insert cell
Insert cell
Plot.plot({
marks: [
boxY(artdf_clean, {x: "type", y: "width"})
]
})
Insert cell
Insert cell
Plot.plot({
marks: [
boxY(artdf_clean, {x: "type", y: "height"})
]
})
Insert cell
Insert cell
viewof group_decade = artdf_clean
.groupby({decade: d => op.round(op.year(d.end)/10)}) // Convert the date into a decade, group data by decade
.rollup({avg_width: d => op.mean(d.width), avg_height: d => op.mean(d.height)}) // Create new columns for average width and height
.view()
Insert cell
Insert cell
Plot.plot({
x: { transform: d => d*10, tickFormat: '.4'}, // Make the x-axis labels look nice
marks: [
Plot.line(group_decade, {x: "decade", y: "avg_height", sort: "decade", stroke: "blue"}), // Plot a line for the height
Plot.line(group_decade, {x: "decade", y: "avg_width", sort: "decade", stroke: "red"}) // Plot a line for the width
]
})
Insert cell
Insert cell
Insert cell
Insert cell
artdf_clean.toCSV()
Insert cell
Insert cell
Insert cell
vangogh = FileAttachment("vangogh.csv").csv()
Insert cell
Insert cell
ids = vangogh.map(v => v.content.match(/\/(\d+)\//)[1])
Insert cell
Insert cell
function get_records(ids) {
const data = Promise.all(
ids.map(async (i) => {
return await (await fetch(`https://services.getty.edu/id-management/links/?body_generator=https://data.getty.edu/local/thesaurus/generators/dor&body_id=urn:getty-local:dor:object:id/${i}`)).json()})
)
return data;
}
Insert cell
records = get_records(ids)
Insert cell
Insert cell
record_urls = records.map(r => r.first.items[0].target.id)
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