chore(plugins/tech-radar): prettier
Signed-off-by: marcofaggian <m@marcofaggian.com>
This commit is contained in:
@@ -28,8 +28,16 @@ export type Props = {
|
||||
svgProps?: object;
|
||||
};
|
||||
|
||||
const Radar = ({ width, height, quadrants, rings, entries, ...props }: Props): JSX.Element => {
|
||||
const [adjustedQuadrants, setAdjustedQuadrants] = useState<Array<Quadrant>>(quadrants);
|
||||
const Radar = ({
|
||||
width,
|
||||
height,
|
||||
quadrants,
|
||||
rings,
|
||||
entries,
|
||||
...props
|
||||
}: Props): JSX.Element => {
|
||||
const [adjustedQuadrants, setAdjustedQuadrants] =
|
||||
useState<Array<Quadrant>>(quadrants);
|
||||
const [adjustedRings, setAdjustedRings] = useState<Array<Ring>>(rings);
|
||||
const [adjustedEntries, setAdjustedEntries] = useState<Array<Entry>>(entries);
|
||||
|
||||
@@ -40,15 +48,23 @@ const Radar = ({ width, height, quadrants, rings, entries, ...props }: Props): J
|
||||
|
||||
useEffect(() => {
|
||||
setAdjustedQuadrants(adjustQuadrants(quadrants, radius, width, height));
|
||||
}, [quadrants, radius, width, height])
|
||||
}, [quadrants, radius, width, height]);
|
||||
|
||||
useEffect(() => {
|
||||
setAdjustedRings(adjustRings(rings, radius));
|
||||
}, [radius, rings])
|
||||
}, [radius, rings]);
|
||||
|
||||
useEffect(() => {
|
||||
setAdjustedEntries(adjustEntries(entries, adjustedQuadrants, adjustedRings, radius, activeEntry));
|
||||
}, [entries, adjustedQuadrants, adjustedRings, radius, activeEntry])
|
||||
setAdjustedEntries(
|
||||
adjustEntries(
|
||||
entries,
|
||||
adjustedQuadrants,
|
||||
adjustedRings,
|
||||
radius,
|
||||
activeEntry,
|
||||
),
|
||||
);
|
||||
}, [entries, adjustedQuadrants, adjustedRings, radius, activeEntry]);
|
||||
|
||||
return (
|
||||
<svg ref={node} width={width} height={height} {...props.svgProps}>
|
||||
|
||||
@@ -84,7 +84,7 @@ export const adjustQuadrants = (
|
||||
return quadrants.slice().map((quadrant, index) => {
|
||||
const legendParam = legendParams[index % 4];
|
||||
|
||||
return ({
|
||||
return {
|
||||
...quadrant,
|
||||
index,
|
||||
radialMin: (index * Math.PI) / 2,
|
||||
@@ -94,8 +94,8 @@ export const adjustQuadrants = (
|
||||
legendX: legendParam.x,
|
||||
legendY: legendParam.y,
|
||||
legendWidth: legendParam.width,
|
||||
legendHeight: legendParam.height
|
||||
})
|
||||
legendHeight: legendParam.height,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -126,10 +126,10 @@ export const adjustEntries = (
|
||||
if (!ring) {
|
||||
throw new Error(`Unknown ring ${entry.ring} for entry ${entry.id}!`);
|
||||
}
|
||||
const segment = new Segment(quadrant, ring, radius, () => seed++)
|
||||
const segment = new Segment(quadrant, ring, radius, () => seed++);
|
||||
const point = segment?.random();
|
||||
|
||||
return ({
|
||||
return {
|
||||
...entry,
|
||||
index: index,
|
||||
quadrant: quadrant,
|
||||
@@ -137,10 +137,11 @@ export const adjustEntries = (
|
||||
segment,
|
||||
x: point.x,
|
||||
y: point.y,
|
||||
color: activeEntry && entry.id === activeEntry?.id
|
||||
? entry.ring.color
|
||||
: color(entry.ring.color).desaturate(0.5).lighten(0.1).string(),
|
||||
})
|
||||
color:
|
||||
activeEntry && entry.id === activeEntry?.id
|
||||
? entry.ring.color
|
||||
: color(entry.ring.color).desaturate(0.5).lighten(0.1).string(),
|
||||
};
|
||||
});
|
||||
|
||||
const simulation = forceSimulation()
|
||||
@@ -151,9 +152,9 @@ export const adjustEntries = (
|
||||
|
||||
for (
|
||||
let i = 0,
|
||||
n = Math.ceil(
|
||||
Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay()),
|
||||
);
|
||||
n = Math.ceil(
|
||||
Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay()),
|
||||
);
|
||||
i < n;
|
||||
++i
|
||||
) {
|
||||
@@ -167,12 +168,13 @@ export const adjustEntries = (
|
||||
}
|
||||
}
|
||||
|
||||
return entries
|
||||
return entries;
|
||||
};
|
||||
|
||||
export const adjustRings = (rings: Ring[], radius: number) => rings.slice().map((ring, index) => ({
|
||||
...ring,
|
||||
index,
|
||||
outerRadius: ((index + 2) / (rings.length + 1)) * radius,
|
||||
innerRadius: ((index === 0 ? 0 : index + 1) / (rings.length + 1)) * radius
|
||||
}))
|
||||
export const adjustRings = (rings: Ring[], radius: number) =>
|
||||
rings.slice().map((ring, index) => ({
|
||||
...ring,
|
||||
index,
|
||||
outerRadius: ((index + 2) / (rings.length + 1)) * radius,
|
||||
innerRadius: ((index === 0 ? 0 : index + 1) / (rings.length + 1)) * radius,
|
||||
}));
|
||||
|
||||
@@ -19,7 +19,6 @@ import { RadarLegendQuadrant } from './RadarLegendQuadrant';
|
||||
import { RadarLegendProps } from './types';
|
||||
import { setupSegments } from './utils';
|
||||
|
||||
|
||||
const useStyles = makeStyles<Theme>(theme => ({
|
||||
quadrant: {
|
||||
height: '100%',
|
||||
@@ -81,8 +80,7 @@ const RadarLegend = ({
|
||||
onEntryMouseEnter,
|
||||
onEntryMouseLeave,
|
||||
...props
|
||||
}: RadarLegendProps
|
||||
): JSX.Element => {
|
||||
}: RadarLegendProps): JSX.Element => {
|
||||
const classes = useStyles(props);
|
||||
|
||||
return (
|
||||
|
||||
@@ -13,23 +13,23 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ClassNameMap } from "@material-ui/core/styles/withStyles";
|
||||
import React from "react";
|
||||
import { WithLink } from "../../utils/components";
|
||||
import { RadarDescription } from "../RadarDescription";
|
||||
import { ClassNameMap } from '@material-ui/core/styles/withStyles';
|
||||
import React from 'react';
|
||||
import { WithLink } from '../../utils/components';
|
||||
import { RadarDescription } from '../RadarDescription';
|
||||
|
||||
type RadarLegendLinkProps = {
|
||||
url?: string;
|
||||
description?: string;
|
||||
title?: string;
|
||||
classes: ClassNameMap<string>
|
||||
classes: ClassNameMap<string>;
|
||||
};
|
||||
|
||||
export const RadarLegendLink = ({
|
||||
url,
|
||||
description,
|
||||
title,
|
||||
classes
|
||||
classes,
|
||||
}: RadarLegendLinkProps) => {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
||||
|
||||
@@ -14,20 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ClassNameMap } from "@material-ui/core/styles/withStyles";
|
||||
import React from "react";
|
||||
import { Quadrant, Ring } from "../../utils/types";
|
||||
import { RadarLegendRing } from "./RadarLegendRing";
|
||||
import { RadarLegendProps, Segments } from "./types";
|
||||
import { getSegment } from "./utils";
|
||||
|
||||
|
||||
import { ClassNameMap } from '@material-ui/core/styles/withStyles';
|
||||
import React from 'react';
|
||||
import { Quadrant, Ring } from '../../utils/types';
|
||||
import { RadarLegendRing } from './RadarLegendRing';
|
||||
import { RadarLegendProps, Segments } from './types';
|
||||
import { getSegment } from './utils';
|
||||
|
||||
type RadarLegendQuadrantProps = {
|
||||
segments: Segments;
|
||||
quadrant: Quadrant;
|
||||
rings: Ring[];
|
||||
classes: ClassNameMap<string>,
|
||||
classes: ClassNameMap<string>;
|
||||
onEntryMouseEnter: RadarLegendProps['onEntryMouseEnter'];
|
||||
onEntryMouseLeave: RadarLegendProps['onEntryMouseLeave'];
|
||||
};
|
||||
@@ -66,4 +64,4 @@ export const RadarLegendQuadrant = ({
|
||||
</div>
|
||||
</foreignObject>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ClassNameMap } from "@material-ui/core/styles/withStyles";
|
||||
import React from "react";
|
||||
import { Entry, Ring } from "../../utils/types";
|
||||
import { RadarLegendLink } from "./RadarLegendLink";
|
||||
import { RadarLegendProps } from "./types";
|
||||
import { ClassNameMap } from '@material-ui/core/styles/withStyles';
|
||||
import React from 'react';
|
||||
import { Entry, Ring } from '../../utils/types';
|
||||
import { RadarLegendLink } from './RadarLegendLink';
|
||||
import { RadarLegendProps } from './types';
|
||||
|
||||
type RadarLegendRingProps = {
|
||||
ring: Ring;
|
||||
@@ -64,4 +64,4 @@ export const RadarLegendRing = ({
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entry, Quadrant, Ring } from "../../utils/types";
|
||||
import { Entry, Quadrant, Ring } from '../../utils/types';
|
||||
|
||||
export type Segments = {
|
||||
[k: number]: { [k: number]: Entry[] };
|
||||
@@ -26,4 +26,4 @@ export type RadarLegendProps = {
|
||||
entries: Entry[];
|
||||
onEntryMouseEnter?: (entry: Entry) => void;
|
||||
onEntryMouseLeave?: (entry: Entry) => void;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entry, Quadrant, Ring } from "../../utils/types";
|
||||
import { Segments } from "./types";
|
||||
import { Entry, Quadrant, Ring } from '../../utils/types';
|
||||
import { Segments } from './types';
|
||||
|
||||
export const setupSegments = (entries: Entry[]) => {
|
||||
const segments: Segments = {};
|
||||
@@ -60,4 +60,4 @@ export const getSegment = (
|
||||
return ringIndex === undefined
|
||||
? []
|
||||
: segmentedData[ringIndex + ringOffset] || [];
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user