-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OJS globe Demo #40
OJS globe Demo #40
Changes from 10 commits
62d5dd3
304692c
7083e11
387b033
c91099b
fd8d6d5
8a35dd5
db789b0
941f382
1aa30b1
ca63c6a
2de09b1
ed00634
32f2847
af3219b
2dbfc23
98527ad
ee2293f
0453599
f209269
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
--- | ||
title: "OJS map" | ||
format: | ||
closeread-html: | ||
code-fold: true | ||
--- | ||
|
||
Close read makes scrolling progress available to users as [Observable JavasScript](https://quarto.org/docs/interactive/ojs) variables, so you can create Close Read sections with interactive graphics that change as you scroll. | ||
|
||
The three variables are: | ||
|
||
- `crScrollerName`: the name of the active element | ||
- `crScrollerProgress`: progress of the active element from 0 to 1 | ||
- `crScrollerDirection`: either `"down"` or `"up"`, depending on the direction a user is scrolling | ||
|
||
Let's see what we can do with these variables. | ||
|
||
I have a list of cities around the world. I'd like to show them off to everyone on a globe, but I'll need to rotate the globe in order to show parts of it. | ||
|
||
If we make a globe using [Observable Plot's `geo` mark](https://observablehq.com/@observablehq/plot-projections?collection=@observablehq/plot), we can change its `rotation` option to turn it. That could be linked to the clock if we wanted it to animate on its own, but we can also link it to Close Read's variables to make it spin as we scroll. | ||
|
||
Before we start, let's define some cities. Here I've done it in OJS, but you could easily make an R or Python data frame available using `ojs_define()` (or even load a CSV from elsewhere): | ||
|
||
```{ojs} | ||
//| label: cities | ||
//| echo: true | ||
//| code-fold: false | ||
cities = [ | ||
{ name: "Brisbane", lat: -27.467778, lon: 153.028056 }, | ||
{ name: "New Delhi", lat: 28.613889, lon: 77.208889 }, | ||
{ name: "Singapore", lat: 1.283333, lon: 103.833333 }, | ||
{ name: "Istanbul", lat: 41.013611, lon: 28.955 }, | ||
{ name: "Paris", lat: 48.856667, lon: 2.352222 }, | ||
{ name: "Nairobi", lat: -1.286389, lon: 36.817222 }, | ||
{ name: "São Paulo", lat: -23.55, lon: -46.633333 }, | ||
{ name: "Montreal", lat: 45.508889, lon: -73.554167 }, | ||
{ name: "Houston", lat: 29.762778, lon: -95.383056 }, | ||
{ name: "Vancouver", lat: 49.260833, lon: -123.113889 }, | ||
{ name: "Honolulu", lat: 21.306944, lom: -157.858333 } | ||
] | ||
``` | ||
|
||
Now let's load in some land, so we can distinguish it from ocean: | ||
|
||
```{ojs} | ||
//| label: download-land | ||
world = FileAttachment("naturalearth-land-110m.geojson").json() | ||
``` | ||
|
||
::::{.cr-layout} | ||
|
||
:::{change-to="map"} | ||
We want our globe to rotate with the scroll progress — between -180 and 180. | ||
::: | ||
|
||
:::{focus-on="map"} | ||
Instead of trying to do the maths to scale it ourselves, we can make a scale with d3. | ||
::: | ||
|
||
:::{focus-on="map"} | ||
There are six narrative blocks that we want to scale over, but I'd like the scrolling to start a little late and end a little early — by the time the last block has just started. | ||
::: | ||
|
||
:::{focus-on="map"} | ||
So between 0.5 (because the scroll starts with the first narrative block of the document) and 5.1. If the numbers go outside this range, we'll _clamp_ them so that the scrolling doesn't continue. | ||
::: | ||
|
||
:::{focus-on="map"} | ||
Here's how we create that scale and then use it with Closeread's variables, `crTriggerIndex` and `crScrollProgress`: | ||
|
||
```{ojs} | ||
//| label: angle-scale | ||
//| echo: true | ||
//| code-fold: false | ||
angleScale = d3.scaleLinear() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised this works! Is the d3 library accessible without the need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll double check that with the Quarto team! Observable Plot uses d3, so maybe that's why it's always available... |
||
.domain([0.5, 5.1]) | ||
.range([-180, 180]) | ||
.clamp(true) | ||
|
||
angle = angleScale( | ||
(crTriggerIndex != null ? crTriggerIndex : -1) | ||
+ crScrollProgress) | ||
``` | ||
::: | ||
|
||
:::{focus-on="map"} | ||
With all that done, we can see our map! | ||
::: | ||
|
||
:::{cr-id="map"} | ||
|
||
```{ojs} | ||
//| label: map | ||
Plot.plot({ | ||
marks: [ | ||
Plot.graticule(), | ||
Plot.geo(world, { | ||
fill: "#222222" | ||
}), | ||
Plot.sphere(), | ||
Plot.dot(cities, { | ||
x: "lon", | ||
y: "lat", | ||
fill: "#eb343d", | ||
stroke: "white", | ||
strokeWidth: 5, | ||
paintOrder: "stroke", | ||
size: 6 | ||
}), | ||
Plot.text(cities, { | ||
x: d => d.lon + 2, | ||
y: d => d.lat + 2, | ||
text: "name", | ||
fill: "#eb343d", | ||
stroke: "white", | ||
strokeWidth: 5, | ||
paintOrder: "stroke", | ||
fontSize: 18, | ||
textAnchor: "start" | ||
}), | ||
], | ||
projection: { | ||
type: "orthographic", | ||
rotate: [angle, -10] | ||
} | ||
}) | ||
``` | ||
|
||
::: | ||
|
||
:::: | ||
|
||
:::{.counter style="position: fixed; top: 10px; right: 10px; background-color: skyblue; border-radius: 5px; padding: 18px 18px 0 18px;"} | ||
```{ojs} | ||
md`Active trigger: ${crTriggerIndex}` | ||
md`Active element: ${crStickyName}` | ||
md`Element progress: ${(crScrollProgress * 100).toFixed(1)}%` | ||
md`Scroll direction: ${crScrollDirection}` | ||
md`Angle: ${angle.toFixed(1)}°` | ||
``` | ||
::: | ||
|
||
And that's all! Let's put some lorem ipsum in so that it can scroll all the way to the end. | ||
|
||
:::{style="color: slategrey; font-style: italic;"} | ||
Eu in culpa officia cupidatat nostrud laborum do consequat officia Lorem tempor consectetur pariatur sunt. Veniam culpa dolore laborum nostrud ipsum pariatur ipsum dolore consectetur commodo ex. Non culpa deserunt voluptate. Amet excepteur incididunt deserunt pariatur velit labore do sunt occaecat eiusmod. Tempor proident sint exercitation culpa incididunt sunt proident sunt reprehenderit. Sint ipsum qui id nisi quis officia in. Anim velit minim fugiat qui dolor enim occaecat amet excepteur do aliqua ex adipisicing laboris labore. | ||
|
||
Culpa aute sint aliquip in aute enim cillum in exercitation cupidatat ex cupidatat mollit dolore ut. Et culpa minim laborum in ipsum laborum velit laboris fugiat ad culpa cillum. Sit nulla eu minim in nulla. Nulla esse sint occaecat eiusmod in irure in dolor veniam pariatur laboris consectetur sunt laboris excepteur. Dolor dolore ad incididunt consequat. Ad elit ullamco veniam cillum reprehenderit pariatur pariatur nisi ea. Pariatur quis ut deserunt eiusmod ipsum magna ullamco. | ||
|
||
Amet velit ea ex. Pariatur anim laboris fugiat labore velit ullamco aute aliquip incididunt. Ut labore voluptate exercitation esse aliquip dolor ex magna occaecat ullamco nisi sit non quis nulla. Elit qui do sunt consectetur officia sint veniam incididunt laboris aute eu nisi qui. Et voluptate consequat sunt commodo dolor dolor veniam minim incididunt culpa anim nulla duis est. Excepteur occaecat tempor veniam magna sit sunt enim sint exercitation dolore fugiat nulla consequat proident. Reprehenderit consequat reprehenderit amet dolore cillum elit dolore officia enim dolor. | ||
::: |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: "Orphaned code output test" | ||
--- | ||
|
||
Test test test | ||
|
||
```{r} | ||
#| echo: true | ||
#| cr-id: big-code | ||
#| layout-ncol: 2 | ||
|
||
a <- rnorm(100) | ||
b <- 1 + rexp(100) | ||
c <- a + b | ||
|
||
a <- rnorm(100) | ||
b <- 1 + rexp(100) | ||
c <- a + b | ||
|
||
a <- rnorm(100) | ||
b <- 1 + rexp(100) | ||
c <- a + b | ||
|
||
plot(mtcars$mpg, mtcars$dist) | ||
|
||
plot(mtcars$hp, mtcars$dist) | ||
|
||
plot(mtcars$hp, mtcars$mpg) | ||
|
||
mtcars | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's some differences here between using
scroll
andscroller
in the name. What about using the name of whatever we settle on: "trigger" or "step"? (we can discuss this in our meeting!)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, yeah! I currently have:
crTriggerIndex
crStickyName
crScrollProgress
crScrollDirection
But I agree that we should standardise it around triggers and steps, which are the names we've been using elsewhere. So how about instead:
crTriggerIndex
crStickyName
crTriggerProgress
crDirection
orcrTriggerDirection
For
crStickyName
, it's important to note that it is the name of the sticky element, not the trigger (the trigger generally being the one you'd want to use to drive animation). I actually don't think this one is super necessary, unless you intended for it to be the ID of the trigger instead! If that's the case and we re-wired it,crTriggerId
would be good too... or we could removetrigger
altogether and just havecrIndex
,crId
,crProgress
andcrDirection
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this proposal looks good! I think flagging
Trigger
vsSticky
is helpful. I know while workign on the js that having those well named helps in thinking through what you're doing.My plan would be to so a search-and-replace of every incidence of
step
in our codebase withtrigger
. Also to change the name ofsidebar-col
tonarrative-col
(I guesscaption-col
is also an option?). The result would be HTML that looks like...Questions for you:
trigger
andnarrative-
(I'm open to alternatives but like these fine).narrative-block
(or.caption
?) and.trigger
on the same div or should thetrigger
live in a separate div inside the block?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to have this added to
main
, both for the demo and the fixed ojs var code. I'm happy to make these last renaming changes, just let me know!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!
Mmm, a double class might be handy. It'd also make the CSS more readable, as we wouldn't have to do
> *
to select the narrative blocks.I might need to ask you to make the changes, sorry! I have a bit of cleaning up to do before we hop on the plane 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No prob, I'm on it!