|
2 | 2 | * 某一 "种" connection 的文字部分是一样的
|
3 | 3 | * 只需预先构造,而后在使用时 cloneNode 即可
|
4 | 4 | */
|
5 |
| -import {ConnectionCategory} from "../../../Store/ConnectionCategory"; |
6 |
| -import {Font} from "../../Font"; |
7 |
| -import {SVGNS} from "../../../Infrastructure/SVGNS"; |
8 |
| -import {Base} from "../../../Infrastructure/Repository"; |
9 |
| -import {View} from "../../View"; |
| 5 | +import {Base} from '../../../Infrastructure/Repository'; |
| 6 | +import {SVGNS} from '../../../Infrastructure/SVGNS'; |
| 7 | +import {ConnectionCategory} from '../../../Store/ConnectionCategory'; |
| 8 | +import {Font} from '../../Font'; |
| 9 | +import {View} from '../../View'; |
10 | 10 |
|
11 | 11 | export namespace ConnectionCategoryElement {
|
12 |
| - class Factory { |
13 |
| - private svgElement: SVGGElement; |
| 12 | + class Factory { |
| 13 | + private svgElement: SVGGElement; |
14 | 14 |
|
15 |
| - constructor( |
16 |
| - private store: ConnectionCategory.Entity, |
17 |
| - font: Font.ValueObject, |
18 |
| - classes: Array<string> |
19 |
| - ) { |
20 |
| - this.svgElement = document.createElementNS(SVGNS, 'g') as SVGGElement; |
21 |
| - const rectElement = document.createElementNS(SVGNS, 'rect') as SVGRectElement; |
22 |
| - // todo: detect background color |
23 |
| - // todo: add an entry in labelCategory |
24 |
| - rectElement.setAttribute('fill', '#ffffff'); |
25 |
| - rectElement.setAttribute('width', (font.widthOf(store.text)).toString()); |
26 |
| - rectElement.setAttribute('height', (font.lineHeight).toString()); |
27 |
| - const textElement = document.createElementNS(SVGNS, 'text') as SVGTextElement; |
28 |
| - textElement.classList.add(...classes); |
29 |
| - textElement.innerHTML = store.text; |
30 |
| - textElement.setAttribute("dy", `${font.topToBaseLine}px`); |
31 |
| - this.svgElement.appendChild(rectElement); |
32 |
| - this.svgElement.appendChild(textElement); |
33 |
| - } |
34 |
| - |
35 |
| - public create(): SVGGElement { |
36 |
| - return this.svgElement.cloneNode(true) as SVGGElement; |
37 |
| - } |
| 15 | + constructor( |
| 16 | + private store: ConnectionCategory.Entity, font: Font.ValueObject, |
| 17 | + classes: Array<string>) { |
| 18 | + this.svgElement = document.createElementNS(SVGNS, 'g') as SVGGElement; |
| 19 | + const rectElement = |
| 20 | + document.createElementNS(SVGNS, 'rect') as SVGRectElement; |
| 21 | + // todo: detect background color |
| 22 | + // todo: add an entry in labelCategory |
| 23 | + rectElement.setAttribute('fill', '#ffffff'); |
| 24 | + rectElement.setAttribute('width', (font.widthOf(store.text)).toString()); |
| 25 | + rectElement.setAttribute('height', (font.lineHeight).toString()); |
| 26 | + const textElement = |
| 27 | + document.createElementNS(SVGNS, 'text') as SVGTextElement; |
| 28 | + textElement.classList.add(...classes); |
| 29 | + textElement.innerHTML = store.text; |
| 30 | + textElement.setAttribute('dy', `${font.topToBaseLine}px`); |
| 31 | + this.svgElement.appendChild(rectElement); |
| 32 | + this.svgElement.appendChild(textElement); |
| 33 | + } |
38 | 34 |
|
39 |
| - get id() { |
40 |
| - return this.store.id; |
41 |
| - } |
| 35 | + get id() { |
| 36 | + return this.store.id; |
42 | 37 | }
|
43 | 38 |
|
44 |
| - export interface Config { |
45 |
| - readonly connectionClasses: Array<string> |
| 39 | + public create(): SVGGElement { |
| 40 | + return this.svgElement.cloneNode(true) as SVGGElement; |
46 | 41 | }
|
| 42 | + } |
| 43 | + |
| 44 | + export interface Config { |
| 45 | + readonly connectionClasses: Array<string> |
| 46 | + } |
47 | 47 |
|
48 |
| - export class FactoryRepository extends Base.Repository<Factory> { |
49 |
| - constructor(view: View, private config: Config) { |
50 |
| - super(); |
51 |
| - for (let entity of view.store.connectionCategoryRepo.values()) { |
52 |
| - super.add(new Factory( |
53 |
| - entity, |
54 |
| - view.connectionFont, |
55 |
| - config.connectionClasses |
56 |
| - )); |
57 |
| - } |
58 |
| - } |
| 48 | + export class FactoryRepository extends Base.Repository<Factory> { |
| 49 | + constructor(view: View, private config: Config) { |
| 50 | + super(); |
| 51 | + for (let entity of view.store.connectionCategoryRepo.values()) { |
| 52 | + super.add( |
| 53 | + new Factory(entity, view.connectionFont, config.connectionClasses)); |
| 54 | + } |
59 | 55 | }
|
| 56 | + } |
60 | 57 | }
|
0 commit comments