private calculateContentPositionFromPoint()

in src/dataLabel/dataLabelManager.ts [166:248]


    private calculateContentPositionFromPoint(anchorPoint: IPoint, contentPosition: ContentPositions, contentSize: ISize, offset: number): IRect {
        let position: IPoint = { x: 0, y: 0 };

        if (anchorPoint) {
            if (anchorPoint.x !== undefined && isFinite(anchorPoint.x)) {
                position.x = anchorPoint.x;

                switch (contentPosition) {
                    // D3 positions the label in the middle by default.
                    // The algorithem asumed the label was positioned in right so this is why we add/substract half width
                    case ContentPositions.TopLeft:
                    case ContentPositions.MiddleLeft:
                    case ContentPositions.BottomLeft:
                        position.x -= contentSize.width / 2.0;
                        break;

                    case ContentPositions.TopRight:
                    case ContentPositions.MiddleRight:
                    case ContentPositions.BottomRight:
                        position.x += contentSize.width / 2.0;
                        break;
                }
            }

            if (anchorPoint.y !== undefined && isFinite(anchorPoint.y)) {
                position.y = anchorPoint.y;
                switch (contentPosition) {
                    case ContentPositions.MiddleLeft:
                    case ContentPositions.MiddleCenter:
                    case ContentPositions.MiddleRight:
                        position.y -= contentSize.height / 2.0;
                        break;
                    case ContentPositions.TopRight:
                    case ContentPositions.TopLeft:
                    case ContentPositions.TopCenter:
                        position.y -= contentSize.height;
                        break;
                }
            }

            if (offset !== undefined && isFinite(offset)) {
                switch (contentPosition) {
                    case ContentPositions.TopLeft:
                        position.x -= offset;
                        position.y -= offset;
                        break;
                    case ContentPositions.MiddleLeft:
                        position.x -= offset;
                        break;
                    case ContentPositions.BottomLeft:
                        position.x -= offset;
                        position.y += offset;
                        break;
                    case ContentPositions.TopCenter:
                        position.y -= offset;
                        break;
                    case ContentPositions.MiddleCenter:
                        // Offset is not applied
                        break;
                    case ContentPositions.BottomCenter:
                        position.y += offset;
                        break;
                    case ContentPositions.TopRight:
                        position.x += offset;
                        position.y -= offset;
                        break;
                    case ContentPositions.MiddleRight:
                        position.x += offset;
                        break;
                    case ContentPositions.BottomRight:
                        position.x += offset;
                        position.y += offset;
                        break;
                }
            }
        }
        return {
            left: position.x,
            top: position.y,
            width: contentSize.width,
            height: contentSize.height
        };
    }