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

Use unique id for tooltip. #413

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Changes from all commits
Commits
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
24 changes: 12 additions & 12 deletions src/components/Polystat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Polystat: React.FC<PolystatOptions> = (options) => {
const [animatedItems, setAnimatedItems] = React.useState<number[]>([]);
const margin = { top: 0, right: 0, bottom: 0, left: 0 };
// this MUST be unique for gradients to work properly
const [gradientId] = React.useState<string>(`polystat_${options.panelId}_` + Math.floor(Math.random() * 10000).toString());
const [uniquePanelId] = React.useState<string>(`polystat_${options.panelId}_` + Math.floor(Math.random() * 10000).toString());

const updateAnimation = (data: PolystatModel[]) => {
if (data.length > 0) {
Expand Down Expand Up @@ -308,7 +308,7 @@ export const Polystat: React.FC<PolystatOptions> = (options) => {
let fillColor = options.processedData![index].color;
if (options.globalGradientsEnabled) {
// TODO: safari needs the location.href
fillColor = `url(#${gradientId}_linear_gradient_state_data_${index})`;
fillColor = `url(#${uniquePanelId}_linear_gradient_state_data_${index})`;
}
const useRadius = lm.generateRadius(options.globalShape);
const coords = getCoords(index);
Expand All @@ -317,11 +317,11 @@ export const Polystat: React.FC<PolystatOptions> = (options) => {
case PolygonShapes.HEXAGON_POINTED_TOP:
return (
<path
data-tooltip-id={options.globalTooltipsEnabled ? `polystat-tooltip-${options.panelId}` : null}
data-tooltip-id={options.globalTooltipsEnabled ? `polystat-tooltip-${uniquePanelId}` : null}
data-tooltip-content={index}
data-tooltip-position-strategy='fixed'
className={svgPathStyles}
key={`polystat-tooltip-${options.panelId}`}
key={`polystat-tooltip-${uniquePanelId}`}
transform={`translate(${coords.x}, ${coords.y})`}
d={customShape}
fill={fillColor}
Expand All @@ -332,10 +332,10 @@ export const Polystat: React.FC<PolystatOptions> = (options) => {
case PolygonShapes.CIRCLE:
return (
<circle
data-tooltip-id={options.globalTooltipsEnabled ? `polystat-tooltip-${options.panelId}` : null}
data-tooltip-id={options.globalTooltipsEnabled ? `polystat-tooltip-${uniquePanelId}` : null}
data-tooltip-content={index}
data-tooltip-position-strategy='fixed'
key={`polystat-tooltip-${options.panelId}`}
key={`polystat-tooltip-${uniquePanelId}`}
className={svgPathStyles}
cx={coords.x}
cy={coords.y}
Expand All @@ -346,10 +346,10 @@ export const Polystat: React.FC<PolystatOptions> = (options) => {
case PolygonShapes.SQUARE:
return (
<rect
data-tooltip-id={options.globalTooltipsEnabled ? `polystat-tooltip-${options.panelId}` : null}
data-tooltip-id={options.globalTooltipsEnabled ? `polystat-tooltip-${uniquePanelId}` : null}
data-tooltip-content={index}
data-tooltip-position-strategy='fixed'
key={`polystat-tooltip-${options.panelId}`}
key={`polystat-tooltip-${uniquePanelId}`}
className={svgPathStyles}
x={coords.x}
y={coords.y}
Expand All @@ -361,11 +361,11 @@ export const Polystat: React.FC<PolystatOptions> = (options) => {
default:
return (
<path
data-tooltip-id={options.globalTooltipsEnabled ? `polystat-tooltip-${options.panelId}` : null}
data-tooltip-id={options.globalTooltipsEnabled ? `polystat-tooltip-${uniquePanelId}` : null}
data-tooltip-content={index}
data-tooltip-position-strategy='fixed'
className={svgPathStyles}
key={`polystat-tooltip-${options.panelId}`}
key={`polystat-tooltip-${uniquePanelId}`}
transform={`translate(${coords.x}, ${coords.y})`}
d={customShape}
fill={fillColor}
Expand Down Expand Up @@ -555,7 +555,7 @@ export const Polystat: React.FC<PolystatOptions> = (options) => {
>

<g transform={`translate(${marginLeft},${marginTop})`}>
<Gradients gradientId={gradientId} data={options.processedData} />
<Gradients gradientId={uniquePanelId} data={options.processedData} />

{options.processedData!.map((item, index) => {
const coords = getCoords(index);
Expand Down Expand Up @@ -594,7 +594,7 @@ export const Polystat: React.FC<PolystatOptions> = (options) => {
style={{
boxShadow: 'rgba(1, 4, 9, 0.75) 0px 4px 8px 0px',
}}
id={options.globalTooltipsEnabled ? `polystat-tooltip-${options.panelId}` : undefined}
id={options.globalTooltipsEnabled ? `polystat-tooltip-${uniquePanelId}` : undefined}
place={'bottom'} // TODO: make this configurable
float={true}
variant={tooltipTheme} // TODO: this could be made configurable (auto, or specified)
Expand Down
Loading