Skip to content

Commit

Permalink
properly extend or insert data gaps at right edge. (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoniya committed Jun 10, 2020
1 parent 702fa3a commit ccd5950
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 46 deletions.
8 changes: 7 additions & 1 deletion demos/missing-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@
data[2][126] = null;
data[2][127] = null;

// data[2][197] = null;
// data[2][198] = null;
// data[2][199] = null;

const opts = {
title: "Missing Data",
width: 1920,
height: 600,
// spanGaps: true,
series: [
{},
{
Expand All @@ -45,20 +48,23 @@
value: (u, v) => v == null ? "-" : v.toFixed(1) + "%",
stroke: "red",
fill: "rgba(255,0,0,0.05)",
// spanGaps: true,
},
{
label: "RAM",
scale: "%",
value: (u, v) => v == null ? "-" : v.toFixed(1) + "%",
stroke: "blue",
fill: "rgba(0,0,255,0.05)",
// spanGaps: true,
},
{
label: "TCP Out",
scale: "mb",
value: (u, v) => v == null ? "-" : v.toFixed(2) + " MB",
stroke: "green",
fill: "rgba(0,255,0,0.05)",
// spanGaps: true,
}
],
axes: [
Expand Down
28 changes: 17 additions & 11 deletions dist/uPlot.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,15 @@ function uPlot(opts, data, then) {
return clip;
}

function addGap(gaps, outX, x) {
var prevGap = gaps[gaps.length - 1];

if (prevGap && prevGap[0] == outX) // TODO: gaps must be encoded at stroke widths?
{ prevGap[1] = x; }
else
{ gaps.push([outX, x]); }
}

function buildPaths(self, is, _i0, _i1) {
var s = series[is];

Expand Down Expand Up @@ -1735,7 +1744,7 @@ function uPlot(opts, data, then) {
}
}
else {
var addGap = false;
var _addGap = false;

if (minY != inf) {
stroke.lineTo(accX, minY);
Expand All @@ -1744,7 +1753,7 @@ function uPlot(opts, data, then) {
outX = accX;
}
else
{ addGap = true; }
{ _addGap = true; }

if (ydata[i] != null) {
outY = round(getYPos(ydata[i], scaleY, plotHgt, plotTop));
Expand All @@ -1753,26 +1762,23 @@ function uPlot(opts, data, then) {

// prior pixel can have data but still start a gap if ends with null
if (x - accX > 1 && ydata[i-1] == null)
{ addGap = true; }
{ _addGap = true; }
}
else {
minY = inf;
maxY = -inf;
}

if (addGap) {
var prevGap = gaps[gaps.length - 1];

if (prevGap && prevGap[0] == outX) // TODO: gaps must be encoded at stroke widths?
{ prevGap[1] = x; }
else
{ gaps.push([outX, x]); }
}
_addGap && addGap(gaps, outX, x);

accX = x;
}
}

// extend or insert rightmost gap if no data exists to the right
if (ydata[_i1] == null)
{ addGap(gaps, outX, accX); }

if (s.band) {
var overShoot = width * 100, _iy, _x;

Expand Down
28 changes: 17 additions & 11 deletions dist/uPlot.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,15 @@ function uPlot(opts, data, then) {
return clip;
}

function addGap(gaps, outX, x) {
let prevGap = gaps[gaps.length - 1];

if (prevGap && prevGap[0] == outX) // TODO: gaps must be encoded at stroke widths?
prevGap[1] = x;
else
gaps.push([outX, x]);
}

function buildPaths(self, is, _i0, _i1) {
const s = series[is];

Expand Down Expand Up @@ -1731,7 +1740,7 @@ function uPlot(opts, data, then) {
}
}
else {
let addGap = false;
let _addGap = false;

if (minY != inf) {
stroke.lineTo(accX, minY);
Expand All @@ -1740,7 +1749,7 @@ function uPlot(opts, data, then) {
outX = accX;
}
else
addGap = true;
_addGap = true;

if (ydata[i] != null) {
outY = round(getYPos(ydata[i], scaleY, plotHgt, plotTop));
Expand All @@ -1749,26 +1758,23 @@ function uPlot(opts, data, then) {

// prior pixel can have data but still start a gap if ends with null
if (x - accX > 1 && ydata[i-1] == null)
addGap = true;
_addGap = true;
}
else {
minY = inf;
maxY = -inf;
}

if (addGap) {
let prevGap = gaps[gaps.length - 1];

if (prevGap && prevGap[0] == outX) // TODO: gaps must be encoded at stroke widths?
prevGap[1] = x;
else
gaps.push([outX, x]);
}
_addGap && addGap(gaps, outX, x);

accX = x;
}
}

// extend or insert rightmost gap if no data exists to the right
if (ydata[_i1] == null)
addGap(gaps, outX, accX);

if (s.band) {
let overShoot = width * 100, _iy, _x;

Expand Down
28 changes: 17 additions & 11 deletions dist/uPlot.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,15 @@ var uPlot = (function () {
return clip;
}

function addGap(gaps, outX, x) {
var prevGap = gaps[gaps.length - 1];

if (prevGap && prevGap[0] == outX) // TODO: gaps must be encoded at stroke widths?
{ prevGap[1] = x; }
else
{ gaps.push([outX, x]); }
}

function buildPaths(self, is, _i0, _i1) {
var s = series[is];

Expand Down Expand Up @@ -1736,7 +1745,7 @@ var uPlot = (function () {
}
}
else {
var addGap = false;
var _addGap = false;

if (minY != inf) {
stroke.lineTo(accX, minY);
Expand All @@ -1745,7 +1754,7 @@ var uPlot = (function () {
outX = accX;
}
else
{ addGap = true; }
{ _addGap = true; }

if (ydata[i] != null) {
outY = round(getYPos(ydata[i], scaleY, plotHgt, plotTop));
Expand All @@ -1754,26 +1763,23 @@ var uPlot = (function () {

// prior pixel can have data but still start a gap if ends with null
if (x - accX > 1 && ydata[i-1] == null)
{ addGap = true; }
{ _addGap = true; }
}
else {
minY = inf;
maxY = -inf;
}

if (addGap) {
var prevGap = gaps[gaps.length - 1];

if (prevGap && prevGap[0] == outX) // TODO: gaps must be encoded at stroke widths?
{ prevGap[1] = x; }
else
{ gaps.push([outX, x]); }
}
_addGap && addGap(gaps, outX, x);

accX = x;
}
}

// extend or insert rightmost gap if no data exists to the right
if (ydata[_i1] == null)
{ addGap(gaps, outX, accX); }

if (s.band) {
var overShoot = width * 100, _iy, _x;

Expand Down
2 changes: 1 addition & 1 deletion dist/uPlot.iife.min.js

Large diffs are not rendered by default.

28 changes: 17 additions & 11 deletions src/uPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,15 @@ export default function uPlot(opts, data, then) {
return clip;
}

function addGap(gaps, outX, x) {
let prevGap = gaps[gaps.length - 1];

if (prevGap && prevGap[0] == outX) // TODO: gaps must be encoded at stroke widths?
prevGap[1] = x;
else
gaps.push([outX, x]);
}

function buildPaths(self, is, _i0, _i1) {
const s = series[is];

Expand Down Expand Up @@ -986,7 +995,7 @@ export default function uPlot(opts, data, then) {
}
}
else {
let addGap = false;
let _addGap = false;

if (minY != inf) {
stroke.lineTo(accX, minY);
Expand All @@ -995,7 +1004,7 @@ export default function uPlot(opts, data, then) {
outX = accX;
}
else
addGap = true;
_addGap = true;

if (ydata[i] != null) {
outY = round(getYPos(ydata[i], scaleY, plotHgt, plotTop));
Expand All @@ -1004,26 +1013,23 @@ export default function uPlot(opts, data, then) {

// prior pixel can have data but still start a gap if ends with null
if (x - accX > 1 && ydata[i-1] == null)
addGap = true;
_addGap = true;
}
else {
minY = inf;
maxY = -inf;
}

if (addGap) {
let prevGap = gaps[gaps.length - 1];

if (prevGap && prevGap[0] == outX) // TODO: gaps must be encoded at stroke widths?
prevGap[1] = x;
else
gaps.push([outX, x]);
}
_addGap && addGap(gaps, outX, x);

accX = x;
}
}

// extend or insert rightmost gap if no data exists to the right
if (ydata[_i1] == null)
addGap(gaps, outX, accX);

if (s.band) {
let overShoot = width * 100, _iy, _x;

Expand Down

0 comments on commit ccd5950

Please sign in to comment.