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

Tooltip in XYChart - a way to make it compatible for mobile/touch devices #1784

Open
mamo-muj opened this issue Jan 9, 2024 · 0 comments
Open

Comments

@mamo-muj
Copy link

mamo-muj commented Jan 9, 2024

Hi there, I'm currently using Tooltip but from XYChart. It works great with mouse, however, when you tap on a bar or line on mobile devices, the tooltip disappears. Is there a way to avoid this from happening?

As far as I understand, it's a mouse trigger so it probably doesn't work the same way for that reason. I do have some bandaid code applied by using the Annotation component butI'm sure there's better ways of executing this. Sharing a snippet of code below

{isAnnotationPresented && (isMobile || isTablet) && (
  <Annotation
    dataKey={annotationDataKey}
    datum={data[annotationDataIndex]}
    dx={dynamicDx}
    dy={dynamicDy}
  >
    <AnnotationLabel
      title={
        hasCurrencyInTooltip
          ? `AED ${convertToLocaleStringHelper(
              yAccessor(annotationDatum),
            )}`
          : hasPercentageInTooltip
          ? `${yAccessor(annotationDatum)}%`
          : yAccessor(annotationDatum)
      }
      subtitle={tooltipSubtext(annotationDatum)}
      showAnchorLine={false}
      width={175}
      backgroundFill={colors.black[400]}
      backgroundProps={{
        fillOpacity: 1,
        rx: 12,
      }}
      titleProps={{
        style: {
          fill: colors.white,
          fontFamily: "CircularXXWeb-Medium",
          fontWeight: "unset",
          fontSize: 14,
        },
      }}
      subtitleProps={{
        style: {
          fill: colors.black[200],
          fontFamily: "CircularXXWeb-Regular",
          fontWeight: "unset",
          fontSize: 14,
        },
      }}
      backgroundPadding={{
        top: 12,
        right: 16,
        bottom: 12,
        left: 16,
      }}
    />
  </Annotation>
)}
{isLaptop && (
  <Tooltip
    snapTooltipToDatumX
    snapTooltipToDatumY
    style={tooltipStyles}
    renderTooltip={({ tooltipData }) => {
      return (
        <div>
          {Object.entries(tooltipData.datumByKey).map(lineDataArray => {
            const [key, value] = lineDataArray;

            return (
              <div className={sharedTooltipClasses("top")} key={key}>
                {hasCurrencyInTooltip ? (
                  <span className="font-medium">
                    AED{" "}
                    {convertToLocaleStringHelper(
                      yAccessor(value.datum as any),
                    )}
                  </span>
                ) : hasPercentageInTooltip ? (
                  <span className="font-medium">
                    {yAccessor(value.datum as any)}%
                  </span>
                ) : (
                  <span className="font-medium">
                    {yAccessor(value.datum as any)}
                  </span>
                )}

                {tooltipSubtext && (
                  <span className="text-black-200">
                    {tooltipSubtext(value.datum)}
                  </span>
                )}
              </div>
            );
          })}
        </div>
      );
    }}
  />
)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant