big cmap refactoring
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Maintain renderer component order and coordinate hit-test priority.
|
||||
* Derived from ionstage/cmap 0.1.3, (c) 2015 iOnStage, MIT License.
|
||||
*/
|
||||
import { Connector, DrawingLink as Link, DrawingNode as Node } from "./drawing-components.js";
|
||||
import { Component, helper } from "./drawing-support.js";
|
||||
|
||||
class ComponentList extends helper.List {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
toFront(component) {
|
||||
var data = this.data;
|
||||
var index = data.indexOf(component);
|
||||
|
||||
if (index === -1)
|
||||
return;
|
||||
|
||||
data.splice(index, 1);
|
||||
data.push(component);
|
||||
}
|
||||
|
||||
fromPoint(ctor, x, y) {
|
||||
var data = this.data;
|
||||
// The visual stack is connector controls, concepts and finally relations.
|
||||
// Use that same priority for coordinate hit testing so a relation that is
|
||||
// hidden behind a concept can never steal the concept's click.
|
||||
var types = (ctor === Component) ? [Connector, Node, Link] : [ctor];
|
||||
|
||||
for (var toleranceIndex = 0; toleranceIndex < 2; toleranceIndex++) {
|
||||
var tolerance = toleranceIndex === 0 ? 0 : 8;
|
||||
for (var typeIndex = 0; typeIndex < types.length; typeIndex++) {
|
||||
for (var i = data.length - 1; i >= 0; i--) {
|
||||
var component = data[i];
|
||||
|
||||
if (!(component instanceof types[typeIndex]))
|
||||
continue;
|
||||
|
||||
if (component.visible === false)
|
||||
continue;
|
||||
|
||||
if (component.contains(x, y, tolerance))
|
||||
return component;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class DisabledConnectorList extends helper.List {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
add(type, link) {
|
||||
super.add( {
|
||||
type: type,
|
||||
link: link
|
||||
});
|
||||
}
|
||||
|
||||
remove(type, link) {
|
||||
super.remove( {
|
||||
type: type,
|
||||
link: link
|
||||
});
|
||||
}
|
||||
|
||||
contains(type, link) {
|
||||
return super.contains( {
|
||||
type: type,
|
||||
link: link
|
||||
});
|
||||
}
|
||||
|
||||
equal(a, b) {
|
||||
return a.type === b.type && a.link === b.link;
|
||||
}
|
||||
}
|
||||
|
||||
export { ComponentList, DisabledConnectorList };
|
||||
Reference in New Issue
Block a user