Skip to content

Commit

Permalink
Merge pull request #18 from trash-and-fire/chart-events-fix
Browse files Browse the repository at this point in the history
Chart events fix
  • Loading branch information
trash-and-fire authored Apr 18, 2022
2 parents e574090 + 2c0bdb7 commit 16e7895
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/demo/app.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SeriesActionParams
} from 'svelte-lightweight-charts/types';
import type {ChartActionParams} from 'svelte-lightweight-charts';
import type {$$EVENTS as ChartEvents} from 'svelte-lightweight-charts/components/chart.svelte'
import type {$$EVENTS as TimeScaleEvents} from 'svelte-lightweight-charts/components/time-scale.svelte';
import {LineStyle} from 'lightweight-charts';
Expand Down Expand Up @@ -94,7 +95,7 @@
updateVolumeData(volumeComponent, day);
}
let action = true;
let action = false;
let components = true;
let showVolume = true;
Expand All @@ -113,7 +114,6 @@
series: showVolume ? [mainProps, volumeProps] : [mainProps],
reference: handleReference,
onClick: handleClick,
onCrosshairMove: handleCrosshairMove,
};
let api: IChartApi | null = null;
Expand Down Expand Up @@ -161,9 +161,9 @@
}
}
function handleCrosshairMove(): void {
function handleCrosshairMove(e: ChartEvents['crosshairMove']): void {
// eslint-disable-next-line no-console
console.log('move');
console.log('move', e.detail);
}
function handleReference(ref: IChartApi | null): void {
Expand Down Expand Up @@ -435,6 +435,7 @@
// eslint-disable-next-line no-console
ref: console.log
}}
on:crosshairMove={handleCrosshairMove}
>
<TimeScale
visible={timeScaleVisible}
Expand Down
4 changes: 3 additions & 1 deletion src/package/components/chart.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export interface $$PROPS extends DeepPartial<ChartOptions> {
}
}

export interface $$EVENTS {
export interface $$EVENTS_DETAIL {
crosshairMove: MouseEventParams,
click: MouseEventParams,
}

export type $$EVENTS = { [K in keyof $$EVENTS_DETAIL]: CustomEvent<$$EVENTS_DETAIL[K]> & { type: K } };
4 changes: 2 additions & 2 deletions src/package/components/chart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<script lang="ts">
import type {ChartOptions, IChartApi, DeepPartial, MouseEventParams} from 'lightweight-charts';
import type {$$EVENTS, $$PROPS} from './chart.interface';
import type {$$EVENTS_DETAIL, $$PROPS} from './chart.interface';
import type {Reference} from '../types';
import {createEventDispatcher} from 'svelte';
import {element} from './internal/element';
import ContextProvider from './internal/context-provider.svelte';
import {chart} from '../index';
const dispatch = createEventDispatcher<$$EVENTS>();
const dispatch = createEventDispatcher<$$EVENTS_DETAIL>();
export let container: $$PROPS['container'] = undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ export function chart<T extends Array<SeriesActionParams>>(

if (nextOnClick !== onClick) {
if (onClick) {
chart.subscribeClick(onClick);
chart.unsubscribeClick(onClick);
}
onClick = nextOnClick;
if (onClick) {
chart.unsubscribeClick(onClick);
chart.subscribeClick(onClick);
}
}

Expand Down

0 comments on commit 16e7895

Please sign in to comment.