1

私はこれに似たものを作成しようとしています http://demo.joostkiens.com/het-parool-4g/

アラームの脈動点

プロットされた円の外側の線が外側にズキズキするところ。

これはこれまでの私のデモです。

http://jsfiddle.net/NYEaX/95/

いくつかのダミー データを使用して円をプロットしました。上には赤ベースの円があります。アニメーションを呼び出して、アラーム データごとにより鮮やかにするにはどうすればよいですか。アラームレベル。

半径が円周を越えて跳ね返ってからフェードアウトするループアニメーションを作成する方法がわかりません-alarmLevelしきい値に基づいてこの多様性を持っています

理想的には、ループでこのように遷移が発生する必要があります。http://jsfiddle.net/pnavarrc/udMUx/

var speedLineGroup = sampleSVG.append("g")
                                        .attr("class", "speedlines");

                            speedLineGroup.selectAll("circle.dl-speed-static")
                                .data(dataset)
                                .enter().append("circle")
                                .style("stroke", "red")
                                .style("fill", "black")
                                .attr("r", function(d){
                                    return d.value;
                                })
                                .attr("cx", function(d){
                                    return d.xcoord;
                                })
                                .attr("cy", function(d){
                                    return d.ycoord;
                                })
                                .attr("class", "dl-speed-static")
                                .attr("stroke-opacity", function (e) {
                                    return 1;
                                    //return var
                                })
                                .attr("fill-opacity", function (e) {
                                    return 1;
                                    //return var
                                })
                                .transition()
                                .ease("linear")
                                .duration(200)
                                .attr("r", function (e) {
                                    return 1;
                                    //return var
                                })

投稿のアイデアを統合しました。リングの作成を独自の機能に配置し、タイムアウトを削除しました。また、マーカーごとのアラームしきい値に接続しようと試み始めました。

http://jsfiddle.net/NYEaX/102/

しかし、アプリケーションはまだ遅延/バグがあるように見えます-主要な例のようにあまり明確ではありません. これをさらに改善するにはどうすればよいでしょうか。一部のアラーム カウントは低いですが、この方法では、リングの鼓動が早すぎたりちらついたりします。アラームを低くするには、値を反転する必要があるようです。応答を遅くします。

            function makeRings() {
                var datapoints = circleGroup.selectAll("circle");
                var radius = 1;

                    function myTransition(circleData){

                        var transition = d3.select(this).transition();

                            speedLineGroup.append("circle")
                              .attr({"class": "ring",
                                     "fill":"red",
                                     "stroke":"red",
                                     "cx": circleData.xcoord,
                                     "cy": circleData.ycoord,
                                     "r":radius,
                                     "opacity": 0.4,
                                     "fill-opacity":0.1
                                    })
                              .transition()
                              .duration(function(){                 
                                return circleData.alarmLevel*100;
                              })
                              .attr("r", radius + 100 )
                              .attr("opacity", 0)
                              .remove();


                        transition.each('end', myTransition);
                    }

              datapoints.each(myTransition);
            } 

これは最新のコードです..

makeRings()

var t = window.setInterval(makeRings, 10000);

                function makeRings() {
                        var datapoints = mapSVG.selectAll("circle.location");
                        var radius = 1;

                            function myTransition(circleData){

                                console.log("circleData", circleData);

                                var transition = d3.select(this).transition();

                                    speedLineGroup.append("circle")
                                      .attr({"class": "ring",
                                             "fill":"red",
                                             "stroke":"red",
                                             "cx": circleData.x * ratio,
                                             "cy": circleData.y * ratio,
                                             "r":radius,
                                             "opacity": 0.4,
                                             "fill-opacity":0.1
                                            })
                                      .transition()
                                      .duration(function(){                 
                                        return (circleData.redSum * 100);
                                      })
                                      .attr("r", radius + 30 )
                                      .attr("opacity", 0)
                                      .remove();


                                transition.each('end', myTransition);
                            }

                      datapoints.each(myTransition);
                    } 
4

2 に答える 2

1

リンク先の例では縮小されたコードを使用しているため、何をしているのかを理解するのは少し面倒です。ただし、DOM インスペクターで変更を確認すると、各リングが新しい円であり、追加され、サイズが大きくなり、反対側を向いてから削除されることがわかります。異なるポイントは、リングが消える前にどれだけ大きくなるかによって異なります (したがって、リングはすべて同じ速度で成長するため、一度に表示されるリングの数も異なります)。

これを無期限に継続させるために私が取るアプローチは次のとおりです。

  1. 「setInterval」を使用して、各データ サークルの周りに新しいリングを作成する関数を定期的に (たとえば、1 秒に 1 回または 2 回) 呼び出します。

  2. .each()データ サークルの呼び出しを使用してリングを作成しますが、それらを別の<g>要素に追加したり、別のクラス名を付けたりして、リングとデータ ポイントを混同しないようにします。

  3. リングの初期半径をデータ ポイントと同じに設定しますが、すぐにその上で遷移を開始します。遷移の持続時間を関連するデータ サークルの「強度」データ値の関数にし、最終的な半径もそのデータ値の関数にします。また、不透明度を値 0 に移行します。

  4. リングの遷移の最終行を作成して.remove()、各リングが拡張を終了した後にそれ自体を削除するようにします。

基本コード:

window.setInterval(makeRings, 1000);

function makeRings() {

  datapoints.each(function(circleData){  
       //datapoints is your d3 selection of circle elements

    speedLineGroup.append("circle")
      .attr({"class": "ring",
             "fill":"red", //or use CSS to set fill and stroke styles
             "stroke":"red",
             "cx": circleData.xCoord,
             "cy": circleData.yCoord,
                 //position according to this circle's position
             "r":radius, //starting radius, 
                         //set according to the radius used for data points
             "opacity": 0.8, //starting opacity
             "fill-opacity":0.5 //fill will always be half of the overall opacity
            })
      .transition()
      .duration( intensityTimeScale(circleData.intensity) )
          //Use an appropriate linear scale to set the time it takes for 
          //the circles to expand to their maximum radius.
          //Note that you *don't* use function(d){}, since we're using the data
          //passed to the .each function from the data point, not data
          //attached to the ring
      .attr("r", radius + intensityRadiusScale(circleData.intensity) )
          //transition radius
          //again, create an appropriate linear scale
      .attr("opacity", 0) //transition opacity
      .remove(); //remove when transition is complete

  });
}

半径の変化と遷移の持続時間の両方が強度値の線形関数であるため、変化はすべてのデータ ポイントで一定の速度になります。

于 2014-02-13T20:45:23.400 に答える