ampproject / ampproject/amphtml

amp-script: Support d3.js

Open
#23,673 8 comments 0 reactions 0 assignees View on GitHub
Component: amp-script P2: Soon Stale Type: Bug WG: runtime
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Our goal is to run JavaScript data visualization libraries using `amp-script` -- avoiding need to use `amp-iframe`.

This example implements `canvas.js` with `amp-script`
https://afdsi.org/amp-script-03/
Source is Weston Ruter and his experiment here:
https://github.com/westonruter/javascriptforwp-conference-amp-examples
using this technique:
```

Start drawing!

```
We would like to implement our `d3.js` applications using a similar technique.
A simple stand-alone D3 version is shown here:
https://afdsi.org/amp-script/reference.html

Our experiment follows `canvas.js` example, but uses a `d3.js` library as follows:
```

```
The experiment is here:
https://afdsi.org/amp-script-01/
We see the following error message:
```
Uncaught ReferenceError: d3 is not defined
amp-script[src="dendrogram.js"].js:10
at Object. (amp-script[src="dendrogram.js"].js:10)
at amp-script[src="dendrogram.js"].js:70
```
Are we doing something wrong?
Is there an alternative way to invoke a `d3.js` library?

We see these discussions:
https://github.com/ampproject/amphtml/issues/23579
https://github.com/ampproject/amphtml/pull/23658
https://github.com/ampproject/amphtml/issues/18830
https://github.com/ampproject/amphtml/issues/13471

Contributor guide

Open the contributing guide

Research direction

Start by comparing the working canvas.js example with the d3.js and dendrogram.js amp-script examples, focusing on why d3 is undefined. Read the linked discussions and related issue and pull request for existing constraints. Done means the requested D3 usage path is resolved or its supported alternative is clearly established without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.