| 1 | import { createSelector } from 'reselect';
|
|---|
| 2 | import { selectAxisWithScale, selectCartesianAxisSize, selectStackGroups, selectTicksOfGraphicalItem, selectUnfilteredCartesianItems } from './axisSelectors';
|
|---|
| 3 | import { isNullish } from '../../util/DataUtils';
|
|---|
| 4 | import { getBandSizeOfAxis } from '../../util/ChartUtils';
|
|---|
| 5 | import { computeBarRectangles } from '../../cartesian/Bar';
|
|---|
| 6 | import { selectChartLayout } from '../../context/chartLayoutContext';
|
|---|
| 7 | import { selectChartDataWithIndexesIfNotInPanoramaPosition3 } from './dataSelectors';
|
|---|
| 8 | import { selectAxisViewBox, selectChartOffsetInternal } from './selectChartOffsetInternal';
|
|---|
| 9 | import { selectBarCategoryGap, selectBarGap, selectRootBarSize, selectRootMaxBarSize } from './rootPropsSelectors';
|
|---|
| 10 | import { combineBarSizeList } from './combiners/combineBarSizeList';
|
|---|
| 11 | import { combineAllBarPositions } from './combiners/combineAllBarPositions';
|
|---|
| 12 | import { combineStackedData } from './combiners/combineStackedData';
|
|---|
| 13 | import { selectXAxisIdFromGraphicalItemId, selectYAxisIdFromGraphicalItemId } from './graphicalItemSelectors';
|
|---|
| 14 | import { combineBarPosition } from './combiners/combineBarPosition';
|
|---|
| 15 | var pickIsPanorama = (_state, _id, isPanorama) => isPanorama;
|
|---|
| 16 | var pickBarId = (_state, id) => id;
|
|---|
| 17 | var selectSynchronisedBarSettings = createSelector([selectUnfilteredCartesianItems, pickBarId], (graphicalItems, id) => graphicalItems.filter(item => item.type === 'bar').find(item => item.id === id));
|
|---|
| 18 | export var selectMaxBarSize = createSelector([selectSynchronisedBarSettings], barSettings => barSettings === null || barSettings === void 0 ? void 0 : barSettings.maxBarSize);
|
|---|
| 19 | var pickCells = (_state, _id, _isPanorama, cells) => cells;
|
|---|
| 20 | export var selectAllVisibleBars = createSelector([selectChartLayout, selectUnfilteredCartesianItems, selectXAxisIdFromGraphicalItemId, selectYAxisIdFromGraphicalItemId, pickIsPanorama], (layout, allItems, xAxisId, yAxisId, isPanorama) => allItems.filter(i => {
|
|---|
| 21 | if (layout === 'horizontal') {
|
|---|
| 22 | return i.xAxisId === xAxisId;
|
|---|
| 23 | }
|
|---|
| 24 | return i.yAxisId === yAxisId;
|
|---|
| 25 | }).filter(i => i.isPanorama === isPanorama).filter(i => i.hide === false).filter(i => i.type === 'bar'));
|
|---|
| 26 | var selectBarStackGroups = (state, id, isPanorama) => {
|
|---|
| 27 | var layout = selectChartLayout(state);
|
|---|
| 28 | var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
|
|---|
| 29 | var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
|
|---|
| 30 | if (xAxisId == null || yAxisId == null) {
|
|---|
| 31 | return undefined;
|
|---|
| 32 | }
|
|---|
| 33 | if (layout === 'horizontal') {
|
|---|
| 34 | return selectStackGroups(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 35 | }
|
|---|
| 36 | return selectStackGroups(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 37 | };
|
|---|
| 38 | export var selectBarCartesianAxisSize = (state, id) => {
|
|---|
| 39 | var layout = selectChartLayout(state);
|
|---|
| 40 | var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
|
|---|
| 41 | var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
|
|---|
| 42 | if (xAxisId == null || yAxisId == null) {
|
|---|
| 43 | return undefined;
|
|---|
| 44 | }
|
|---|
| 45 | if (layout === 'horizontal') {
|
|---|
| 46 | return selectCartesianAxisSize(state, 'xAxis', xAxisId);
|
|---|
| 47 | }
|
|---|
| 48 | return selectCartesianAxisSize(state, 'yAxis', yAxisId);
|
|---|
| 49 | };
|
|---|
| 50 | export var selectBarSizeList = createSelector([selectAllVisibleBars, selectRootBarSize, selectBarCartesianAxisSize], combineBarSizeList);
|
|---|
| 51 | export var selectBarBandSize = (state, id, isPanorama) => {
|
|---|
| 52 | var _ref, _getBandSizeOfAxis;
|
|---|
| 53 | var barSettings = selectSynchronisedBarSettings(state, id);
|
|---|
| 54 | if (barSettings == null) {
|
|---|
| 55 | return 0;
|
|---|
| 56 | }
|
|---|
| 57 | var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
|
|---|
| 58 | var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
|
|---|
| 59 | if (xAxisId == null || yAxisId == null) {
|
|---|
| 60 | return 0;
|
|---|
| 61 | }
|
|---|
| 62 | var layout = selectChartLayout(state);
|
|---|
| 63 | var globalMaxBarSize = selectRootMaxBarSize(state);
|
|---|
| 64 | var {
|
|---|
| 65 | maxBarSize: childMaxBarSize
|
|---|
| 66 | } = barSettings;
|
|---|
| 67 | var maxBarSize = isNullish(childMaxBarSize) ? globalMaxBarSize : childMaxBarSize;
|
|---|
| 68 | var axis, ticks;
|
|---|
| 69 | if (layout === 'horizontal') {
|
|---|
| 70 | axis = selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 71 | ticks = selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 72 | } else {
|
|---|
| 73 | axis = selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 74 | ticks = selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 75 | }
|
|---|
| 76 | return (_ref = (_getBandSizeOfAxis = getBandSizeOfAxis(axis, ticks, true)) !== null && _getBandSizeOfAxis !== void 0 ? _getBandSizeOfAxis : maxBarSize) !== null && _ref !== void 0 ? _ref : 0;
|
|---|
| 77 | };
|
|---|
| 78 | export var selectAxisBandSize = (state, id, isPanorama) => {
|
|---|
| 79 | var layout = selectChartLayout(state);
|
|---|
| 80 | var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
|
|---|
| 81 | var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
|
|---|
| 82 | if (xAxisId == null || yAxisId == null) {
|
|---|
| 83 | return undefined;
|
|---|
| 84 | }
|
|---|
| 85 | var axis, ticks;
|
|---|
| 86 | if (layout === 'horizontal') {
|
|---|
| 87 | axis = selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 88 | ticks = selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 89 | } else {
|
|---|
| 90 | axis = selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 91 | ticks = selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 92 | }
|
|---|
| 93 | return getBandSizeOfAxis(axis, ticks);
|
|---|
| 94 | };
|
|---|
| 95 | export var selectAllBarPositions = createSelector([selectBarSizeList, selectRootMaxBarSize, selectBarGap, selectBarCategoryGap, selectBarBandSize, selectAxisBandSize, selectMaxBarSize], combineAllBarPositions);
|
|---|
| 96 | var selectXAxisWithScale = (state, id, isPanorama) => {
|
|---|
| 97 | var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
|
|---|
| 98 | if (xAxisId == null) {
|
|---|
| 99 | return undefined;
|
|---|
| 100 | }
|
|---|
| 101 | return selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 102 | };
|
|---|
| 103 | var selectYAxisWithScale = (state, id, isPanorama) => {
|
|---|
| 104 | var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
|
|---|
| 105 | if (yAxisId == null) {
|
|---|
| 106 | return undefined;
|
|---|
| 107 | }
|
|---|
| 108 | return selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 109 | };
|
|---|
| 110 | var selectXAxisTicks = (state, id, isPanorama) => {
|
|---|
| 111 | var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
|
|---|
| 112 | if (xAxisId == null) {
|
|---|
| 113 | return undefined;
|
|---|
| 114 | }
|
|---|
| 115 | return selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 116 | };
|
|---|
| 117 | var selectYAxisTicks = (state, id, isPanorama) => {
|
|---|
| 118 | var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
|
|---|
| 119 | if (yAxisId == null) {
|
|---|
| 120 | return undefined;
|
|---|
| 121 | }
|
|---|
| 122 | return selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 123 | };
|
|---|
| 124 | export var selectBarPosition = createSelector([selectAllBarPositions, selectSynchronisedBarSettings], combineBarPosition);
|
|---|
| 125 | export var selectStackedDataOfItem = createSelector([selectBarStackGroups, selectSynchronisedBarSettings], combineStackedData);
|
|---|
| 126 | export var selectBarRectangles = createSelector([selectChartOffsetInternal, selectAxisViewBox, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks, selectBarPosition, selectChartLayout, selectChartDataWithIndexesIfNotInPanoramaPosition3, selectAxisBandSize, selectStackedDataOfItem, selectSynchronisedBarSettings, pickCells], (offset, axisViewBox, xAxis, yAxis, xAxisTicks, yAxisTicks, pos, layout, _ref2, bandSize, stackedData, barSettings, cells) => {
|
|---|
| 127 | var {
|
|---|
| 128 | chartData,
|
|---|
| 129 | dataStartIndex,
|
|---|
| 130 | dataEndIndex
|
|---|
| 131 | } = _ref2;
|
|---|
| 132 | if (barSettings == null || pos == null || axisViewBox == null || layout !== 'horizontal' && layout !== 'vertical' || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || bandSize == null) {
|
|---|
| 133 | return undefined;
|
|---|
| 134 | }
|
|---|
| 135 | var {
|
|---|
| 136 | data
|
|---|
| 137 | } = barSettings;
|
|---|
| 138 | var displayedData;
|
|---|
| 139 | if (data != null && data.length > 0) {
|
|---|
| 140 | displayedData = data;
|
|---|
| 141 | } else {
|
|---|
| 142 | displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
|
|---|
| 143 | }
|
|---|
| 144 | if (displayedData == null) {
|
|---|
| 145 | return undefined;
|
|---|
| 146 | }
|
|---|
| 147 | return computeBarRectangles({
|
|---|
| 148 | layout,
|
|---|
| 149 | barSettings,
|
|---|
| 150 | pos,
|
|---|
| 151 | parentViewBox: axisViewBox,
|
|---|
| 152 | bandSize,
|
|---|
| 153 | xAxis,
|
|---|
| 154 | yAxis,
|
|---|
| 155 | xAxisTicks,
|
|---|
| 156 | yAxisTicks,
|
|---|
| 157 | stackedData,
|
|---|
| 158 | displayedData,
|
|---|
| 159 | offset,
|
|---|
| 160 | cells,
|
|---|
| 161 | dataStartIndex
|
|---|
| 162 | });
|
|---|
| 163 | }); |
|---|