Published
Edited
Mar 29, 2020
Importers
Insert cell
md`# SVG_lib

Shortcuts for SVG elements`
Insert cell
xmlns = "http://www.w3.org/2000/svg"
Insert cell
svgSettings = {
let svgSettings = {
'backgroundColor':'#ffffff',
'strokeColor':'#000000',
'strokeWidth':'1',
'fill':'none'
}
return svgSettings
}
Insert cell
function svgElem(width,height){
const svgElem = document.createElementNS(xmlns, "svg");
svgElem.setAttributeNS(null, 'width', width);
svgElem.setAttributeNS(null, 'height', height);
svgElem.style.backgroundColor = svgSettings.backgroundColor;
return svgElem
}
Insert cell
function polyline(path) {
const node = document.createElementNS(xmlns, "polyline");
var path_points = ''
for (var i=0; i<path.length; i++){
const x = path[i][0]
const y = path[i][1]
path_points += x+','+y+' '
}
path_points = path_points.slice(0,-1);
node.setAttributeNS(null, 'points', path_points);
node.setAttributeNS(null, 'fill', 'none');
node.setAttributeNS(null, 'style',
'stroke:'+svgSettings['strokeColor']+
';stroke-width:'+svgSettings['strokeWidth']+';'
);
return node;
}
Insert cell
function rect(width,height,x,y) {
if (x === undefined) { x = 0 }
if (y === undefined) { y = 0 }
let rectangle = document.createElementNS(xmlns, "rect")
rectangle.setAttributeNS(null, 'width', width);
rectangle.setAttributeNS(null, 'height', height);
rectangle.setAttributeNS(null, 'x', x);
rectangle.setAttributeNS(null, 'y', y);
rectangle.setAttributeNS(null, 'fill', svgSettings['fill']);
rectangle.setAttributeNS(null, 'style',
'stroke:'+svgSettings['strokeColor']+
';stroke-width:'+svgSettings['strokeWidth']+';'
)
return rectangle
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more