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

Aplly defaults when absent #1

Merged
merged 7 commits into from
May 26, 2022
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
2 changes: 1 addition & 1 deletion packages/demo/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {BrowserRouter, Route, Routes} from 'react-router-dom';
import {Gallery} from './gallery';
import {Terminal} from './terminal';
import {Terminal} from './terminal/terminal';

function App() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,193 +1,236 @@
import React, {useLayoutEffect} from 'react';
import {folder, LevaInputs, useControls} from 'leva';
import {LastPriceAnimationMode, LineStyle, LineType, LineWidth, PriceLineSource} from 'lightweight-charts';
import {Link} from 'react-router-dom';
import {AreaSeries, Chart, PriceLine, PriceScale, TimeScale} from 'lightweight-charts-react-wrapper';
import {folder, Leva, LevaInputs, useControls} from 'leva';
import {ReactNode} from 'react';
import {AreaSeries, AreaSeriesProps} from 'lightweight-charts-react-wrapper';

import styles from './terminal.module.css';

export function Terminal() {
useLayoutEffect(() => {
document.documentElement.classList.add(styles['app-mode']);
return () => document.documentElement.classList.remove(styles['app-mode']);
},[]);

const chart = useControls('Chart', {
width: 600,
height: 300,
});
export interface ControlledAreaSeriesProps {
data: AreaSeriesProps['data'];
children?: ReactNode;
}

export function ControlledAreaSeries(props: ControlledAreaSeriesProps): JSX.Element {
const {top, bottom, ...series} = useControls('Series', {
lastValueVisible: true,
visible: {
value: true,
label: 'Visible',
},
title: {
type: LevaInputs.STRING,
value: '',
label: 'Title',
},
lastValueVisible: {
value: true,
label: 'Show last value',
},

priceScaleId: {
value: 'right',
label: 'Price scale',
},

topColor: {
type: LevaInputs.COLOR,
value: '#FF0000',
label: 'Top color',
disabled: true,
optional: true,
},
bottomColor: {
type: LevaInputs.COLOR,
value: '#FF0000',
label: 'Bottom color',
disabled: true,
optional: true,
},
lineColor: {
type: LevaInputs.COLOR,
value: '#FF0000',
label: 'Line color',
disabled: true,
optional: true,
},

lineWidth: {
type: LevaInputs.SELECT,
value: 3 as LineWidth,
label: 'Line width',
options: [1,2,3,4] as LineWidth[],
disabled: true,
optional: true,
},
lineType: {
type: LevaInputs.SELECT,
value: LineType.Simple,
label: 'Line type',
options: {
Simple: LineType.Simple,
'With steps': LineType.WithSteps,
},
disabled: true,
optional: true,
},
priceScaleId: 'right',
visible: true,
priceLineVisible: false,
lineStyle: {
type: LevaInputs.SELECT,
value: LineStyle.Solid,
label: 'Line style',
options: {
Solid: LineStyle.Solid,
Dashed: LineStyle.Dashed,
'Large dashed': LineStyle.LargeDashed,
Dotted: LineStyle.Dotted,
'Sparse dotted': LineStyle.SparseDotted,
},
disabled: true,
optional: true,
},

lastPriceAnimation: {
type: LevaInputs.SELECT,
value: LastPriceAnimationMode.Disabled,
label: 'Last price animation',
options: {
Disabled: LastPriceAnimationMode.Disabled,
Continuous: LastPriceAnimationMode.Continuous,
'On data update': LastPriceAnimationMode.OnDataUpdate,
},
optional: true,
disabled: true,
},

priceLineVisible: {
value: false,
label: 'Show price line:',
},

priceLineSource: {
type: LevaInputs.SELECT,
value: PriceLineSource.LastBar,
options: [PriceLineSource.LastBar, PriceLineSource.LastVisible],
label: '-- source',
options: {
'Last bar': PriceLineSource.LastBar,
'Last visible': PriceLineSource.LastVisible,
},
disabled: true,
optional: true,
render: (get) => get('Series.priceLineVisible'),
},
priceLineWidth: {
type: LevaInputs.SELECT,
value: 1 as LineWidth,
label: '-- width',
options: [1,2,3,4] as LineWidth[],
disabled: true,
optional: true,
render: (get) => get('Series.priceLineVisible'),
},
priceLineStyle: {
type: LevaInputs.SELECT,
value: LineStyle.Solid,
options: [LineStyle.Solid, LineStyle.Dashed, LineStyle.LargeDashed, LineStyle.Dotted, LineStyle.SparseDotted],
label: '-- style',
options: {
Solid: LineStyle.Solid,
Dashed: LineStyle.Dashed,
'Large dashed': LineStyle.LargeDashed,
Dotted: LineStyle.Dotted,
'Sparse dotted': LineStyle.SparseDotted,
},
disabled: true,
optional: true,
render: (get) => get('Series.priceLineVisible'),
},
priceLineColor: {
type: LevaInputs.COLOR,
value: '#FF0000',
label: '-- color',
disabled: true,
optional: true,
render: (get) => get('Series.priceLineVisible'),
},
baseLineVisible: false,

baseLineVisible: {
value: false,
label: 'Show base line:'
},
baseLineColor: {
type: LevaInputs.COLOR,
value: '#FF0000',
label: '-- color',
disabled: true,
optional: true,
render: (get) => get('Series.baseLineVisible'),
},
baseLineWidth: {
type: LevaInputs.SELECT,
value: 1 as LineWidth,
label: '-- width',
options: [1,2,3,4] as LineWidth[],
render: (get) => get('Series.baseLineVisible'),
},
baseLineStyle: {
type: LevaInputs.SELECT,
value: LineStyle.Solid,
options: [LineStyle.Solid, LineStyle.Dashed, LineStyle.LargeDashed, LineStyle.Dotted, LineStyle.SparseDotted],
disabled: true,
optional: true,
render: (get) => get('Series.baseLineVisible'),
},
topColor: {
type: LevaInputs.COLOR,
value: '#FF0000',
disabled: true,
optional: true,
},
bottomColor: {
type: LevaInputs.COLOR,
value: '#FF0000',
disabled: true,
optional: true,
},
lineColor: {
type: LevaInputs.COLOR,
value: '#FF0000',
disabled: true,
optional: true,
},
scaleMargins: folder({
top: {
min: 0,
max: 1,
value: 0.1,
},
bottom: {
min: 0,
max: 1,
value: 0.1,
},
}),
lineStyle: {
baseLineStyle: {
type: LevaInputs.SELECT,
value: LineStyle.Solid,
options: [LineStyle.Solid, LineStyle.Dashed, LineStyle.LargeDashed, LineStyle.Dotted, LineStyle.SparseDotted],
label: '-- style',
options: {
Solid: LineStyle.Solid,
Dashed: LineStyle.Dashed,
'Large dashed': LineStyle.LargeDashed,
Dotted: LineStyle.Dotted,
'Sparse dotted': LineStyle.SparseDotted,
},
disabled: true,
optional: true,
render: (get) => get('Series.baseLineVisible'),
},
lineWidth: {
type: LevaInputs.SELECT,
value: 3 as LineWidth,
options: [1,2,3,4] as LineWidth[],
},
lineType: {
type: LevaInputs.SELECT,
value: LineType.Simple,
options: [LineType.Simple, LineType.WithSteps],
crosshairMarkerVisible: {
value: true,
label: 'Show crosshair marker:',
},
crosshairMarkerVisible: true,
crosshairMarkerRadius: {
value: 4,
label: '-- radius',
optional: true,
disabled: true,
render: (get) => get('Series.crosshairMarkerVisible'),
},
crosshairMarkerBorderColor: {
type: LevaInputs.COLOR,
value: '#FFFFFF',
label: '-- color',
optional: true,
disabled: true,
render: (get) => get('Series.crosshairMarkerVisible'),
},
crosshairMarkerBackgroundColor: {
type: LevaInputs.COLOR,
value: '#FFFFFF',
label: '-- background color',
optional: true,
disabled: true,
render: (get) => get('Series.crosshairMarkerVisible'),
},
lastPriceAnimation: {
type: LevaInputs.SELECT,
value: LastPriceAnimationMode.Disabled,
options: [LastPriceAnimationMode.Disabled, LastPriceAnimationMode.Continuous, LastPriceAnimationMode.OnDataUpdate],
},

'Scale margins (deprecated)': folder({
top: {
min: 0,
max: 1,
value: 0.1,
},
bottom: {
min: 0,
max: 1,
value: 0.1,
},
}, { collapsed: true }),
});

return (
<main className={styles.main}>
<section className={styles.chart}>
<Link to="/">
Gallery
</Link>
<Chart {...chart}>
<PriceScale id="left" visible={true}/>
<TimeScale onVisibleLogicalRangeChange={console.log}/>
<AreaSeries
{...series}
scaleMargins={{top, bottom}}
data={[
{time: '2018-10-19', value: 52.89},
{time: '2018-10-22', value: 51.65},
{time: '2018-10-23', value: 51.56},
{time: '2018-10-24', value: 50.19},
{time: '2018-10-25', value: 51.86},
{time: '2018-10-26', value: 51.25},
{time: '2018-10-29', value: 52.23},
{time: '2018-10-30', value: 52.69}
]}
>
<PriceLine
title="price"
price={51}
color="#FF0000"
lineWidth={1}
lineStyle={LineStyle.Solid}
lineVisible={true}
axisLabelVisible={true}
/>
</AreaSeries>
</Chart>
</section>
<section className={styles.settings}>
<Leva fill={true} flat={true} titleBar={false} collapsed={false}/>
</section>
</main>
);
<AreaSeries
{...props}
{...series}
scaleMargins={{top, bottom}}
/>
)
}
Loading