Skip to content

Commit

Permalink
fix: rendering using new renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
nimec01 committed Sep 4, 2024
1 parent d0ac482 commit 2dbeec2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { lean_left } from './shapes/leanLeft.js';
import { trapezoid } from './shapes/trapezoid.js';
import { inv_trapezoid } from './shapes/invertedTrapezoid.js';
import { labelRect } from './shapes/labelRect.js';
import { history, deephistory } from './shapes/history.js';

const shapes = {
state,
Expand All @@ -47,6 +48,8 @@ const shapes = {
trapezoid,
inv_trapezoid,
labelRect,
history,
deephistory,
};

const nodeElems = new Map();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { log } from '$root/logger.js';
import { labelHelper, updateNodeBounds, getNodeClasses } from './util.js';
import intersect from '../intersect/index.js';
import type { Node } from '$root/rendering-util/types.d.ts';
import {
styles2String,
userNodeOverrides,
} from '$root/rendering-util/rendering-elements/shapes/handDrawnShapeStyles.js';
import rough from 'roughjs';

const historyBase = async (parent: SVGAElement, node: Node): Promise<SVGAElement> => {
const { labelStyles, nodeStyles } = styles2String(node);
node.labelStyle = labelStyles;
const { shapeSvg } = await labelHelper(parent, node, getNodeClasses(node));

const radius = 16;
let circleElem;
const { cssStyles } = node;

if (node.look === 'handDrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
const roughNode = rc.circle(0, 0, radius * 2, options);

circleElem = shapeSvg.insert(() => roughNode, ':first-child');
circleElem.attr('class', 'basic label-container history').attr('style', cssStyles);
} else {
circleElem = shapeSvg
.insert('circle', ':first-child')
.attr('class', 'basic label-container history')
.attr('style', nodeStyles)
.attr('r', radius)
.attr('cx', 0)
.attr('cy', 0);
}

updateNodeBounds(node, circleElem);

node.intersect = function (point) {
log.info('History intersect', node, radius, point);
return intersect.circle(node, radius, point);
};

return shapeSvg;
};

export const history = async (parent: SVGAElement, node: Node): Promise<SVGAElement> => {
node.label = 'H';
node.labelStyle = 'font-weight: bold;';
return await historyBase(parent, node);
};

export const deephistory = async (parent: SVGAElement, node: Node): Promise<SVGAElement> => {
node.label = 'H*';
node.labelStyle = 'font-weight: bold;';
return await historyBase(parent, node);
};

0 comments on commit 2dbeec2

Please sign in to comment.