Skip to content

Commit

Permalink
Merge pull request #4464 from owid/remove-grapher-exports
Browse files Browse the repository at this point in the history
🔨 Switch grapher exports to use CF worker
  • Loading branch information
ikesau authored Jan 24, 2025
2 parents ec1d3e9 + aa21f55 commit 6063099
Show file tree
Hide file tree
Showing 44 changed files with 332 additions and 720 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

The monorepo we use at [Our World in Data](https://ourworldindata.org) to create and publish embeddable, interactive visualizations like this one:

[![A Grapher chart showing world-wide life expectancy at birth. Click for interactive.](https://ourworldindata.org/grapher/exports/life-expectancy.svg)](https://ourworldindata.org/grapher/life-expectancy)
[![A Grapher chart showing world-wide life expectancy at birth. Click for interactive.](https://ourworldindata.org/grapher/life-expectancy.svg)](https://ourworldindata.org/grapher/life-expectancy)

## ✋ Disclaimer

Expand Down
14 changes: 11 additions & 3 deletions adminSiteClient/ChartRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Timeago } from "./Forms.js"
import { EditableTags } from "./EditableTags.js"
import { AdminAppContext, AdminAppContextType } from "./AdminAppContext.js"
import {
BAKED_GRAPHER_EXPORTS_BASE_URL,
BAKED_GRAPHER_URL,
GRAPHER_DYNAMIC_THUMBNAIL_URL,
} from "../settings/clientSettings.js"
import { ChartListItem, showChartType } from "./ChartList.js"
import { TaggableType, DbChartTagJoin } from "@ourworldindata/utils"
Expand Down Expand Up @@ -48,11 +48,19 @@ export class ChartRow extends React.Component<{

return (
<tr>
<td style={{ minWidth: "140px", width: "12.5%" }}>
<td
style={{
minWidth: "140px",
width: "12.5%",
textAlign: "center",
}}
>
{chart.isPublished ? (
<a href={`${BAKED_GRAPHER_URL}/${chart.slug}`}>
<img
src={`${BAKED_GRAPHER_EXPORTS_BASE_URL}/${chart.slug}.svg`}
src={`${GRAPHER_DYNAMIC_THUMBNAIL_URL}/${chart.slug}.png`}
height={850}
width={600}
className="chartPreview"
/>
</a>
Expand Down
1 change: 1 addition & 0 deletions adminSiteClient/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ main:not(.ChartEditorPage):not(.GdocsEditPage) {
.chartPreview {
width: 100%;
height: auto;
max-width: 140px;
}

.internalNotes {
Expand Down
25 changes: 1 addition & 24 deletions adminSiteServer/mockSiteRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import {
BAKED_BASE_URL,
BASE_DIR,
BAKED_SITE_DIR,
LEGACY_WORDPRESS_IMAGE_URL,
} from "../settings/serverSettings.js"

Expand All @@ -35,13 +34,9 @@ import {
countriesIndexPage,
} from "../baker/countryProfiles.js"
import { makeSitemap } from "../baker/sitemap.js"
import {
getChartConfigBySlug,
getChartVariableData,
} from "../db/model/Chart.js"
import { getChartConfigBySlug } from "../db/model/Chart.js"
import { countryProfileSpecs } from "../site/countryProfileProjects.js"
import { ExplorerAdminServer } from "../explorerAdminServer/ExplorerAdminServer.js"
import { grapherToSVG } from "../baker/GrapherImageBaker.js"
import { getVariableData, getVariableMetadata } from "../db/model/Variable.js"
import { MultiEmbedderTestPage } from "../site/multiembedder/MultiEmbedderTestPage.js"
import {
Expand Down Expand Up @@ -429,27 +424,9 @@ mockSiteRouter.use(
res.redirect(assetUrl)
}
)
mockSiteRouter.use(
"/exports",
express.static(path.join(BAKED_SITE_DIR, "exports"))
)

mockSiteRouter.use("/assets", express.static("dist/assets"))

// TODO: this used to be a mockSiteRouter.use call but otherwise it looked like a route and
// it didn't look like it was making use of any middleware - if this causese issues then
// this has to be reverted to a use call
getPlainRouteWithROTransaction(
mockSiteRouter,
"/grapher/exports/:slug.svg",
async (req, res, trx) => {
const grapher = await getChartConfigBySlug(trx, req.params.slug)
const vardata = await getChartVariableData(grapher.config)
res.setHeader("Content-Type", "image/svg+xml")
res.send(await grapherToSVG(grapher.config, vardata))
}
)

mockSiteRouter.use(
"/fonts",
express.static(path.join(BASE_DIR, "public/fonts"), {
Expand Down
17 changes: 11 additions & 6 deletions adminSiteServer/testPageRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
ColorSchemes,
GrapherProgrammaticInterface,
} from "@ourworldindata/grapher"
import { GRAPHER_DYNAMIC_THUMBNAIL_URL } from "../settings/clientSettings.js"

const IS_LIVE = ADMIN_BASE_URL === "https://owid.cloud"
const DEFAULT_COMPARISON_URL = "https://ourworldindata.org"
Expand Down Expand Up @@ -467,7 +468,7 @@ getPlainRouteWithROTransaction(
Pick<DbPlainChart, "id"> & { config: DbRawChartConfig["full"] }
>(
trx,
`--sql
`-- sql
select ca.id, cc.full as config
from charts ca
join chart_configs cc
Expand Down Expand Up @@ -539,11 +540,15 @@ function PreviewTestPage(props: { charts: any[] }) {
href={`https://ourworldindata.org/grapher/${chart.slug}`}
>
<img
src={`https://ourworldindata.org/grapher/exports/${chart.slug}.svg`}
src={`https://ourworldindata.org/grapher/${chart.slug}.svg`}
/>
</a>
<a href={`/grapher/${chart.slug}`}>
<img src={`/grapher/exports/${chart.slug}.svg`} />
<a
href={`${GRAPHER_DYNAMIC_THUMBNAIL_URL}/${chart.slug}.svg`}
>
<img
src={`${GRAPHER_DYNAMIC_THUMBNAIL_URL}/${chart.slug}.svg`}
/>
</a>
</div>
))}
Expand Down Expand Up @@ -732,7 +737,7 @@ getPlainRouteWithROTransaction(
async (req, res, trx) => {
const rows = await db.knexRaw<{ config: DbRawChartConfig["full"] }>(
trx,
`--sql
`-- sql
SELECT cc.full as config
FROM charts ca
JOIN chart_configs cc
Expand All @@ -752,7 +757,7 @@ getPlainRouteWithROTransaction(
async (req, res, trx) => {
const rows = await db.knexRaw<{ config: DbRawChartConfig["full"] }>(
trx,
`--sql
`-- sql
SELECT cc.full as config
FROM charts ca
JOIN chart_configs cc
Expand Down
Loading

0 comments on commit 6063099

Please sign in to comment.