mxGraph 连接处理程序鼠标光标不会更改为手形光标
mxGraph connection handler mouse cursor does not change to hand cursor
我创建了一个新的 mxgraph 反应项目。
当鼠标移动到顶点光标变为 move_cursor。但我想创建一个 link 并且光标将是手形光标。我怎么解决这个问题?
有一个关于连接设置的代码片段。
settingConnection = () => {
const { graph } = this.state;
mxConstraintHandler.prototype.intersects = function(
icon,
point,
source,
existingEdge
) {
return !source || existingEdge || mxUtils.intersects(icon.bounds, point);
};
var mxConnectionHandlerUpdateEdgeState =
mxConnectionHandler.prototype.updateEdgeState;
mxConnectionHandler.prototype.updateEdgeState = function(pt, constraint) {
if (pt != null && this.previous != null) {
var constraints = this.graph.getAllConnectionConstraints(this.previous);
var nearestConstraint = null;
var dist = null;
for (var i = 0; i < constraints.length; i++) {
var cp = this.graph.getConnectionPoint(this.previous, constraints[i]);
if (cp != null) {
var tmp =
(cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
if (dist == null || tmp < dist) {
nearestConstraint = constraints[i];
dist = tmp;
}
}
}
if (nearestConstraint != null) {
this.sourceConstraint = nearestConstraint;
}
// In case the edge style must be changed during the preview:
// this.edgeState.style['edgeStyle'] = 'orthogonalEdgeStyle';
// And to use the new edge style in the new edge inserted into the graph,
// update the cell style as follows:
//this.edgeState.cell.style = mxUtils.setStyle(this.edgeState.cell.style, 'edgeStyle', this.edgeState.style['edgeStyle']);
}
mxConnectionHandlerUpdateEdgeState.apply(this, arguments);
};
if (graph.connectionHandler.connectImage == null) {
graph.connectionHandler.isConnectableCell = function(cell) {
return false;
};
mxEdgeHandler.prototype.isConnectableCell = function(cell) {
return graph.connectionHandler.isConnectableCell(cell);
};
}
graph.getAllConnectionConstraints = function(terminal) {
if (terminal != null && this.model.isVertex(terminal.cell)) {
return [
new mxConnectionConstraint(new mxPoint(0.5, 0), true),
new mxConnectionConstraint(new mxPoint(0, 0.5), true),
new mxConnectionConstraint(new mxPoint(1, 0.5), true),
new mxConnectionConstraint(new mxPoint(0.5, 1), true)
];
}
return null;
};
// Connect preview
graph.connectionHandler.createEdgeState = function(me) {
var edge = graph.createEdge(
null,
null,
"Edge",
null,
null,
"edgeStyle=orthogonalEdgeStyle"
);
return new mxCellState(
this.graph.view,
edge,
this.graph.getCellStyle(edge)
);
};
};
鼠标光标只变为移动光标,但我想当鼠标移动到顶点时变为手形光标。
当我删除一些代码时,
var mxConnectionHandlerUpdateEdgeState =
mxConnectionHandler.prototype.updateEdgeState;
mxConnectionHandler.prototype.updateEdgeState = function(pt, constraint) {
if (pt != null && this.previous != null) {
var constraints = this.graph.getAllConnectionConstraints(this.previous);
var nearestConstraint = null;
var dist = null;
for (var i = 0; i < constraints.length; i++) {
var cp = this.graph.getConnectionPoint(this.previous, constraints[i]);
if (cp != null) {
var tmp =
(cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
if (dist == null || tmp < dist) {
nearestConstraint = constraints[i];
dist = tmp;
}
}
}
if (nearestConstraint != null) {
this.sourceConstraint = nearestConstraint;
}
// In case the edge style must be changed during the preview:
// this.edgeState.style['edgeStyle'] = 'orthogonalEdgeStyle';
// And to use the new edge style in the new edge inserted into the graph,
// update the cell style as follows:
//this.edgeState.cell.style = mxUtils.setStyle(this.edgeState.cell.style, 'edgeStyle', this.edgeState.style['edgeStyle']);
}
mxConnectionHandlerUpdateEdgeState.apply(this, arguments);
};
if (graph.connectionHandler.connectImage == null) {
graph.connectionHandler.isConnectableCell = function(cell) {
return false;
};
mxEdgeHandler.prototype.isConnectableCell = function(cell) {
return graph.connectionHandler.isConnectableCell(cell);
};
}
我写了这段代码,
// Enables connect preview for the default edge style
graph.connectionHandler.createEdgeState = function(me) {
var edge = graph.createEdge(null, null, null, null, null);
return new gr.mxCellState(
this.graph.view,
edge,
this.graph.getCellStyle(edge)
);
我解决了这个问题:)
我创建了一个新的 mxgraph 反应项目。 当鼠标移动到顶点光标变为 move_cursor。但我想创建一个 link 并且光标将是手形光标。我怎么解决这个问题? 有一个关于连接设置的代码片段。
settingConnection = () => {
const { graph } = this.state;
mxConstraintHandler.prototype.intersects = function(
icon,
point,
source,
existingEdge
) {
return !source || existingEdge || mxUtils.intersects(icon.bounds, point);
};
var mxConnectionHandlerUpdateEdgeState =
mxConnectionHandler.prototype.updateEdgeState;
mxConnectionHandler.prototype.updateEdgeState = function(pt, constraint) {
if (pt != null && this.previous != null) {
var constraints = this.graph.getAllConnectionConstraints(this.previous);
var nearestConstraint = null;
var dist = null;
for (var i = 0; i < constraints.length; i++) {
var cp = this.graph.getConnectionPoint(this.previous, constraints[i]);
if (cp != null) {
var tmp =
(cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
if (dist == null || tmp < dist) {
nearestConstraint = constraints[i];
dist = tmp;
}
}
}
if (nearestConstraint != null) {
this.sourceConstraint = nearestConstraint;
}
// In case the edge style must be changed during the preview:
// this.edgeState.style['edgeStyle'] = 'orthogonalEdgeStyle';
// And to use the new edge style in the new edge inserted into the graph,
// update the cell style as follows:
//this.edgeState.cell.style = mxUtils.setStyle(this.edgeState.cell.style, 'edgeStyle', this.edgeState.style['edgeStyle']);
}
mxConnectionHandlerUpdateEdgeState.apply(this, arguments);
};
if (graph.connectionHandler.connectImage == null) {
graph.connectionHandler.isConnectableCell = function(cell) {
return false;
};
mxEdgeHandler.prototype.isConnectableCell = function(cell) {
return graph.connectionHandler.isConnectableCell(cell);
};
}
graph.getAllConnectionConstraints = function(terminal) {
if (terminal != null && this.model.isVertex(terminal.cell)) {
return [
new mxConnectionConstraint(new mxPoint(0.5, 0), true),
new mxConnectionConstraint(new mxPoint(0, 0.5), true),
new mxConnectionConstraint(new mxPoint(1, 0.5), true),
new mxConnectionConstraint(new mxPoint(0.5, 1), true)
];
}
return null;
};
// Connect preview
graph.connectionHandler.createEdgeState = function(me) {
var edge = graph.createEdge(
null,
null,
"Edge",
null,
null,
"edgeStyle=orthogonalEdgeStyle"
);
return new mxCellState(
this.graph.view,
edge,
this.graph.getCellStyle(edge)
);
};
};
鼠标光标只变为移动光标,但我想当鼠标移动到顶点时变为手形光标。
当我删除一些代码时,
var mxConnectionHandlerUpdateEdgeState =
mxConnectionHandler.prototype.updateEdgeState;
mxConnectionHandler.prototype.updateEdgeState = function(pt, constraint) {
if (pt != null && this.previous != null) {
var constraints = this.graph.getAllConnectionConstraints(this.previous);
var nearestConstraint = null;
var dist = null;
for (var i = 0; i < constraints.length; i++) {
var cp = this.graph.getConnectionPoint(this.previous, constraints[i]);
if (cp != null) {
var tmp =
(cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
if (dist == null || tmp < dist) {
nearestConstraint = constraints[i];
dist = tmp;
}
}
}
if (nearestConstraint != null) {
this.sourceConstraint = nearestConstraint;
}
// In case the edge style must be changed during the preview:
// this.edgeState.style['edgeStyle'] = 'orthogonalEdgeStyle';
// And to use the new edge style in the new edge inserted into the graph,
// update the cell style as follows:
//this.edgeState.cell.style = mxUtils.setStyle(this.edgeState.cell.style, 'edgeStyle', this.edgeState.style['edgeStyle']);
}
mxConnectionHandlerUpdateEdgeState.apply(this, arguments);
};
if (graph.connectionHandler.connectImage == null) {
graph.connectionHandler.isConnectableCell = function(cell) {
return false;
};
mxEdgeHandler.prototype.isConnectableCell = function(cell) {
return graph.connectionHandler.isConnectableCell(cell);
};
}
我写了这段代码,
// Enables connect preview for the default edge style
graph.connectionHandler.createEdgeState = function(me) {
var edge = graph.createEdge(null, null, null, null, null);
return new gr.mxCellState(
this.graph.view,
edge,
this.graph.getCellStyle(edge)
);
我解决了这个问题:)