Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/component/modals/GraphCompDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,33 @@ const ModalComp = ({ closeModal, superState, dispatcher }) => {
const [createHelpClicked, setCreateHelpClicked] = useState(false);
const { modalPayload, ModelOpen } = superState;
const {
cb, title, submitText, Children, defaultStyle, defaultLabel, labelAllowed, type,
cb, title, submitText, Children, defaultStyle, defaultLabel,
defaultSummary, labelAllowed, type,
} = modalPayload;

useEffect(() => {
setErrorMessage('');
}, [ModelOpen]);

useEffect(() => {
setData({ label: defaultLabel || '', style: defaultStyle });
setData({
label: defaultLabel || '',
style: defaultStyle,
summary: defaultSummary || '',
});
setErrorMessage('');
}, [defaultLabel, defaultStyle]);
}, [defaultLabel, defaultStyle, defaultSummary]);

const submit = (e) => {
e.preventDefault();
const message = cb(data.label, data.style);
const message = cb(data.label, data.style, data.summary || '');
if (message.ok) {
setErrorMessage('');
setData({ label: defaultLabel || '', style: defaultStyle });
setData({
label: defaultLabel || '',
style: defaultStyle,
summary: defaultSummary || '',
});
closeModal();
} else setErrorMessage(message.err);
};
Expand Down Expand Up @@ -173,4 +182,5 @@ const ModalComp = ({ closeModal, superState, dispatcher }) => {
</ParentModal>
);
};

export default ModalComp;
62 changes: 44 additions & 18 deletions src/component/modals/NodeDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const NodeDetails = ({
const indexOfFile = [];
indexOfFile.push(0);

const currentLabel = String(data.label || '');
const currentSummary = String(data.summary || '');

const setStyle = (prop) => {
setData({ ...data, style: { ...data.style, ...prop } });
};
Expand All @@ -42,16 +45,16 @@ const NodeDetails = ({
}, [state.fileState]);

useEffect(() => {
if (!widthSet) {
if (!widthSet && textRef.current) {
setStyle({
width: Math.max(data.style.width, Math.min(500, textRef.current.offsetWidth + 20)),
});
}
}, [!widthSet && data.label]);

useEffect(() => {
setLabelName(data.label.split(':')[0]);
}, [data.label]);
setLabelName(currentLabel.split(':')[0]);
}, [currentLabel]);

return (
<div className="nodeform" onSubmit={submit}>
Expand All @@ -63,8 +66,7 @@ const NodeDetails = ({
borderRadius: data.style.shape === 'ellipse' ? '100%' : 0,
}}
>
<span ref={textRef}>{labelAllowed ? data.label : ''}</span>

<span ref={textRef}>{labelAllowed ? currentLabel : ''}</span>
</div>
</div>
<div className="form" style={{ padding: 20 }}>
Expand Down Expand Up @@ -105,7 +107,7 @@ const NodeDetails = ({
required
label="Node Label"
placeholder="Enter Node Label"
value={data.label.split(':')[0]}
value={currentLabel.split(':')[0]}
onChange={(e) => {
if (e.target.value.slice(-1) !== ':') {
setLabelName(`${e.target.value}:`);
Expand All @@ -122,9 +124,15 @@ const NodeDetails = ({
type="text"
label="Node Label file"
placeholder="Select file"
value={data.label.split(':')[1]}
value={currentLabel.split(':')[1] || ''}
onChange={(e) => {
setLabelFile(e.target.value.split('/').pop().split(' DESC: ')[0]);
const selectedFile = e.target.value
.split('/')
.pop()
.split(' DESC: ')[0];

setLabelFile(selectedFile);

if (labelName) {
let lname = labelName;
if (labelName.slice(-1) !== ':') {
Expand All @@ -133,14 +141,12 @@ const NodeDetails = ({
}
setData({
...data,
// eslint-disable-next-line max-len
label: lname + e.target.value.split('/').pop().split(' DESC: ')[0],
label: lname + selectedFile,
});
} else {
setData({
...data,
// eslint-disable-next-line max-len
label: `:${e.target.value.split('/').pop().split(' DESC: ')[0]}`,
label: `:${selectedFile}`,
});
}
}}
Expand All @@ -149,7 +155,6 @@ const NodeDetails = ({
<datalist id="files">
{
localStorageManager.getFileList()
// eslint-disable-next-line max-len, prefer-arrow-callback
? state.fileState
.map((item) => {
const list = [];
Expand All @@ -161,11 +166,15 @@ const NodeDetails = ({
if (item.key.toString().split('/').length > 2) {
return null;
}
// eslint-disable-next-line max-len
if ((acceptedTypes.some((substring) => item.key.toString().includes(substring)))) {
const fileName = item.key.toString().split('.')[0].concat('.md');
// eslint-disable-next-line max-len
const matchingFile = mdList.find((ele) => ele.key.toString() === fileName);
if (acceptedTypes.some(
(substring) => item.key.toString().includes(substring),
)) {
const fileName = item.key.toString()
.split('.')[0]
.concat('.md');
const matchingFile = mdList.find(
(ele) => ele.key.toString() === fileName,
);
if (mdCont.get(matchingFile)) {
list.push(item.key.toString().concat(mdCont.get(matchingFile)));
} else {
Expand All @@ -190,6 +199,23 @@ const NodeDetails = ({
</datalist>
</>
) : ''}

{labelAllowed ? (
<>
<div className="nodeSummaryLabel">Summary</div>
<textarea
className="nodeSummary"
placeholder="Enter a short summary of this node"
rows={4}
value={currentSummary}
onChange={(e) => setData({
...data,
summary: e.target.value,
})}
/>
</>
) : ''}

{/* <div> Width</div>
<input
type="number"
Expand Down
153 changes: 152 additions & 1 deletion src/graph-builder/graph-core/1-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ class CoreGraph {

cy;

container;

quickViewElement = null;

quickViewTitle = null;

quickViewContent = null;

quickViewNode = null;

quickViewPinned = false;

originalContainerPosition = '';

bendNode;

darkMode = false;
Expand All @@ -45,10 +59,19 @@ class CoreGraph {
gridGuide(cytoscape);
}
// if (cy) this.cy = cy;
this.container = element;
this.originalContainerPosition = element.style.position;
this.container.style.position = 'relative';

this.cy = cytoscape({ ...cyOptions(darkMode), container: element });
this.cy.on('position', 'node', () => {
this.createQuickView();
this.cy.on('position', 'node', (event) => {
this.cy.edges().updateStyle();
if (this.quickViewNode && event.target.id() === this.quickViewNode.id()) {
this.updateQuickViewPosition();
}
});
this.cy.on('pan zoom', () => this.updateQuickViewPosition());
this.id = id;
this.projectName = projectName;
this.authorName = authorName;
Expand Down Expand Up @@ -246,6 +269,108 @@ class CoreGraph {
});
}

createQuickView() {
const quickView = document.createElement('div');
quickView.className = 'node-quick-view';
Object.assign(quickView.style, {
position: 'absolute',
display: 'none',
zIndex: '1000',
maxWidth: '260px',
minWidth: '150px',
padding: '10px 12px',
borderRadius: '6px',
boxShadow: '0 3px 12px rgba(0, 0, 0, 0.25)',
pointerEvents: 'none',
whiteSpace: 'normal',
overflowWrap: 'anywhere',
transform: 'translate(-50%, -100%)',
fontFamily: 'Arial, sans-serif',
fontSize: '12px',
lineHeight: '1.45',
});

const title = document.createElement('div');
Object.assign(title.style, {
fontWeight: '700',
marginBottom: '5px',
});

const content = document.createElement('div');
Object.assign(content.style, {
fontWeight: '400',
});

quickView.appendChild(title);
quickView.appendChild(content);
this.container.appendChild(quickView);

this.quickViewElement = quickView;
this.quickViewTitle = title;
this.quickViewContent = content;
this.updateQuickViewTheme();
}

updateQuickViewTheme() {
if (!this.quickViewElement) return;

this.quickViewElement.style.backgroundColor = this.darkMode ? '#333333' : '#ffffff';
this.quickViewElement.style.color = this.darkMode ? '#f5f5f5' : '#222222';
this.quickViewElement.style.border = this.darkMode
? '1px solid #555555'
: '1px solid #dddddd';
}

showQuickView(node, pinned = false) {
if (!node || !node.length || !node.isNode() || node.data('type') !== 'ordin') {
this.hideQuickView();
return;
}

const summary = (node.data('summary') || '').trim();
if (!summary) {
this.hideQuickView();
return;
}

this.quickViewNode = node;
this.quickViewPinned = pinned;
this.quickViewTitle.textContent = node.data('label') || 'Node summary';
this.quickViewContent.textContent = summary;
this.quickViewElement.style.display = 'block';
this.updateQuickViewTheme();
this.updateQuickViewPosition();
}

updateQuickViewPosition() {
if (!this.quickViewElement || !this.quickViewNode || !this.quickViewNode.length) return;

const position = this.quickViewNode.renderedPosition();
this.quickViewElement.style.left = `${position.x}px`;
this.quickViewElement.style.top = `${position.y - 12}px`;
}

hideQuickView() {
if (this.quickViewElement) this.quickViewElement.style.display = 'none';
this.quickViewNode = null;
this.quickViewPinned = false;
}

removeQuickView() {
this.hideQuickView();
if (this.quickViewElement && this.quickViewElement.parentNode) {
this.quickViewElement.parentNode.removeChild(this.quickViewElement);
}
this.quickViewElement = null;
this.quickViewTitle = null;
this.quickViewContent = null;

if (this.container) {
this.container.style.position = this.originalContainerPosition;
}
this.container = null;
}

registerEvents() {
this.cy.on('select unselect', () => this.selectDeselectEventHandler());
this.cy.on('grab', 'node[type = "ordin"]', (e) => {
Expand Down Expand Up @@ -297,8 +422,31 @@ class CoreGraph {
this.cy.on('grabon', (evt) => (evt.target[0].data('type') !== 'bend' ? this.cy.emit('hide-bend') : 0));
this.cy.on('freeon', (evt) => (evt.target[0].data('type') !== 'bend' ? this.cy.emit('show-bend') : 0));

this.cy.on('mouseover', 'node[type = "ordin"]', (ev) => {
if (!this.quickViewPinned) {
this.showQuickView(ev.target);
}
});

this.cy.on('mouseout', 'node[type = "ordin"]', () => {
if (!this.quickViewPinned) this.hideQuickView();
});

this.cy.on('click tap', 'node[type = "ordin"]', (ev) => {
this.showQuickView(ev.target, true);
});

this.cy.on('click tap', 'edge', () => this.hideQuickView());

this.cy.on('remove', 'node', (ev) => {
if (this.quickViewNode && ev.target.id() === this.quickViewNode.id()) {
this.hideQuickView();
}
});

this.cy.on('click tap', (ev) => {
if (ev.target === this.cy) {
this.hideQuickView();
this.cy.emit('hide-bend');
this.cy.$('.eh-handle').remove();
}
Expand Down Expand Up @@ -354,6 +502,7 @@ class CoreGraph {
this.darkMode = darkMode;
const newStyle = getCytoscapeStyle(darkMode);
this.cy.style(newStyle);
this.updateQuickViewTheme();

// Update grid colors for dark mode
const gridColors = darkMode ? {
Expand All @@ -376,12 +525,14 @@ class CoreGraph {
if (!this.cy) return;
if (this.autoSaveIntervalId !== null) clearTimeout(this.autoSaveIntervalId);
this.autoSaveIntervalId = null;
this.removeQuickView();
this.cy.destroy();
this.cy = null;
this.dispatcher = null;
}

reset() {
this.hideQuickView();
this.resetAllComp();
this.resetAllAction();
}
Expand Down
Loading