| [a762898] | 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.selectStackRects = exports.selectAllBarsInStack = exports.expandRectangle = void 0;
|
|---|
| 7 | var _reselect = require("reselect");
|
|---|
| 8 | var _axisSelectors = require("./axisSelectors");
|
|---|
| 9 | var _barSelectors = require("./barSelectors");
|
|---|
| 10 | var pickStackId = (state, stackId) => stackId;
|
|---|
| 11 | var pickIsPanorama = (state, stackId, isPanorama) => isPanorama;
|
|---|
| 12 | var 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 | });
|
|---|
| 15 | var 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 | */
|
|---|
| 25 | var 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 | };
|
|---|
| 45 | exports.expandRectangle = expandRectangle;
|
|---|
| 46 | var 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 | };
|
|---|
| 57 | var selectStackRects = exports.selectStackRects = (0, _reselect.createSelector)([state => state, pickStackId, pickIsPanorama], combineStackRects); |
|---|