-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from hatemhosny/website-options-editor
Website options editor
- Loading branch information
Showing
18 changed files
with
407 additions
and
57 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { createRenderer } from './create-renderer'; | ||
export { createResizeObserver } from './resize-observer'; | ||
export { elements } from './elements'; | ||
export { rendererSubscriber } from './renderer-subscriber'; | ||
export type { Renderer } from './renderer.models'; |
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,18 @@ | ||
export function createResizeObserver(resizeFn: () => void) { | ||
if (window.ResizeObserver && window.requestAnimationFrame) { | ||
return new ResizeObserver((entries) => { | ||
window.requestAnimationFrame((): void | undefined => { | ||
if (!entries?.length) return; | ||
resizeFn(); | ||
}); | ||
}); | ||
} | ||
return { | ||
observe: () => { | ||
window.addEventListener('resize', resizeFn); | ||
}, | ||
unobserve: () => { | ||
window.removeEventListener('resize', resizeFn); | ||
}, | ||
}; | ||
} |
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
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,86 @@ | ||
// eslint-disable-next-line import/no-unresolved | ||
import { getBaseUrl } from '@site/src/helpers/base-url'; | ||
import RacingBars from '../RacingBars'; | ||
import type { Props } from '../../../../src'; | ||
import styles from './styles.module.css'; | ||
|
||
const PARAMS: Props = { | ||
dataTransform: (data) => | ||
data.map((d) => ({ | ||
...d, | ||
icon: `https://flagsapi.com/${d.code}/flat/64.png`, | ||
})), | ||
colorSeed: '', | ||
showGroups: false, | ||
topN: 10, | ||
autorun: false, | ||
loop: false, | ||
title: 'World Population', | ||
subTitle: 'in millions', | ||
caption: 'Source: World Bank', | ||
dateCounter: 'MM/YYYY', | ||
labelsPosition: 'inside', | ||
labelsWidth: 150, | ||
showIcons: true, | ||
controlButtons: 'all', | ||
overlays: 'all', | ||
theme: 'dark', | ||
fixedScale: false, | ||
highlightBars: true, | ||
selectBars: true, | ||
}; | ||
|
||
async function initPane(racer) { | ||
const baseUrl = getBaseUrl(); | ||
const mod = await import(/* webpackIgnore: true */ `${baseUrl}/js/tweakpane.min.js`); | ||
const { Pane } = mod; | ||
const pane = new Pane({ | ||
container: document.querySelector<HTMLElement>('#tweakpane')!, | ||
expanded: true, | ||
title: 'Change Options:', | ||
}); | ||
|
||
pane.addBinding(PARAMS, 'theme', { options: { dark: 'dark', light: 'light' } }); | ||
pane.addBinding(PARAMS, 'title'); | ||
pane.addBinding(PARAMS, 'subTitle'); | ||
pane.addBinding(PARAMS, 'caption'); | ||
pane.addBinding(PARAMS, 'dateCounter'); | ||
pane.addBinding(PARAMS, 'showIcons'); | ||
pane.addBinding(PARAMS, 'showGroups'); | ||
pane.addBinding(PARAMS, 'topN', { min: 2, max: 15, step: 1 }); | ||
pane.addBinding(PARAMS, 'labelsPosition', { | ||
options: { inside: 'inside', outside: 'outside' }, | ||
}); | ||
pane.addBinding(PARAMS, 'labelsWidth', { min: 0, max: 300, step: 1 }); | ||
pane.addBinding(PARAMS, 'loop'); | ||
pane.addBinding(PARAMS, 'controlButtons', { | ||
options: { all: 'all', play: 'play', none: 'none' }, | ||
}); | ||
pane.addBinding(PARAMS, 'overlays', { | ||
options: { all: 'all', play: 'play', repeat: 'repeat', none: 'none' }, | ||
}); | ||
pane.addBinding(PARAMS, 'fixedScale'); | ||
pane.addBinding(PARAMS, 'colorSeed'); | ||
pane.addBinding(PARAMS, 'highlightBars'); | ||
pane.addBinding(PARAMS, 'selectBars'); | ||
|
||
pane.on('change', (ev: any) => { | ||
const key = ev.target.label; | ||
racer.changeOptions({ [key]: ev.value }); | ||
}); | ||
} | ||
|
||
export default function ChartOptions() { | ||
return ( | ||
<div className={styles.container}> | ||
<RacingBars | ||
dataUrl="/data/population.csv" | ||
{...PARAMS} | ||
callback={(racer) => initPane(racer)} | ||
showCode={false} | ||
className={styles.chart} | ||
/> | ||
<div id="tweakpane" className={styles.tweakpane}></div> | ||
</div> | ||
); | ||
} |
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,17 @@ | ||
.container { | ||
display: flex; | ||
justify-content: center; | ||
min-width: 100%; | ||
gap: 1em; | ||
} | ||
|
||
.tweakpane { | ||
width: 300px; | ||
} | ||
|
||
@media screen and (max-width: 600px) { | ||
.container { | ||
align-items: center; | ||
flex-direction: column; | ||
} | ||
} |
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,6 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; | ||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
|
||
export const getBaseUrl = () => | ||
ExecutionEnvironment.canUseDOM ? location.origin : useDocusaurusContext().siteConfig.url; |
Oops, something went wrong.