Skip to content
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

Add nextjs circular genome view demo #3766

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
35 changes: 35 additions & 0 deletions embedded_demos/jbrowse-react-circular-genome-view-nextjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# jbrowse-react-circular-genome-view-nextjs

This is a demo of using the circular genome view with next.js (which uses
webpack 5).

# Demo of `@jbrowse/react-circular-genome-view` with next.js

See this app running at https://jbrowse.org/demos/cgv-nextjs/.

Download this directory from the monorepo using

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

## Deploy

This page is deployed to https://jbrowse.org/demos/cgv-nextjs (uses
`yarn build && yarn export` to create static build with no server side)

## Notes

Note that tsconfig.json had to be updated to target >ES5 and

```
transpilePackages: ['@jbrowse/react-circular-genome-view'],
```

added to the `next.config.js` file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
basePath: '/demos/cgv-nextjs',
}

module.exports = nextConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "jbrowse-react-circular-genome-view-next",
"version": "0.1.0",
"private": true,
"license": "MIT",
"scripts": {
"dev": "next dev",
"build": "next build",
"export": "next export",
"start": "next start",
"predeploy": "npm run build && npm run export",
"deploy": "aws s3 sync --delete out s3://jbrowse.org/demos/cgv-nextjs/",
"postdeploy": "aws cloudfront create-invalidation --distribution-id E13LGELJOT4GQO --paths \"/demos/cgv-nextjs/*\""
},
"dependencies": {
"@fontsource/roboto": "^4.5.7",
"@jbrowse/react-circular-genome-view": "^2.6.1",
"@jbrowse/react-linear-genome-view": "^2.0.0",
"next": "^13.0.7",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"eslint": "^8.28.0",
"eslint-config-next": "^13.0.4",
"typescript": "^4.9.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { useState, useEffect } from 'react'
import '@fontsource/roboto'
import {
createViewState,
JBrowseCircularGenomeView,
} from '@jbrowse/react-circular-genome-view'

import assembly from '../utils/assembly'
import tracks from '../utils/tracks'
import defaultSession from '../utils/defaultSession'

type ViewModel = ReturnType<typeof createViewState>

function View() {
const [viewState, setViewState] = useState<ViewModel>()
const [patches, setPatches] = useState('')
const [stateSnapshot, setStateSnapshot] = useState('')

useEffect(() => {
const state = createViewState({
assembly,
tracks,
onChange: (patch: any) => {
setPatches(previous => previous + JSON.stringify(patch) + '\n')
},
defaultSession,
})
setViewState(state)
}, [])

if (!viewState) {
return null
}

return (
<>
<h1>JBrowse 2 React Circular Genome View Demo (with create-next-app)</h1>
<JBrowseCircularGenomeView viewState={viewState} />
<h3>Code</h3>
<p>
The code for this app is available at{' '}
<a
href="https://github.com/GMOD/jbrowse-components/tree/main/embedded_demos/jbrowse-react-circular-genome-view"
target="_blank"
rel="noreferrer"
>
https://github.com/GMOD/jbrowse-components/tree/main/embedded_demos/jbrowse-react-circular-genome-view
</a>
.
</p>
<h3>Control the view</h3>
<div>
<p>
This is an example of controlling the view from other elements on the
page. Clicking on a button will rotate the view.
</p>
<button
onClick={() => {
viewState.session.view.rotateClockwise()
}}
>
Rotate clockwise
</button>
<button
onClick={() => {
viewState.session.view.rotateCounterClockwise()
}}
>
Rotate counter clockwise
</button>
</div>
<h3>See the state</h3>
<div>
<p>
The button below will show you the current session, which includes
things like what region the view is showing and which tracks are open.
This session JSON object can be used in the{' '}
<code>defaultSession</code> of <code>createViewState</code>.
</p>
<button
onClick={() => {
setStateSnapshot(JSON.stringify(viewState.session, undefined, 2))
}}
>
Show session
</button>
</div>
<textarea value={stateSnapshot} readOnly rows={20} cols={80} />
<h3>React to the view</h3>
<p>
Using <code>onChange</code> in <code>createViewState</code>, you can
observe what is happening in the view and react to it. The changes in
the state of the view are emitted as{' '}
<a href="http://jsonpatch.com/" target="_blank" rel="noreferrer">
JSON patches
</a>
. The patches for the component on this page are shown below.
</p>
<textarea value={patches} readOnly rows={5} cols={80} wrap="off" />
</>
)
}

export default View
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.container {
min-height: 100vh;
padding: 0 0.5rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.title a {
color: #0070f3;
text-decoration: none;
}

.title a:hover,
.title a:focus,
.title a:active {
text-decoration: underline;
}

.title {
margin: 0 0 1rem;
line-height: 1.15;
font-size: 3.6rem;
}

.title {
text-align: center;
}

.title,
.description {
text-align: center;
}

.description {
line-height: 1.5;
font-size: 1.5rem;
}

.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;

max-width: 800px;
margin-top: 3rem;
}

.card {
margin: 1rem;
flex-basis: 45%;
padding: 1.5rem;
text-align: left;
color: inherit;
text-decoration: none;
border: 1px solid #eaeaea;
border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease;
}

.card:hover,
.card:focus,
.card:active {
color: #0070f3;
border-color: #0070f3;
}

.card h3 {
margin: 0 0 1rem 0;
font-size: 1.5rem;
}

.card p {
margin: 0;
font-size: 1.25rem;
line-height: 1.5;
}

.logo {
height: 1em;
}

@media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
html,
body {
padding: 0;
margin: 0;
font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,
Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}

a {
color: inherit;
text-decoration: none;
}

* {
box-sizing: border-box;
}

img {
max-width: 100%;
height: auto;
}

h1,
h2,
p,
ul {
margin: 0;
}

ul {
padding: 0;
list-style: none;
}

button {
padding: 0.5rem 1rem;
font-weight: bold;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es2018",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Loading