Skip to content

Commit

Permalink
♻️ Reuse shared functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Jun 9, 2022
1 parent a075626 commit f931f54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function hasNumericHistogramDimension(
}

/**
* Finds the table data min and max
* Finds the table data min and max. Returns undefined when no min/max is found
* @param layerId
* @param tables
* @param columnId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { AxisExtentConfig } from '@kbn/expression-xy-plugin/common';
import { Datatable } from '@kbn/expressions-plugin/public';
import type { IFieldFormat, SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
import { FormatFactory } from '../../common';
import { validateAxisDomain, validateZeroInclusivityExtent } from '../shared_components';
import {
getDataBounds,
validateAxisDomain,
validateZeroInclusivityExtent,
} from '../shared_components';
import { XYDataLayerConfig } from './types';

interface FormattedMetric {
Expand All @@ -35,14 +39,11 @@ export function isFormatterCompatible(
export function getXDomain(layers: XYDataLayerConfig[] = [], tables?: Record<string, Datatable>) {
const dataBounds = layers.reduce(
(bounds, layer) => {
const table = tables?.[layer.layerId];
if (layer.xAccessor && table) {
const sortedRows = table.rows
.map(({ [layer.xAccessor!]: xValue }) => xValue)
.sort((a, b) => a - b);
const tableBounds = getDataBounds(layer.layerId, tables, layer.xAccessor);
if (tableBounds) {
return {
min: Math.min(bounds.min, sortedRows[0]),
max: Math.max(bounds.max, sortedRows[sortedRows.length - 1]),
min: Math.min(bounds.min, tableBounds.min),
max: Math.max(bounds.max, tableBounds.max),
};
}
return bounds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { LegendSize } from '@kbn/visualizations-plugin/public';
import type { VisualizationToolbarProps, FramePublicAPI } from '../../types';
import { State, XYState } from '../types';
import { isHorizontalChart } from '../state_helpers';
import { LegendSettingsPopover } from '../../shared_components';
import { hasNumericHistogramDimension, LegendSettingsPopover } from '../../shared_components';
import { AxisSettingsPopover } from './axis_settings_popover';
import { getAxesConfiguration, getXDomain, GroupsConfiguration } from '../axes_configuration';
import { VisualOptionsPopover } from './visual_options_popover';
import { getScaleType } from '../to_expression';
import { TooltipWrapper } from '../../shared_components';
import { getDefaultVisualValuesForLayer } from '../../shared_components/datasource_default_values';
import { checkScaleOperation, getDataLayers } from '../visualization_helpers';
import { getDataLayers } from '../visualization_helpers';
import { LegendSettingsPopoverProps } from '../../shared_components/legend_settings_popover';

type UnwrapArray<T> = T extends Array<infer P> ? P : T;
Expand Down Expand Up @@ -299,8 +299,8 @@ export const XyToolbar = memo(function XyToolbar(
}
);

const hasNumberHistogram = dataLayers.some(
checkScaleOperation('interval', 'number', props.frame.datasourceLayers)
const hasNumberHistogram = dataLayers.some(({ layerId, xAccessor }) =>
hasNumericHistogramDimension(props.frame.datasourceLayers[layerId], xAccessor)
);

// Ask the datasource if it has a say about default truncation value
Expand Down

0 comments on commit f931f54

Please sign in to comment.