Skip to content

Commit

Permalink
refactor(visualizator-fe): Add types for AccountsAmountPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldev5 authored and dudo50 committed Jul 9, 2024
1 parent 237e171 commit 3f64036
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { FC } from 'react';
import { AccountCountsQuery } from '../../gql/graphql';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import HC_more from 'highcharts/highcharts-more';
import { useTranslation } from 'react-i18next';
import { ChartDataItem, CustomPoint } from '../../types/types';
HC_more(Highcharts);

type Props = {
Expand All @@ -15,7 +13,7 @@ type Props = {

const AccountsAmountPlot: FC<Props> = ({ counts }) => {
const { t } = useTranslation();
const handlePointClick = (point: any) => {
const handlePointClick = (point: CustomPoint) => {
void navigator.clipboard.writeText(point.name);
};

Expand All @@ -32,7 +30,7 @@ const AccountsAmountPlot: FC<Props> = ({ counts }) => {
series: [
{
type: 'packedbubble',
data: counts.map(item => ({ name: item.id, value: item.count }))
data: counts.map((item): ChartDataItem => ({ name: item.id, value: item.count }))
}
],
legend: {
Expand All @@ -44,11 +42,9 @@ const AccountsAmountPlot: FC<Props> = ({ counts }) => {
tooltip: {
useHTML: true,
formatter: function () {
const idHash = this.point.name.startsWith('0x') ? this.point.name : '0x' + this.point.name;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const count = (this.point as any).value;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
return t('idHash', { idHash, count });
const point = this.point as CustomPoint;
const idHash = point.name.startsWith('0x') ? point.name : '0x' + point.name;
return t('idHash', { idHash, count: point.value });
}
},
plotOptions: {
Expand All @@ -57,13 +53,14 @@ const AccountsAmountPlot: FC<Props> = ({ counts }) => {
dataLabels: {
enabled: true,
formatter: function () {
return (this.point as any).value > 1000 ? `${this.point.name.substring(0, 10)}...` : '';
const point = this.point as CustomPoint;
return point.value > 1000 ? `${point.name.substring(0, 10)}...` : '';
}
},
point: {
events: {
click: function () {
handlePointClick(this);
handlePointClick(this as CustomPoint);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions apps/visualizator-fe/src/types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type ChartDataItem = {
name: string;
value: number;
};

export interface CustomPoint extends Highcharts.Point {
name: string;
value: number;
}

0 comments on commit 3f64036

Please sign in to comment.