Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmadom committed Oct 10, 2024
1 parent 3a28b47 commit c86ff6b
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 70 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"@gravity-ui/eslint-config/import-order"
],
"rules": {
"valid-jsdoc": 0
"valid-jsdoc": 0,
"no-console": ["error", {"allow": ["warn", "error"]}]
},
"root": true,
"overrides": [{
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/d3/renderer/hooks/useSeries/prepare-bar-y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ function prepareDataLabels(series: BarYSeries) {
});
const inside = series.stacking === 'percent' ? true : get(series, 'dataLabels.inside', false);

console.log('prepareDataLabels', {maxWidth});

return {
enabled,
inside,
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/d3/renderer/hooks/useShapes/HtmlLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ import React from 'react';

import {Portal} from '@gravity-ui/uikit';

import {HtmlItem} from '../../types';
import {HtmlItem, ShapeDataWithHtmlItems} from '../../types';

type Props = {
htmlLayout: HTMLElement | null;
items: HtmlItem[];
preparedData: ShapeDataWithHtmlItems | ShapeDataWithHtmlItems[];
};

export const HtmlLayer = (props: Props) => {
const {items, htmlLayout} = props;
const {htmlLayout, preparedData} = props;

const items = React.useMemo(() => {
if (Array.isArray(preparedData)) {
return preparedData.reduce<HtmlItem[]>((result, d) => {
result.push(...d.htmlElements);
return result;
}, []);
} else {
return preparedData.htmlElements;
}
}, [preparedData]);

if (!htmlLayout) {
return null;
Expand Down
10 changes: 1 addition & 9 deletions src/plugins/d3/renderer/hooks/useShapes/area/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import get from 'lodash/get';
import type {TooltipDataChunkArea} from '../../../../../../types';
import {block} from '../../../../../../utils/cn';
import type {LabelData} from '../../../types';
import {HtmlItem} from '../../../types';
import {filterOverlappingLabels} from '../../../utils';
import type {PreparedSeriesOptions} from '../../useSeries/types';
import {HtmlLayer} from '../HtmlLayer';
Expand Down Expand Up @@ -37,13 +36,6 @@ export const AreaSeriesShapes = (args: Args) => {

const ref = React.useRef<SVGGElement | null>(null);

const htmlItems = React.useMemo(() => {
return preparedData.reduce<HtmlItem[]>((result, d) => {
result.push(...d.htmlElements);
return result;
}, []);
}, [preparedData]);

React.useEffect(() => {
if (!ref.current) {
return () => {};
Expand Down Expand Up @@ -205,7 +197,7 @@ export const AreaSeriesShapes = (args: Args) => {
return (
<React.Fragment>
<g ref={ref} className={b()} />
<HtmlLayer items={htmlItems} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
</React.Fragment>
);
};
11 changes: 2 additions & 9 deletions src/plugins/d3/renderer/hooks/useShapes/bar-x/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {Dispatch} from 'd3';
import get from 'lodash/get';

import {block} from '../../../../../../utils/cn';
import {HtmlItem, LabelData} from '../../../types';
import {LabelData} from '../../../types';
import {filterOverlappingLabels} from '../../../utils';
import type {PreparedSeriesOptions} from '../../useSeries/types';
import {HtmlLayer} from '../HtmlLayer';
Expand All @@ -29,13 +29,6 @@ export const BarXSeriesShapes = (args: Args) => {

const ref = React.useRef<SVGGElement>(null);

const htmlItems = React.useMemo(() => {
return preparedData.reduce<HtmlItem[]>((result, d) => {
result.push(...d.htmlElements);
return result;
}, []);
}, [preparedData]);

React.useEffect(() => {
if (!ref.current) {
return () => {};
Expand Down Expand Up @@ -132,7 +125,7 @@ export const BarXSeriesShapes = (args: Args) => {
return (
<React.Fragment>
<g ref={ref} className={b()} />
<HtmlLayer items={htmlItems} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
</React.Fragment>
);
};
11 changes: 2 additions & 9 deletions src/plugins/d3/renderer/hooks/useShapes/bar-y/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {Dispatch} from 'd3';
import get from 'lodash/get';

import {block} from '../../../../../../utils/cn';
import {HtmlItem, LabelData} from '../../../types';
import {LabelData} from '../../../types';
import type {PreparedSeriesOptions} from '../../useSeries/types';
import {HtmlLayer} from '../HtmlLayer';

Expand All @@ -25,13 +25,6 @@ export const BarYSeriesShapes = (args: Args) => {
const {dispatcher, preparedData, seriesOptions, htmlLayout} = args;
const ref = React.useRef<SVGGElement>(null);

const htmlItems = React.useMemo(() => {
return preparedData.reduce<HtmlItem[]>((result, d) => {
result.push(...d.htmlElements);
return result;
}, []);
}, [preparedData]);

React.useEffect(() => {
if (!ref.current) {
return () => {};
Expand Down Expand Up @@ -117,7 +110,7 @@ export const BarYSeriesShapes = (args: Args) => {
return (
<React.Fragment>
<g ref={ref} className={b()} />
<HtmlLayer items={htmlItems} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
</React.Fragment>
);
};
9 changes: 1 addition & 8 deletions src/plugins/d3/renderer/hooks/useShapes/line/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import get from 'lodash/get';
import type {TooltipDataChunkLine} from '../../../../../../types';
import {block} from '../../../../../../utils/cn';
import type {LabelData} from '../../../types';
import {HtmlItem} from '../../../types';
import {filterOverlappingLabels} from '../../../utils';
import type {PreparedSeriesOptions} from '../../useSeries/types';
import {HtmlLayer} from '../HtmlLayer';
Expand Down Expand Up @@ -36,12 +35,6 @@ export const LineSeriesShapes = (args: Args) => {
const {dispatcher, preparedData, seriesOptions, htmlLayout} = args;

const ref = React.useRef<SVGGElement>(null);
const htmlItems = React.useMemo(() => {
return preparedData.reduce<HtmlItem[]>((result, d) => {
result.push(...d.htmlElements);
return result;
}, []);
}, [preparedData]);

React.useEffect(() => {
if (!ref.current) {
Expand Down Expand Up @@ -191,7 +184,7 @@ export const LineSeriesShapes = (args: Args) => {
return (
<React.Fragment>
<g ref={ref} className={b()} />
<HtmlLayer items={htmlItems} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
</React.Fragment>
);
};
10 changes: 1 addition & 9 deletions src/plugins/d3/renderer/hooks/useShapes/pie/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import get from 'lodash/get';

import {TooltipDataChunkPie} from '../../../../../../types';
import {block} from '../../../../../../utils/cn';
import {HtmlItem} from '../../../types';
import {setEllipsisForOverflowTexts} from '../../../utils';
import {PreparedSeriesOptions} from '../../useSeries/types';
import {HtmlLayer} from '../HtmlLayer';
Expand All @@ -33,13 +32,6 @@ export function PieSeriesShapes(args: PreparePieSeriesArgs) {
const {dispatcher, preparedData, seriesOptions, htmlLayout} = args;
const ref = React.useRef<SVGGElement | null>(null);

const htmlItems = React.useMemo(() => {
return preparedData.reduce<HtmlItem[]>((result, d) => {
result.push(...d.htmlElements);
return result;
}, []);
}, [preparedData]);

React.useEffect(() => {
if (!ref.current) {
return () => {};
Expand Down Expand Up @@ -229,7 +221,7 @@ export function PieSeriesShapes(args: PreparePieSeriesArgs) {
return (
<React.Fragment>
<g ref={ref} className={b()} style={{zIndex: 9}} />
<HtmlLayer items={htmlItems} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
</React.Fragment>
);
}
9 changes: 1 addition & 8 deletions src/plugins/d3/renderer/hooks/useShapes/scatter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import get from 'lodash/get';

import {TooltipDataChunkScatter} from '../../../../../../types';
import {block} from '../../../../../../utils/cn';
import {HtmlItem} from '../../../types';
import {PreparedSeriesOptions} from '../../useSeries/types';
import {HtmlLayer} from '../HtmlLayer';
import {
Expand All @@ -33,12 +32,6 @@ const b = block('d3-scatter');
export function ScatterSeriesShape(props: ScatterSeriesShapeProps) {
const {dispatcher, preparedData, seriesOptions, htmlLayout} = props;
const ref = React.useRef<SVGGElement>(null);
const htmlItems = React.useMemo(() => {
return preparedData.reduce<HtmlItem[]>((result, d) => {
result.push(...d.htmlElements);
return result;
}, []);
}, [preparedData]);

React.useEffect(() => {
if (!ref.current) {
Expand Down Expand Up @@ -111,7 +104,7 @@ export function ScatterSeriesShape(props: ScatterSeriesShapeProps) {
return (
<React.Fragment>
<g ref={ref} className={b()} />
<HtmlLayer items={htmlItems} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
</React.Fragment>
);
}
5 changes: 1 addition & 4 deletions src/plugins/d3/renderer/hooks/useShapes/treemap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ type ShapeProps = {
export const TreemapSeriesShape = (props: ShapeProps) => {
const {dispatcher, preparedData, seriesOptions, htmlLayout} = props;
const ref = React.useRef<SVGGElement>(null);
const htmlItems = React.useMemo(() => {
return preparedData.htmlElements ?? [];
}, [preparedData]);

React.useEffect(() => {
if (!ref.current) {
Expand Down Expand Up @@ -126,7 +123,7 @@ export const TreemapSeriesShape = (props: ShapeProps) => {
return (
<React.Fragment>
<g ref={ref} className={b()} />
<HtmlLayer items={htmlItems} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
</React.Fragment>
);
};
9 changes: 1 addition & 8 deletions src/plugins/d3/renderer/hooks/useShapes/waterfall/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import get from 'lodash/get';
import {DashStyle} from '../../../../../../constants';
import {block} from '../../../../../../utils/cn';
import type {LabelData} from '../../../types';
import {HtmlItem} from '../../../types';
import {filterOverlappingLabels, getWaterfallPointColor} from '../../../utils';
import type {PreparedSeriesOptions} from '../../useSeries/types';
import {HtmlLayer} from '../HtmlLayer';
Expand All @@ -32,12 +31,6 @@ export const WaterfallSeriesShapes = (args: Args) => {

const ref = React.useRef<SVGGElement | null>(null);
const connectorSelector = `.${b('connector')}`;
const htmlItems = React.useMemo(() => {
return preparedData.reduce<HtmlItem[]>((result, d) => {
result.push(...d.htmlElements);
return result;
}, []);
}, [preparedData]);

React.useEffect(() => {
if (!ref.current) {
Expand Down Expand Up @@ -165,7 +158,7 @@ export const WaterfallSeriesShapes = (args: Args) => {
return (
<React.Fragment>
<g ref={ref} className={b()} />
<HtmlLayer items={htmlItems} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
</React.Fragment>
);
};
4 changes: 4 additions & 0 deletions src/plugins/d3/renderer/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export type HtmlItem = {
y: number;
content: string;
};

export type ShapeDataWithHtmlItems = {
htmlElements: HtmlItem[];
};

0 comments on commit c86ff6b

Please sign in to comment.