简体   繁体   English

向Series.Toggle中的人力车添加事件

[英]Add event to Series.Toggle in Rickshaw

I want to add functionality when clicking on items in the legend in Rickshaw. 单击人力车中图例中的项目时,我想添加功能。 I use the standard code to add toggle functionality, which I want to extend to run my own function: 我使用标准代码添加了切换功能,我想对其进行扩展以运行自己的功能:

shelving = new Rickshaw.Graph.Behavior.Series.Toggle( { 
        graph: graph,
        legend: legend
}

Is there a way add a function of my own here? 有没有办法在这里添加自己的功能? I also tried looking through and editing the code in Rickshaw.Graph.Behavior.Series.Toggle.js, but I couldn't get anything to run upon clicking items in the legend. 我还尝试浏览并编辑Rickshaw.Graph.Behavior.Series.Toggle.js中的代码,但是单击图例中的项目后我什么也无法运行。 (Might it be that the imported js file is cached so that my edits don't take effect?) (可能是导入的js文件被缓存了,这样我的编辑才能生效吗?)

As you explicitly asked about what source code to modify, I highlighted it below. 当您明确询问要修改哪些源代码时,我在下面突出显示了它。 If you modify the source, upgrading to a new version becomes much harder, extending/creating own version would be the preferred way to go. 如果您修改源代码,则升级到新版本将变得更加困难,扩展/创建自己的版本将是首选方法。

In Rickshaw.Graph.Behavior.Series.Toggle.js 'Rickshaw.Graph.Behavior.Series.Toggle.js' change the following Rickshaw.Graph.Behavior.Series.Toggle.js'Rickshaw.Graph.Behavior.Series.Toggle.js '中,更改以下内容

Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
  ...
  this._addBehavior = function() {
    this.graph.series.forEach( function(s) {
       s.disable = function() {
         if (self.graph.series.length <= 1) {
           throw('only one series left');
         }
         s.disabled = true;
         alert('disabling ' + s.name); //HERE
         self.graph.update();
       };

       s.enable = function() {
         s.disabled = false;
         alert('enabling ' + s.name); //HERE
         self.graph.update();
       };
    } );
  };
  ...
};

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

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