Public
Edited
Apr 4, 2023
Insert cell
Insert cell
proportionalSymbols = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(topojson.feature(basepolygons, basepolygons.objects.states_simple))
.attr("fill", "#ccc")
.attr("d", path_basemap);
//How do you create the basemap from polygon topojson, and how do you set its symbology?
//The above code creates the polygon basemap by loading in the states_simple topojson file.
//This code also defines the fill color.

svg.append("text")
.attr("x", (width / 2))
.attr("y", 20)
.attr("text-anchor", "middle")
.style("font-size", "24px")
.text("Bike/Scooter Share Docks by City");

svg.append("text")
.attr("x", (150))
.attr("y", 475)
.attr("text-anchor", "middle")
.style("font-size", "12px")
.text("Number of Docks");
svg.append("path")
.datum(topojson.mesh(basepolygons, basepolygons.objects.states_simple, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path_basemap);
//This cell block defines the lines that divide the enumeration units on the basemap.
const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(150,450)") //position of legend
.attr("text-anchor", "middle")
.style("font", "10px sans-serif") //font size of legend
.selectAll("g")
.data([4e2, d3.max([...data.values()])]) //sets value within legend
.join("g");

//How do you create a legend? The code above creates the legend, determines its location,
//font size, and the values within the legend.
legend.append("circle")
.attr("fill", "none")
.attr("stroke", "#7f0000")
.attr("cy", d => -radius(d))
.attr("r", radius);
//How do you create and use colors on Observable? Explain how you map values to the fill colors of polygons?
//Colors can be read into Observable with a variety of color models. Here, hexcode colors generated from ColorBrewer //are read in. For the legend, the fill is defined as "none" while the outline/stroke is a reddish color.
legend.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(format);
svg.append("g")
.attr("fill", "#ef6548")
.attr("fill-opacity", 0.5)
.attr("stroke", "#7f0000")
.attr("stroke-width", 0.5)
//How do you determine the style, width and color of the outlines of the point symbol //(outlines)?
//The above code defines the look of the point symbols. The "fill color" and "stroke" color //are both defined using hexcode colors from ColorBrewer.
.selectAll("circle")
//How do you determine the type of point symbol (e.g., circle, square, etc.)? This code sets the symbol as a circle for
//the map. The shape can be changed but circles are generally accepted as the best shape to use for comparison.
.data(points.features
.map(d => (d.value = data.get(d.properties.PLACEID), d))
.sort((a, b) => b.value - a.value))
.join("circle")
.attr("transform", d => `translate(${path_points.centroid(d)})`)
.attr("r", d => radius(data.get(d.properties.PLACEID)))
.append("title")
.text(d => `${d.properties.CITY}: ${format(d.value)}`);

//How do the values get displayed when you hover over each point? The above code creates
//text that displays the city name and value when you hover over the point


//How do you join the geometries that come with the geojson file with the attributes that come with a csv file?
//In the above code, (data.get(d.properties.PLACEID)) identifies the .csv data (defined as //data in later code) and selects PLACEID to use as the join with the geojson file.
return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//proportional symbols
radius = d3.scaleSqrt([0, d3.max([...data.values()])], [0, 20])

//How do you create a scale for mapping (linking) the values of an attribute of your points to the radius of the point?
//This code creates the scale for the radius of each point value. The range of values is defined as from 0 to the maximum
//and the scale chosen is "square root." Other scale options include "scaleLog" and "scalePow." This cell is read into
//the above map code.
Insert cell
data = Object.assign(new Map(csv_data))
Insert cell
Insert cell
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