I'm using svg.js's polyline array method to draw lines from values logged by storing the cursor's x,y coordinates on a page.
The idea is to first let a user browsing the page and move the cursor around, and so feed values into the array, then when clicking on a button svg.js will draw lines based on the cursor' movement.
Being this the syntax to follow:
var polyline = draw.polyline([[0,0], [100,50], [50,100]]).fill('none').stroke({ width: 1 })
if I manually copy-paste the values in the array as in:
var polyline = draw.polyline([[475,76], [475,76], [489,75], (...)]]).fill('none').stroke({ width: 1 });
svg.js works as expected.
If I pass in a variable, it tells me this:
svg.js:2632 Error: <polyline> attribute points: Expected number, "NaN,528 NaN,531 …".
This is my code:
// movement
var array_cursor_movement = [];
$(document).mousemove(function(e) {
var cursor_movement = "["+ e.pageX +","+ e.pageY +"]";
array_cursor_movement.push(cursor_movement);
var cursor_movement = array_cursor_movement.join(', ');
console.log("movement:" + cursor_movement);
localStorage.setItem("cursor_movement_pos", JSON.stringify(array_cursor_movement));
});
// click for preview lines
$(".preview--lines, .close--button").click(function(){
$(".preview").toggleClass("show--hide");
// draw lines
var retrievedData = localStorage.getItem("cursor_movement_pos");
var array_cursor_movement_b = JSON.parse(retrievedData);
var cursor_movement = array_cursor_movement_b.join(', ');
cursor_movement = "["+cursor_movement+"]";
console.log("preview:" + cursor_movement);
var width = window.innerWidth;
var height = window.innerHeight;
var draw = SVG('drawing').size(width, height);
var polyline = draw.polyline(cursor_movement).fill('none').stroke({ width: 1 });
})
Anyone has experience?
Thanks, André