2023-02-23 10:46:18 +09:00
|
|
|
import { Component, ElementRef, ViewChild, Input, OnChanges, OnInit } from '@angular/core';
|
|
|
|
import { tap } from 'rxjs';
|
2023-02-28 10:59:39 +09:00
|
|
|
import { Price, PriceService } from '../../services/price.service';
|
2023-03-12 17:36:45 +09:00
|
|
|
import { StateService } from '../../services/state.service';
|
|
|
|
import { environment } from '../../../environments/environment';
|
2022-09-17 01:20:08 +00:00
|
|
|
|
2022-09-17 17:23:44 +00:00
|
|
|
interface Xput {
|
|
|
|
type: 'input' | 'output' | 'fee';
|
|
|
|
value?: number;
|
2023-03-29 07:41:45 +09:00
|
|
|
displayValue?: number;
|
2022-09-17 17:23:44 +00:00
|
|
|
index?: number;
|
2022-11-22 10:05:14 +09:00
|
|
|
txid?: string;
|
|
|
|
vin?: number;
|
|
|
|
vout?: number;
|
2022-09-17 17:23:44 +00:00
|
|
|
address?: string;
|
|
|
|
rest?: number;
|
|
|
|
coinbase?: boolean;
|
|
|
|
pegin?: boolean;
|
|
|
|
pegout?: string;
|
|
|
|
confidential?: boolean;
|
2023-02-23 10:46:18 +09:00
|
|
|
timestamp?: number;
|
2023-03-12 17:36:45 +09:00
|
|
|
asset?: string;
|
2022-09-17 17:23:44 +00:00
|
|
|
}
|
|
|
|
|
2022-09-17 01:20:08 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'app-tx-bowtie-graph-tooltip',
|
|
|
|
templateUrl: './tx-bowtie-graph-tooltip.component.html',
|
|
|
|
styleUrls: ['./tx-bowtie-graph-tooltip.component.scss'],
|
|
|
|
})
|
|
|
|
export class TxBowtieGraphTooltipComponent implements OnChanges {
|
2022-09-17 17:23:44 +00:00
|
|
|
@Input() line: Xput | void;
|
2022-09-17 01:20:08 +00:00
|
|
|
@Input() cursorPosition: { x: number, y: number };
|
2022-11-22 10:05:14 +09:00
|
|
|
@Input() isConnector: boolean = false;
|
2023-03-12 17:36:45 +09:00
|
|
|
@Input() assetsMinimal: any;
|
2022-09-17 01:20:08 +00:00
|
|
|
|
|
|
|
tooltipPosition = { x: 0, y: 0 };
|
2023-02-23 10:46:18 +09:00
|
|
|
blockConversion: Price;
|
2022-09-17 01:20:08 +00:00
|
|
|
|
2023-03-12 17:36:45 +09:00
|
|
|
nativeAssetId = this.stateService.network === 'liquidtestnet' ? environment.nativeTestAssetId : environment.nativeAssetId;
|
|
|
|
|
2022-09-17 01:20:08 +00:00
|
|
|
@ViewChild('tooltip') tooltipElement: ElementRef<HTMLCanvasElement>;
|
|
|
|
|
2023-03-12 17:36:45 +09:00
|
|
|
constructor(
|
|
|
|
private priceService: PriceService,
|
|
|
|
private stateService: StateService,
|
|
|
|
) {}
|
2022-09-17 01:20:08 +00:00
|
|
|
|
|
|
|
ngOnChanges(changes): void {
|
2023-02-23 10:46:18 +09:00
|
|
|
if (changes.line?.currentValue) {
|
2023-02-23 13:13:20 +09:00
|
|
|
this.priceService.getBlockPrice$(changes.line?.currentValue.timestamp, true).pipe(
|
2023-02-23 10:46:18 +09:00
|
|
|
tap((price) => {
|
|
|
|
this.blockConversion = price;
|
|
|
|
})
|
|
|
|
).subscribe();
|
|
|
|
}
|
|
|
|
|
2022-09-17 01:20:08 +00:00
|
|
|
if (changes.cursorPosition && changes.cursorPosition.currentValue) {
|
|
|
|
let x = Math.max(10, changes.cursorPosition.currentValue.x - 50);
|
|
|
|
let y = changes.cursorPosition.currentValue.y + 20;
|
|
|
|
if (this.tooltipElement) {
|
|
|
|
const elementBounds = this.tooltipElement.nativeElement.getBoundingClientRect();
|
|
|
|
const parentBounds = this.tooltipElement.nativeElement.offsetParent.getBoundingClientRect();
|
|
|
|
if ((parentBounds.left + x + elementBounds.width) > parentBounds.right) {
|
|
|
|
x = Math.max(0, parentBounds.width - elementBounds.width - 10);
|
|
|
|
}
|
|
|
|
if (y + elementBounds.height > parentBounds.height) {
|
|
|
|
y = y - elementBounds.height - 20;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.tooltipPosition = { x, y };
|
|
|
|
}
|
|
|
|
}
|
2023-03-12 17:36:45 +09:00
|
|
|
|
|
|
|
pow(base: number, exponent: number): number {
|
|
|
|
return Math.pow(base, exponent);
|
|
|
|
}
|
2022-09-17 01:20:08 +00:00
|
|
|
}
|