@hpcc-js/common 3.6.2 → 3.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +43 -43
- package/README.md +59 -59
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +4 -4
- package/src/CanvasWidget.ts +31 -31
- package/src/Class.ts +72 -72
- package/src/Database.ts +860 -860
- package/src/Entity.ts +235 -235
- package/src/EntityCard.ts +66 -66
- package/src/EntityPin.ts +103 -103
- package/src/EntityRect.css +15 -15
- package/src/EntityRect.ts +254 -254
- package/src/EntityVertex.ts +86 -86
- package/src/FAChar.css +2 -2
- package/src/FAChar.ts +89 -89
- package/src/HTMLWidget.ts +191 -191
- package/src/IList.ts +4 -4
- package/src/IMenu.ts +5 -5
- package/src/Icon.css +9 -9
- package/src/Icon.ts +176 -176
- package/src/Image.ts +104 -104
- package/src/List.css +13 -13
- package/src/List.ts +102 -102
- package/src/Menu.css +23 -23
- package/src/Menu.ts +139 -139
- package/src/Palette.ts +341 -341
- package/src/Platform.ts +125 -125
- package/src/ProgressBar.ts +115 -115
- package/src/PropertyExt.ts +770 -770
- package/src/ResizeSurface.css +39 -39
- package/src/ResizeSurface.ts +225 -225
- package/src/SVGWidget.ts +583 -583
- package/src/SVGZoomWidget.css +12 -12
- package/src/SVGZoomWidget.ts +427 -427
- package/src/Shape.css +3 -3
- package/src/Shape.ts +186 -186
- package/src/Surface.css +35 -35
- package/src/Surface.ts +364 -364
- package/src/Text.css +4 -4
- package/src/Text.ts +131 -131
- package/src/TextBox.css +4 -4
- package/src/TextBox.ts +183 -183
- package/src/TitleBar.css +114 -114
- package/src/TitleBar.ts +407 -407
- package/src/Transition.ts +45 -45
- package/src/Utility.ts +839 -839
- package/src/Widget.css +8 -8
- package/src/Widget.ts +731 -731
- package/src/WidgetArray.ts +15 -15
- package/src/__package__.ts +3 -3
- package/src/index.ts +55 -55
package/src/Icon.ts
CHANGED
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
import { FAChar } from "./FAChar.ts";
|
|
2
|
-
import { textColor } from "./Palette.ts";
|
|
3
|
-
import { Shape } from "./Shape.ts";
|
|
4
|
-
import { SVGWidget } from "./SVGWidget.ts";
|
|
5
|
-
|
|
6
|
-
import "../src/Icon.css";
|
|
7
|
-
|
|
8
|
-
export class Icon extends SVGWidget {
|
|
9
|
-
|
|
10
|
-
protected _shapeWidget;
|
|
11
|
-
protected _faChar;
|
|
12
|
-
protected _defs;
|
|
13
|
-
protected _root;
|
|
14
|
-
protected _tooltipElement;
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
super();
|
|
18
|
-
|
|
19
|
-
this._shapeWidget = new Shape();
|
|
20
|
-
this._faChar = new FAChar();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getBBox(refresh = false, round = false) {
|
|
24
|
-
const diameter = this.diameter();
|
|
25
|
-
return {
|
|
26
|
-
x: - diameter / 2,
|
|
27
|
-
y: - diameter / 2,
|
|
28
|
-
width: diameter,
|
|
29
|
-
height: diameter
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
contains(point) {
|
|
34
|
-
return this._shapeWidget.contains(point);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
intersection(pointA, pointB) {
|
|
38
|
-
return this._shapeWidget.intersection(pointA, pointB);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
enter(domNode, element) {
|
|
42
|
-
super.enter(domNode, element);
|
|
43
|
-
delete this._prevHash;
|
|
44
|
-
this._defs = element.append("defs");
|
|
45
|
-
this._defs.append("clipPath")
|
|
46
|
-
.attr("id", "clip_" + this.id() + "_circle")
|
|
47
|
-
.append("circle")
|
|
48
|
-
.attr("x", 0)
|
|
49
|
-
.attr("y", 0)
|
|
50
|
-
;
|
|
51
|
-
this._defs.append("clipPath")
|
|
52
|
-
.attr("id", "clip_" + this.id() + "_square")
|
|
53
|
-
.append("rect")
|
|
54
|
-
;
|
|
55
|
-
this._root = element.append("g");
|
|
56
|
-
this._shapeWidget
|
|
57
|
-
.target(this._root.node())
|
|
58
|
-
;
|
|
59
|
-
this._faChar
|
|
60
|
-
.target(element.node())
|
|
61
|
-
;
|
|
62
|
-
this._tooltipElement = element.append("title");
|
|
63
|
-
const context = this;
|
|
64
|
-
element
|
|
65
|
-
.on("click", function (el) {
|
|
66
|
-
context.click(el);
|
|
67
|
-
})
|
|
68
|
-
.on("dblclick", function (el) {
|
|
69
|
-
context.dblclick(el);
|
|
70
|
-
})
|
|
71
|
-
;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
click(_domNode) {
|
|
75
|
-
// console.log("Clicked the icon");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
dblclick(_domNode) {
|
|
79
|
-
// console.log("Double clicked the icon");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_prevHash;
|
|
83
|
-
update(domNode, element) {
|
|
84
|
-
super.update(domNode, element);
|
|
85
|
-
const hash = this.hashSum();
|
|
86
|
-
if (this._prevHash !== hash) {
|
|
87
|
-
this._prevHash = hash;
|
|
88
|
-
|
|
89
|
-
const diameter = this.diameter();
|
|
90
|
-
const radius = diameter / 2;
|
|
91
|
-
this._defs.select("circle")
|
|
92
|
-
.attr("r", radius)
|
|
93
|
-
;
|
|
94
|
-
this._defs.select("rect")
|
|
95
|
-
.attr("x", -radius)
|
|
96
|
-
.attr("y", -radius)
|
|
97
|
-
.attr("width", diameter)
|
|
98
|
-
.attr("height", diameter)
|
|
99
|
-
;
|
|
100
|
-
this._faChar
|
|
101
|
-
.fontSize(diameter * (100 - this.paddingPercent()) / 100)
|
|
102
|
-
.render()
|
|
103
|
-
;
|
|
104
|
-
this._shapeWidget
|
|
105
|
-
.shape(this.shape())
|
|
106
|
-
.width(diameter)
|
|
107
|
-
.height(diameter)
|
|
108
|
-
.render()
|
|
109
|
-
;
|
|
110
|
-
const image = this._root.selectAll("image").data(this.imageUrl() ? [this.imageUrl()] : [], function (d) { return d; });
|
|
111
|
-
image.enter()
|
|
112
|
-
.append("image")
|
|
113
|
-
.attr("xlink:href", this.imageUrl())
|
|
114
|
-
.merge(image)
|
|
115
|
-
.attr("clip-path", "url(#clip_" + this.id() + "_" + this.shape() + ")")
|
|
116
|
-
.attr("x", -radius)
|
|
117
|
-
.attr("y", -radius)
|
|
118
|
-
.attr("width", diameter)
|
|
119
|
-
.attr("height", diameter)
|
|
120
|
-
;
|
|
121
|
-
if (this.shape_colorFill_exists() && !this.image_colorFill_exists()) {
|
|
122
|
-
this.image_colorFill(textColor(this.shape_colorFill()));
|
|
123
|
-
}
|
|
124
|
-
image.exit()
|
|
125
|
-
.remove()
|
|
126
|
-
;
|
|
127
|
-
this._tooltipElement.text(this.tooltip());
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
exit(domNode, element) {
|
|
132
|
-
super.exit(domNode, element);
|
|
133
|
-
this._shapeWidget
|
|
134
|
-
.target(null)
|
|
135
|
-
;
|
|
136
|
-
this._faChar
|
|
137
|
-
.target(null)
|
|
138
|
-
;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
Icon.prototype._class += " common_Icon";
|
|
143
|
-
|
|
144
|
-
export interface Icon {
|
|
145
|
-
shape(): string;
|
|
146
|
-
shape(_: string): this;
|
|
147
|
-
faChar(): string;
|
|
148
|
-
faChar(_: string): this;
|
|
149
|
-
imageUrl(): string;
|
|
150
|
-
imageUrl(_: string): this;
|
|
151
|
-
image_colorFill(): string;
|
|
152
|
-
image_colorFill(_: string): this;
|
|
153
|
-
image_colorFill_exists(): boolean;
|
|
154
|
-
tooltip(): string;
|
|
155
|
-
tooltip(_: string): this;
|
|
156
|
-
diameter(): number;
|
|
157
|
-
diameter(_: number): this;
|
|
158
|
-
paddingPercent(): number;
|
|
159
|
-
paddingPercent(_: number): this;
|
|
160
|
-
shape_colorFill(): string;
|
|
161
|
-
shape_colorFill(_: string): this;
|
|
162
|
-
shape_colorFill_exists(): boolean;
|
|
163
|
-
shape_colorStroke(): string;
|
|
164
|
-
shape_colorStroke(_: string): this;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
Icon.prototype.publish("shape", "circle", "set", "Shape Type", ["circle", "square"], { tags: ["Private"] });
|
|
168
|
-
Icon.prototype.publishProxy("faChar", "_faChar", "char");
|
|
169
|
-
Icon.prototype.publishProxy("fontFamily", "_faChar", "text_fontFamily");
|
|
170
|
-
Icon.prototype.publish("imageUrl", null, "string", "Image URL", null, { optional: true });
|
|
171
|
-
Icon.prototype.publishProxy("image_colorFill", "_faChar", "text_colorFill");
|
|
172
|
-
Icon.prototype.publish("tooltip", "", "string", "Tooltip", null, { tags: ["Private"] });
|
|
173
|
-
Icon.prototype.publish("diameter", 24, "number", "Diameter", null, { tags: ["Private"] });
|
|
174
|
-
Icon.prototype.publish("paddingPercent", 45, "number", "Padding Percent", null, { tags: ["Private"] });
|
|
175
|
-
Icon.prototype.publishProxy("shape_colorFill", "_shapeWidget", "colorFill");
|
|
176
|
-
Icon.prototype.publishProxy("shape_colorStroke", "_shapeWidget", "colorStroke");
|
|
1
|
+
import { FAChar } from "./FAChar.ts";
|
|
2
|
+
import { textColor } from "./Palette.ts";
|
|
3
|
+
import { Shape } from "./Shape.ts";
|
|
4
|
+
import { SVGWidget } from "./SVGWidget.ts";
|
|
5
|
+
|
|
6
|
+
import "../src/Icon.css";
|
|
7
|
+
|
|
8
|
+
export class Icon extends SVGWidget {
|
|
9
|
+
|
|
10
|
+
protected _shapeWidget;
|
|
11
|
+
protected _faChar;
|
|
12
|
+
protected _defs;
|
|
13
|
+
protected _root;
|
|
14
|
+
protected _tooltipElement;
|
|
15
|
+
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
|
|
19
|
+
this._shapeWidget = new Shape();
|
|
20
|
+
this._faChar = new FAChar();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getBBox(refresh = false, round = false) {
|
|
24
|
+
const diameter = this.diameter();
|
|
25
|
+
return {
|
|
26
|
+
x: - diameter / 2,
|
|
27
|
+
y: - diameter / 2,
|
|
28
|
+
width: diameter,
|
|
29
|
+
height: diameter
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
contains(point) {
|
|
34
|
+
return this._shapeWidget.contains(point);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
intersection(pointA, pointB) {
|
|
38
|
+
return this._shapeWidget.intersection(pointA, pointB);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
enter(domNode, element) {
|
|
42
|
+
super.enter(domNode, element);
|
|
43
|
+
delete this._prevHash;
|
|
44
|
+
this._defs = element.append("defs");
|
|
45
|
+
this._defs.append("clipPath")
|
|
46
|
+
.attr("id", "clip_" + this.id() + "_circle")
|
|
47
|
+
.append("circle")
|
|
48
|
+
.attr("x", 0)
|
|
49
|
+
.attr("y", 0)
|
|
50
|
+
;
|
|
51
|
+
this._defs.append("clipPath")
|
|
52
|
+
.attr("id", "clip_" + this.id() + "_square")
|
|
53
|
+
.append("rect")
|
|
54
|
+
;
|
|
55
|
+
this._root = element.append("g");
|
|
56
|
+
this._shapeWidget
|
|
57
|
+
.target(this._root.node())
|
|
58
|
+
;
|
|
59
|
+
this._faChar
|
|
60
|
+
.target(element.node())
|
|
61
|
+
;
|
|
62
|
+
this._tooltipElement = element.append("title");
|
|
63
|
+
const context = this;
|
|
64
|
+
element
|
|
65
|
+
.on("click", function (el) {
|
|
66
|
+
context.click(el);
|
|
67
|
+
})
|
|
68
|
+
.on("dblclick", function (el) {
|
|
69
|
+
context.dblclick(el);
|
|
70
|
+
})
|
|
71
|
+
;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
click(_domNode) {
|
|
75
|
+
// console.log("Clicked the icon");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
dblclick(_domNode) {
|
|
79
|
+
// console.log("Double clicked the icon");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
_prevHash;
|
|
83
|
+
update(domNode, element) {
|
|
84
|
+
super.update(domNode, element);
|
|
85
|
+
const hash = this.hashSum();
|
|
86
|
+
if (this._prevHash !== hash) {
|
|
87
|
+
this._prevHash = hash;
|
|
88
|
+
|
|
89
|
+
const diameter = this.diameter();
|
|
90
|
+
const radius = diameter / 2;
|
|
91
|
+
this._defs.select("circle")
|
|
92
|
+
.attr("r", radius)
|
|
93
|
+
;
|
|
94
|
+
this._defs.select("rect")
|
|
95
|
+
.attr("x", -radius)
|
|
96
|
+
.attr("y", -radius)
|
|
97
|
+
.attr("width", diameter)
|
|
98
|
+
.attr("height", diameter)
|
|
99
|
+
;
|
|
100
|
+
this._faChar
|
|
101
|
+
.fontSize(diameter * (100 - this.paddingPercent()) / 100)
|
|
102
|
+
.render()
|
|
103
|
+
;
|
|
104
|
+
this._shapeWidget
|
|
105
|
+
.shape(this.shape())
|
|
106
|
+
.width(diameter)
|
|
107
|
+
.height(diameter)
|
|
108
|
+
.render()
|
|
109
|
+
;
|
|
110
|
+
const image = this._root.selectAll("image").data(this.imageUrl() ? [this.imageUrl()] : [], function (d) { return d; });
|
|
111
|
+
image.enter()
|
|
112
|
+
.append("image")
|
|
113
|
+
.attr("xlink:href", this.imageUrl())
|
|
114
|
+
.merge(image)
|
|
115
|
+
.attr("clip-path", "url(#clip_" + this.id() + "_" + this.shape() + ")")
|
|
116
|
+
.attr("x", -radius)
|
|
117
|
+
.attr("y", -radius)
|
|
118
|
+
.attr("width", diameter)
|
|
119
|
+
.attr("height", diameter)
|
|
120
|
+
;
|
|
121
|
+
if (this.shape_colorFill_exists() && !this.image_colorFill_exists()) {
|
|
122
|
+
this.image_colorFill(textColor(this.shape_colorFill()));
|
|
123
|
+
}
|
|
124
|
+
image.exit()
|
|
125
|
+
.remove()
|
|
126
|
+
;
|
|
127
|
+
this._tooltipElement.text(this.tooltip());
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
exit(domNode, element) {
|
|
132
|
+
super.exit(domNode, element);
|
|
133
|
+
this._shapeWidget
|
|
134
|
+
.target(null)
|
|
135
|
+
;
|
|
136
|
+
this._faChar
|
|
137
|
+
.target(null)
|
|
138
|
+
;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
Icon.prototype._class += " common_Icon";
|
|
143
|
+
|
|
144
|
+
export interface Icon {
|
|
145
|
+
shape(): string;
|
|
146
|
+
shape(_: string): this;
|
|
147
|
+
faChar(): string;
|
|
148
|
+
faChar(_: string): this;
|
|
149
|
+
imageUrl(): string;
|
|
150
|
+
imageUrl(_: string): this;
|
|
151
|
+
image_colorFill(): string;
|
|
152
|
+
image_colorFill(_: string): this;
|
|
153
|
+
image_colorFill_exists(): boolean;
|
|
154
|
+
tooltip(): string;
|
|
155
|
+
tooltip(_: string): this;
|
|
156
|
+
diameter(): number;
|
|
157
|
+
diameter(_: number): this;
|
|
158
|
+
paddingPercent(): number;
|
|
159
|
+
paddingPercent(_: number): this;
|
|
160
|
+
shape_colorFill(): string;
|
|
161
|
+
shape_colorFill(_: string): this;
|
|
162
|
+
shape_colorFill_exists(): boolean;
|
|
163
|
+
shape_colorStroke(): string;
|
|
164
|
+
shape_colorStroke(_: string): this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
Icon.prototype.publish("shape", "circle", "set", "Shape Type", ["circle", "square"], { tags: ["Private"] });
|
|
168
|
+
Icon.prototype.publishProxy("faChar", "_faChar", "char");
|
|
169
|
+
Icon.prototype.publishProxy("fontFamily", "_faChar", "text_fontFamily");
|
|
170
|
+
Icon.prototype.publish("imageUrl", null, "string", "Image URL", null, { optional: true });
|
|
171
|
+
Icon.prototype.publishProxy("image_colorFill", "_faChar", "text_colorFill");
|
|
172
|
+
Icon.prototype.publish("tooltip", "", "string", "Tooltip", null, { tags: ["Private"] });
|
|
173
|
+
Icon.prototype.publish("diameter", 24, "number", "Diameter", null, { tags: ["Private"] });
|
|
174
|
+
Icon.prototype.publish("paddingPercent", 45, "number", "Padding Percent", null, { tags: ["Private"] });
|
|
175
|
+
Icon.prototype.publishProxy("shape_colorFill", "_shapeWidget", "colorFill");
|
|
176
|
+
Icon.prototype.publishProxy("shape_colorStroke", "_shapeWidget", "colorStroke");
|
package/src/Image.ts
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import { select as d3Select } from "d3-selection";
|
|
2
|
-
import { HTMLWidget } from "./HTMLWidget.ts";
|
|
3
|
-
|
|
4
|
-
export class Image extends HTMLWidget {
|
|
5
|
-
private _imgElement;
|
|
6
|
-
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
enter(domNode, element) {
|
|
12
|
-
super.enter(domNode, element);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
update(domNode, element) {
|
|
16
|
-
super.update(domNode, element);
|
|
17
|
-
const context = this;
|
|
18
|
-
const img = element.selectAll("img").data(this.source() ? [this.source()] : [], function (d) { return d; });
|
|
19
|
-
img.enter()
|
|
20
|
-
.append("img")
|
|
21
|
-
.attr("src", this.source())
|
|
22
|
-
.style("opacity", 0)
|
|
23
|
-
.on("load", function () {
|
|
24
|
-
context._imgElement = d3Select(this);
|
|
25
|
-
context.styleImageElement();
|
|
26
|
-
context._imgElement.style("opacity", 1);
|
|
27
|
-
})
|
|
28
|
-
;
|
|
29
|
-
this.styleImageElement();
|
|
30
|
-
img.exit()
|
|
31
|
-
.remove()
|
|
32
|
-
;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
styleImageElement() {
|
|
36
|
-
if (!this._imgElement) return;
|
|
37
|
-
switch (this.sizing()) {
|
|
38
|
-
case "actual":
|
|
39
|
-
this._imgElement.style("width", "auto");
|
|
40
|
-
this._imgElement.style("height", "auto");
|
|
41
|
-
break;
|
|
42
|
-
case "fit":
|
|
43
|
-
if (this.lockAspectRatio()) {
|
|
44
|
-
this._imgElement.style("width", "auto");
|
|
45
|
-
this._imgElement.style("height", "auto");
|
|
46
|
-
const bbox = this._imgElement.node().getBoundingClientRect();
|
|
47
|
-
const xScale = bbox.width / this.width();
|
|
48
|
-
const yScale = bbox.height / this.height();
|
|
49
|
-
if (xScale > yScale) {
|
|
50
|
-
this._imgElement.style("width", this.width() + "px");
|
|
51
|
-
this._imgElement.style("height", (bbox.height / xScale) + "px");
|
|
52
|
-
} else {
|
|
53
|
-
this._imgElement.style("width", (bbox.width / yScale) + "px");
|
|
54
|
-
this._imgElement.style("height", this.height() + "px");
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
this._imgElement.style("width", this.width() + "px");
|
|
58
|
-
this._imgElement.style("height", this.height() + "px");
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
case "custom":
|
|
62
|
-
this._imgElement.style("width", this.customWidth());
|
|
63
|
-
this._imgElement.style("height", this.customHeight());
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
switch (this.alignment()) {
|
|
67
|
-
case "origin":
|
|
68
|
-
break;
|
|
69
|
-
case "center":
|
|
70
|
-
const bbox = this._imgElement.node().getBoundingClientRect();
|
|
71
|
-
this._imgElement.style("margin-left", `${(this.width() - bbox.width) / 2}px`);
|
|
72
|
-
this._imgElement.style("margin-top", `${(this.height() - bbox.height) / 2}px`);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
exit(domNode, element) {
|
|
78
|
-
super.exit(domNode, element);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
Image.prototype._class += " common_Image";
|
|
83
|
-
|
|
84
|
-
export interface Image {
|
|
85
|
-
source(): string;
|
|
86
|
-
source(_: string): this;
|
|
87
|
-
sizing(): "actual" | "fit" | "custom";
|
|
88
|
-
sizing(_: "actual" | "fit" | "custom"): this;
|
|
89
|
-
customWidth(): string;
|
|
90
|
-
customWidth(_: string): this;
|
|
91
|
-
customHeight(): string;
|
|
92
|
-
customHeight(_: string): this;
|
|
93
|
-
lockAspectRatio(): boolean;
|
|
94
|
-
lockAspectRatio(_: boolean): this;
|
|
95
|
-
alignment(): "center" | "origin";
|
|
96
|
-
alignment(_: "center" | "origin"): this;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
Image.prototype.publish("source", null, "string", "Image Source", null, { tags: ["Basic"] });
|
|
100
|
-
Image.prototype.publish("sizing", "actual", "set", "Controls sizing mode", ["actual", "fit", "custom"], { tags: ["Basic"] });
|
|
101
|
-
Image.prototype.publish("customWidth", "50%", "string", "Applies this width to IMG element if 'sizing' is set to 'custom' (user should set 'px' or 'em' etc.)", null, { tags: ["Basic"], disable: (w) => w.sizing() !== "custom" });
|
|
102
|
-
Image.prototype.publish("customHeight", "20%", "string", "Applies this height to IMG element if 'sizing' is set to 'custom' (user should set 'px' or 'em' etc.)", null, { tags: ["Basic"], disable: (w) => w.sizing() !== "custom" });
|
|
103
|
-
Image.prototype.publish("lockAspectRatio", true, "boolean", "Locks the aspect ratio when scaling/stretching", null, { tags: ["Basic"], disable: (w) => w.sizing() !== "fit" });
|
|
104
|
-
Image.prototype.publish("alignment", "center", "set", "Image Alignment", ["center", "origin"], { tags: ["Basic"] });
|
|
1
|
+
import { select as d3Select } from "d3-selection";
|
|
2
|
+
import { HTMLWidget } from "./HTMLWidget.ts";
|
|
3
|
+
|
|
4
|
+
export class Image extends HTMLWidget {
|
|
5
|
+
private _imgElement;
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
enter(domNode, element) {
|
|
12
|
+
super.enter(domNode, element);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
update(domNode, element) {
|
|
16
|
+
super.update(domNode, element);
|
|
17
|
+
const context = this;
|
|
18
|
+
const img = element.selectAll("img").data(this.source() ? [this.source()] : [], function (d) { return d; });
|
|
19
|
+
img.enter()
|
|
20
|
+
.append("img")
|
|
21
|
+
.attr("src", this.source())
|
|
22
|
+
.style("opacity", 0)
|
|
23
|
+
.on("load", function () {
|
|
24
|
+
context._imgElement = d3Select(this);
|
|
25
|
+
context.styleImageElement();
|
|
26
|
+
context._imgElement.style("opacity", 1);
|
|
27
|
+
})
|
|
28
|
+
;
|
|
29
|
+
this.styleImageElement();
|
|
30
|
+
img.exit()
|
|
31
|
+
.remove()
|
|
32
|
+
;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
styleImageElement() {
|
|
36
|
+
if (!this._imgElement) return;
|
|
37
|
+
switch (this.sizing()) {
|
|
38
|
+
case "actual":
|
|
39
|
+
this._imgElement.style("width", "auto");
|
|
40
|
+
this._imgElement.style("height", "auto");
|
|
41
|
+
break;
|
|
42
|
+
case "fit":
|
|
43
|
+
if (this.lockAspectRatio()) {
|
|
44
|
+
this._imgElement.style("width", "auto");
|
|
45
|
+
this._imgElement.style("height", "auto");
|
|
46
|
+
const bbox = this._imgElement.node().getBoundingClientRect();
|
|
47
|
+
const xScale = bbox.width / this.width();
|
|
48
|
+
const yScale = bbox.height / this.height();
|
|
49
|
+
if (xScale > yScale) {
|
|
50
|
+
this._imgElement.style("width", this.width() + "px");
|
|
51
|
+
this._imgElement.style("height", (bbox.height / xScale) + "px");
|
|
52
|
+
} else {
|
|
53
|
+
this._imgElement.style("width", (bbox.width / yScale) + "px");
|
|
54
|
+
this._imgElement.style("height", this.height() + "px");
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
this._imgElement.style("width", this.width() + "px");
|
|
58
|
+
this._imgElement.style("height", this.height() + "px");
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case "custom":
|
|
62
|
+
this._imgElement.style("width", this.customWidth());
|
|
63
|
+
this._imgElement.style("height", this.customHeight());
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
switch (this.alignment()) {
|
|
67
|
+
case "origin":
|
|
68
|
+
break;
|
|
69
|
+
case "center":
|
|
70
|
+
const bbox = this._imgElement.node().getBoundingClientRect();
|
|
71
|
+
this._imgElement.style("margin-left", `${(this.width() - bbox.width) / 2}px`);
|
|
72
|
+
this._imgElement.style("margin-top", `${(this.height() - bbox.height) / 2}px`);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exit(domNode, element) {
|
|
78
|
+
super.exit(domNode, element);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
Image.prototype._class += " common_Image";
|
|
83
|
+
|
|
84
|
+
export interface Image {
|
|
85
|
+
source(): string;
|
|
86
|
+
source(_: string): this;
|
|
87
|
+
sizing(): "actual" | "fit" | "custom";
|
|
88
|
+
sizing(_: "actual" | "fit" | "custom"): this;
|
|
89
|
+
customWidth(): string;
|
|
90
|
+
customWidth(_: string): this;
|
|
91
|
+
customHeight(): string;
|
|
92
|
+
customHeight(_: string): this;
|
|
93
|
+
lockAspectRatio(): boolean;
|
|
94
|
+
lockAspectRatio(_: boolean): this;
|
|
95
|
+
alignment(): "center" | "origin";
|
|
96
|
+
alignment(_: "center" | "origin"): this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Image.prototype.publish("source", null, "string", "Image Source", null, { tags: ["Basic"] });
|
|
100
|
+
Image.prototype.publish("sizing", "actual", "set", "Controls sizing mode", ["actual", "fit", "custom"], { tags: ["Basic"] });
|
|
101
|
+
Image.prototype.publish("customWidth", "50%", "string", "Applies this width to IMG element if 'sizing' is set to 'custom' (user should set 'px' or 'em' etc.)", null, { tags: ["Basic"], disable: (w) => w.sizing() !== "custom" });
|
|
102
|
+
Image.prototype.publish("customHeight", "20%", "string", "Applies this height to IMG element if 'sizing' is set to 'custom' (user should set 'px' or 'em' etc.)", null, { tags: ["Basic"], disable: (w) => w.sizing() !== "custom" });
|
|
103
|
+
Image.prototype.publish("lockAspectRatio", true, "boolean", "Locks the aspect ratio when scaling/stretching", null, { tags: ["Basic"], disable: (w) => w.sizing() !== "fit" });
|
|
104
|
+
Image.prototype.publish("alignment", "center", "set", "Image Alignment", ["center", "origin"], { tags: ["Basic"] });
|
package/src/List.css
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
.common_List .common_TextBox .common_Shape {
|
|
2
|
-
fill: #dcf1ff;
|
|
3
|
-
stroke: #dcf1ff;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
.common_List .common_TextBox .common_Text {
|
|
7
|
-
pointer-events: none;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.common_List .common_TextBox .common_Shape:hover {
|
|
11
|
-
fill: white;
|
|
12
|
-
stroke: white;
|
|
13
|
-
}
|
|
1
|
+
.common_List .common_TextBox .common_Shape {
|
|
2
|
+
fill: #dcf1ff;
|
|
3
|
+
stroke: #dcf1ff;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.common_List .common_TextBox .common_Text {
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.common_List .common_TextBox .common_Shape:hover {
|
|
11
|
+
fill: white;
|
|
12
|
+
stroke: white;
|
|
13
|
+
}
|