Skip to content

Commit

Permalink
test: fix fallback for isXDomain check
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 committed Oct 11, 2021
1 parent 9822ee5 commit 8e768d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { createCustomCachedSelector } from '../../../../state/create_selector';
import { getChartRotationSelector } from '../../../../state/selectors/get_chart_rotation';
import { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs';
import { getTooltipHeaderFormatterSelector } from '../../../../state/selectors/get_tooltip_header_formatter';
import { Rotation } from '../../../../utils/common';
import { Position, Rotation } from '../../../../utils/common';
import { isValidPointerOverEvent } from '../../../../utils/events';
import { IndexedGeometry } from '../../../../utils/geometry';
import { Point } from '../../../../utils/point';
Expand Down Expand Up @@ -164,8 +164,7 @@ function getTooltipAndHighlightFromValue(
}

// format the tooltip values
const position = yAxis?.position ? yAxis?.position : xAxis?.position;
const yAxisFormatSpec = isXDomain(position!, chartRotation) ? xAxis : yAxis;
const yAxisFormatSpec = isXDomain(yAxis?.position ?? Position.Bottom, chartRotation) ? xAxis : yAxis;
const formattedTooltip = formatTooltip(
indexedGeometry,
spec,
Expand All @@ -178,7 +177,7 @@ function getTooltipAndHighlightFromValue(
// format only one time the x value
if (!header) {
// if we have a tooltipHeaderFormatter, then don't pass in the xAxis as the user will define a formatter
const xAxisFormatSpec = isXDomain(xAxis?.position ?? axesSpecs[0].position, chartRotation) ? xAxis : yAxis;
const xAxisFormatSpec = isXDomain(xAxis?.position ?? Position.Bottom, chartRotation) ? xAxis : yAxis;
const formatterAxis = tooltipHeaderFormatter ? undefined : xAxisFormatSpec;
header = formatTooltip(indexedGeometry, spec, true, false, hasSingleSeries, formatterAxis);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/charts/src/chart_types/xy_chart/state/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getPredicateFn, Predicate } from '../../../../common/predicate';
import { SeriesIdentifier, SeriesKey } from '../../../../common/series_id';
import { Scale } from '../../../../scales';
import { SettingsSpec, TickFormatter } from '../../../../specs';
import { isUniqueArray, mergePartial, Rotation } from '../../../../utils/common';
import { isUniqueArray, mergePartial, Position, Rotation } from '../../../../utils/common';
import { CurveType } from '../../../../utils/curves';
import { Dimensions, Size } from '../../../../utils/dimensions';
import {
Expand Down Expand Up @@ -349,8 +349,7 @@ function renderGeometries(

const barSeriesStyle = mergePartial(chartTheme.barSeriesStyle, spec.barSeriesStyle);
const { xAxis, yAxis } = getAxesSpecForSpecId(axesSpecs, spec.groupId, chartRotation);
const position = yAxis?.position ? yAxis?.position : xAxis?.position;
const valueFormatter = isXDomain(position!, chartRotation)
const valueFormatter = isXDomain(yAxis?.position ?? Position.Bottom, chartRotation)
? xAxis?.tickFormat ?? fallBackTickFormatter
: yAxis?.tickFormat ?? fallBackTickFormatter;

Expand Down

0 comments on commit 8e768d2

Please sign in to comment.