Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Add properties setters and getters #93

Merged
merged 33 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5d4585f
New: Add node properties setters
AlexIchenskiy Feb 26, 2024
2ba6729
New: Add edge properties setters
AlexIchenskiy Feb 26, 2024
bbe8797
New: Add properties getters
AlexIchenskiy Feb 26, 2024
0fe1ee7
New: Add patch for nodes and edges
AlexIchenskiy Feb 26, 2024
c401f1e
Fix: Make getters return copies
AlexIchenskiy Feb 27, 2024
d328a1d
Fix: Edge factory listeners copying
AlexIchenskiy Feb 27, 2024
13d90d9
Fix: Jest outdated tests
AlexIchenskiy Feb 28, 2024
b8144bb
Fix: Github actions node version
AlexIchenskiy Feb 28, 2024
91b913e
Chore: Refactor observer interface
AlexIchenskiy Feb 28, 2024
7fdfeb0
Chore: Refactor node/edge constructor settings
AlexIchenskiy Feb 28, 2024
1a28187
Chore: Refactor node/edge function grouping
AlexIchenskiy Feb 28, 2024
81f5f14
Chore: Refactor node/edge function grouping
AlexIchenskiy Feb 28, 2024
0b2549c
Fix: Listeners behaviour
AlexIchenskiy Feb 28, 2024
f6bbec5
Chore: Refactor property copying
AlexIchenskiy Feb 28, 2024
3a8049f
Chore: Refactor subject implementation
AlexIchenskiy Feb 28, 2024
386a076
Fix: Set position behaviour on node drag
AlexIchenskiy Mar 7, 2024
040c487
Chore: Upgrade node version
AlexIchenskiy Mar 7, 2024
5a43a56
Chore: Refactor function type check
AlexIchenskiy Mar 7, 2024
00257a3
Fix: Remove listener behaviour
AlexIchenskiy Mar 7, 2024
05584e0
Chore: Refactor util naming
AlexIchenskiy Mar 7, 2024
dd3909c
Chore: Remove unused type assertion
AlexIchenskiy Mar 7, 2024
7dc0fe7
Chore: Refactor position setter options
AlexIchenskiy Mar 14, 2024
84921da
Chore: Refactor property patch function
AlexIchenskiy Mar 14, 2024
f9e13a0
Fix: Set map node position behaviour
AlexIchenskiy Mar 14, 2024
e574358
Chore: Refactor simulator data patching
AlexIchenskiy Mar 18, 2024
0ee733d
Chore: Change observers to callbacks
AlexIchenskiy Mar 18, 2024
c9de1cf
New: Add state setters with options (#95)
AlexIchenskiy Mar 20, 2024
d802e50
Merge branch 'new/simulator-fixes' into new/add-setters-and-getters
AlexIchenskiy Mar 20, 2024
428f4d2
Merge branch 'new/simulator-fixes' into new/add-setters-and-getters
AlexIchenskiy Mar 20, 2024
8138f41
Fix: Rename merged function usage
AlexIchenskiy Mar 20, 2024
5d42df5
Merge branch 'new/add-setters-and-getters' of https://github.com/memg…
AlexIchenskiy Mar 20, 2024
d5dde27
Fix: Merged variable naming
AlexIchenskiy Mar 20, 2024
81442f7
Chore: Fix tests
AlexIchenskiy Mar 20, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "16.x"
node-version: "18.x"

- name: 'Install'
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "16.x"
node-version: "18.x"

- name: 'Install'
run: npm ci
Expand Down
6 changes: 3 additions & 3 deletions examples/example-custom-styled-graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ <h1>Example 2 - Basic + Custom default style</h1>
colorHover: '#e7644e',
colorSelected: '#e7644e',
fontSize: 3,
label: node.data.label,
label: node.getData().label,
size: 6,
};

if (node.data.label === 'Node A') {
if (node.getData().label === 'Node A') {
return {
...basicStyle,
size: 10,
Expand All @@ -84,7 +84,7 @@ <h1>Example 2 - Basic + Custom default style</h1>
width: 0.3,
widthHover: 0.9,
widthSelected: 0.9,
label: edge.data.label,
label: edge.getData().label,
};
},
});
Expand Down
6 changes: 3 additions & 3 deletions examples/example-fixed-coordinates-graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h1>Example 3 - Fixed coordinates</h1>
];

const orb = new Orb.OrbView(container, {
getPosition: (node) => ({ x: node.data.x, y: node.data.y })
getPosition: (node) => ({ x: node.getData().x, y: node.getData().y })
});

// Initialize nodes and edges
Expand All @@ -59,7 +59,7 @@ <h1>Example 3 - Fixed coordinates</h1>
colorHover: '#e7644e',
colorSelected: '#e7644e',
fontSize: 3,
label: node.data.label,
label: node.getData().label,
size: 6,
};
},
Expand All @@ -72,7 +72,7 @@ <h1>Example 3 - Fixed coordinates</h1>
width: 0.3,
widthHover: 0.9,
widthSelected: 0.9,
label: edge.data.label,
label: edge.getData().label,
};
},
});
Expand Down
8 changes: 4 additions & 4 deletions examples/example-graph-data-changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h1>Example 5 - Dynamics</h1>
colorHover: '#e7644e',
colorSelected: '#e7644e',
fontSize: 3,
label: node.data.label,
label: node.getData().label,
size: 6,
};
},
Expand All @@ -70,7 +70,7 @@ <h1>Example 5 - Dynamics</h1>
width: 0.3,
widthHover: 0.9,
widthSelected: 0.9,
label: edge.data.label,
label: edge.getData().label,
};
},
});
Expand All @@ -97,7 +97,7 @@ <h1>Example 5 - Dynamics</h1>
if (currentNodes.length) {
const newEdge = {
id: n,
start: currentNodes[Math.floor(Math.random() * currentNodes.length)].id,
start: currentNodes[Math.floor(Math.random() * currentNodes.length)].getId(),
end: n,
label: `Edge ${n} (new)`
};
Expand All @@ -115,7 +115,7 @@ <h1>Example 5 - Dynamics</h1>

orb.events.on(Orb.OrbEventType.NODE_CLICK, (event) => {
console.log('Node clicked: ', event.node);
orb.data.remove({ nodeIds: [event.node.id] });
orb.data.remove({ nodeIds: [event.node.getId()] });
orb.render();
});

Expand Down
18 changes: 9 additions & 9 deletions examples/example-graph-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h1>Example 4 - Events</h1>
colorHover: '#e7644e',
colorSelected: '#e7644e',
fontSize: 3,
label: node.data.label,
label: node.getData().label,
size: 6,
};
},
Expand All @@ -78,7 +78,7 @@ <h1>Example 4 - Events</h1>
width: 0.3,
widthHover: 0.9,
widthSelected: 0.9,
label: edge.data.label,
label: edge.getData().label,
};
},
});
Expand All @@ -103,27 +103,27 @@ <h1>Example 4 - Events</h1>

orb.events.on(Orb.OrbEventType.NODE_CLICK, (event) => {
console.log('Event: node-click', event);
output.innerHTML = `<b>${event.node.data.label}</b> clicked!`;
output.innerHTML = `<b>${event.node.getData().label}</b> clicked!`;
});
orb.events.on(Orb.OrbEventType.NODE_HOVER, (event) => {
console.log('Event: node-hover', event);
output.innerHTML = `<b>${event.node.data.label}</b> hovered!`;
output.innerHTML = `<b>${event.node.getData().label}</b> hovered!`;
});
orb.events.on(Orb.OrbEventType.EDGE_CLICK, (event) => {
console.log('Event: edge-click', event);
output.innerHTML = `Edge with id <b>${event.edge.data.id}</b> clicked!`;
output.innerHTML = `Edge with id <b>${event.edge.getData().id}</b> clicked!`;
});

orb.events.on(Orb.OrbEventType.NODE_RIGHT_CLICK, (data) => {
data.event.preventDefault();
console.log("Event: node-right-click", data);
output.innerHTML = `<b>${data.node.data.label}</b> right clicked!`;
output.innerHTML = `<b>${data.node.getData().label}</b> right clicked!`;
})

orb.events.on(Orb.OrbEventType.EDGE_RIGHT_CLICK, (data) => {
data.event.preventDefault();
console.log("Event: edge-right-click", data);
output.innerHTML = `Edge with id <b>${data.edge.data.id}</b> right clicked!`;
output.innerHTML = `Edge with id <b>${data.edge.getData().id}</b> right clicked!`;
})

orb.events.on(Orb.OrbEventType.MOUSE_RIGHT_CLICK, (data) => {
Expand All @@ -136,12 +136,12 @@ <h1>Example 4 - Events</h1>

orb.events.on(Orb.OrbEventType.NODE_DOUBLE_CLICK, (data) => {
console.log("Event: node-double-click", data);
output.innerHTML = `<b>${data.node.data.label}</b> double clicked!`;
output.innerHTML = `<b>${data.node.getData().label}</b> double clicked!`;
})

orb.events.on(Orb.OrbEventType.EDGE_DOUBLE_CLICK, (data) => {
console.log("Event: edge-double-click", data);
output.innerHTML = `Edge with id <b>${data.edge.data.id}</b> double clicked!`;
output.innerHTML = `Edge with id <b>${data.edge.getData().id}</b> double clicked!`;
})

orb.events.on(Orb.OrbEventType.MOUSE_DOUBLE_CLICK, (data) => {
Expand Down
6 changes: 3 additions & 3 deletions examples/example-graph-on-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1>Example 6 - Map</h1>
];

const orb = new Orb.OrbMapView(container, {
getGeoPosition: (node) => ({ lat: node.data.lat, lng: node.data.lng, }),
getGeoPosition: (node) => ({ lat: node.getData().lat, lng: node.getData().lng, }),
});

// Assign a basic style
Expand All @@ -58,7 +58,7 @@ <h1>Example 6 - Map</h1>
colorHover: '#e7644e',
colorSelected: '#e7644e',
fontSize: 10,
label: node.data.label,
label: node.getData().label,
size: 6,
};
},
Expand All @@ -71,7 +71,7 @@ <h1>Example 6 - Map</h1>
width: 1,
widthHover: 0.9,
widthSelected: 0.9,
label: edge.data.label,
label: edge.getData().label,
};
},
});
Expand Down
6 changes: 3 additions & 3 deletions examples/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
colorHover: '#e7644e',
colorSelected: '#e7644e',
fontSize: 3,
label: node.data.labels[0],
label: node.getData().labels[0],
size: 6,
};
},
Expand All @@ -54,15 +54,15 @@
width: 0.3,
widthHover: 0.9,
widthSelected: 0.9,
label: edge.data.label,
label: edge.getData().label,
};
},
};
};

const getOrbMapView = (container) => {
const view = new Orb.OrbMapView(container, {
getGeoPosition: (node) => ({ lat: node.data.lat, lng: node.data.lng, }),
getGeoPosition: (node) => ({ lat: node.getData().lat, lng: node.getData().lng, }),
});

// Assign a basic style
Expand Down
20 changes: 10 additions & 10 deletions examples/simulator-scenarios.html
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ <h4 class="scenario-title">
})),
edges: [...Array(newNodeCount).keys()].map((key) => ({
id: oldNodeCount + key,
start: key ? oldNodeCount + key : (sourceNode?.id || 0),
start: key ? oldNodeCount + key : (sourceNode?.getId() || 0),
end: oldNodeCount + key + 1
})),
});
Expand Down Expand Up @@ -2455,8 +2455,8 @@ <h4 class="scenario-title">

const graphStyle = {
getNodeStyle(node) {
const isNewNode = node.id >= NODE_COUNT;
const isFixed = node.data.x !== undefined && node.data.y !== undefined;
const isNewNode = node.getId() >= NODE_COUNT;
const isFixed = node.getData().x !== undefined && node.getData().y !== undefined;

// Old nodes
let color = isFixed ? '#5B0078' : '#003A58';
Expand All @@ -2476,7 +2476,7 @@ <h4 class="scenario-title">
colorSelected,
fontSize: 4,
fontColor: '#000000',
label: node.data.label,
label: node.getData().label,
size: 6,
};
},
Expand All @@ -2490,7 +2490,7 @@ <h4 class="scenario-title">
width: 1.2,
widthHover: 1.3,
widthSelected: 1.5,
label: edge.data.label,
label: edge.getData().label,
};
},
};
Expand All @@ -2501,7 +2501,7 @@ <h4 class="scenario-title">
const container = document.getElementById(graphContainerId);

let orb = new Orb.OrbView(container, {
getPosition: (node) => ({ x: node.data.x, y: node.data.y })
getPosition: (node) => ({ x: node.getData().x, y: node.getData().y })
});

// Assign a basic style
Expand Down Expand Up @@ -2603,7 +2603,7 @@ <h4 class="scenario-title">
const container = document.getElementById(graphContainerId);

let orb = new Orb.OrbView(container, {
getPosition: (node) => ({ x: node.data.x, y: node.data.y }),
getPosition: (node) => ({ x: node.getData().x, y: node.getData().y }),
simulation: {
isPhysicsEnabled,
}
Expand Down Expand Up @@ -2741,10 +2741,10 @@ <h4 class="scenario-title">

// Delete all nodes
const deleteAllNodes = (orb) => {
console.log('orb', orb.data.getNodes(), orb.data.getNodes().map((node) => node.id))
console.log('orb', orb.data.getNodes(), orb.data.getNodes().map((node) => node.getId()))
orb.data.remove({
nodeIds: orb.data.getNodes().map((node) => node.id),
edgeIds: orb.data.getEdges().map((edge) => edge.id),
nodeIds: orb.data.getNodes().map((node) => node.getId()),
edgeIds: orb.data.getEdges().map((edge) => edge.getId()),
});
orb.render(() => {
setTimeout(() => {
Expand Down
Loading
Loading