🚧 Support for rendering text on paths
This commit is contained in:
parent
ffff09904a
commit
1811e736c0
4 changed files with 46 additions and 7 deletions
|
@ -1,6 +1,15 @@
|
|||
export class Attributes {
|
||||
list: any = {};
|
||||
|
||||
constructor(init) {
|
||||
for (let key in init) {
|
||||
let val = init[key];
|
||||
this.add(key, val);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Adds an attribute */
|
||||
add(name: string, value: string): Attributes {
|
||||
if(typeof this.list[name] === 'undefined') {
|
||||
|
@ -14,17 +23,31 @@ export class Attributes {
|
|||
|
||||
/** Retrieves an attribute */
|
||||
get(name: string): string {
|
||||
return this.list[name].join(' ');
|
||||
if(typeof this.list[name] === 'undefined') return false;
|
||||
else return this.list[name].join(' ');
|
||||
}
|
||||
|
||||
/** Returns SVG code for attributes */
|
||||
render(): string {
|
||||
let svg = '';
|
||||
for (let key in this.list) {
|
||||
let attrs = this.list
|
||||
svg += ` ${key}="${this.list[key].join(' ')}"`;
|
||||
}
|
||||
|
||||
return svg;
|
||||
}
|
||||
|
||||
/** Returns SVG code for attributes with a fiven prefix
|
||||
* typically used for data-text*/
|
||||
renderIfPrefixIs(prefix:string = ''): string {
|
||||
let svg = '';
|
||||
let prefixLen = prefix.length;
|
||||
for (let key in this.list) {
|
||||
if(key.substr(0,prefixLen) === prefix) {
|
||||
svg += ` ${key.substr(prefixLen)}="${this.list[key].join(' ')}"`;
|
||||
}
|
||||
}
|
||||
|
||||
return svg;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue