Skip to content

Commit

Permalink
Merge pull request #48 from MetaCell/feature/32_2
Browse files Browse the repository at this point in the history
Feature/32 2
  • Loading branch information
zsinnema authored Aug 31, 2022
2 parents 23b61fb + 0170119 commit c2f503d
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 10,919 deletions.
11 changes: 3 additions & 8 deletions dev_setup.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
#!/bin/bash

# TODO we will uncomment the below when we will have the deployment for this
#mv package.json old_package.json
#mv package.dev package.json
npm -g install yalc
PSYVIEW=`pwd`

if [ -d '../meta-diagram' ]; then
cd ../meta-diagram;
yarn && yarn run build:dev && yalc push --changed
cd -
cd $PSYVIEW
else
cd ../
git clone https://github.com/metacell/meta-diagram
cd meta-diagram
yarn && yarn run build:dev && yalc push --changed
cd -
cd $PSYVIEW
fi

yalc add @metacell/meta-diagram
yarn
yarn run start
#mv package.json package.dev
#mv old_package.json package.json

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"test": "react-app-rewired test",
"test-no-watch": "react-app-rewired test --watchAll=false",
"eject": "react-app-rewired eject",
"dev": "concurrently -k \"BROWSER=none npm start\" \"npm:electron\"",
"dev": "concurrently -k \"BROWSER=none yarn run start\" \"yarn:electron\"",
"electron": "wait-on tcp:3000 && electron ."
},
"eslintConfig": {
Expand Down
15 changes: 15 additions & 0 deletions src/assets/styles/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ const nodeGray = {
nodeGrayBoxShadow: '0 0.25rem 0.625rem -0.25rem rgba(129, 129, 129, 0.3)',
};

export const projectionLink = {
stroke: "#3C3C43",
strokeWidth: "2",
strokeOpacity: "0.6",
strokeLinecap: "round",
}

export const projectionLinkArrow = {
stroke: "#3C3C43",
strokeWidth: "2",
strokeOpacity: "0.6",
strokeLinecap: "round",
fill: "none",
}

const vars = {
fontFamily: 'Inter, sans-serif',
primaryBg: '#f1f1f1',
Expand Down
29 changes: 25 additions & 4 deletions src/components/views/mechanisms/MechMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import NodeSelection from "./NodeSelection";
import InputOutputNode from "./InputOutputNode";
import TextField from '@mui/material/TextField';
import Typography from "@mui/material/Typography";
import { PortTypes, PortWidget } from "@metacell/meta-diagram";

const styles = () => ({
root: {
Expand Down Expand Up @@ -123,8 +124,18 @@ class MechMetadata extends React.Component {
</Box>

<Box className={classes.block}>
<InputOutputNode variant={options?.variant} text={"Input from Frame 1"} />
<InputOutputNode variant={options?.variant} text={"Input from Frame 2"} direction="right" />
{ options.ports.map(port => {
switch (port.getType()) {
case PortTypes.INPUT_PORT:
return (
<PortWidget key={model.getID() + '_' + port.getId()} engine={engine} port={model.getPort(port.getId())}>
<InputOutputNode variant={options?.variant} text={port.getId()} />
</PortWidget>
);
default:
return <></>
}
})}
</Box>

<Box
Expand Down Expand Up @@ -161,8 +172,18 @@ class MechMetadata extends React.Component {
/>

<Box className={classes.block}>
<InputOutputNode variant={options?.variant} text={"Output from Frame 1"} />
<InputOutputNode variant={options?.variant} text={"Output from Frame 1"} direction="right" />
{ options.ports.map(port => {
switch (port.getType()) {
case PortTypes.OUTPUT_PORT:
return (
<PortWidget key={model.getID() + '_' + port.getId()} engine={engine} port={model.getPort(port.getId())}>
<InputOutputNode variant={options?.variant} text={port.getId()} direction="right" />
</PortWidget>
);
default:
return <></>
}
})}
</Box>
</Box>
</>
Expand Down
22 changes: 21 additions & 1 deletion src/components/views/mechanisms/MechSimple.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from "react";
import { Box, Typography } from "@mui/material";
import NodeSelection from "./NodeSelection";
import { Box, Typography } from "@mui/material";
import { PortWidget, PortTypes } from "@metacell/meta-diagram";
// import { PortWidget } from "../ports/PortWidget";

class MechSimple extends React.Component {
render() {
Expand All @@ -18,6 +20,24 @@ class MechSimple extends React.Component {
<Typography component="p">
{options.name}
</Typography>
{ options.ports.map(port => {
switch (port.getType()) {
case PortTypes.INPUT_PORT:
return (
<PortWidget key={model.getID() + '_' + port.getId()} engine={engine} port={model.getPort(port.getId())} className="simple-input-port">
<div className="simple-input-port" />
</PortWidget>
);
case PortTypes.OUTPUT_PORT:
return (
<PortWidget key={model.getID() + '_' + port.getId()} engine={engine} port={model.getPort(port.getId())} className="simple-output-port">
<div className="simple-output-port" />
</PortWidget>
);
default:
console.log('different port found' + port.getName() + ' ' + port.getType());
}
})}
</Box>
</Box>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/mechanisms/NodeSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ class NodeSelection extends React.Component {
const OUT = 'out';
return (
<>
<Button className="node-button">
<Button className="node-button" onClick={changeVisibility}>
<Box
className="icon"
/>
{text}
</Button>

<Box className="nodes">
<PortWigetComp engine={engine} port={node} direction={IN} startPoints={{ left: selectionPoint, top: selectionPoint }} />
{/* <PortWigetComp engine={engine} port={node} direction={IN} startPoints={{ left: selectionPoint, top: selectionPoint }} />
<PortWigetComp engine={engine} port={node} direction={OUT} startPoints={{ right: selectionPoint, top: selectionPoint }} />
<PortWigetComp engine={engine} port={node} direction={IN} startPoints={{ left: selectionPoint, bottom: selectionPoint }} />
<PortWigetComp engine={engine} port={node} direction={OUT} startPoints={{ right: selectionPoint, bottom: selectionPoint }} />
<PortWigetComp engine={engine} port={node} direction={OUT} startPoints={{ right: selectionPoint, bottom: selectionPoint }} /> */}
</Box>
</>
);
Expand Down
167 changes: 128 additions & 39 deletions src/components/views/projections/CustomLinkWidget.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,152 @@
import * as React from "react";
import {MetaLinkModel} from "@metacell/meta-diagram";
import {
DefaultLinkWidget, LinkWidget, PointModel
} from '@projectstorm/react-diagrams';
import { projectionLinkArrow, projectionLink } from "../../../assets/styles/variables";

export class CustomLinkWidget extends React.Component {
const pointlength = 6;

const CustomLinkArrowWidget = (props) => {
const { point, previousPoint } = props;

const angle =
90 +
(Math.atan2(
point.getPosition().y - previousPoint.getPosition().y,
(point.getPosition().x - 10) - (previousPoint.getPosition().x + 10)
) *
180) /
Math.PI;

return (
<g className="arrow" transform={'translate(' + point.getPosition().x + ', ' + point.getPosition().y + ')'}>
<g style={{ transform: 'rotate(' + angle + 'deg)' }}>
<g transform={'translate(0, -3)'}>
<polyline
points={`${pointlength * -2},${pointlength * 4} 0,${pointlength + 2} ${pointlength * 2},${pointlength * 4}`}
{
...projectionLinkArrow
}
data-id={point.getID()}
data-linkid={point.getLink().getID()}
/>
</g>
</g>
</g>
);
};


class CustomLink extends React.Component {
constructor(props) {
super(props);
this.percent = 0;

this.path = React.createRef();
}

componentDidMount() {
this.mounted = true;
this.callback = () => {
if (!this.circle || !this.path) {
return;
}

this.percent += 2;
if (this.percent > 100) {
this.percent = 0;
}

let point = this.path.getPointAtLength(this.path.getTotalLength() * (this.percent / 100.0));

this.circle.setAttribute('cx', '' + point.x);
this.circle.setAttribute('cy', '' + point.y);

if (this.mounted) {
requestAnimationFrame(this.callback);
}
};
requestAnimationFrame(this.callback);
}

componentWillUnmount() {
this.mounted = false;
}

shouldComponentUpdate() {
return true;
}

render() {
return (
<>
<g>
<path
fill="none"
ref={(ref) => {
this.path = ref;
}}
strokeWidth={this.props.model.getOptions().width}
stroke="rgba(255,0,0,0.5)"
ref={this.path}
{
...projectionLink
}
d={this.props.path}
/>
</g>
);
}
}


export class CustomLinkWidget extends DefaultLinkWidget {
generateArrow(point, previousPoint) {
return (
<CustomLinkArrowWidget
key={point.getID()}
point={point}
previousPoint={previousPoint}
colorSelected={this.props.link.getOptions().selectedColor}
color={this.props.link.getOptions().color}
/>
);
}

generateLinePath(firstPoint, lastPoint) {
// the below shorten the touching point as per design, computing a point of the segment minus the arrow height
if (firstPoint.x <= lastPoint.x) {
let x = lastPoint.x - firstPoint.x;
let y = lastPoint.y - firstPoint.y;
let distance = Math.sqrt(x * x + y * y);
let newDistance = distance - (pointlength * 3);
const angle = (Math.atan2( lastPoint.y - firstPoint.y, (lastPoint.x) - (firstPoint.x)) * 180) / Math.PI;
let newX = Math.round(Math.cos(angle * Math.PI / 180) * newDistance + firstPoint.x);
let newY = Math.round(Math.sin(angle * Math.PI / 180) * newDistance + firstPoint.y);
return `M${firstPoint.x + 10},${firstPoint.y} L ${newX},${newY}`;
} else {
let x = firstPoint.x - lastPoint.x;
let y = firstPoint.y - lastPoint.y;
let distance = Math.sqrt(x * x + y * y);
let newDistance = distance - (pointlength * 3);
const angle = (Math.atan2( lastPoint.y - firstPoint.y, (lastPoint.x) - (firstPoint.x)) * 180) / Math.PI;
let newX = Math.round(Math.cos(angle * Math.PI / 180) * newDistance + firstPoint.x);
let newY = Math.round(Math.sin(angle * Math.PI / 180) * newDistance + firstPoint.y);
return `M${firstPoint.x - 10},${firstPoint.y} L ${newX},${newY}`;
}
}

render() {
//ensure id is present for all points on the path
var points = this.props.link.getPoints();
var paths = [];
this.refPaths = [];

//draw the multiple anchors and complex line instead
for (let j = 0; j < points.length - 1; j++) {
paths.push(
<CustomLink
key={`link-from-${points[j].getID()}-to-${points[j+1].getID()}`}
path={this.generateLinePath(
{x: points[j].getX(), y: points[j].getY()},
{x: points[j + 1].getX(), y: points[j + 1].getY()}
)}
{...this.props}
/>
<circle
ref={(ref) => {
this.circle = ref;
}}
r={10}
fill="orange"
/>
</>
);
}

if (this.props.link.getTargetPort() !== null) {
paths.push(this.generateArrow(points[points.length - 1], points[points.length - 2]));
} else {
paths.push(this.generatePoint(points[points.length - 1]));
}

return <g data-default-link-test={this.props.link.getOptions().testName}>{paths}</g>;
}
}


class CustomLinkAdapter extends React.Component {
render() {
const {model, engine} = this.props;
return (
<CustomLinkWidget link={model} diagramEngine={engine}/>
);
}
}

// @ts-ignore
export default CustomLinkWidget;
export default CustomLinkAdapter;
12 changes: 12 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

.simple-input-port {
position:absolute;
top: 50%;
left: 0%;
}

.simple-output-port {
position:absolute;
top: 50%;
left: 100%;
}
Loading

0 comments on commit c2f503d

Please sign in to comment.