Fleet cards do not match

I use fleet diagrams to display ecg signals. The requirement is that the background of the chart look exactly like an ecg graphic document.

All inner gray lines must be aligned with exact dots to draw perfect squares on the ecg sheet. However, there are several lines that are not evenly spaced (they are closer to each other), which makes the ecg graph background incorrect.

Here is what my code does:

MARKING: I wrote a function to create labels on the x and y axis. Markings are dark pink lines on the chart. These markings will be generated on the x and y axis after 4 gray lines (which make up the smaller gray squares inside the large dark pink boxes). It seems that they are drawn correctly.

TONGS: I redefined my own Flot loop generator by writing two functions that generate ticks along the x and y axis. On the x axis, every 40 ms represents one tick (one gray line), and on the y axis 0.1 millivolts represents one gray line. Despite the fact that the functions generate the correct arrays with the correct values ​​for ticks, the tick interval on the fleet chart is small. Some tick lines are more closely spaced, which is incorrect.

Not all ticks are drawn incorrectly. However, those that have the wrong interval are significant in number and are visible with a closer inspection of the chart. For starters, the 4th column and line of the graph have uneven lines. (In a browser outside of jsfiddle, this becomes the third row and third column). These uneven ticks are repeated randomly throughout the chart.

. JSFiddle

- ? ? .

JavaScript:

    $(function() {
        var d2=[];

         // Make markings on x and y axis for drawing the more spaced grid lines
         function markingsArray(axes) {
            var markings = [];
            for (var x = 200; x < axes.xaxis.max; x += 200)
                markings.push({ xaxis: { from: x, to: x },color: "#EE1983" });
            for (var y = -5; y < axes.yaxis.max; y += 0.5)
                markings.push({ yaxis: { from: y, to: y },color: "#EE1983" });
            return markings;
     }

     var options = {
        series: {
            shadowSize: 0,  // Drawing is faster without shadows
             lines: {
                    lineWidth: 1,
                }
        },
        yaxis: {
            ticks: function(axis){
                var res = [];
                var tickDrawCounter = 1;
                var tickIncrement=0.1;
                for(var i=-4.9;i<5;i+=tickIncrement){
                    if(tickDrawCounter<5){
                        res.push([parseFloat(i).toFixed(1),""]);
                        tickDrawCounter++;
                }else{
                    tickDrawCounter=1;
                }
                }
                return res;
            },
            min: -5,
            max: 5          
            },
        xaxis: {
            ticks: function(axis) {
                var res = [];
                var tickDrawCounter = 1;
                var tickIncrement=40;
                for(var i=tickIncrement;i<8000;i+=tickIncrement){
                    if(tickDrawCounter<5){
                        res.push([parseFloat(i),""]);
                        tickDrawCounter++;
                }else
                    tickDrawCounter=1;
                }
                return res;
            },
            min:0,
            max:8000,
            },
        colors: ["#0000A0"], // color of the series plot
        grid:{
            markings: markingsArray,
            backgroundColor:"pink",
            markingsLineWidth:1,
            }
    }
    $.plot("#placeholder",[ d2],options);

    // Add the Flot version string to the footer

    $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
}   


);
+4
1

.

:

 [1] -4.9 -4.8 -4.7 -4.6 -4.4 -4.3 -4.2 -4.1 -3.9 -3.8 -3.7 -3.6 -3.4 -3.3 -3.2
[16] -3.1 -2.9 -2.8 -2.7 -2.6 -2.4 -2.3 -2.2 -2.1 -1.9 -1.8 -1.7 -1.6 -1.4 -1.3

:

 [1] 0.1 0.1 0.1 0.2 0.1 0.1 0.1 0.2 0.1 0.1 0.1 0.2 0.1 0.1 0.1 0.2 0.1 0.1 0.1
[20] 0.2 0.1 0.1 0.1 0.2 0.1 0.1 0.1 0.2 0.1 0.1 0.1 0.2 0.1 0.1 0.1 0.2 0.1 0.1

, . , . :

 [1] 479.16 474.32 469.48 464.64 454.96 450.12 445.28 440.44 430.76 425.92
[11] 421.08 416.24 406.56 401.72 396.88 392.04 382.36 377.52 372.68 367.84

diff:

 [1] -4.84 -4.84 -4.84 -9.68 -4.84 -4.84 -4.84 -9.68 -4.84 -4.84 -4.84 -9.68
[13] -4.84 -4.84 -4.84 -9.68 -4.84 -4.84 -4.84 -9.68 -4.84 -4.84 -4.84 -9.68

, .

, flot 479.16. , . , ? Math.floors . " " :

 [1] 479 474 469 464 454 450 445 440 430 425 421 416 406 401 396 392 382 377 372
[20] 367 358 353 348 343 333 329 324 319 309 304 300 295 285 280 275 271 261 256

diff:

 [1]  -5  -5  -5 -10  -4  -5  -5 -10  -5  -4  -5 -10  -5  -5  -4 -10  -5  -5  -5
[20]  -9  -5  -5  -5 -10  -4  -5  -5 -10  -5  -4  -5 -10  -5  -5  -4 -10  -5  -5
[39]  -5  -9  -5  -5  -5 -10  -4  -5  -5 -10  -5  -4  -5 -10  -5  -5  -4 -10  -5

, .

, - , , . , ( ​​ ).

, ?

1.) . , .

2.) . . - , . .

. , , ( , ..). , :

ticks: function(axis){
    var startTickPos = -4.9;
    var endTickPos = 5;
    var tickIncrement = 0.1;
    var tickDrawCounter = 2;
    if (plot) { 
        // this is the re-draw
        var yaxis = plot.getAxes().yaxis;
        // our first tick pixel position
        var currentTickPix = yaxis.p2c(yaxis.ticks[0].v);
        var ticks = [[startTickPos,""]];
        for(var i=startTickPos + tickIncrement;
            i<endTickPos;
            i+=tickIncrement){
            // we are spacing each tick 5 pixels apart, adjust as needed for get a good plot height
            currentTickPix -= 5;
            if(tickDrawCounter<5){ 
                // convert the pixel to tick position
                ticks.push([yaxis.c2p(currentTickPix),""]);
                tickDrawCounter += 1;
            } else {
                tickDrawCounter = 1;
            }
        }
        return ticks;
    } else {
        // this is the first time through, we only need the initial tick starting position
        return [startTickPos];
    }
},

fiddle. xaxis , .

2

, , - . 510 , . diff:

[1]  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5
[20] -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5
[39]  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5
[58]  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10  -5  -5  -5 -10
[77]  -5  -5  -5
+4

All Articles