123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /**
- * Licensed Materials - Property of IBM IBM Cognos Products: Modeling UI (C) Copyright IBM Corp. 2016, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP
- * Schedule Contract with IBM Corp.
- */
- // This function has never been able to achieve what it meant to achieve (e.g. cardinality position dynamically changed according to the length of the node box). Need to revisit.
- function calculateCardinalityPosition(source, target) {
- var opposite = source.y - target.y,
- adjacent = target.x - source.x,
- angle = Math.atan(opposite / adjacent) || 0;
- var tableDetailsOffset = source.displayTableInfo ? 15 : 0,
- cardinalityNodeOffset = 10,
- itemWidth = 200,
- itemHeight = 70,
- itemMidpoint = itemHeight / 2,
- theta1 = Math.PI + angle, // Quadrant 2, 3
- theta2 = Math.atan(itemHeight / itemWidth);
- // Quadrant 1
- if (source.x > target.x && source.y < target.y) {
- theta1 = angle;
- }
- // Quadrant 4
- else if (source.x > target.x && source.y > target.y) {
- theta1 = 2 * Math.PI + angle;
- }
- // Left
- if ((theta1 > 2 * Math.PI - theta2) || (theta1 < theta2)) {
- return {
- x: Math.floor(source.x - cardinalityNodeOffset - itemWidth / 2),
- y: Math.floor((itemWidth / 2) * (Math.tan(theta1)) + source.y - cardinalityNodeOffset + (tableDetailsOffset / 2))
- };
- }
- // Bottom
- else if ((theta1 > theta2) && (theta1 < Math.PI - theta2)) {
- return {
- x: Math.floor(source.x - cardinalityNodeOffset - ((itemHeight) / (2 * Math.tan(theta1)))),
- y: Math.floor(source.y - cardinalityNodeOffset + itemMidpoint + tableDetailsOffset)
- };
- }
- // Right
- else if ((theta1 > Math.PI - theta2) && (theta1 < Math.PI + theta2)) {
- return {
- x: Math.floor(source.x - cardinalityNodeOffset + itemWidth / 2),
- y: Math.floor((-1 * itemWidth / 2) * (Math.tan(theta1)) + source.y - cardinalityNodeOffset + (tableDetailsOffset / 2))
- };
- }
- // Top
- return {
- x: Math.floor(source.x - cardinalityNodeOffset + (itemHeight / (2 * Math.tan(theta1)))),
- y: Math.floor(source.y - cardinalityNodeOffset - itemMidpoint)
- };
- }
- define([], function() {
- return {
- d3Attrs: function(selection, map) {
- for (var name in map) selection.attr(name, map[name]);
- return selection;
- },
- d3Styles: function(selection, map) {
- for (var name in map) selection.style(name, map[name]);
- return selection;
- },
- isOffset: function (p1, p2, deadzone) {
- var zone = deadzone || 3;
- return Math.abs(p1.x - p2.x) > zone || Math.abs(p1.y - p2.y) > zone;
- },
- getCardinalityPosition: function(linkData, linkType) {
- if (linkType === 'source') {
- return calculateCardinalityPosition(linkData.source, linkData.target);
- }
- return calculateCardinalityPosition(linkData.target, linkData.source);
- }
- };
- });
|