Skip to content

Commit

Permalink
refactor: decouple directly chart dependent logic from the interactio…
Browse files Browse the repository at this point in the history
…n reducer
  • Loading branch information
monfera committed Feb 6, 2021
1 parent 7137cd0 commit 7e32a70
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/state/reducers/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { ChartTypes } from '../../chart_types';
import { getPickedShapesLayerValues } from '../../chart_types/partition_chart/state/selectors/picked_shapes';
import { getSeriesIndex } from '../../chart_types/xy_chart/utils/series';
import { LegendItem } from '../../common/legend';
Expand Down Expand Up @@ -82,10 +83,9 @@ export function interactionsReducer(
},
};
case ON_MOUSE_DOWN:
const layerValues: LayerValue[] = getPickedShapesLayerValues(globalState)[0];
return {
...state,
drilldown: layerValues ? layerValues[layerValues.length - 1].path.map((n) => n.value) : [],
drilldown: getDrilldownData(globalState),
pointer: {
...state.pointer,
dragging: false,
Expand Down Expand Up @@ -174,7 +174,10 @@ export function interactionsReducer(
}
}

/** @internal */
/**
* Helper functions that currently depend on chart type eg. xy or partition
*/

function toggleDeselectedDataSeries(
{ legendItemId: id, negate }: ToggleDeselectSeriesAction,
deselectedDataSeries: SeriesIdentifier[],
Expand All @@ -199,3 +202,11 @@ function toggleDeselectedDataSeries(
}
return [...deselectedDataSeries, id];
}

function getDrilldownData(globalState: GlobalChartState) {
if (globalState.chartType !== ChartTypes.Partition) {
return [];
}
const layerValues: LayerValue[] = getPickedShapesLayerValues(globalState)[0];
return layerValues ? layerValues[layerValues.length - 1].path.map((n) => n.value) : [];
}

0 comments on commit 7e32a70

Please sign in to comment.