简体   繁体   English

d3事件未触发

[英]d3 Events not triggering

I'm using D3's arc shape and have attached the D3 drag handler to catch drag movement. 我正在使用D3的弧形并附加了D3 drag处理器来捕捉拖动。 Looking at the browser's debugger: 查看浏览器的调试器:

在此输入图像描述

You can see that the resulting Arc's path is indeed listening for the appropriate events and yet the callbacks are never fired and no JS errors are reported to the console. 您可以看到生成的Arc的路径确实正在侦听相应的事件,但回调从未被触发,并且没有向控制台报告JS错误。

The code used to add the handlers (as well as the callbacks) are here. 用于添加处理程序(以及回调)的代码在这里。 For those of you familiar with Ember, great, for those of you not I've tried to only show the relevant JS parts. 对于那些熟悉Ember的人来说,很棒,对于你们这些人我并没有尝试只显示相关的JS部分。

import { drag } from 'd3-drag';
import { arc } from 'd3-shape';
import { select } from 'd3-selection';

const uiArc = Ember.Component.extend({
  layout,
  tagName: '',
  init() {
    this._super(...arguments);
    Ember.run.schedule('afterRender', () => {
      this.svg = document.getElementById(this.elementId);
      this.addDragListeners(`#${this.elementId} .unselected`);
    });
  },

  addDragListeners(target) {
    drag.container = this;
    select(target).call(drag().on('start', this._dragStart));
    select(target).call(drag().on('drag', this._dragging));
    select(target).call(drag().on('end', this._dragEnd));
  },

  _dragStart(e) {
    console.log('drag starting', e);
  },
  _dragging(e) {
    console.log('dragging', e);
  },
  _dragEnd(e) {
    console.log('drag ending', e);
  },

Can anyone help me figure out how to debug this or suggest what might be wrong? 任何人都可以帮我弄清楚如何调试或建议可能出错的地方?

Note: I am using d3 version 4, latest build as of today (30 May, 2016) 注意:我使用的是d3版本4,截至今日(2016年5月30日)的最新版本


For additional context, here too is the Handlebars template responsible for drawing the path: 对于其他上下文,负责绘制路径的Handlebars模板也是:

<path
  d={{arc}}
  class='unselected'
  style="stroke: {{unselectedColor}}; fill: {{unselectedColor}};"
></path>

Nothing very remarkable here, it's just to point out that the template does not invoke any native DOM events and that the class name of "unselected" is available in the DOM for the d3 selector to find it (which it appears to have done; hence the DOM event listeners showing up in debugger). 这里没有什么值得注意的,只是要指出模板不会调用任何本机DOM事件,并且在DOM中可以使用“未选择”的类名来让d3选择器找到它(它似乎已经完成了;因此在调试器中显示的DOM事件侦听器)。


I've added an online demo of the problem: demo . 我已经添加了一个问题的在线演示: demo The drag event is attached to the arc with classname 'unselected'. 拖动事件附加到弧,类名为“未选中”。 You should be able to drag from that shape and have the callbacks fire. 您应该可以从该形状拖动并触发回调。

There's no possibility there's an applied css style that includes pointer-events: none ? 没有可能存在包含pointer-events: none的应用css样式pointer-events: none

IF you look at this jsfiddle example you'll see you can't drag the circles with the class undraggable applied, but it doesn't affect the events the chrome inspector says the elements are listening to 如果您看一下这个jsfiddle示例,您将看到无法拖动应用了类undraggable的圆圈,但它不会影响chrome检查器所说的元素正在侦听的事件

.undraggable {
   pointer-events: none;
}

http://jsfiddle.net/2y2yqy55/1/ http://jsfiddle.net/2y2yqy55/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM