source: node_modules/recharts/lib/state/selectors/barStackSelectors.js

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

Added visualizations

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