-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from redbearsam/feature/legend_resizable
Feature/legend resizable
- Loading branch information
Showing
6 changed files
with
323 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/perspective-viewer-d3fc/src/js/legend/styling/enforceContainerBoundaries.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2017, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
|
||
import * as d3 from "d3"; | ||
import {isElementOverflowing} from "../../utils/utils"; | ||
import {getChartElement} from "../../plugin/root"; | ||
|
||
export const margin = 10; | ||
|
||
export function enforceContainerBoundaries(innerNode, offsetX, offsetY) { | ||
const chartNodeRect = d3 | ||
.select(getChartElement(innerNode).getContainer()) | ||
.node() | ||
.getBoundingClientRect(); | ||
|
||
const innerNodeRect = innerNode.getBoundingClientRect(); | ||
|
||
const draggedInnerNodeRect = { | ||
top: innerNodeRect.top + offsetY - margin, | ||
right: innerNodeRect.right + offsetX + margin, | ||
bottom: innerNodeRect.bottom + offsetY + margin, | ||
left: innerNodeRect.left + offsetX - margin | ||
}; | ||
|
||
const adjustedOffsets = {x: offsetX, y: offsetY}; | ||
const boundaries = [{edge: "right", dimension: "x"}, {edge: "left", dimension: "x"}, {edge: "top", dimension: "y"}, {edge: "bottom", dimension: "y"}]; | ||
|
||
boundaries.forEach(bound => { | ||
if (isElementOverflowing(chartNodeRect, draggedInnerNodeRect, bound.edge)) { | ||
const adjustment = draggedInnerNodeRect[bound.edge] - chartNodeRect[bound.edge]; | ||
adjustedOffsets[bound.dimension] = adjustedOffsets[bound.dimension] - adjustment; | ||
} | ||
}); | ||
|
||
return adjustedOffsets; | ||
} |
Oops, something went wrong.