Skip to content

Commit b6f4b85

Browse files
committed
readme for chart tools
1 parent 92c584b commit b6f4b85

File tree

4 files changed

+54
-43
lines changed

4 files changed

+54
-43
lines changed

src/README.md

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -117,58 +117,70 @@ There is also a file watcher, which monitors the `content` directory and automat
117117
npm run watch
118118
```
119119
120-
## Generating chapter images
121120
122-
We can automate the generation of chapter images from the command line to save this onerous task.
121+
## Figures preparation
123122
124-
This requires the figure markup to exist in the chapter's markdown file, including the `image` and `chart_url` attributes:
123+
The following tools help automate figure positioning and metadata:
125124
126-
```py
127-
{{ figure_markup(
128-
image="pwa-timeseries-of-service-worker-installations.png",
129-
...
130-
chart_url="https://docs.google.com/spreadsheets/d/e/2PACX-1vRRpTSA4fsHwUap-ByQ08j95uo7Zm1kY6lTSvA-DZT54g2QZ0guV7db3QyQwQgMPzsKsJ43gbzqfJst/pubchart?oid=1883263914&format=interactive",
131-
...
132-
)
133-
}}
134-
```
125+
1. **Running queries and exporting to sheets**: [bq_to_sheets.ipynb](../sql/util/bq_to_sheets.ipynb) runs queries and exports the results to Google Sheets.
126+
2. **Normalization**: [chart-adjustments.ipynb](../sql/util/chart-adjustments.ipynb) normalizes chart sizes in Google Sheets to ensure consistent dimensions for image generation.
127+
3. **Figures markup generation**: [generate_figure_markup.py](../sql/util/generate_figure_markup.py) scans Google Sheets for charts and generates the corresponding `figure_markup` shortcodes with mapped SQL files and sheet IDs.
128+
4. **Generating chapter images**: We can automate the generation of chapter images from the command line to save this onerous task.
135129
136-
It can be run like below, by passing a chapter markdown (with or without the `.md` extension):
130+
This requires the figure markup to exist in the chapter's markdown file, including the `image` and `chart_url` attributes:
137131

138-
```bash
139-
npm run figure-images en/2021/pwa
140-
```
132+
```py
133+
{{ figure_markup(
134+
image="pwa-timeseries-of-service-worker-installations.png",
135+
...
136+
chart_url="https://docs.google.com/spreadsheets/d/e/2PACX-1vRRpTSA4fsHwUap-ByQ08j95uo7Zm1kY6lTSvA-DZT54g2QZ0guV7db3QyQwQgMPzsKsJ43gbzqfJst/pubchart?oid=1883263914&format=interactive",
137+
...
138+
)
139+
}}
140+
```
141141

142-
Which will then generate any missing figures based on the chapter markup, skipping images that already exist:
142+
It can be run like below, by passing a chapter markdown (with or without the `.md` extension):
143143

144-
```log
145-
> almanac.httparchive.org@0.0.1 figure-images
146-
> node ./tools/generate/generate_figure_images "en/2021/pwa"
147-
148-
Generating for chapter: pwa for year 2021
149-
Skipping: pwa-service-worker-controlled-pages-by-rank.png as image already exists
150-
Skipping: pwa-most-used-service-worker-events.png as image already exists
151-
Skipping: pwa-service-worker-and-manifest-usage.png as image already exists
152-
Skipping: pwa-top-pwa-manifest-properties.png as image already exists
153-
Skipping: pwa-top-pwa-manifest-icon-sizes.png as image already exists
154-
Skipping: pwa-manifest-display-values.png as image already exists
155-
Skipping: pwa-manifests-preferring-native-app.png as image already exists
156-
Skipping: pwa-industry-categories.png as image already exists
157-
Skipping: pwa-lighthouse-pwa-audits.png as image already exists
158-
Skipping: pwa-lighthouse-pwa-scores.png as image already exists
159-
Skipping: pwa-libraries-and-scripts.png as image already exists
160-
Skipping: pwa-top-workbox-versions.png as image already exists
161-
Skipping: pwa-top-workbox-packages.png as image already exists
162-
Generating image pwa-workbox-runtime-caching-strategies.png...
163-
Generating image pwa-notification-acceptance-rates.png...
164-
Generating image pwa-install-events.png...
165-
```
144+
```bash
145+
npm run figure-images en/2021/pwa
146+
```
147+
148+
Which will then generate any missing figures based on the chapter markup, skipping images that already exist:
149+
150+
```log
151+
> almanac.httparchive.org@0.0.1 figure-images
152+
> node ./tools/generate/generate_figure_images "en/2021/pwa"
153+
154+
Generating for chapter: pwa for year 2021
155+
Skipping: pwa-service-worker-controlled-pages-by-rank.png as image already exists
156+
Skipping: pwa-most-used-service-worker-events.png as image already exists
157+
Skipping: pwa-service-worker-and-manifest-usage.png as image already exists
158+
Skipping: pwa-top-pwa-manifest-properties.png as image already exists
159+
Skipping: pwa-top-pwa-manifest-icon-sizes.png as image already exists
160+
Skipping: pwa-manifest-display-values.png as image already exists
161+
Skipping: pwa-manifests-preferring-native-app.png as image already exists
162+
Skipping: pwa-industry-categories.png as image already exists
163+
Skipping: pwa-lighthouse-pwa-audits.png as image already exists
164+
Skipping: pwa-lighthouse-pwa-scores.png as image already exists
165+
Skipping: pwa-libraries-and-scripts.png as image already exists
166+
Skipping: pwa-top-workbox-versions.png as image already exists
167+
Skipping: pwa-top-workbox-packages.png as image already exists
168+
Generating image pwa-workbox-runtime-caching-strategies.png...
169+
Generating image pwa-notification-acceptance-rates.png...
170+
Generating image pwa-install-events.png...
171+
```
172+
173+
Authors can delete images and rerun if they want to, to regenerate images.
166174

167-
Authors can delete images and rerun if they want to, to regenerate images.
175+
Images will automatically be compressed by our Calibre GitHub Action when uploaded to GitHub, but you can get a lot more compression (about 44% more!) by running them through <https://tinypng.com> instead (at which point the Calibre Action will usually not find any further compression gains). It's quite simple to drag them up, and download them, so would encourage analysts/authors to take this step.
168176
169-
Images will automatically be compressed by our Calibre GitHub Action when uploaded to GitHub, but you can get a lot more compression (about 44% more!) by running them through <https://tinypng.com> instead (at which point the Calibre Action will usually not find any further compression gains). It's quite simple to drag them up, and download them, so would encourage analysts/authors to take this step.
177+
Running them through <https://tinypng.com> also has the added advantage of the compression being repeatable each time. So if you are not sure which images you have changed, you can delete them all, regenerate them all, run them through TinyPNG, and then a `git diff` will only show differences on the images that have changed. This will not be the case if you use the Calibre GitHub Action and it will look like all images have changed.
170178
171-
Running them through <https://tinypng.com> also has the added advantage of the compression being repeatable each time. So if you are not sure which images you have changed, you can delete them all, regenerate them all, run them through TinyPNG, and then a `git diff` will only show differences on the images that have changed. This will not be the case if you use the Calibre GitHub Action and it will look like all images have changed.
179+
1. **Automated descriptions**: [generate_figure_descriptions.js](tools/generate/generate_figure_descriptions.js) uses OCR (via Tesseract.js) to automatically populate `description=""` fields in markdown chapters based on the generated images.
180+
181+
```bash
182+
node ./tools/generate/generate_figure_descriptions en/2025/privacy
183+
```
172184
173185
## Linting files
174186

src/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"test": "node ./tools/test",
1818
"generate": "node ./tools/generate",
1919
"figure-images": "node ./tools/generate/generate_figure_images",
20-
"chart-descriptions": "node ./tools/generate/generate_chart_descriptions",
2120
"watch": "node ./tools/generate/chapter_watcher",
2221
"ebooks": "node ./tools/generate/generate_ebook_pdfs",
2322
"deploy": "./tools/scripts/deploy.sh",
File renamed without changes.

0 commit comments

Comments
 (0)