Skip to content

Commit

Permalink
Updated crossed circle
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhg772244 committed Aug 9, 2024
1 parent 4c48b8c commit ac48f01
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import {
import rough from 'roughjs';
import intersect from '../intersect/index.js';

function createLine(cx: number, cy: number, r: number) {
function createLine(r: number) {
const xAxis45 = Math.cos(Math.PI / 4); // cosine of 45 degrees
const yAxis45 = Math.sin(Math.PI / 4); // sine of 45 degrees
const lineLength = r * 2;

const pointQ1 = { x: cx + (lineLength / 2) * xAxis45, y: cy + (lineLength / 2) * yAxis45 }; // Quadrant I
const pointQ2 = { x: cx - (lineLength / 2) * xAxis45, y: cy + (lineLength / 2) * yAxis45 }; // Quadrant II
const pointQ3 = { x: cx - (lineLength / 2) * xAxis45, y: cy - (lineLength / 2) * yAxis45 }; // Quadrant III
const pointQ4 = { x: cx + (lineLength / 2) * xAxis45, y: cy - (lineLength / 2) * yAxis45 }; // Quadrant IV
const pointQ1 = { x: (lineLength / 2) * xAxis45, y: (lineLength / 2) * yAxis45 }; // Quadrant I
const pointQ2 = { x: -(lineLength / 2) * xAxis45, y: (lineLength / 2) * yAxis45 }; // Quadrant II
const pointQ3 = { x: -(lineLength / 2) * xAxis45, y: -(lineLength / 2) * yAxis45 }; // Quadrant III
const pointQ4 = { x: (lineLength / 2) * xAxis45, y: -(lineLength / 2) * yAxis45 }; // Quadrant IV

return `M ${pointQ2.x},${pointQ2.y} L ${pointQ4.x},${pointQ4.y}
M ${pointQ1.x},${pointQ1.y} L ${pointQ3.x},${pointQ3.y}`;
Expand All @@ -26,8 +26,6 @@ export const crossedCircle = async (parent: SVGAElement, node: Node) => {
const { labelStyles, nodeStyles } = styles2String(node);
node.labelStyle = labelStyles;
const { shapeSvg, bbox, halfPadding } = await labelHelper(parent, node, getNodeClasses(node));
const cy = 0;
const cx = 0;
const radius = Math.max(bbox.width, bbox.height) / 2 + halfPadding;
const { cssStyles } = node;

Expand All @@ -40,8 +38,8 @@ export const crossedCircle = async (parent: SVGAElement, node: Node) => {
options.fillStyle = 'solid';
}

const circleNode = rc.circle(cx, cy, radius * 2, options);
const linePath = createLine(cx, -cy, radius);
const circleNode = rc.circle(0, 0, radius * 2, options);
const linePath = createLine(radius);
const lineNode = rc.path(linePath, options);

const crossedCircle = shapeSvg.insert('g', ':first-child');
Expand Down

0 comments on commit ac48f01

Please sign in to comment.