@operato/scene-polypath 1.2.46

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/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as PolyPath } from './polypath'
@@ -0,0 +1,142 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import { Component, POSITION, Shape } from '@hatiolab/things-scene'
6
+
7
+ var controlHandler = {
8
+ ondragstart: function (point: POSITION, index: number, component: Component) {
9
+ component.mutatePath(null, function (path) {
10
+ path.splice(index, 0, point) // array.insert(index, point) 의 의미임.
11
+ })
12
+ },
13
+
14
+ ondragmove: function (point: POSITION, index: number, component: Component) {
15
+ component.mutatePath(null, function (path) {
16
+ path[index] = point
17
+ })
18
+ },
19
+
20
+ ondragend: function (point: POSITION, index: number, component: Component) {}
21
+ }
22
+
23
+ const NATURE = {
24
+ mutable: true,
25
+ resizable: false,
26
+ rotatable: false,
27
+ properties: [
28
+ {
29
+ type: 'number',
30
+ label: 'w',
31
+ name: 'w'
32
+ }
33
+ ],
34
+ help: 'scene/component/polypath'
35
+ }
36
+
37
+ export default class PolyPath extends Shape {
38
+ get pathExtendable() {
39
+ return true
40
+ }
41
+
42
+ get path() {
43
+ return this.getState('path')
44
+ }
45
+
46
+ set path(path) {
47
+ this.setState('path', path)
48
+ }
49
+
50
+ contains(x: number, y: number) {
51
+ var path = this.state.path
52
+ var result = false
53
+
54
+ path.forEach((p: { x: number; y: number }, idx: number) => {
55
+ let j = (idx + path.length + 1) % path.length
56
+
57
+ let x1 = p.x
58
+ let y1 = p.y
59
+ let x2 = path[j].x
60
+ let y2 = path[j].y
61
+
62
+ if (y1 > y != y2 > y && x < ((x2 - x1) * (y - y1)) / (y2 - y1) + x1) result = !result
63
+ })
64
+
65
+ return result
66
+ }
67
+
68
+ get controls() {
69
+ // 폴리라인에서의 control은 새로운 path를 추가하는 포인트이다.
70
+ var path = this.path
71
+ var controls = []
72
+
73
+ for (let i = 0; i < path.length - 1; i++) {
74
+ let p1 = path[i]
75
+ let p2 = path[i + 1]
76
+
77
+ if (i == 0) {
78
+ controls.push({
79
+ x: p1.x,
80
+ y: p1.y,
81
+ handler: controlHandler
82
+ })
83
+ }
84
+
85
+ controls.push({
86
+ x: (p1.x + p2.x) / 2,
87
+ y: (p1.y + p2.y) / 2,
88
+ handler: controlHandler
89
+ })
90
+
91
+ if (i == path.length - 2) {
92
+ controls.push({
93
+ x: p2.x,
94
+ y: p2.y,
95
+ handler: controlHandler
96
+ })
97
+ }
98
+ }
99
+
100
+ return controls
101
+ }
102
+
103
+ render(ctx: CanvasRenderingContext2D) {
104
+ var { path, w = 50 } = this.state
105
+
106
+ ctx.beginPath()
107
+ ctx.moveTo(path[0].x, path[0].y)
108
+
109
+ // 폭 적용하여 폐곡선 그리기
110
+ for (let i = 1; i < path.length; i++) {
111
+ const { x: prevX, y: prevY } = path[i - 1]
112
+ const { x: currX, y: currY } = path[i]
113
+ const angle = Math.atan2(currY - prevY, currX - prevX)
114
+ const offsetX = w * Math.sin(angle)
115
+ const offsetY = w * Math.cos(angle)
116
+ ctx.lineTo(currX + offsetX, currY - offsetY)
117
+ }
118
+
119
+ // for (let i = path.length - 1; i >= 0; i--) {
120
+ // const { x: prevX, y: prevY } = path[i + 1] || path[path.length - 1]
121
+ // const { x: currX, y: currY } = path[i]
122
+ // const angle = Math.atan2(currY - prevY, currX - prevX)
123
+ // const offsetX = w * Math.sin(angle)
124
+ // const offsetY = w * Math.cos(angle)
125
+ // ctx.lineTo(currX - offsetX, currY + offsetY)
126
+ // }
127
+
128
+ ctx.closePath()
129
+ }
130
+
131
+ is3dish() {
132
+ return false
133
+ }
134
+
135
+ get nature() {
136
+ return NATURE
137
+ }
138
+ }
139
+
140
+ Component.memoize(PolyPath.prototype, 'controls', false)
141
+
142
+ Component.register('polypath', PolyPath)
@@ -0,0 +1,67 @@
1
+ <!doctype html>
2
+ <!--
3
+ @license
4
+ Copyright © HatioLab Inc. All rights reserved.
5
+ -->
6
+ <html>
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
10
+
11
+ <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
12
+ <script src="../../web-component-tester/browser.js"></script>
13
+
14
+ <!-- Step 1: import the element to test -->
15
+ <link rel="import" href="../things-scene-gauge.html">
16
+ </head>
17
+ <body>
18
+
19
+ <!-- You can use the document as a place to set up your fixtures. -->
20
+ <test-fixture id="things-scene-gauge-fixture">
21
+ <template>
22
+ <things-scene-gauge>
23
+ <h2>things-scene-gauge</h2>
24
+ </things-scene-gauge>
25
+ </template>
26
+ </test-fixture>
27
+
28
+ <script>
29
+ suite('<things-scene-gauge>', function() {
30
+
31
+ var myEl;
32
+
33
+ setup(function() {
34
+ myEl = fixture('things-scene-gauge-fixture');
35
+ });
36
+
37
+ test('defines the "author" property', function() {
38
+ assert.equal(myEl.author.name, 'Dimitri Glazkov');
39
+ assert.equal(myEl.author.image, 'http://addyosmani.com/blog/wp-content/uploads/2013/04/unicorn.jpg');
40
+ });
41
+
42
+ test('says hello', function() {
43
+ assert.equal(myEl.sayHello(), 'things-scene-gauge says, Hello World!');
44
+
45
+ var greetings = myEl.sayHello('greetings Earthlings');
46
+ assert.equal(greetings, 'things-scene-gauge says, greetings Earthlings');
47
+ });
48
+
49
+ test('fires lasers', function(done) {
50
+ myEl.addEventListener('things-scene-gauge-lasers', function(event) {
51
+ assert.equal(event.detail.sound, 'Pew pew!');
52
+ done();
53
+ });
54
+ myEl.fireLasers();
55
+ });
56
+
57
+ test('distributed children', function() {
58
+ var els = myEl.getContentChildren();
59
+ assert.equal(els.length, 1, 'one distributed node');
60
+ assert.equal(els[0], myEl.querySelector('h2'), 'content distributed correctly');
61
+ });
62
+
63
+ });
64
+ </script>
65
+
66
+ </body>
67
+ </html>
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <!--
3
+ @license
4
+ Copyright © HatioLab Inc. All rights reserved.
5
+ -->
6
+ <html><head>
7
+ <meta charset="utf-8">
8
+ <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
9
+
10
+ <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
11
+ <script src="../../web-component-tester/browser.js"></script>
12
+ </head>
13
+ <body>
14
+ <script>
15
+ // Load and run all tests (.html, .js):
16
+ WCT.loadSuites([
17
+ 'basic-test.html',
18
+ 'basic-test.html?dom=shadow'
19
+ ]);
20
+ </script>
21
+
22
+ </body></html>
@@ -0,0 +1,34 @@
1
+ const icon = new URL('./icons/polypath.png', import.meta.url).href
2
+
3
+ var templates = [
4
+ {
5
+ type: 'polypath',
6
+ description: 'poly path',
7
+ group: 'shape' /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */,
8
+ icon,
9
+ model: {
10
+ type: 'polypath',
11
+ left: 100,
12
+ top: 100,
13
+ width: 100,
14
+ height: 100,
15
+ path: [
16
+ { x: 100, y: 100 },
17
+ { x: 200, y: 100 },
18
+ { x: 200, y: 200 },
19
+ { x: 100, y: 200 }
20
+ ],
21
+ fillStyle: '#fff',
22
+ strokeStyle: '#000',
23
+ alpha: 1,
24
+ hidden: false,
25
+ lineWidth: 1,
26
+ lineDash: 'solid',
27
+ lineCap: 'butt'
28
+ }
29
+ }
30
+ ]
31
+
32
+ export default {
33
+ templates
34
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2018",
4
+ "module": "esnext",
5
+ "moduleResolution": "node",
6
+ "noEmitOnError": true,
7
+ "lib": ["es2019", "dom"],
8
+ "strict": true,
9
+ "esModuleInterop": false,
10
+ "allowSyntheticDefaultImports": true,
11
+ "experimentalDecorators": true,
12
+ "importHelpers": true,
13
+ "outDir": "dist",
14
+ "sourceMap": true,
15
+ "inlineSources": true,
16
+ "rootDir": "src",
17
+ "declaration": true,
18
+ "incremental": true,
19
+ "types": []
20
+ },
21
+ "include": ["**/*.ts", "*.d.ts"]
22
+ }
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../node_modules/tslib/tslib.d.ts","../../node_modules/@hatiolab/things-scene/things-scene.d.ts","./src/polypath.ts","./src/index.ts"],"fileInfos":[{"version":"f59215c5f1d886b05395ee7aca73e0ac69ddfad2843aa88530e797879d511bad","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","dc48272d7c333ccf58034c0026162576b7d50ea0e69c3b9292f803fc20720fd5","27147504487dc1159369da4f4da8a26406364624fa9bc3db632f7d94a5bae2c3","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7",{"version":"3dda5344576193a4ae48b8d03f105c86f20b2f2aff0a1d1fd7935f5d68649654","affectsGlobalScope":true},{"version":"9d9885c728913c1d16e0d2831b40341d6ad9a0ceecaabc55209b306ad9c736a5","affectsGlobalScope":true},{"version":"17bea081b9c0541f39dd1ae9bc8c78bdd561879a682e60e2f25f688c0ecab248","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"ab22100fdd0d24cfc2cc59d0a00fc8cf449830d9c4030dc54390a46bd562e929","affectsGlobalScope":true},{"version":"f7bd636ae3a4623c503359ada74510c4005df5b36de7f23e1db8a5c543fd176b","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"0c20f4d2358eb679e4ae8a4432bdd96c857a2960fd6800b21ec4008ec59d60ea","affectsGlobalScope":true},{"version":"36ae84ccc0633f7c0787bc6108386c8b773e95d3b052d9464a99cd9b8795fbec","affectsGlobalScope":true},{"version":"82d0d8e269b9eeac02c3bd1c9e884e85d483fcb2cd168bccd6bc54df663da031","affectsGlobalScope":true},{"version":"b8deab98702588840be73d67f02412a2d45a417a3c097b2e96f7f3a42ac483d1","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"376d554d042fb409cb55b5cbaf0b2b4b7e669619493c5d18d5fa8bd67273f82a","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"c4138a3dd7cd6cf1f363ca0f905554e8d81b45844feea17786cdf1626cb8ea06","affectsGlobalScope":true},{"version":"6ff3e2452b055d8f0ec026511c6582b55d935675af67cdb67dd1dc671e8065df","affectsGlobalScope":true},{"version":"03de17b810f426a2f47396b0b99b53a82c1b60e9cba7a7edda47f9bb077882f4","affectsGlobalScope":true},{"version":"8184c6ddf48f0c98429326b428478ecc6143c27f79b79e85740f17e6feb090f1","affectsGlobalScope":true},{"version":"261c4d2cf86ac5a89ad3fb3fafed74cbb6f2f7c1d139b0540933df567d64a6ca","affectsGlobalScope":true},{"version":"6af1425e9973f4924fca986636ac19a0cf9909a7e0d9d3009c349e6244e957b6","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"15a630d6817718a2ddd7088c4f83e4673fde19fa992d2eae2cf51132a302a5d3","affectsGlobalScope":true},{"version":"189c0703923150aa30673fa3de411346d727cc44a11c75d05d7cf9ef095daa22","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"f1c9fe42b65437a61104e601eb298c5c859fb522b483f1bdb700eed67a16f980","1ec425c4c916d3a75b0557409a967eb5fee869beb69eefc2fbbf563f92bda771",{"version":"a303d41f36752fef51db7e149f316609fafb777fe76317d0ac66b5b0e1cf90a3","signature":"5b5a769816e3890b2d1b1e20d04313bced2e22da7395cdd10cc4b309fece0b2f"},{"version":"5c8bf786f2ceb87c1622e50d9fe6476a412df88a57222d5f382b3de90e54c8b3","signature":"a6da775445708dbeee29b3bae8acff86a069026a135ad2e10e95ed7e7881b614"}],"root":[37,38],"options":{"allowSyntheticDefaultImports":true,"declaration":true,"esModuleInterop":false,"experimentalDecorators":true,"importHelpers":true,"inlineSources":true,"module":99,"noEmitOnError":true,"outDir":"./dist","rootDir":"./src","sourceMap":true,"strict":true,"target":5},"fileIdsList":[[35,37],[35,36],[37],[36]],"referencedMap":[[38,1],[37,2]],"exportedModulesMap":[[38,3],[37,4]],"semanticDiagnosticsPerFile":[36,35,33,34,7,9,8,2,10,11,12,13,14,15,16,17,3,4,21,18,19,20,22,23,24,5,25,26,27,28,6,32,29,30,31,1,38,37]},"version":"5.1.3"}