Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akmal / feat: remove relative indicator if it's blocking current price [flutter] #1456

Open
wants to merge 24 commits into
base: flutter-chart
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bf7582d
feat: remove relative indicator if it's blocking current price
akmal-deriv Mar 29, 2023
22c4e72
Merge branch 'master' into f-price-line-priority
akmal-deriv Mar 29, 2023
be6cb9b
Merge branch 'master' into f-price-line-priority
akmal-deriv Apr 28, 2023
c8eb5db
chore: refactor code
akmal-deriv Apr 28, 2023
6a42e3a
feat: parse the decimal
akmal-deriv Apr 28, 2023
3533623
Merge branch 'master' into f-price-line-priority
akmal-deriv May 5, 2023
f7069e5
Merge branch 'master' into f-price-line-priority
akmal-deriv Jun 20, 2023
c5a7432
Merge branch 'master' into f-price-line-priority
akmal-deriv Aug 9, 2023
9c6ecfd
Merge branch 'master' into f-price-line-priority
akmal-deriv Sep 7, 2023
303e853
feat: new UI for strike overlap
akmal-deriv Oct 3, 2023
1c7e86c
feat: interim solution
akmal-deriv Oct 10, 2023
9d0496b
feature: updated UI and overlap behaviour for strike and barrier
akmal-deriv Oct 23, 2023
95e83ac
fix stylint issues
akmal-deriv Oct 23, 2023
a8dbf34
fix: stylelint formatting
akmal-deriv Oct 23, 2023
8e7f13e
Merge branch 'master' into f-price-line-priority
akmal-deriv Oct 23, 2023
6dd67c9
fix broken styles in vercel development bundle
akmal-deriv Oct 23, 2023
575e676
feat: remove overlay from barrier
akmal-deriv Oct 25, 2023
7d10fd8
fix: overlay style
akmal-deriv Oct 26, 2023
50532bb
feat: trigger vercel
akmal-deriv Oct 26, 2023
abecc4d
chore: remove unused styles
akmal-deriv Oct 26, 2023
e0cb5d4
chore: apply review suggestion
akmal-deriv Nov 3, 2023
523cf6f
fix: add missing comma
akmal-deriv Nov 3, 2023
b65fc78
fix: inherit colors from deriv app for turbos
akmal-deriv Nov 7, 2023
7faa870
feat: move div to a separate component
akmal-deriv Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions sass/components/_barrier.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
width: 100%;
margin-left: -10px;
position: relative;
border-top-width: 0;
border-top-width: 1px;
border-top-color: $color-blue;
}
.title-wrapper {
$title-height: 24px;
Expand Down Expand Up @@ -74,12 +75,13 @@
}

.drag-price {
display: block;
display: flex;
height: 24px;
top: -11px;
top: -12px;
position: absolute;
right: -1px;
border: 1px solid inherit;
background-color: $color-blue;
justify-content: space-between;

.arrow-icon {
height: 41px;
Expand Down Expand Up @@ -123,26 +125,54 @@
/*hover*/

.price {
display: block;
font-size: 12px;
font-weight: bold;
display: block;
padding: 3px 1px;
line-height: 18px;
overflow: hidden;
overflow: unset;
padding: 3px 1px;
position: relative;
right: 45px;
text-align: center;
}
width: max-content;

.draggable .price {
padding-left: 16px;
&--zero {
color: $color-blue;
@include themify($themes) {
background-color: themed('DefaultBg');
}
}
&-overlay {
background-color: $color-blue;
height: 24px;
opacity: 0.3;
position: relative;
right: -10px;
top: -12px;
}
}

&:after {
font-weight: normal;
content: '≡';
font-size: 25px;
position: absolute;
left: 1px;
top: 1px;
transform: scaleX(0.8);
.draggable {
&-area-wrapper {
display: flex;
}
.price {
overflow: unset;
position: relative;
right: 55px;
}
.drag-icon {
display: flex;
flex-direction: column;
justify-content: center;
margin-left: 3px;

div {
background-color: $color-white;
height: 1px;
margin: 1px;
width: 8px;
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/Barrier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ const Barrier = ({ store, ...props }: TBarrierBaseProps) => {
aboveShadeStore,
belowShadeStore,
betweenShadeStore,
shadeColor = '#39b19d',
color = '#39b19d',
foregroundColor = '#ffffff',
hideBarrierLine,
hideOffscreenBarrier,
hideOffscreenLine,
hideBarrierLine,
hidePriceLines,
lineStyle,
isInitialized,
priceLabelWidth,
isSingleBarrier,
lineStyle,
opacityOnOverlap,
overlappedBarrierWidth,
shadeColor = '#39b19d',
} = store;

if (!isInitialized) return null;
Expand All @@ -41,7 +41,7 @@ const Barrier = ({ store, ...props }: TBarrierBaseProps) => {
>
<PriceLine
store={_high_barrier}
width={priceLabelWidth}
width={overlappedBarrierWidth}
lineStyle={lineStyle}
color={color}
foregroundColor={foregroundColor}
Expand All @@ -55,7 +55,7 @@ const Barrier = ({ store, ...props }: TBarrierBaseProps) => {
<>
<PriceLine
store={_low_barrier}
width={priceLabelWidth}
width={overlappedBarrierWidth}
lineStyle={lineStyle}
color={color}
foregroundColor={foregroundColor}
Expand Down
11 changes: 11 additions & 0 deletions src/components/HamburgerDragIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

const HamburgerDragIcon = () => (
<div className='drag-icon'>
<div></div>
<div></div>
<div></div>
</div>
);

export default HamburgerDragIcon;
74 changes: 58 additions & 16 deletions src/components/PriceLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import classNames from 'classnames';
import PriceLineStore from 'src/store/PriceLineStore';
import PriceLineArrow from './PriceLineArrow';
import PriceLineTitle from './PriceLineTitle';
import HamburgerDragIcon from './HamburgerDragIcon';

type TPriceLineProps = {
store: PriceLineStore;
lineStyle?: string;
lineStyle?: React.CSSProperties['borderStyle'];
hideOffscreenBarrier?: boolean;
hideOffscreenLine?: boolean;
hideBarrierLine?: boolean;
Expand All @@ -29,18 +30,19 @@ const PriceLine = ({
store,
}: TPriceLineProps) => {
const {
priceDisplay,
visible,
setDragLine,
className,
draggable,
isDragging,
init,
title,
yAxiswidth,
isDragging,
isOverlapping,
isOverlappingWithPriceLine,
offScreen,
offScreenDirection,
isOverlapping,
priceDisplay,
setDragLine,
title,
visible,
yAxiswidth,
} = store;

const showBarrier = React.useMemo(() => !(hideOffscreenBarrier && offScreen), [hideOffscreenBarrier, offScreen]);
Expand All @@ -57,26 +59,66 @@ const PriceLine = ({
if (!showBarrier) return null;

return (
<div className='barrier-area' style={{ top: 0 }} ref={setDragLine} hidden={!visible}>
<div
className={classNames('barrier-area', { 'barrier-area--zero': isOverlappingWithPriceLine })}
style={{ top: 0 }}
ref={setDragLine}
hidden={!visible}
>
<div
className={classNames('chart-line', 'horizontal', className || '', {
draggable,
dragging: isDragging,
})}
style={{
color: foregroundColor,
backgroundImage:
lineStyle && lineStyle !== 'solid' ? '' : `linear-gradient(to left, ${color} 90%, ${color}00`,
}}
>
{showBarrierDragLine && (
<div className='drag-line' style={{ borderTop: `${lineStyle} ${color} 1px` }} />
<div
className={classNames('drag-line', { 'drag-line--zero': isOverlappingWithPriceLine })}
style={{
borderTopColor: color,
borderTopStyle: lineStyle as React.CSSProperties['borderTopStyle'],
width: `calc(100% - ${yAxiswidth}px + ${width}px)`,
}}
/>
)}
<div className='draggable-area' />
<div className='drag-price' style={{ backgroundColor: color, width, opacity }}>
<div className='price'>{priceDisplay}</div>
{offScreen && offScreenDirection && (
<PriceLineArrow offScreenDirection={offScreenDirection} color={color} />
<div className='draggable-area-wrapper'>
<div
className={'drag-price'}
style={{
backgroundColor: color,
width: isOverlappingWithPriceLine ? width : yAxiswidth,
opacity,
right: isOverlappingWithPriceLine ? yAxiswidth - width : 0,
}}
>
<HamburgerDragIcon />
<div
className={classNames('price', { 'price--zero': isOverlappingWithPriceLine })}
style={{
color: isOverlappingWithPriceLine ? color : '',
right: isOverlappingWithPriceLine
? width + priceDisplay.length * 8 - (!draggable ? 16 : 0)
: 0,
}}
>
{priceDisplay}
</div>
<div />
{offScreen && offScreenDirection && (
<PriceLineArrow offScreenDirection={offScreenDirection} color={color} />
)}
</div>
{isOverlappingWithPriceLine && (
<div>
<div
className='price-overlay'
style={{ backgroundColor: color, width: yAxiswidth - width }}
/>
</div>
)}
</div>
{title && <PriceLineTitle color={color} title={title} yAxiswidth={yAxiswidth} opacity={opacity} />}
Expand Down
15 changes: 8 additions & 7 deletions src/store/BarrierStore.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CSSProperties } from 'react';
import { action, computed, observable, makeObservable } from 'mobx';
import MainStore from '.';
import Context from '../components/ui/Context';
Expand Down Expand Up @@ -47,7 +48,7 @@ export default class BarrierStore {
isTopShadeVisible = false;
isBottomShadeVisible = false;
hidePriceLines = false;
lineStyle?: string;
lineStyle?: CSSProperties['borderStyle'];
isInitialized = false;
initializePromise = PendingPromise<void, void>();
hideBarrierLine = false;
Expand All @@ -63,8 +64,8 @@ export default class BarrierStore {
get yAxisWidth(): number {
return this.mainStore.chart.yAxiswidth;
}
get priceLabelWidth(): number {
return this.yAxisWidth + 1;
get overlappedBarrierWidth(): number {
return 16;
}

constructor(mainStore: MainStore) {
Expand All @@ -83,12 +84,12 @@ export default class BarrierStore {
hideOffscreenLine: observable,
hideOffscreenBarrier: observable,
isSingleBarrier: observable,
pip: computed,
yAxisWidth: computed,
priceLabelWidth: computed,
destructor: action.bound,
init: action.bound,
overlappedBarrierWidth: computed,
pip: computed,
updateProps: action.bound,
destructor: action.bound
yAxisWidth: computed,
});

this.mainStore = mainStore;
Expand Down
2 changes: 1 addition & 1 deletion src/store/ChartStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ class ChartStore {

const { context } = this.context?.stx.chart;
// barrier price can be wider than current tick price for 1 decimal digit
const priceWidth = context.measureText(price.toFixed((this.pip as number) + 1)).width + 20;
const priceWidth = context.measureText(price.toFixed((this.pip as number) + 1)).width + 26;
if (priceWidth > this.yAxiswidth) {
this.yAxiswidth = priceWidth;

Expand Down
11 changes: 9 additions & 2 deletions src/store/PriceLineStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class PriceLineStore {
offScreen = false;
title?: string;
isOverlapping = false;
isOverlappingWithPriceLine = false;
offScreenDirection: keyof typeof DIRECTIONS | null = null;

set zIndex(value: string | number | null) {
Expand All @@ -51,6 +52,7 @@ export default class PriceLineStore {
offScreen: observable,
title: observable,
isOverlapping: observable,
isOverlappingWithPriceLine: observable,
offScreenDirection: observable,
pip: computed,
priceDisplay: computed,
Expand Down Expand Up @@ -225,6 +227,10 @@ export default class PriceLineStore {
return price;
}

_distanceFromCurrentPrice() {
return Math.abs(this._locationFromPrice(+this.realPrice) - this._locationFromPrice(+this.realPrice - +this._price));
}

_calculateTop = () => {
if (this.stx.currentQuote() === null) {
return;
Expand Down Expand Up @@ -265,10 +271,12 @@ export default class PriceLineStore {
this.isOverlapping = this.overlapCheck(top);
}

this.isOverlappingWithPriceLine = this._distanceFromCurrentPrice() < 25;

return Math.round(top) | 0;
};

// Mantually update the top to improve performance.
// Manually update the top to improve performance.
// We don't pay for react reconciler and mobx observable tracking in animation frames.
set top(v) {
this.__top = v;
Expand Down Expand Up @@ -304,7 +312,6 @@ export default class PriceLineStore {
if (i === current_barrier_idx) {
continue;
}

const barrier = filtered_barriers[i];
const diffTop = barrier._high_barrier.top && Math.abs(barrier._high_barrier.top - top);

Expand Down