|
1 | 1 | <script> |
| 2 | + import { extent, groups, rollup } from 'd3-array'; |
2 | 3 | import data from './_data/endpoint-changes.csv'; |
3 | 4 |
|
4 | 5 | data.forEach((d) => { |
|
7 | 8 |
|
8 | 9 | data.sort((b, a) => a.change_date - b.change_date); |
9 | 10 |
|
| 11 | + const changes = rollup(data, (D) => D.length, (d) => d.change); |
| 12 | +
|
| 13 | + const changes_added = changes.get("Added"); |
| 14 | + const changes_removed = (changes.get("Removed") === undefined) ? 0:changes.get("Removed"); |
| 15 | +
|
10 | 16 | function format_date(myDate) { |
11 | 17 | let formatted = new Intl.DateTimeFormat('en-US', { |
12 | 18 | year: 'numeric', |
|
23 | 29 | //let { data } = $props(); |
24 | 30 | </script> |
25 | 31 |
|
26 | | -<!-- Show or hide dataset descriptions (often lengthy) in table --> |
27 | | -<div class="button-group"> |
28 | | - <button |
29 | | - class="table-button" |
30 | | - type="button" |
31 | | - onclick={() => { |
32 | | - expanded_desc = !expanded_desc; |
33 | | - }} |
34 | | - > |
35 | | - {#if expanded_desc} |
36 | | - − Hide descriptions |
37 | | - {:else} |
38 | | - + Show descriptions |
39 | | - {/if}</button |
40 | | - > |
41 | | - <!--div class="checkbox"> |
42 | | - <div class="toggle-label-text">Show dataset descriptions</div> |
43 | | - <div class="toggle-holder"> |
44 | | - <input |
45 | | - class="toggle-input" |
46 | | - id="descriptions-toggle" |
47 | | - type="checkbox" |
48 | | - role="switch" |
49 | | - name="descriptions-toggle" |
50 | | - bind:checked={expanded_desc} |
51 | | - /> |
52 | | - <label class="toggle-label" for="descriptions-toggle"> Toggle </label> |
53 | | - </div> |
54 | | - </div--> |
55 | | -</div> |
56 | | - |
57 | | -<table id="tb" {expanded_desc} {all_rows}> |
58 | | - <thead> |
59 | | - <tr class="border-bottom"> |
60 | | - <th class="col-change" scope="col">Change</th> |
61 | | - <th class="col-endpoint" scope="col">Endpoint</th> |
62 | | - <th class="col-type" scope="col">Type</th> |
63 | | - </tr> |
64 | | - </thead> |
65 | | - <tbody> |
66 | | - {#each data as d} |
67 | | - <tr> |
68 | | - <td class={d.change + ' change info'}>{d.change} {format_date(d.change_date)}</td> |
69 | | - <td class="endpoint info" |
70 | | - ><a href={d.url.replace('http://', 'https://') + '.html'} target="_blank" |
71 | | - >{d.url.replace('http://api.census.gov/data/', '')}</a |
72 | | - ></td |
73 | | - > |
74 | | - <td class="type info">{d.type}</td> |
75 | | - </tr> |
76 | | - <tr class="border-bottom"> |
77 | | - <td colspan="3" |
78 | | - ><div class="title">{d.title}</div> |
79 | | - <p class="description">{d.description}</p></td |
80 | | - > |
81 | | - </tr> |
82 | | - {/each} |
83 | | - </tbody> |
84 | | -</table> |
| 32 | +<p>{changes_added} dataset endpoints have been added and {changes_removed} removed since July 2025.</p> |
85 | 33 |
|
86 | | -<!-- Make toggle buttons for showing all/fewer rows IF there are many rows --> |
87 | | -{#if data.length > 8} |
| 34 | +<div class="chart"> |
| 35 | + <h2 class="chart-title"> |
| 36 | + {#if (changes_removed === undefined | changes_removed === 0)} |
| 37 | + Recently added datasets |
| 38 | + {:else} |
| 39 | + Recently added and removed datasets |
| 40 | + {/if} |
| 41 | + </h2> |
| 42 | + <!-- Show or hide dataset descriptions (often lengthy) in table --> |
88 | 43 | <div class="button-group"> |
89 | 44 | <button |
90 | 45 | class="table-button" |
91 | 46 | type="button" |
92 | 47 | onclick={() => { |
93 | | - all_rows = !all_rows; |
| 48 | + expanded_desc = !expanded_desc; |
94 | 49 | }} |
95 | 50 | > |
96 | | - {#if all_rows} |
97 | | - − Show fewer rows |
| 51 | + {#if expanded_desc} |
| 52 | + − Hide descriptions |
98 | 53 | {:else} |
99 | | - + Show all {data.length} rows |
| 54 | + + Show descriptions |
100 | 55 | {/if}</button |
101 | 56 | > |
102 | | - |
103 | 57 | <!--div class="checkbox"> |
104 | | - <div class="toggle-label-text">Show all {data.length} rows</div> |
| 58 | + <div class="toggle-label-text">Show dataset descriptions</div> |
105 | 59 | <div class="toggle-holder"> |
106 | 60 | <input |
107 | 61 | class="toggle-input" |
108 | | - id="rows-toggle" |
| 62 | + id="descriptions-toggle" |
109 | 63 | type="checkbox" |
110 | 64 | role="switch" |
111 | | - name="rows-toggle" |
112 | | - bind:checked={all_rows} |
| 65 | + name="descriptions-toggle" |
| 66 | + bind:checked={expanded_desc} |
113 | 67 | /> |
114 | | - <label class="toggle-label" for="rows-toggle"> Toggle </label> |
| 68 | + <label class="toggle-label" for="descriptions-toggle"> Toggle </label> |
115 | 69 | </div> |
116 | 70 | </div--> |
117 | 71 | </div> |
118 | | -{/if} |
| 72 | + |
| 73 | + <table id="tb" {expanded_desc} {all_rows}> |
| 74 | + <thead> |
| 75 | + <tr class="border-bottom"> |
| 76 | + <th class="col-change" scope="col">Change</th> |
| 77 | + <th class="col-endpoint" scope="col">Endpoint</th> |
| 78 | + <th class="col-type" scope="col">Type</th> |
| 79 | + </tr> |
| 80 | + </thead> |
| 81 | + <tbody> |
| 82 | + {#each data as d} |
| 83 | + <tr> |
| 84 | + <td class={d.change + ' change info'}>{d.change} {format_date(d.change_date)}</td> |
| 85 | + <td class="endpoint info" |
| 86 | + ><a href={d.url.replace('http://', 'https://') + '.html'} target="_blank" |
| 87 | + >{d.url.replace('http://api.census.gov/data/', '')}</a |
| 88 | + ></td |
| 89 | + > |
| 90 | + <td class="type info">{d.type}</td> |
| 91 | + </tr> |
| 92 | + <tr class="border-bottom"> |
| 93 | + <td colspan="3" |
| 94 | + ><div class="title">{d.title}</div> |
| 95 | + <p class="description">{d.description}</p></td |
| 96 | + > |
| 97 | + </tr> |
| 98 | + {/each} |
| 99 | + </tbody> |
| 100 | + </table> |
| 101 | + |
| 102 | + <!-- Make toggle buttons for showing all/fewer rows IF there are many rows --> |
| 103 | + {#if data.length > 8} |
| 104 | + <div class="button-group"> |
| 105 | + <button |
| 106 | + class="table-button" |
| 107 | + type="button" |
| 108 | + onclick={() => { |
| 109 | + all_rows = !all_rows; |
| 110 | + }} |
| 111 | + > |
| 112 | + {#if all_rows} |
| 113 | + − Show fewer rows |
| 114 | + {:else} |
| 115 | + + Show all {data.length} rows |
| 116 | + {/if}</button |
| 117 | + > |
| 118 | + |
| 119 | + <!--div class="checkbox"> |
| 120 | + <div class="toggle-label-text">Show all {data.length} rows</div> |
| 121 | + <div class="toggle-holder"> |
| 122 | + <input |
| 123 | + class="toggle-input" |
| 124 | + id="rows-toggle" |
| 125 | + type="checkbox" |
| 126 | + role="switch" |
| 127 | + name="rows-toggle" |
| 128 | + bind:checked={all_rows} |
| 129 | + /> |
| 130 | + <label class="toggle-label" for="rows-toggle"> Toggle </label> |
| 131 | + </div> |
| 132 | + </div--> |
| 133 | + </div> |
| 134 | + {/if} |
| 135 | + |
| 136 | + <p class="chart-note"> |
| 137 | + Note: Dataset titles and descriptions were written by the Census Bureau. |
| 138 | + </p> |
| 139 | +</div> |
119 | 140 |
|
120 | 141 | <style> |
121 | 142 | table { |
|
0 commit comments