Skip to content

feat(dia.Graph, dia.Paper): cell layers #3025

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

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
5ddbc5e
wip
Geliogabalus Feb 19, 2025
724b1a8
wip
Geliogabalus Feb 21, 2025
044af30
layer models
Geliogabalus Feb 23, 2025
af043f2
wip
Geliogabalus Feb 23, 2025
60bbcd9
update
Geliogabalus Feb 25, 2025
5832a22
fix
Geliogabalus Feb 25, 2025
bb09418
up
Geliogabalus Feb 25, 2025
9a9aeac
up
Geliogabalus Feb 26, 2025
6249685
up
Geliogabalus Feb 28, 2025
1a208bc
up
Geliogabalus Mar 2, 2025
309edaa
wip
Geliogabalus Mar 4, 2025
099cf81
up
Geliogabalus Mar 9, 2025
2f2c482
up
Geliogabalus Mar 18, 2025
62ed851
wip
Geliogabalus Mar 18, 2025
903e922
wip
Geliogabalus Mar 18, 2025
b491ea8
fix
Geliogabalus Mar 18, 2025
1533570
up
Geliogabalus Mar 19, 2025
0752076
up
Geliogabalus May 16, 2025
163c221
wip
Geliogabalus May 16, 2025
c66280b
wip
Geliogabalus May 29, 2025
c2dc6ae
wip
Geliogabalus Jun 5, 2025
0a2f047
up
Geliogabalus Jun 5, 2025
8a03a89
up
Geliogabalus Jun 6, 2025
d058bac
reset fix
Geliogabalus Jun 6, 2025
468a6c6
wip
Geliogabalus Jun 9, 2025
5083b69
up
Geliogabalus Jun 9, 2025
dab0da8
update
Geliogabalus Jun 16, 2025
58be262
up
Geliogabalus Jun 16, 2025
15ec945
tests start
Geliogabalus Jun 17, 2025
e4786f2
fixes and tests
Geliogabalus Jun 18, 2025
1487770
update
Geliogabalus Jun 29, 2025
bf9a4c8
wip
Geliogabalus Jul 10, 2025
7864d01
update
Geliogabalus Jul 11, 2025
4d8ed05
up
Geliogabalus Jul 11, 2025
4152946
refactor
Geliogabalus Jul 14, 2025
2c6c5d9
up
Geliogabalus Jul 14, 2025
29ca501
revert
Geliogabalus Jul 14, 2025
ec9a33a
up
Geliogabalus Jul 14, 2025
505fc50
up
Geliogabalus Jul 15, 2025
6eb29f1
wip
Geliogabalus Jul 16, 2025
a94376e
async removing
Geliogabalus Jul 17, 2025
ed79f8e
wip (probably doesn't work)
Geliogabalus Jul 21, 2025
8358fa8
up
Geliogabalus Jul 23, 2025
5e4b02b
up
Geliogabalus Jul 23, 2025
8328efe
wip
Geliogabalus Jul 23, 2025
34812b6
up
Geliogabalus Jul 24, 2025
d861c35
fix
Geliogabalus Jul 24, 2025
3c6aa1d
fix
Geliogabalus Jul 25, 2025
a852825
final
Geliogabalus Jul 25, 2025
8782e66
typings
Geliogabalus Jul 26, 2025
b08e3ec
up
Geliogabalus Jul 28, 2025
49f8a85
up
Geliogabalus Jul 28, 2025
c32030d
wip
Geliogabalus Jul 29, 2025
57f18b0
update
Geliogabalus Jul 30, 2025
df14e67
start
Geliogabalus Jul 30, 2025
eaa5e16
up
Geliogabalus Jul 30, 2025
5fe337b
up types
Geliogabalus Jul 31, 2025
359b5eb
update
Geliogabalus Aug 1, 2025
5b83676
up
Geliogabalus Aug 1, 2025
43dc407
Merge branch 'master' into cell-layers
Geliogabalus Aug 3, 2025
92e5dbe
fix
Geliogabalus Aug 3, 2025
1834a9d
tests
Geliogabalus Aug 4, 2025
54885ce
Merge branch 'master' into cell-layers
Geliogabalus Aug 5, 2025
d322a9b
fix
Geliogabalus Aug 5, 2025
bf1bc6c
update
Geliogabalus Aug 5, 2025
1299a18
fix
Geliogabalus Aug 5, 2025
2e3d8ac
up
Geliogabalus Aug 5, 2025
056d201
up
Geliogabalus Aug 6, 2025
0c0e703
test fix
Geliogabalus Aug 6, 2025
8f3fe32
fix
Geliogabalus Aug 6, 2025
35e4d22
update
Geliogabalus Aug 10, 2025
3259f79
updates
Geliogabalus Aug 10, 2025
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
Prev Previous commit
Next Next commit
up
  • Loading branch information
Geliogabalus committed Mar 2, 2025
commit 1a208bc967cb44fe4e8c86b98de0e10517deacc2
39 changes: 36 additions & 3 deletions packages/joint-core/src/dia/Graph.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const Graph = Model.extend({
opt = opt || {};

this.defaultLayerName = LayersNames.CELLS;
this.activeLayerName = this.defaultLayerName;

const defaultLayer = new Layer({
name: this.defaultLayerName,
Expand Down Expand Up @@ -150,7 +151,7 @@ export const Graph = Model.extend({
this._nodes[cell.id] = true;
}

const layerName = cell.layer() || this.defaultLayerName;
const layerName = cell.layer() || this.activeLayerName;
const layer = this.get('layers')[layerName];

if (!cell.has('z')) {
Expand All @@ -175,6 +176,7 @@ export const Graph = Model.extend({
delete this._nodes[cell.id];
}

// should be defined at any time ideally
const layerName = cell.layer() || this.defaultLayerName;

const layers = this.get('layers');
Expand All @@ -188,7 +190,7 @@ export const Graph = Model.extend({
const embeddingLayer = embeddingLayers[cell.id];
const cells = embeddingLayer.get('cells').models;
cells.forEach((cell) => {
layers[this.defaultLayerName].add(cell);
layers[this.activeLayerName].add(cell);
});

this.trigger('embeddingLayer:remove', embeddingLayer, {});
Expand Down Expand Up @@ -259,7 +261,7 @@ export const Graph = Model.extend({
this.trigger('embeddingLayer:insert', embeddingLayers[parentId], {});
}

const targetLayer = embeddingLayers[parentId] || layers[this.defaultLayerName];
const targetLayer = embeddingLayers[parentId] || layers[this.activeLayerName];

targetLayer.add(cell);
}
Expand Down Expand Up @@ -500,10 +502,41 @@ export const Graph = Model.extend({
this.stopBatch(batchName);
},

getActiveLayer() {
return this.get('layers')[this.activeLayerName];
},

addLayer(layer, opt) {
const layers = this.get('layers');
if (layers[layer.name]) {
throw new Exception(`dia.Graph: Layer with name '${layer.name}' already exists.`);
}

layers[layer.name] = layer;
},

removeLayer(layerName, opt) {
const layers = this.get('layers');
if (!layers[layerName]) {
throw new Exception(`dia.Graph: Layer with name '${layerName}' does not exist.`);
}

delete layers[layerName];
},

getLayers() {
return Object.values(this.get('layers'));
},

setActiveLayer(layerName) {
const layers = this.get('layers');
if (!layers[layerName]) {
throw new Exception(`dia.Graph: Layer with name '${layerName}' does not exist.`);
}

this.activeLayerName = layerName;
},

// Get a cell by `id`.
getCell: function(id) {

Expand Down
18 changes: 15 additions & 3 deletions packages/joint-core/src/dia/Paper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ export const Paper = View.extend({
this.listenTo(model, 'embeddingLayer:insert', this.onEmbeddingLayerInsert);
this.listenTo(model, 'embeddingLayer:remove', this.onEmbeddingLayerRemove);

this.listenTo(model, 'layer:insert', this.onLayerInsert);
this.listenTo(model, 'layer:remove', this.onLayerRemove);

this.on('cell:highlight', this.onCellHighlight)
.on('cell:unhighlight', this.onCellUnhighlight)
.on('transform', this.update);
Expand Down Expand Up @@ -554,6 +557,16 @@ export const Paper = View.extend({
layerView.remove();
},

onLayerInsert: function(layer, opt) {
const layerView = this.createLayer({ name: layer.get('name'), model: layer });
this.addLayer(layer.get('name'), layerView, { insertBefore: LayersNames.LABELS });
},

onLayerRemove: function(layerName, opt) {
const { viewsMap } = this._layers;
this.removeLayer(viewsMap[layerName]);
},

cloneOptions: function() {

const { options } = this;
Expand Down Expand Up @@ -675,13 +688,12 @@ export const Paper = View.extend({
viewsMap[layerName] = layerView;
},

_getLayerView(layer) {
_getLayerView(layerName) {
const { _layers: { viewsMap }} = this;
if (layer in viewsMap) return viewsMap[layer];
if (layerName in viewsMap) return viewsMap[layerName];
return null;
},


_requireLayerView(layer) {
const layerView = this._getLayerView(layer);
if (!layerView) {
Expand Down