简体   繁体   English

用于响应平移/缩放的范围更新的浮动事件

[英]Flot event for range updates in response to panning/zooming

For Flot, is there an event that fires after the user has completed panning or zooming using the mouse scroll wheel (after the range.xaxis.to / from and range.yaxis.to / from have settled)?对于 Flot,是否有在用户使用鼠标滚轮完成平移或缩放后触发的事件(在range.xaxis.to / fromrange.yaxis.to / from确定之后)? I am trying to use the line below to update the selection on an overview plot after the user has panned or zoomed in the main plot, but am finding that either the update to the overview plot happens after panning or zooming(not both).我正在尝试使用下面的行在用户平移或放大主图后更新概览图上的选择,但我发现对概览图的更新发生在平移或缩放(不是两者)之后。

$("#plot").bind("mouseup scroll",updateOverviewSelection);

Edit : http://jsfiddle.net/apandit/nu2rr58h/9/编辑http : //jsfiddle.net/apandit/nu2rr58h/9/

In the jsfiddle, I am unable to pan in the main plot and the cursor does not seem to change back to normal.在 jsfiddle 中,我无法在主图中平移,并且光标似乎没有恢复正常。 The user can click and drag in the overview plot to make a selection, which leads to zooming in the main plot.用户可以在概览图中单击并拖动以进行选择,从而放大主图。 I would also like to be able to allow the user to pan and zoom in the main plot and have the selection box in the overview plot updated;我还希望能够允许用户在主图中平移和放大并更新概览图中的选择框; I am attempting to do this by binding the updateOverviewSelection method to the plot div for the scroll and mouseup events.我试图通过将updateOverviewSelection方法绑定到 scroll 和 mouseup 事件的 plot div 来做到这一点。 Is there an event in Flot that fires every time the x- and y-axis limits are updated?每次更新 x 轴和 y 轴限制时,Flot 中是否都会触发一个事件?

The solution to this issue is below.此问题的解决方案如下。 The issue was that setting the overview plot's selection( overview.setSelection(ranges); ) was triggering the zoom method because it was bound to the plotselected event in the overview plot.问题是设置概览图的选择( overview.setSelection(ranges); )会触发缩放方法,因为它绑定到概览图中的plotselected事件。 At the end of the zoom method, the main plot was plotted, which was again calling the overview.setSelection(ranges);zoom方法的最后,绘制了主图,它再次调用了overview.setSelection(ranges); line in the updateOverviewSelection method. updateOverviewSelection方法中的行。 To prevent this ping-pong between the two methods/events, I added an updatingOverviewSelection flag.为了防止这两种方法/事件之间发生这种情况,我添加了一个updatingOverviewSelection标志。

http://jsfiddle.net/apandit/nu2rr58h/12/ http://jsfiddle.net/apandit/nu2rr58h/12/

var datasets = [[
                    [0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9]
                ],
                [
                    [0,0],[-1,-1],[-2,-2],[-3,-3],[-4,-4],[-5,-5],[-6,-6],[-7,-7],[-8,-8],[-9,-9]
                ]];

var plot = $.plot("#plot",datasets,{
        pan: {
          interactive: true
        },
        zoom: {
          interactive: true,
          mode: "x"
        }
    });

var overview = $.plot("#overview",datasets,{
    selection: {
        mode: "xy"
    }
});

var updatingOverviewSelection = false;

$("#plot").bind("plotpan plotzoom",updateOverviewSelection);
$("#overview").bind("plotselected", zoom);

function zoom(event,ranges) {
    if(updatingOverviewSelection) {
        updatingOverviewSelection = false;
    }
    else {
        var options = plot.getOptions();

        options.xaxes[0].min = ranges.xaxis.from;
        options.xaxes[0].max = ranges.xaxis.to;
        options.yaxes[0].min = ranges.yaxis.from;
        options.yaxes[0].max = ranges.yaxis.to;         

        plot = $.plot("#plot",datasets,options);
    }
};

// get the window x-axis and y-axis ranges for the main plot
// and set the selection in the overview plot to those ranges
function updateOverviewSelection(event) {
        var options = plot.getOptions();

        var ranges = {
            xaxis: {
                from: options.xaxes[0].min,
                to: options.xaxes[0].max
            },
            yaxis: {
                from: options.yaxes[0].min,
                to: options.yaxes[0].max
            }
        };

        updatingOverviewSelection = true;
        overview.setSelection(ranges);
};

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

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