This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including pareto-frontier
with all npm
packages installed. Try it out:
const pf = require('pareto-frontier');
const graph = [
[55, 42],
[60, 22],
[83, 20],
[20, 81],
[41, 35],
[12, 32],
[29, 17],
[64, 55],
[47, 31],
[89, 10],
[68, 66],
[33, 35],
[72, 47],
[33, 90],
[49, 25],
];
const paretoPoints = pf.getParetoFrontier(graph, {optimize: 'topRight'});
/* -- graph -- */
const Canvas = require('canvas');
const canvas = new Canvas(400, 400);
const ctx = canvas.getContext('2d');
ctx.transform(1, 0, 0, -1, 0, canvas.height); // set +Y-axis upwards
function drawCircles(points) { ctx.lineWidth = 5; ctx.fillStyle = 'rgba(0, 0, 255, 0.5)'; points.forEach(p => { ctx.beginPath(); ctx.arc(4*p[0], 4*p[1], 25, 0, 2 * Math.PI); ctx.fill(); ctx.closePath(); ctx.stroke(); }); }
function drawLine(points) { ctx.lineCap = 'round'; ctx.lineWidth = 15; ctx.strokeStyle = 'rgba(255, 0, 0, 0.5)'; ctx.beginPath(); points.forEach((p, i, arr) => { if (arr[i+1]) { ctx.moveTo(4*p[0], 4*p[1]); ctx.lineTo(4*arr[i+1][0], 4*arr[i+1][1]); } }); ctx.stroke(); ctx.closePath(); }
drawCircles(graph);
drawLine(paretoPoints);
canvas.toBuffer();
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.