Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


Cubism Study

24 Jan 2021 »

Concepts

https://bernatgel.github.io/karyoploter_tutorial/Tutorial/PlotHorizon/PlotHorizon.html

Code

https://github.com/square/cubism/blob/master/cubism.v1.js

// consistent overplotting
var round = start / context.step() & 1
    ? cubism_comparisonRoundOdd
    : cubism_comparisonRoundEven;

// positive changes
canvas.fillStyle = colors[2];
for (var i = 0, n = width; i < n; ++i) {
  var y0 = scale(primary_.valueAt(i)),
      y1 = scale(secondary_.valueAt(i));
  if (y0 < y1) canvas.fillRect(round(i), y0, 1, y1 - y0);
}

// negative changes
canvas.fillStyle = colors[0];
for (i = 0; i < n; ++i) {
  var y0 = scale(primary_.valueAt(i)),
      y1 = scale(secondary_.valueAt(i));
  if (y0 > y1) canvas.fillRect(round(i), y1, 1, y0 - y1);
}

// positive values
canvas.fillStyle = colors[3];
for (i = 0; i < n; ++i) {
  var y0 = scale(primary_.valueAt(i)),
      y1 = scale(secondary_.valueAt(i));
  if (y0 <= y1) canvas.fillRect(round(i), y0, 1, strokeWidth);
}

// negative values
canvas.fillStyle = colors[1];
for (i = 0; i < n; ++i) {
  var y0 = scale(primary_.valueAt(i)),
      y1 = scale(secondary_.valueAt(i));
  if (y0 > y1) canvas.fillRect(round(i), y0 - strokeWidth, 1, strokeWidth);
}

canvas.restore();
}

Examples

  • https://bl.ocks.org/tomshanley/2e783361974c41d401993cc4aaae7e8a

  • http://bl.ocks.org/tomshanley/61b8c01eb29130a0061b549931315c42

  • https://bl.ocks.org/tomshanley/dd93d10cc2959f72b2bc3858bf486075

  • http://bl.ocks.org/tomshanley/1d58d9d4ab24b5fc3d16901c02229c62

  • https://bl.ocks.org/kmandov/dcb94f02e71e3560eb3255f2de3120e4

  • https://bl.ocks.org/kmandov/6e91165d4f32534ec4cab806b18b6684

  • https://bl.ocks.org/kmandov/a1abe4aa380fb8b4bd0b4c081a76ce13

Others

https://towardsdatascience.com/using-strip-charts-to-visualize-dozens-of-time-series-at-once-a983baabb54f