Skip to content

Commit 07f079e

Browse files
committed
padding自适应
fix: #47 & #34
1 parent 8089775 commit 07f079e

File tree

8 files changed

+261
-227
lines changed

8 files changed

+261
-227
lines changed

src/Develop/test.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"content": "lucsfl asdf",
2+
"content": "测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本 测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本 测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本",
33
"labelCategories": [
44
{
55
"id": 0,
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"id": 2,
18-
"text": "形容词",
18+
"text": "超长标签超长标签超长标签",
1919
"color": "#9d61ff",
2020
"borderColor": "#6d43b2"
2121
},

src/View/Entities/ConnectionView/ConnectionCategoryElement.ts

+43-46
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,56 @@
22
* 某一 "种" connection 的文字部分是一样的
33
* 只需预先构造,而后在使用时 cloneNode 即可
44
*/
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';
1010

1111
export namespace ConnectionCategoryElement {
12-
class Factory {
13-
private svgElement: SVGGElement;
12+
class Factory {
13+
private svgElement: SVGGElement;
1414

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+
}
3834

39-
get id() {
40-
return this.store.id;
41-
}
35+
get id() {
36+
return this.store.id;
4237
}
4338

44-
export interface Config {
45-
readonly connectionClasses: Array<string>
39+
public create(): SVGGElement {
40+
return this.svgElement.cloneNode(true) as SVGGElement;
4641
}
42+
}
43+
44+
export interface Config {
45+
readonly connectionClasses: Array<string>
46+
}
4747

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+
}
5955
}
56+
}
6057
}

0 commit comments

Comments
 (0)