Skip to content

Feature request: More flexible prop setting for simplified/series #541

@huntabyte

Description

@huntabyte

For example, using a stacked AreaChart, it would be nice if there was a way to set the highlighted points/configurations on a per-series basis (without needing to override the whole highlight snippet), simply via props.

Currently, the AreaChart getHighlightProps function looks like this:

function getHighlightProps(
    s: SeriesData<TData, typeof Area>,
    i: number
  ): ComponentProps<typeof Highlight> {
    if (!context) return {};
    const seriesTooltipData =
      s.data && context.tooltip.data
        ? findRelatedData(s.data, context.tooltip.data, context.x)
        : null;
    const highlightPointsProps =
      typeof props.highlight?.points === 'object' ? props.highlight.points : null;

    return {
      data: seriesTooltipData,
      y: stackSeries ? (d) => getStackData(s, d, i)[1] : (s.value ?? (s.data ? undefined : s.key)),
      lines: i == 0,
      onPointClick: onPointClick
        ? (e, detail) => onPointClick(e, { ...detail, series: s })
        : undefined,
      onPointEnter: () => (seriesState.highlightKey.current = s.key),
      onPointLeave: () => (seriesState.highlightKey.current = null),
      ...props.highlight,
      points:
        props.highlight?.points == false
          ? false
          : {
              ...highlightPointsProps,
              fill: s.color,
              class: cls(
                'transition-opacity',
                seriesState.highlightKey.current &&
                  seriesState.highlightKey.current !== s.key &&
                  'opacity-10',
                highlightPointsProps?.class
              ),
            },
    };
  }

Perhaps we could add ...s.props.highlight and ...s.highlight.points into the mix here. This pattern would probably be useful across all the simplified component parts. I can take a shot at implementing this later this week/end!

An example use case for this would be something like having different sizes highlighted points for different series.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions