plotly / plotly/react-plotly.js

Can't disable sunburst default animation

Open
#331 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.1k
Forks
138
Avg merge
3d 2h
Merged PRs (30d)
4

Description

Using NextJS 13, passing onSunburstClick={() => false} to the Plot component does not disable the default behaviour of clicking in a sunburst node and zooming in to that node.

The component I'm creating:

import {
  Content,
  ContextualHelp,
  Flex,
  Heading,
  Slider,
} from '@adobe/react-spectrum';
import plotly, { Font, PlotData } from 'plotly.js';
import { useState } from 'react';
import createPlotComponent from 'react-plotly.js/factory';

const Plot = createPlotComponent(plotly);

interface SunburstPlotData extends Partial<PlotData> {
  outsidetextfont?: Partial<Font>;
  leaf?: { opacity?: number };
  maxdepth?: number;
}

// NOTE: to access the taxon id:
// e.points[0].customdata

export default function TaxonSunburst() {
  const [maxDepthValue, setMaxDepthValue] = useState<number>(3);

  const data: SunburstPlotData[] = [
    {
      type: 'sunburst',
      // NOTE: this is for the taxon names
      labels: [
        'Eve',
        'Cain',
        'Seth',
        'Enos',
        'Noam',
        'Abel',
        'Awan',
        'Enoch',
        'Azura',
      ],
      // NOTE: this is going to be used for the taxids
      customdata: [1, 2, 3, 4, 5, 6, 7, 8, 9],
      // NOTE: parent of each taxon
      parents: ['', 'Eve', 'Eve', 'Seth', 'Seth', 'Eve', 'Eve', 'Awan', 'Eve'],
      // NOTE: paper counts per taxon
      values: [10, 14, 12, 10, 2, 6, 6, 4, 4],
      outsidetextfont: { size: 20, color: '#377eb8' },
      leaf: { opacity: 0.4 },
      marker: { line: { width: 2 } },
      maxdepth: maxDepthValue,
    },
  ];

  return (
    <Flex
      direction="column"
      alignItems="center"
      marginY="size-200"
      maxWidth="100%"
    >
      <Slider
        label="Depth"
        minValue={1}
        maxValue={3}
        value={maxDepthValue}
        onChange={setMaxDepthValue}
        isFilled
        contextualHelp={
          <ContextualHelp>
            <Heading>What is depth?</Heading>
            <Content>
              Depth controls the maximum taxonomic level that is shown in the
              plot.
            </Content>
          </ContextualHelp>
        }
      />
      <Plot
        data={data}
        style={{ width: '100%' }}
        layout={{ autosize: true }}
        useResizeHandler
        onSunburstClick={() => false}
      />
    </Flex>
  );
}

In order for SSR to work properly, I'm loading the component like so (from my pages/index.tsx):

// ...
import dynamic from 'next/dynamic';
// ...

const TaxonSunburst = dynamic(import('../components/TaxonSunburst'), {
  ssr: false,
  loading: () => (
    <Flex
      justifyContent="center"
      marginY="size-200"
    >
      <ProgressCircle
        aria-label="Loading sunburst plot"
        isIndeterminate
      />
    </Flex>
  ),
});

The onClick event works properly. Also, modifying onSunburstClick with something like onSunburstClick={() => alert("test")} also works. I would like to disable the default behaviour of the sunburst plots.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Plot component's onSunburstClick handling and Plotly's sunburst click behavior. Compare it with the working onClick callback and identify a focused regression test for preventing the default zoom. Done means the callback can suppress the default sunburst behavior while still receiving the event.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.