source: node_modules/recharts/es6/state/selectors/barStackSelectors.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import { createSelector } from 'reselect';
2import { selectUnfilteredCartesianItems } from './axisSelectors';
3import { selectBarRectangles } from './barSelectors';
4var pickStackId = (state, stackId) => stackId;
5var pickIsPanorama = (state, stackId, isPanorama) => isPanorama;
6export var selectAllBarsInStack = createSelector([pickStackId, selectUnfilteredCartesianItems, pickIsPanorama], (stackId, allItems, isPanorama) => {
7 return allItems.filter(i => i.type === 'bar').filter(i => i.stackId === stackId).filter(i => i.isPanorama === isPanorama).filter(i => !i.hide);
8});
9var selectAllBarIdsInStack = createSelector([selectAllBarsInStack], allBars => {
10 return allBars.map(bar => bar.id);
11});
12/**
13 * Takes two rectangles and returns a new rectangle that encompasses both.
14 * It takes the minimum x and y, and the maximum width and height.
15 * It handles overlapping rectangles, and rectangles with a gap between them.
16 * @param rect1
17 * @param rect2
18 */
19export var expandRectangle = (rect1, rect2) => {
20 if (!rect1) {
21 return rect2;
22 }
23 if (!rect2) {
24 return rect1;
25 }
26 var x = Math.min(rect1.x, rect1.x + rect1.width, rect2.x, rect2.x + rect2.width);
27 var y = Math.min(rect1.y, rect1.y + rect1.height, rect2.y, rect2.y + rect2.height);
28 var maxX = Math.max(rect1.x, rect1.x + rect1.width, rect2.x, rect2.x + rect2.width);
29 var maxY = Math.max(rect1.y, rect1.y + rect1.height, rect2.y, rect2.y + rect2.height);
30 var width = maxX - x;
31 var height = maxY - y;
32 return {
33 x,
34 y,
35 width,
36 height
37 };
38};
39var combineStackRects = (state, stackId, isPanorama) => {
40 var allBarIds = selectAllBarIdsInStack(state, stackId, isPanorama);
41 var stackRects = [];
42 allBarIds.forEach(barId => {
43 var rectangles = selectBarRectangles(state, barId, isPanorama, undefined);
44 rectangles === null || rectangles === void 0 || rectangles.forEach((rect, index) => {
45 stackRects[index] = expandRectangle(stackRects[index], rect);
46 });
47 });
48 return stackRects;
49};
50export var selectStackRects = createSelector([state => state, pickStackId, pickIsPanorama], combineStackRects);
Note: See TracBrowser for help on using the repository browser.