@yanqirenshi/d3.wireframe 0.2.0 → 0.2.1

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.
@@ -1,66 +1,66 @@
1
- import ElementFounder from './ElementFounder';
2
-
3
- export default class ElementLabel extends ElementFounder {
4
- constructor (params) {
5
- super('label', params);
6
- }
7
- /* **************************************************************** *
8
- * Data
9
- * **************************************************************** */
10
- templateElement () {
11
- return this.makeTemplateElement({
12
- text: '????????',
13
- position: null,
14
- font: null,
15
- });
16
- }
17
- makeElement (core, parent) {
18
- let element = this.templateElement();
19
-
20
- this.initElement(element, core, parent);
21
-
22
- if (core.text)
23
- element.text = core.text;
24
-
25
- this.fittingPosition(element, core);
26
- this.fittingFont(element, core);
27
-
28
- return element;
29
- }
30
- makeElements (labels) {
31
- if (!labels)
32
- return [];
33
-
34
- return labels.map((d) => this.makeElement(d));
35
- }
36
- /* **************************************************************** *
37
- * Draw
38
- * **************************************************************** */
39
- /**
40
- * ラベルを描く。回転ビュー(projector あり)では、親要素の絶対位置 +
41
- * ラベル相対位置を射影した点に置き、フォントサイズは距離スケール(k)で
42
- * 近似する(SVG の文字は遠近で歪ませられないため、位置と大きさのみ)。
43
- */
44
- draw (place, data, projector) {
45
- const project = (d) => projector.point(
46
- data.position.x + d.position.x,
47
- data.position.y + d.position.y,
48
- projector.depthZ(data._depth));
49
-
50
- place.selectAll('label')
51
- .data(data.labels, d => d._id)
52
- .enter()
53
- .append("text")
54
- .attr("x", d => projector ? project(d).x : d.position.x)
55
- .attr("y", d => projector ? project(d).y : d.position.y)
56
- .style("font-size", d => {
57
- if (!projector)
58
- return `${d.font.size}px`;
59
-
60
- return `${d.font.size * project(d).k}px`;
61
- })
62
- .style("fill", d => d.font.color)
63
- .style("font-weight", d => d.font.weight)
64
- .text(d => d.text);
65
- }
66
- }
1
+ import ElementFounder from './ElementFounder';
2
+
3
+ export default class ElementLabel extends ElementFounder {
4
+ constructor (params) {
5
+ super('label', params);
6
+ }
7
+ /* **************************************************************** *
8
+ * Data
9
+ * **************************************************************** */
10
+ templateElement () {
11
+ return this.makeTemplateElement({
12
+ text: '????????',
13
+ position: null,
14
+ font: null,
15
+ });
16
+ }
17
+ makeElement (core, parent) {
18
+ let element = this.templateElement();
19
+
20
+ this.initElement(element, core, parent);
21
+
22
+ if (core.text)
23
+ element.text = core.text;
24
+
25
+ this.fittingPosition(element, core);
26
+ this.fittingFont(element, core);
27
+
28
+ return element;
29
+ }
30
+ makeElements (labels) {
31
+ if (!labels)
32
+ return [];
33
+
34
+ return labels.map((d) => this.makeElement(d));
35
+ }
36
+ /* **************************************************************** *
37
+ * Draw
38
+ * **************************************************************** */
39
+ /**
40
+ * ラベルを描く。回転ビュー(projector あり)では、親要素の絶対位置 +
41
+ * ラベル相対位置を射影した点に置き、フォントサイズは距離スケール(k)で
42
+ * 近似する(SVG の文字は遠近で歪ませられないため、位置と大きさのみ)。
43
+ */
44
+ draw (place, data, projector) {
45
+ const project = (d) => projector.point(
46
+ data.position.x + d.position.x,
47
+ data.position.y + d.position.y,
48
+ projector.depthZ(data._depth));
49
+
50
+ place.selectAll('label')
51
+ .data(data.labels, d => d._id)
52
+ .enter()
53
+ .append("text")
54
+ .attr("x", d => projector ? project(d).x : d.position.x)
55
+ .attr("y", d => projector ? project(d).y : d.position.y)
56
+ .style("font-size", d => {
57
+ if (!projector)
58
+ return `${d.font.size}px`;
59
+
60
+ return `${d.font.size * project(d).k}px`;
61
+ })
62
+ .style("fill", d => d.font.color)
63
+ .style("font-weight", d => d.font.weight)
64
+ .text(d => d.text);
65
+ }
66
+ }
@@ -1,61 +1,61 @@
1
- import ElementFounder from './ElementFounder';
2
-
3
- export default class ElementModal extends ElementFounder {
4
- constructor (params) {
5
- super('modal', params);
6
- }
7
- /* **************************************************************** *
8
- * Data
9
- * **************************************************************** */
10
- templateElement () {
11
- return this.makeTemplateElement({
12
- position: null,
13
- rectangle: null,
14
- children: [],
15
- });
16
- }
17
- makeElement (core, parent) {
18
- let element = this.templateElement();
19
-
20
- this.initElement(element, core, parent);
21
-
22
- this.fittingRectangle(element, core);
23
- this.fittingPosition(element, core);
24
- this.fittingBackground(element, core);
25
-
26
- return element;
27
- }
28
- /* **************************************************************** *
29
- * Draw
30
- * **************************************************************** */
31
- drawAdd (place, data, projector) {
32
- const g = place.selectAll(`g.${this.name}`)
33
- .data([data], (d) => { return d._id; })
34
- .enter()
35
- .append('g')
36
- .attr('class', this.name)
37
- .attr("transform", d => this.groupTransform(d, projector));
38
-
39
- // modal は stroke 無し + 半透明の面。共通の drawBase(rect/polygon の
40
- // 切替)を使い、追加の属性だけここで上書きする。
41
- this.drawBase(g, projector)
42
- .attr('stroke', null)
43
- .attr('stroke-width', null)
44
- .attr('fill-opacity', d => d.background.opacity);
45
- }
46
- drawUpdate (place, data) {
47
- place.selectAll(`g.${this.name}`)
48
- .data([data], (d) => { return d._id; });
49
- }
50
- drawDelete (place, data) {
51
- place.selectAll(`g.${this.name}`)
52
- .data([data], (d) => { return d._id; })
53
- .exit()
54
- .remove();
55
- }
56
- draw (place, data, projector) {
57
- // this.drawDelete(place, data);
58
- this.drawUpdate(place, data);
59
- this.drawAdd(place, data, projector);
60
- }
61
- }
1
+ import ElementFounder from './ElementFounder';
2
+
3
+ export default class ElementModal extends ElementFounder {
4
+ constructor (params) {
5
+ super('modal', params);
6
+ }
7
+ /* **************************************************************** *
8
+ * Data
9
+ * **************************************************************** */
10
+ templateElement () {
11
+ return this.makeTemplateElement({
12
+ position: null,
13
+ rectangle: null,
14
+ children: [],
15
+ });
16
+ }
17
+ makeElement (core, parent) {
18
+ let element = this.templateElement();
19
+
20
+ this.initElement(element, core, parent);
21
+
22
+ this.fittingRectangle(element, core);
23
+ this.fittingPosition(element, core);
24
+ this.fittingBackground(element, core);
25
+
26
+ return element;
27
+ }
28
+ /* **************************************************************** *
29
+ * Draw
30
+ * **************************************************************** */
31
+ drawAdd (place, data, projector) {
32
+ const g = place.selectAll(`g.${this.name}`)
33
+ .data([data], (d) => { return d._id; })
34
+ .enter()
35
+ .append('g')
36
+ .attr('class', this.name)
37
+ .attr("transform", d => this.groupTransform(d, projector));
38
+
39
+ // modal は stroke 無し + 半透明の面。共通の drawBase(rect/polygon の
40
+ // 切替)を使い、追加の属性だけここで上書きする。
41
+ this.drawBase(g, projector)
42
+ .attr('stroke', null)
43
+ .attr('stroke-width', null)
44
+ .attr('fill-opacity', d => d.background.opacity);
45
+ }
46
+ drawUpdate (place, data) {
47
+ place.selectAll(`g.${this.name}`)
48
+ .data([data], (d) => { return d._id; });
49
+ }
50
+ drawDelete (place, data) {
51
+ place.selectAll(`g.${this.name}`)
52
+ .data([data], (d) => { return d._id; })
53
+ .exit()
54
+ .remove();
55
+ }
56
+ draw (place, data, projector) {
57
+ // this.drawDelete(place, data);
58
+ this.drawUpdate(place, data);
59
+ this.drawAdd(place, data, projector);
60
+ }
61
+ }