-
Notifications
You must be signed in to change notification settings - Fork 853
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(dia.CellView)!: early evaluation of calc attributes (#2459)
- Loading branch information
1 parent
1d392a1
commit da5000b
Showing
19 changed files
with
796 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Point } from '../../g/index.mjs'; | ||
|
||
function atConnectionWrapper(method, opt) { | ||
var zeroVector = new Point(1, 0); | ||
return function(value) { | ||
var p, angle; | ||
var tangent = this[method](value); | ||
if (tangent) { | ||
angle = (opt.rotate) ? tangent.vector().vectorAngle(zeroVector) : 0; | ||
p = tangent.start; | ||
} else { | ||
p = this.path.start; | ||
angle = 0; | ||
} | ||
if (angle === 0) return { transform: 'translate(' + p.x + ',' + p.y + ')' }; | ||
return { transform: 'translate(' + p.x + ',' + p.y + ') rotate(' + angle + ')' }; | ||
}; | ||
} | ||
|
||
function isLinkView() { | ||
return this.model.isLink(); | ||
} | ||
|
||
const connectionAttributesNS = { | ||
|
||
'connection': { | ||
qualify: isLinkView, | ||
set: function({ stubs = 0 }) { | ||
let d; | ||
if (isFinite(stubs) && stubs !== 0) { | ||
let offset; | ||
if (stubs < 0) { | ||
offset = (this.getConnectionLength() + stubs) / 2; | ||
} else { | ||
offset = stubs; | ||
} | ||
const path = this.getConnection(); | ||
const segmentSubdivisions = this.getConnectionSubdivisions(); | ||
const sourceParts = path.divideAtLength(offset, { segmentSubdivisions }); | ||
const targetParts = path.divideAtLength(-offset, { segmentSubdivisions }); | ||
if (sourceParts && targetParts) { | ||
d = `${sourceParts[0].serialize()} ${targetParts[1].serialize()}`; | ||
} | ||
} | ||
|
||
return { d: d || this.getSerializedConnection() }; | ||
} | ||
}, | ||
|
||
'at-connection-length-keep-gradient': { | ||
qualify: isLinkView, | ||
set: atConnectionWrapper('getTangentAtLength', { rotate: true }) | ||
}, | ||
|
||
'at-connection-length-ignore-gradient': { | ||
qualify: isLinkView, | ||
set: atConnectionWrapper('getTangentAtLength', { rotate: false }) | ||
}, | ||
|
||
'at-connection-ratio-keep-gradient': { | ||
qualify: isLinkView, | ||
set: atConnectionWrapper('getTangentAtRatio', { rotate: true }) | ||
}, | ||
|
||
'at-connection-ratio-ignore-gradient': { | ||
qualify: isLinkView, | ||
set: atConnectionWrapper('getTangentAtRatio', { rotate: false }) | ||
} | ||
|
||
}; | ||
|
||
connectionAttributesNS['at-connection-length'] = connectionAttributesNS['at-connection-length-keep-gradient']; | ||
connectionAttributesNS['at-connection-ratio'] = connectionAttributesNS['at-connection-ratio-keep-gradient']; | ||
|
||
export default connectionAttributesNS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { assign, isPlainObject } from '../../util/util.mjs'; | ||
|
||
function contextMarker(context) { | ||
var marker = {}; | ||
// Stroke | ||
// The context 'fill' is disregarded here. The usual case is to use the marker with a connection | ||
// (for which 'fill' attribute is set to 'none'). | ||
var stroke = context.stroke; | ||
if (typeof stroke === 'string') { | ||
marker['stroke'] = stroke; | ||
marker['fill'] = stroke; | ||
} | ||
// Opacity | ||
// Again the context 'fill-opacity' is ignored. | ||
var strokeOpacity = context['stroke-opacity']; | ||
if (strokeOpacity === undefined) strokeOpacity = context.opacity; | ||
if (strokeOpacity !== undefined) { | ||
marker['stroke-opacity'] = strokeOpacity; | ||
marker['fill-opacity'] = strokeOpacity; | ||
} | ||
return marker; | ||
} | ||
|
||
function setPaintURL(def) { | ||
const { paper } = this; | ||
const url = (def.type === 'pattern') | ||
? paper.definePattern(def) | ||
: paper.defineGradient(def); | ||
return `url(#${url})`; | ||
} | ||
|
||
const defsAttributesNS = { | ||
|
||
'source-marker': { | ||
qualify: isPlainObject, | ||
set: function(marker, refBBox, node, attrs) { | ||
marker = assign(contextMarker(attrs), marker); | ||
return { 'marker-start': 'url(#' + this.paper.defineMarker(marker) + ')' }; | ||
} | ||
}, | ||
|
||
'target-marker': { | ||
qualify: isPlainObject, | ||
set: function(marker, refBBox, node, attrs) { | ||
marker = assign(contextMarker(attrs), { 'transform': 'rotate(180)' }, marker); | ||
return { 'marker-end': 'url(#' + this.paper.defineMarker(marker) + ')' }; | ||
} | ||
}, | ||
|
||
'vertex-marker': { | ||
qualify: isPlainObject, | ||
set: function(marker, refBBox, node, attrs) { | ||
marker = assign(contextMarker(attrs), marker); | ||
return { 'marker-mid': 'url(#' + this.paper.defineMarker(marker) + ')' }; | ||
} | ||
}, | ||
|
||
'fill': { | ||
qualify: isPlainObject, | ||
set: setPaintURL | ||
}, | ||
|
||
'stroke': { | ||
qualify: isPlainObject, | ||
set: setPaintURL | ||
}, | ||
|
||
'filter': { | ||
qualify: isPlainObject, | ||
set: function(filter) { | ||
return 'url(#' + this.paper.defineFilter(filter) + ')'; | ||
} | ||
}, | ||
}; | ||
|
||
export default defsAttributesNS; |
Oops, something went wrong.