亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

畫筆和過渡并存

畫筆和過渡并存

收到一只叮咚 2021-12-02 19:10:55
我正在使用 d3.js,但遇到了問題。我有一個圖表,在該圖表中我使用畫筆功能來調整軸的比例。當我刷時,我調用函數updateChart:var brush = d3.brush()                    .extent( [ [0,0], [width,height] ] )     .on("end", updateChart)updateChart功能在哪里:function updateChart() {        extent = d3.event.selection        if (!idleTimeout) return idleTimeout = setTimeout(idled, 350);              x = d3.scaleTime()                .domain(d3.extent(data, function(d) {                 return new Date(d.valueX);}))                .rangeRound([0, width]);                y = d3.scaleLinear()                .domain([d3.min(data, function(d){return d.valueY;}),                         d3.max(data, function(d){return d.valueY;})])                .range([ height, 0]);        }else{            x.domain([ x.invert(extent[0][0]), x.invert(extent[1][0]) ])            y.domain([ y.invert(extent[1][1]), y.invert(extent[0][1]) ])            scatter.select(".brush").call(brush.move, null) // This remove the grey brush area as soon as the selection has been done        }        // Update axis and circle position        xAxis.transition().duration(1000).call(d3.axisBottom(x).tickFormat(multiFormat));        yAxis.transition().duration(1000).call(d3.axisLeft(y))        scatter        .selectAll("circle")        .transition().duration(1000)        .attr("cx",function(d) {return x(new Date(d.valueX))} )        .attr("cy", function (d) { return y(d.valueY); } )    }我還有一個功能,當我把鼠標放在一個圓圈上時,它會顯示我的信息。area.on("mouseover", highlight)var highlight = function(d) {            var selected_specie = d.Group            d3.selectAll(".dot")            .transition()            .duration(200)            .style("fill", "lightgrey")            .attr("r", 3)問題是:當我把鼠標放在一個圓圈上時,過渡就完成了。鼠標懸停功能不允許您正確完成過渡。有什么方法可以在我進行轉換時停止監聽鼠標事件?
查看完整描述

1 回答

?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

可以使用以下代碼停止事件:


var brush = d3.brush()                 // Add the brush feature using the d3.brush function

  .extent( [ [0,0], [width,height] ] ) // initialise the brush area: start at 0,0 and finishes at width,height: it means I select the whole graph area

  .on("start", function () {(scatter.attr("pointer-events","none"))})

  .on("end", updateChart)


這樣您就可以在畫筆開始時停止事件。在 updateChart 函數中,最后您必須再次啟動它:


setTimeout(function (){scatter.attr("pointer-events","all");},1001);

這對我有用。


查看完整回答
反對 回復 2021-12-02
  • 1 回答
  • 0 關注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號