Skip to content

Commit

Permalink
Bala/Fix trackjs issues (#1476)
Browse files Browse the repository at this point in the history
* fix: trackjs issues

* fix: console error

* fix: end of data

* chore: update version
  • Loading branch information
balakrishna-deriv authored Feb 2, 2024
1 parent 7848a0e commit 96a7360
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
26 changes: 19 additions & 7 deletions chart_app/lib/src/models/indicators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class IndicatorsModel {
values: values,
));
} else if (item is AlligatorSeries) {
//TODO : enable offset after fixing in the flutter charts
//TO DO : enable offset after fixing in the flutter charts
tooltipContent.add(JsIndicatorTooltip(
name: AlligatorIndicatorConfig.name,
values: <String?>[
Expand Down Expand Up @@ -368,6 +368,16 @@ class IndicatorsModel {
double y,
int bottomIndicatorIndex,
) {
/// Called to get epoch from x position
int? _getClosestEpoch(int? x, int granularity) {
try {
return getClosestEpoch?.call(x, granularity);
// ignore: avoid_catches_without_on_clauses
} catch (_) {
return null;
}
}

int configIndex = 0;
Series? bottomItemIndicator;
final List<Series> sortedSeriesList = <Series>[...seriesList];
Expand All @@ -388,9 +398,11 @@ class IndicatorsModel {

final Offset target = Offset(x, y);
final int? epoch =
getClosestEpoch?.call(controller.getEpochFromX(x), granularity);
_getClosestEpoch(controller.getEpochFromX(x), granularity);

if (bottomItemIndicator != null && bottomIndicatorIndex != null) {
if (bottomItemIndicator != null &&
bottomIndicatorIndex > -1 &&
epoch != null) {
if (bottomItemIndicator is AwesomeOscillatorSeries) {
final List<Tick> aoEntries = bottomItemIndicator.entries ?? <Tick>[];

Expand Down Expand Up @@ -816,11 +828,11 @@ class IndicatorsModel {
}
}
} else if (item is AlligatorSeries) {
final List<Tick> teethEntries = item.teethSeries!.entries ?? <Tick>[];
final List<Tick> teethEntries = item.teethSeries?.entries ?? <Tick>[];

final List<Tick> jawEntries = item.jawSeries!.entries ?? <Tick>[];
final List<Tick> jawEntries = item.jawSeries?.entries ?? <Tick>[];

final List<Tick> lipEntries = item.lipsSeries!.entries ?? <Tick>[];
final List<Tick> lipEntries = item.lipsSeries?.entries ?? <Tick>[];

if (isPointOnIndicator(
teethEntries,
Expand Down Expand Up @@ -864,7 +876,7 @@ class IndicatorsModel {
if (index != null) {
final int quoteIndex = index - offset;

if (quoteIndex <= entries.length - 1) {
if (quoteIndex <= entries.length - 1 && quoteIndex > 0) {
final Tick prevIndex = entries[quoteIndex - 1];
final Tick currIndex = entries[quoteIndex];

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deriv/deriv-charts",
"version": "2.0.2",
"version": "2.0.3",
"main": "dist/smartcharts.js",
"author": "[email protected]",
"contributors": [
Expand Down
10 changes: 10 additions & 0 deletions src/feed/Feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ class Feed {
end: number,
callback: TPaginationCallback
) {
if (this._mainStore.state.hasReachedEndOfData) {
return;
}

const isMainChart = true;
// TODO There is no need to get historical data before startTime
if (this.startEpoch /* && start < this.startEpoch */ || (this.endEpoch && end > this.endEpoch)) {
Expand Down Expand Up @@ -407,6 +411,12 @@ class Feed {
callback({ moreAvailable: false, quotes: [] });
this.setHasReachedEndOfData(true);
}

if (result.quotes?.length && result.quotes.length < count) {
callback({ moreAvailable: false, quotes: result.quotes });
this.setHasReachedEndOfData(true);
return;
}
} catch (err) {
console.error(err);
result = { error: err };
Expand Down
15 changes: 15 additions & 0 deletions src/flutter-chart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const createChartElement = ({ onChartLoad }: TCreateChartElementProps) =>
return;
}

setupListeners();

const flutterChartElement = document.createElement('div');
flutterChartElement.classList.add('flutter-chart');

Expand Down Expand Up @@ -42,6 +44,19 @@ export const createChartElement = ({ onChartLoad }: TCreateChartElementProps) =>
return flutterChartElement;
};

const setupListeners = () => {
const listener = (ev: KeyboardEvent) => {
// To fix a trackjs issue caused by some keyboard events that don't contain `key` or `code` props.
// https://github.com/flutter/engine/blob/f20657354d8b53baafcec55650830ead89adf3e9/lib/web_ui/lib/src/engine/keyboard_binding.dart#L386
if (!ev.key || !ev.code) {
ev.stopImmediatePropagation();
}
};

window.addEventListener('keydown', listener, true);
window.addEventListener('keyup', listener, true);
};

export const runChartApp = () => {
if (window._flutter.initState.isMounted) {
window._flutter.appRunner?.runApp();
Expand Down

0 comments on commit 96a7360

Please sign in to comment.