Published
Edited
Nov 23, 2020
Insert cell
md`# 9 занятие`
Insert cell
md`# Осадки в России`
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell
import {city_humidity} from "@glebtr/lesson-9"
Insert cell
Insert cell
md`# Zoo`
Insert cell
zoo = { return await FileAttachment("zoo.csv").csv()}
Insert cell
animals = {
const selection1 =
vl.selectSingle()
.on("mouseover")
.empty('none')
.nearest(false)
;
let bars = vl.markBar()
.data(zoo)
.select(selection1)
.width(500)
.transform({fold: ["hair", "eggs", "feathers", "airborne", "aquatic", "predator", "toothed", "backbone", "milk"] , as: ["name" , "value"]})
.encode(
vl.color().value("#8D230F").if(selection1 , {value: "#1E434C"}),
vl.x().fieldN("name").axis({"labelAngle" : 0}).title(false),
vl.y().sum("value").title("Количество зверей").axis({"format" : "f"}),
vl.tooltip().sum("value")
)

return vl.vconcat(bars)
.render()

}
Insert cell
md`# Maps`
Insert cell
import {russia} from "@glebtr/lesson-9"
Insert cell
rmap = {
const selection =
vl.selectSingle()
.on("mouseover")
.empty("all")
.nearest(true)

const ru_map = vl.markGeoshape()
.width(600)
.height(400)
.data(russia.features)
.encode(
vl.color().value("#dbdcdd")
)

const cities = vl.markCircle()
.data(city_humidity)
.select(selection)
.encode(
vl.size().fieldQ("osadki_mm").title("Осадки, мм"),
vl.tooltip().fieldN("city"),
vl.longitude().fieldQ("Longitude"),
vl.latitude().fieldQ("Latitude"),
vl.color().value("gray").if(selection , {value: "#1c51bc"})
)

return vl.layer(ru_map , cities)
.view({stroke: "transparent"})
.project(
vl.projection("Albers")
.parallels([52,64])
.rotate([-105 , 0 ])
.center([-10,65])
).render()


}
Insert cell
import {capitals} from "@glebtr/lesson-9"
Insert cell
map ={
const selection4 =
vl.selectSingle()
.on("mouseover")
.empty("all")
.nearest(false)

const big_map = vl.markGeoshape()
.width(800)
.height(600)
.data(vl.topojson(world).feature('land'))
.select(selection4)
.encode(
vl.color().value("#c5dddd")
)
const centers = vl.markCircle()
.data(capitals)
.encode(
vl.size().fieldQ("pop_max").title("Население"),
vl.longitude().fieldQ("longitude"),
vl.latitude().fieldQ("latitude"),
vl.tooltip().fieldN("name-rus"),
vl.color().value("#1E434C").if(selection4, {value: "#8D230F"}),
)
return vl.layer(big_map , centers)
.view({stroke: "transparent"})
.project(
vl.projection("Mercator")
).render()
}
Insert cell
md`# Столицы мира`
Insert cell
world_capitals = {
const selection5 =
vl.selectSingle()
.on("mouseover")
.empty('none')
.nearest(false)
;
let capital = vl.markBar ()
.title("Столицы")
.data(capitals)
.select(selection5)
.transform(
{filter: "datum.pop_max>800"}
)
.encode(
vl.x().fieldQ("pop_max"),
vl.y().fieldN("name-rus").sort("-x"),
vl.tooltip().fieldQ("pop_max"),
vl.color().value("#008080").if(selection5 , {value: "#00FFFF"})
)


return vl.vconcat(capital)
.render()

}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more