D3.js 焦点布局拖动和鼠标功能
我理解正在使用的|、&、~运算符,但仍然无法解释这些函数:D3.js 焦点布局拖动和鼠标功能,d3.js,D3.js,我理解正在使用的|、&、~运算符,但仍然无法解释这些函数: function d3_layout_forceDragstart(d) { d.fixed |= 2; } function d3_layout_forceDragend(d) { d.fixed &= ~6; } function d3_layout_forceMouseover(d) { d.fixed |= 4; d.px = d.x, d.py = d.y; } function d3_
function d3_layout_forceDragstart(d) {
d.fixed |= 2;
}
function d3_layout_forceDragend(d) {
d.fixed &= ~6;
}
function d3_layout_forceMouseover(d) {
d.fixed |= 4;
d.px = d.x, d.py = d.y;
}
function d3_layout_forceMouseout(d) {
d.fixed &= ~4;
}
这些只是使用按位AND、OR和NOT设置位标志。如果您查看文档,则会记录它们的使用情况:
// The fixed property has three bits:
// Bit 1 can be set externally (e.g., d.fixed = true) and show persist.
// Bit 2 stores the dragging state, from mousedown to mouseup.
// Bit 3 stores the hover state, from mouseover to mouseout.
// Dragend is a special case: it also clears the hover state.
function d3_layout_forceDragstart(d) {
d.fixed |= 2; // set bit 2
}
function d3_layout_forceDragend(d) {
d.fixed &= ~6; // unset bits 2 and 3
}
function d3_layout_forceMouseover(d) {
d.fixed |= 4; // set bit 3
d.px = d.x, d.py = d.y; // set velocity to zero
}
function d3_layout_forceMouseout(d) {
d.fixed &= ~4; // unset bit 3
}
嘿,谢谢,我想我在看一个旧版本,我没有看到任何评论