Skip to content

Commit 73864e0

Browse files
82: fix sample compilation
1 parent 001b7b4 commit 73864e0

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/demo/samples/custom-series.svelte

+19-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
</Chart>
1919

2020
<script lang="ts">
21+
import type {
22+
BitmapCoordinatesRenderingScope,
23+
CanvasRenderingTarget2D,
24+
} from 'fancy-canvas';
2125
import {Chart, CustomSeries} from 'svelte-lightweight-charts';
2226
import {
2327
CustomData,
@@ -33,15 +37,12 @@
3337
ICustomSeriesPaneRenderer,
3438
PriceToCoordinateConverter,
3539
LineData,
40+
IChartApi,
3641
} from 'lightweight-charts';
37-
import {
38-
BitmapCoordinatesRenderingScope,
39-
CanvasRenderingTarget2D,
40-
} from 'fancy-canvas';
4142
import {onMount} from 'svelte';
4243
43-
let container;
44-
let chart;
44+
let container: HTMLElement | null = null;
45+
let chart: IChartApi | null = null;
4546
4647
const greenStyle: Partial<BrushableAreaStyle> = {
4748
lineColor: 'rgb(4,153,129)',
@@ -69,6 +70,10 @@
6970
7071
onMount(
7172
() => {
73+
if (chart === null || container === null) {
74+
return;
75+
}
76+
7277
chart.timeScale().fitContent();
7378
7479
interface MouseState {
@@ -84,6 +89,10 @@
8489
};
8590
8691
function determinePaneXLogical(mouseX: number): Logical | null {
92+
if (chart === null || container === null) {
93+
return null;
94+
}
95+
8796
const chartBox = container.getBoundingClientRect();
8897
const x = mouseX - chartBox.left - chart.priceScale('left').width();
8998
if (x < 0 || x > chart.timeScale().width()) return null;
@@ -118,7 +127,7 @@
118127
},
119128
],
120129
...fadeStyle,
121-
} as Partial<BrushableAreaSeriesOptions>;
130+
} as unknown as Partial<BrushableAreaSeriesOptions>;
122131
}
123132
});
124133
@@ -145,7 +154,7 @@
145154
/**
146155
* BrushableArea Series Data
147156
*/
148-
export interface BrushableAreaData extends CustomData {
157+
interface BrushableAreaData extends CustomData {
149158
value: number;
150159
}
151160
@@ -185,11 +194,7 @@
185194
TData,
186195
BrushableAreaSeriesOptions
187196
> {
188-
_renderer: BrushableAreaSeriesRenderer<TData>;
189-
190-
constructor() {
191-
this._renderer = new BrushableAreaSeriesRenderer();
192-
}
197+
_renderer: BrushableAreaSeriesRenderer<TData> = new BrushableAreaSeriesRenderer();
193198
194199
priceValueBuilder(plotRow: TData): CustomSeriesPricePlotValues {
195200
return [plotRow.value];
@@ -220,7 +225,7 @@
220225
y: number;
221226
}
222227
223-
export class BrushableAreaSeriesRenderer<TData extends BrushableAreaData> implements ICustomSeriesPaneRenderer {
228+
class BrushableAreaSeriesRenderer<TData extends BrushableAreaData> implements ICustomSeriesPaneRenderer {
224229
_data: PaneRendererCustomData<Time, TData> | null = null;
225230
_options: BrushableAreaSeriesOptions | null = null;
226231

0 commit comments

Comments
 (0)