Skip to content

Commit 96a7360

Browse files
Bala/Fix trackjs issues (#1476)
* fix: trackjs issues * fix: console error * fix: end of data * chore: update version
1 parent 7848a0e commit 96a7360

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

chart_app/lib/src/models/indicators.dart

+19-7
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class IndicatorsModel {
309309
values: values,
310310
));
311311
} else if (item is AlligatorSeries) {
312-
//TODO : enable offset after fixing in the flutter charts
312+
//TO DO : enable offset after fixing in the flutter charts
313313
tooltipContent.add(JsIndicatorTooltip(
314314
name: AlligatorIndicatorConfig.name,
315315
values: <String?>[
@@ -368,6 +368,16 @@ class IndicatorsModel {
368368
double y,
369369
int bottomIndicatorIndex,
370370
) {
371+
/// Called to get epoch from x position
372+
int? _getClosestEpoch(int? x, int granularity) {
373+
try {
374+
return getClosestEpoch?.call(x, granularity);
375+
// ignore: avoid_catches_without_on_clauses
376+
} catch (_) {
377+
return null;
378+
}
379+
}
380+
371381
int configIndex = 0;
372382
Series? bottomItemIndicator;
373383
final List<Series> sortedSeriesList = <Series>[...seriesList];
@@ -388,9 +398,11 @@ class IndicatorsModel {
388398

389399
final Offset target = Offset(x, y);
390400
final int? epoch =
391-
getClosestEpoch?.call(controller.getEpochFromX(x), granularity);
401+
_getClosestEpoch(controller.getEpochFromX(x), granularity);
392402

393-
if (bottomItemIndicator != null && bottomIndicatorIndex != null) {
403+
if (bottomItemIndicator != null &&
404+
bottomIndicatorIndex > -1 &&
405+
epoch != null) {
394406
if (bottomItemIndicator is AwesomeOscillatorSeries) {
395407
final List<Tick> aoEntries = bottomItemIndicator.entries ?? <Tick>[];
396408

@@ -816,11 +828,11 @@ class IndicatorsModel {
816828
}
817829
}
818830
} else if (item is AlligatorSeries) {
819-
final List<Tick> teethEntries = item.teethSeries!.entries ?? <Tick>[];
831+
final List<Tick> teethEntries = item.teethSeries?.entries ?? <Tick>[];
820832

821-
final List<Tick> jawEntries = item.jawSeries!.entries ?? <Tick>[];
833+
final List<Tick> jawEntries = item.jawSeries?.entries ?? <Tick>[];
822834

823-
final List<Tick> lipEntries = item.lipsSeries!.entries ?? <Tick>[];
835+
final List<Tick> lipEntries = item.lipsSeries?.entries ?? <Tick>[];
824836

825837
if (isPointOnIndicator(
826838
teethEntries,
@@ -864,7 +876,7 @@ class IndicatorsModel {
864876
if (index != null) {
865877
final int quoteIndex = index - offset;
866878

867-
if (quoteIndex <= entries.length - 1) {
879+
if (quoteIndex <= entries.length - 1 && quoteIndex > 0) {
868880
final Tick prevIndex = entries[quoteIndex - 1];
869881
final Tick currIndex = entries[quoteIndex];
870882

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deriv/deriv-charts",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"main": "dist/smartcharts.js",
55
"author": "[email protected]",
66
"contributors": [

src/feed/Feed.ts

+10
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ class Feed {
362362
end: number,
363363
callback: TPaginationCallback
364364
) {
365+
if (this._mainStore.state.hasReachedEndOfData) {
366+
return;
367+
}
368+
365369
const isMainChart = true;
366370
// TODO There is no need to get historical data before startTime
367371
if (this.startEpoch /* && start < this.startEpoch */ || (this.endEpoch && end > this.endEpoch)) {
@@ -407,6 +411,12 @@ class Feed {
407411
callback({ moreAvailable: false, quotes: [] });
408412
this.setHasReachedEndOfData(true);
409413
}
414+
415+
if (result.quotes?.length && result.quotes.length < count) {
416+
callback({ moreAvailable: false, quotes: result.quotes });
417+
this.setHasReachedEndOfData(true);
418+
return;
419+
}
410420
} catch (err) {
411421
console.error(err);
412422
result = { error: err };

src/flutter-chart/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const createChartElement = ({ onChartLoad }: TCreateChartElementProps) =>
1212
return;
1313
}
1414

15+
setupListeners();
16+
1517
const flutterChartElement = document.createElement('div');
1618
flutterChartElement.classList.add('flutter-chart');
1719

@@ -42,6 +44,19 @@ export const createChartElement = ({ onChartLoad }: TCreateChartElementProps) =>
4244
return flutterChartElement;
4345
};
4446

47+
const setupListeners = () => {
48+
const listener = (ev: KeyboardEvent) => {
49+
// To fix a trackjs issue caused by some keyboard events that don't contain `key` or `code` props.
50+
// https://github.com/flutter/engine/blob/f20657354d8b53baafcec55650830ead89adf3e9/lib/web_ui/lib/src/engine/keyboard_binding.dart#L386
51+
if (!ev.key || !ev.code) {
52+
ev.stopImmediatePropagation();
53+
}
54+
};
55+
56+
window.addEventListener('keydown', listener, true);
57+
window.addEventListener('keyup', listener, true);
58+
};
59+
4560
export const runChartApp = () => {
4661
if (window._flutter.initState.isMounted) {
4762
window._flutter.appRunner?.runApp();

0 commit comments

Comments
 (0)