@@ -60,7 +60,7 @@ import {ApiHistogram} from "./components/apiHistogram.js";
60
60
61
61
``` js
62
62
const incomeHistogram = FileAttachment (" data/income-histogram.parquet" ).parquet ();
63
- const histogramCanvas = document .createElement (" canvas" );
63
+ const incomeCanvas = document .createElement (" canvas" );
64
64
```
65
65
66
66
``` js
@@ -70,17 +70,30 @@ const sectorColor = Object.assign(Plot.scale({color: {domain: sectorColorMapping
70
70
const sectorSwatch = (sector ) => html ` <span style =" white-space : nowrap ;" ><svg width =10 height =10 fill =${sectorColor.apply(sector)} ><rect width =10 height =10 ></rect ></svg > <span class =" small" >${ sector} </span ></span >` ;
71
71
```
72
72
73
+ ``` js
74
+ // Import the rent histogram data from the parquet file
75
+ const rentHistogram = FileAttachment (" data/rent-histogram.parquet" ).parquet ();
76
+ const rentCanvas = document .createElement (" canvas" );
77
+ ```
78
+
79
+ ``` js
80
+ // Create the color mapping for regions
81
+ const regionColorMapping = d3 .sort (d3 .rollups (rentHistogram .getChild (" region" ), (D ) => D .length , (d ) => d).filter (([d ]) => d), ([, d ]) => - d).map (([region , count ]) => ({ region, count }));
82
+ const regionColor = Object .assign (Plot .scale ({ color: { domain: regionColorMapping .map ((d ) => d .region ) } }), {label: " region" });
83
+ const regionSwatch = (region ) => html ` <span style =" white-space : nowrap ;" ><svg width =10 height =10 fill =${regionColor.apply(region)} ><rect width =10 height =10 ></rect ></svg ><span class =" small" >${ region} </span ></span >` ;
84
+ ```
73
85
74
- <!-- <div class="grid grid-cols-2" style="grid-auto-rows: 504px;"> -->
86
+
87
+ <div class =" grid grid-cols-2 " style =" grid-auto-rows : 504px ;" >
88
+ <div class =" card " >
89
+ <h2>Income distribution by sector (<a href="https://github.com/jaanli/exploring_american_community_survey_data/blob/main/american_community_survey/models/public_use_microdata_sample/income-histogram-with-sector.sql">code</a> for data transform)</h2>
90
+ ${resize((width) => ApiHistogram(incomeHistogram.getChild("income"), incomeHistogram.getChild("count"), incomeHistogram.getChild("sector"), {canvas: incomeCanvas, color: sectorColor, width, label: "Income ($)", y1: 1_000, y2: 200_000}))}
91
+ </div >
75
92
<div class =" card " >
76
- <h2>Income distribution by sector </h2>
77
- ${resize((width) => ApiHistogram(incomeHistogram .getChild("income "), incomeHistogram .getChild("count"), incomeHistogram .getChild("sector "), {canvas: histogramCanvas , color: sectorColor , width, label: "Income ($)", y1: 1_000 , y2: 200_000 }))}
93
+ <h2>Rent Distribution by Region (<a href="https://github.com/jaanli/exploring_american_community_survey_data/blob/main/american_community_survey/models/public_use_microdata_sample/household-histogram-with-region.sql">code</a> for data transform) </h2>
94
+ ${resize((width) => ApiHistogram(rentHistogram .getChild("rent "), rentHistogram .getChild("count"), rentHistogram .getChild("region "), {canvas: rentCanvas , color: regionColor , width, label: "Rent ($)", y1: 100 , y2: 20_000 }))}
78
95
</div >
79
- <!-- <div class="card">
80
- <h2>Response latency histogram</h2>
81
- ${resize((width) => ApiHistogram(latencyHistogram.getChild("duration"), latencyHistogram.getChild("count"), latencyHistogram.getChild("route"), {canvas: histogramCanvas_new, color: routeColor, width, label: "Duration (ms)", y1: 0.5, y2: 10_000}))}
82
- </div> -->
83
- <!-- </div> -->
96
+ </div >
84
97
85
98
---
86
99
<!--
0 commit comments