Skip to content

Commit

Permalink
feat: exclude x-axis from forced scroll area
Browse files Browse the repository at this point in the history
  • Loading branch information
maryia-deriv committed Aug 15, 2024
1 parent 27cbc34 commit 22b8cfb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion chart_app/lib/src/chart_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class ChartApp {

bool _prevShowChart = false;

/// height of xAxis
double xAxisHeight = 24;

/// width of yAxis
double yAxisWidth = 60;

Expand Down Expand Up @@ -73,13 +76,14 @@ class ChartApp {
feedModel.newChart();
}

/// Calculates the width of yAxis
/// Calculates the width of yAxis and sets the height of xAxis
void calculateTickWidth() {
yAxisWidth = calculateYAxisWidth(
feedModel.ticks,
configModel.theme,
configModel.pipSize,
);
xAxisHeight = configModel.theme.gridStyle.xLabelsAreaHeight;

currentTickWidth = calculateCurrentTickWidth(
feedModel.ticks,
Expand Down
6 changes: 6 additions & 0 deletions chart_app/lib/src/interop/dart_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ void initDartInterop(ChartApp app) {
JsObject _exposeApp(ChartApp app) {
final JsObject jsObject = JsObject(context['Object']);

setProperty(
jsObject,
'getXAxisHeight',
allowInterop(() => app.xAxisHeight),
);

setProperty(
jsObject,
'getYAxisWidth',
Expand Down
10 changes: 6 additions & 4 deletions src/store/ChartAdapterStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,12 @@ export default class ChartAdapterStore {
const { pageX, pageY } = e.changedTouches[0];

if (['touchmove', 'touchend'].includes(e.type)) {
const nonScrollableAreaWidth = chartNode.offsetWidth - this.mainStore.chart.yAxisWidth;
const { left } = chartNode.getBoundingClientRect();
const x = pageX - left;
const isForcedScrollArea = x < nonScrollableAreaWidth;
const forcedScrollAreaWidth = chartNode.offsetWidth - this.mainStore.chart.yAxisWidth;
const forcedScrollAreaHeight = chartNode.offsetHeight - this.mainStore.chart.xAxisHeight;
const { top, left } = chartNode.getBoundingClientRect();
const xCoord = pageX - left;
const yCoord = pageY - top;
const isForcedScrollArea = xCoord < forcedScrollAreaWidth && yCoord < forcedScrollAreaHeight;

if (this.touchValues.x && this.touchValues.y) {
const xDiff = this.touchValues.x - pageX;
Expand Down
5 changes: 5 additions & 0 deletions src/store/ChartStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ChartStore {
networkStatus: observable,
serverTime: observable,
shouldRenderDialogs: observable,
xAxisHeight: computed,
yAxisWidth: computed,
lastQuote: observable,
_initChart: action.bound,
Expand Down Expand Up @@ -134,6 +135,10 @@ class ChartStore {
return this.currentCloseQuote()?.Close;
}

get xAxisHeight(): number {
return window.flutterChart?.app.getXAxisHeight() || 24;
}

get yAxisWidth(): number {
return window.flutterChart?.app.getYAxisWidth() || 60;
}
Expand Down
1 change: 1 addition & 0 deletions src/types/props.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export type TDrawingToolConfig = {

export type TFlutterChart = {
app: {
getXAxisHeight: () => number;
getYAxisWidth: () => number;
getCurrentTickWidth: () => number;
newChart: (payload: TNewChartPayload) => void;
Expand Down

0 comments on commit 22b8cfb

Please sign in to comment.