-
Notifications
You must be signed in to change notification settings - Fork 884
feat(layers): Graph and Paper embedding layers implementation #2908
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
base: master
Are you sure you want to change the base?
Changes from 33 commits
5ddbc5e
724b1a8
044af30
af043f2
60bbcd9
5832a22
bb09418
9a9aeac
6249685
1a208bc
309edaa
099cf81
2f2c482
62ed851
903e922
b491ea8
1533570
0752076
163c221
c66280b
c2dc6ae
0a2f047
8a03a89
d058bac
468a6c6
5083b69
dab0da8
58be262
15ec945
e4786f2
1487770
bf9a4c8
7864d01
4d8ed05
4152946
2c6c5d9
29ca501
ec9a33a
505fc50
6eb29f1
a94376e
ed79f8e
8358fa8
5e4b02b
8328efe
34812b6
d861c35
3c6aa1d
a852825
8782e66
b08e3ec
49f8a85
c32030d
57f18b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| import * as util from '../util/index.mjs'; | ||
| import * as g from '../g/index.mjs'; | ||
|
|
||
| import { GraphLayer } from './layers/GraphLayer.mjs'; | ||
| import { Model } from '../mvc/Model.mjs'; | ||
| import { Collection } from '../mvc/Collection.mjs'; | ||
| import { wrappers, wrapWith } from '../util/wrappers.mjs'; | ||
| import { cloneCells } from '../util/index.mjs'; | ||
| import { GraphLayersController } from './controllers/GraphLayersController.mjs'; | ||
|
|
||
| const GraphCells = Collection.extend({ | ||
|
|
||
|
|
@@ -19,7 +21,6 @@ const GraphCells = Collection.extend({ | |
| /* eslint-enable no-undef */ | ||
| } | ||
|
|
||
|
|
||
| this.graph = opt.graph; | ||
| }, | ||
|
|
||
|
|
@@ -70,6 +71,17 @@ export const Graph = Model.extend({ | |
|
|
||
| opt = opt || {}; | ||
|
|
||
| this.enableCellLayers = opt.enableCellLayers || false; | ||
|
|
||
| this.defaultLayerName = 'cells'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should move this outside as class property |
||
|
|
||
| const defaultLayer = new GraphLayer({ | ||
| name: this.defaultLayerName | ||
| }); | ||
|
|
||
| this.layersController = new GraphLayersController({ graph: this }); | ||
| this.layersController.addLayer(defaultLayer); | ||
|
|
||
| // Passing `cellModel` function in the options object to graph allows for | ||
| // setting models based on attribute objects. This is especially handy | ||
| // when processing JSON graphs that are in a different than JointJS format. | ||
|
|
@@ -84,10 +96,6 @@ export const Graph = Model.extend({ | |
| // to the outside world. | ||
| cells.on('all', this.trigger, this); | ||
|
|
||
| // JointJS automatically doesn't trigger re-sort if models attributes are changed later when | ||
| // they're already in the collection. Therefore, we're triggering sort manually here. | ||
| this.on('change:z', this._sortOnChangeZ, this); | ||
|
|
||
| // `joint.dia.Graph` keeps an internal data structure (an adjacency list) | ||
| // for fast graph queries. All changes that affect the structure of the graph | ||
| // must be reflected in the `al` object. This object provides fast answers to | ||
|
|
@@ -120,11 +128,6 @@ export const Graph = Model.extend({ | |
| cells.on('remove', this._removeCell, this); | ||
| }, | ||
|
|
||
| _sortOnChangeZ: function() { | ||
|
|
||
| this.get('cells').sort(); | ||
| }, | ||
|
|
||
| _restructureOnAdd: function(cell) { | ||
|
|
||
| if (cell.isLink()) { | ||
|
|
@@ -157,10 +160,10 @@ export const Graph = Model.extend({ | |
| } | ||
| }, | ||
|
|
||
| _restructureOnReset: function(cells) { | ||
| _restructureOnReset: function(collection) { | ||
|
|
||
| // Normalize into an array of cells. The original `cells` is GraphCells mvc collection. | ||
| cells = cells.models; | ||
| // Normalize into an array of cells. The original `collection` is GraphCells mvc collection. | ||
| const cells = collection.models; | ||
|
|
||
| this._out = {}; | ||
| this._in = {}; | ||
|
|
@@ -295,16 +298,16 @@ export const Graph = Model.extend({ | |
| return cell; | ||
| }, | ||
|
|
||
| minZIndex: function() { | ||
|
|
||
| var firstCell = this.get('cells').first(); | ||
| return firstCell ? (firstCell.get('z') || 0) : 0; | ||
| minZIndex: function(layerName) { | ||
| return this.layersController.minZIndex(layerName); | ||
| }, | ||
|
|
||
| maxZIndex: function() { | ||
| maxZIndex: function(layerName) { | ||
| return this.layersController.maxZIndex(layerName); | ||
| }, | ||
|
|
||
| var lastCell = this.get('cells').last(); | ||
| return lastCell ? (lastCell.get('z') || 0) : 0; | ||
| addToLayer: function(cell, layer) { | ||
| this.layersController.addToLayer(cell, layer); | ||
| }, | ||
|
|
||
| addCell: function(cell, opt) { | ||
|
|
@@ -314,17 +317,6 @@ export const Graph = Model.extend({ | |
| return this.addCells(cell, opt); | ||
| } | ||
|
|
||
| if (cell instanceof Model) { | ||
|
|
||
| if (!cell.has('z')) { | ||
| cell.set('z', this.maxZIndex() + 1); | ||
| } | ||
|
|
||
| } else if (cell.z === undefined) { | ||
|
|
||
| cell.z = this.maxZIndex() + 1; | ||
| } | ||
|
|
||
| this.get('cells').add(this._prepareCell(cell, opt), opt || {}); | ||
|
|
||
| return this; | ||
|
|
@@ -338,10 +330,10 @@ export const Graph = Model.extend({ | |
| opt.maxPosition = opt.position = cells.length - 1; | ||
|
|
||
| this.startBatch('add', opt); | ||
| cells.forEach(function(cell) { | ||
| cells.forEach((cell) => { | ||
| this.addCell(cell, opt); | ||
| opt.position--; | ||
| }, this); | ||
| }); | ||
| this.stopBatch('add', opt); | ||
|
|
||
| return this; | ||
|
|
@@ -352,11 +344,16 @@ export const Graph = Model.extend({ | |
| // Useful for bulk operations and optimizations. | ||
| resetCells: function(cells, opt) { | ||
|
|
||
| this.startBatch('reset', opt); | ||
|
|
||
| var preparedCells = util.toArray(cells).map(function(cell) { | ||
| return this._prepareCell(cell, opt); | ||
| }, this); | ||
|
|
||
| this.get('cells').reset(preparedCells, opt); | ||
|
|
||
| this.stopBatch('reset', opt); | ||
|
|
||
| return this; | ||
| }, | ||
|
|
||
|
|
@@ -429,35 +426,63 @@ export const Graph = Model.extend({ | |
| this.stopBatch(batchName); | ||
| }, | ||
|
|
||
| addLayer(layer, opt) { | ||
| this.layersController.addLayer(layer, opt); | ||
| }, | ||
|
|
||
| removeLayer(layer, opt) { | ||
| this.layersController.removeLayer(layer.name, opt); | ||
| }, | ||
|
|
||
| getDefaultLayer() { | ||
| return this.layersController.getDefaultLayer(); | ||
| }, | ||
|
|
||
| getLayer(name) { | ||
| return this.layersController.getLayer(name); | ||
| }, | ||
|
|
||
| hasLayer(name) { | ||
| return this.layersController.hasLayer(name); | ||
| }, | ||
|
|
||
| getLayers() { | ||
| return this.layersController.getLayers(); | ||
| }, | ||
|
|
||
| getLayerCells(layerName) { | ||
| return this.layersController.getLayerCells(layerName); | ||
| }, | ||
|
|
||
| // Get a cell by `id`. | ||
| getCell: function(id) { | ||
|
|
||
| return this.get('cells').get(id); | ||
| }, | ||
|
|
||
| getCells: function() { | ||
|
|
||
| return this.get('cells').toArray(); | ||
| // Preserve old order without layers | ||
| return this.layersController.getCells(); | ||
| }, | ||
|
|
||
| getElements: function() { | ||
|
|
||
| return this.get('cells').toArray().filter(cell => cell.isElement()); | ||
| return this.getCells().filter(cell => cell.isElement()); | ||
| }, | ||
|
|
||
| getLinks: function() { | ||
|
|
||
| return this.get('cells').toArray().filter(cell => cell.isLink()); | ||
| return this.getCells().filter(cell => cell.isLink()); | ||
| }, | ||
|
|
||
| getFirstCell: function() { | ||
|
|
||
| return this.get('cells').first(); | ||
| return this.getCells().first(); | ||
| }, | ||
|
|
||
| getLastCell: function() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should accept |
||
|
|
||
| return this.get('cells').last(); | ||
| return this.getCells().last(); | ||
| }, | ||
|
|
||
| // Get all inbound and outbound links connected to the cell `model`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,7 @@ export const HighlighterView = mvc.View.extend({ | |
| vGroup = V('g').addClass('highlight-transform').append(el); | ||
| } | ||
| this.transformGroup = vGroup; | ||
| paper.getLayerView(layerName).insertSortedNode(vGroup.node, options.z); | ||
| paper.getLayer(layerName).insertSortedNode(vGroup.node, options.z); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } else { | ||
| // TODO: prepend vs append | ||
| if (!el.parentNode || el.nextSibling) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not seem to be used anywhere