-
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
Merged
Merged
OJS globe Demo #40
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
62d5dd3
Make scroller progress OJS var numeric
304692c
Add scroller direction OJS var
7083e11
scrollerSection -> scrollerName
387b033
Ignore extension folders for demos and tests
c91099b
WIP - globe spin demo
fd8d6d5
Restore OJS trigger index; change OJS names (again!
8a35dd5
Merge branch 'rename-steps' into feature-demos
db789b0
Working scroll demo!
941f382
Ensure scroll progress updates on new trigger
1aa30b1
merge in from main
andrewpbray ca63c6a
Merge in :branch 'main'
andrewpbray 2de09b1
move into docs site
andrewpbray ed00634
switch from change-to to focus-on
andrewpbray 32f2847
standarize ojs variable names
andrewpbray af3219b
reorder slightly
andrewpbray 2dbfc23
merge in from main
andrewpbray 98527ad
fix typos
andrewpbray ee2293f
simplify yaml
andrewpbray 0453599
update meta info for listing
andrewpbray f209269
initial commit
andrewpbray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
--- | ||
title: "OJS map" | ||
format: | ||
closeread-html: | ||
code-fold: true | ||
theme: cosmo | ||
--- | ||
|
||
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: | ||
|
||
- `crTriggerIndex`: the index of the active element | ||
- `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 | ||
//| echo: true | ||
world = FileAttachment("naturalearth-land-110m.geojson").json() | ||
``` | ||
|
||
::::{.cr-layout} | ||
|
||
:::{focus-on="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() | ||
.domain([0.5, 5.1]) | ||
.range([-180, 180]) | ||
.clamp(true) | ||
|
||
angle = angleScale( | ||
jimjam-slam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(crTriggerIndex != null ? crTriggerIndex : -1) | ||
+ crScrollProgress) | ||
``` | ||
::: | ||
|
||
:::{focus-on="map"} | ||
With all that done, we can see our map! | ||
::: | ||
|
||
:::{#cr-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. | ||
::: |
134 changes: 134 additions & 0 deletions
134
docs/gallery/demos/ojs-map/naturalearth-land-110m.geojson
Large diffs are not rendered by default.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!