vtm/quelldatein/darstellung_steuerung/svg.ts
Christian Fraß 8dd4d54f94 sicherung
2017-11-08 18:41:56 +01:00

80 lines
1.8 KiB
TypeScript

module mod_vtm_darstellung_steuerung
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export const svg_float_praezission : int = 4;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export const svg_form_pfeil : string = "M +4 0 L 0 +1 L 0 -1 Z";
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function svg_pfad
(
vertices : Array<mod_vtm_helfer.typ_vektor>,
schliessen : boolean = true,
attribute : {[schlussel : string] : string} = {},
)
: mod_vtm_helfer.schnittstelle_xmlknoten
{
let d : string = "";
vertices.forEach
(
(vertex, index) =>
{
let c : string = ((index <= 0) ? "M" : "L");
let x : string = vertex.x.toFixed(svg_float_praezission);
let y : string = vertex.y.toFixed(svg_float_praezission);
d += [c, x, y].join(" ");
}
)
;
if (schliessen)
d += "Z";
attribute["d"] = d;
return (new mod_vtm_helfer.klasse_xmlknoten_normal("path", attribute));
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function svg_wurzel
(
von_x : float,
von_y : float,
bis_x : float,
bis_y : float,
hoehe : int = 500,
breite : int = 500,
kinder : Array<mod_vtm_helfer.schnittstelle_xmlknoten> = []
)
: mod_vtm_helfer.schnittstelle_xmlknoten
{
return (
new mod_vtm_helfer.klasse_xmlknoten_normal
(
"svg",
{
"xmlns": "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
"width": breite.toFixed(0),
"height": hoehe.toFixed(0),
"viewBox": [von_x.toFixed(4), von_y.toFixed(4), (bis_x-von_x).toFixed(4), (bis_y-von_y).toFixed(4)].join(" "),
},
kinder,
)
);
}
}