@pirireis/webglobeplugins 0.4.1-a → 0.5.0

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,19 +1,20 @@
1
- import { keyMethod } from "./util";
2
1
  /**
3
2
  * set and get node data
4
3
  * node indexes;
5
4
  */
6
5
  export class ChainListMap {
7
6
 
8
- constructor() {
7
+ constructor(keyMethod) {
9
8
  this._chainMap = new Map();
10
9
  this._chainSideProperties = new Map();
11
10
  this._indexMap = new Map(); // hold list index of lastly updated nodes. on add delete goes empty
11
+ this.keyMethod = keyMethod;
12
12
  }
13
13
 
14
14
  getChain(chainKey) {
15
15
  if (!this._chainMap.has(chainKey)) this._chainMap.set(chainKey, []);
16
16
  return this._chainMap.get(chainKey);
17
+
17
18
  }
18
19
 
19
20
  /**
@@ -35,6 +36,7 @@ export class ChainListMap {
35
36
  break;
36
37
  }
37
38
  }
39
+ node.identity = this.keyMethod(chainKey, node.key);
38
40
  this._resetIndexChain(chainKey);
39
41
  }
40
42
 
@@ -51,7 +53,7 @@ export class ChainListMap {
51
53
  const removeSet = new Set(nodeKeys);
52
54
  const newChain = []
53
55
  for (const node of chain) {
54
- const dKey = keyMethod(chainKey, node.key);
56
+ const dKey = node.identity;
55
57
  this._indexMap.delete(dKey);
56
58
  if (removeSet.has(node.key)) {
57
59
  compKeys.push(dKey);
@@ -65,7 +67,6 @@ export class ChainListMap {
65
67
 
66
68
  deleteChainAndReturnChainKeys(chainKey) {
67
69
  const keys = this.getNodeKeysOfChain(chainKey);
68
- console.log('chainKey', chainKey, "keys", keys);
69
70
  this._chainMap.delete(chainKey);
70
71
  for (const key of keys) this._indexMap.delete(key);
71
72
  return keys;
@@ -74,6 +75,7 @@ export class ChainListMap {
74
75
  updateNode(node, chainKey) {
75
76
  const index = this.getIndexOfNode(chainKey, node.key)
76
77
  const chain = this._chainMap.get(chainKey);
78
+ node.identity = this.keyMethod(chainKey, node.key);
77
79
  chain[index] = node;
78
80
  }
79
81
 
@@ -81,6 +83,7 @@ export class ChainListMap {
81
83
  setChain(chainKey, nodeList) {
82
84
  if (this._chainMap.has(chainKey)) this._flushIndexMap();
83
85
  this._chainMap.set(chainKey, nodeList);
86
+ nodeList.forEach((v) => v.identity = this.keyMethod(chainKey, v.key))
84
87
  }
85
88
 
86
89
 
@@ -151,7 +154,7 @@ export class ChainListMap {
151
154
 
152
155
 
153
156
  getIndexOfNode(chainKey, nodeKey) {
154
- const key = keyMethod(chainKey, nodeKey);
157
+ const key = this.keyMethod(chainKey, nodeKey);
155
158
  if (this._indexMap.has(key)) return this._indexMap.get(key);
156
159
 
157
160
  const chain = this._chainMap.get(chainKey);
@@ -172,16 +175,14 @@ export class ChainListMap {
172
175
  const chain = this._chainMap.get(chainKey);
173
176
  for (let i = 0; i < chain.length; i++) {
174
177
  const node = chain[i]
175
- this._indexMap.set(keyMethod(chainKey, node.key), i);
178
+ this._indexMap.set(this.keyMethod(chainKey, node.key), i);
176
179
  }
177
180
  }
178
181
 
179
182
  getNodeKeysOfChain(chainKey) {
180
183
  const chain = this._chainMap.get(chainKey);
181
- console.log("node keys", chain);
182
184
  if (!chain) return [];
183
- const result = chain.map((v) => keyMethod(chainKey, v.key));
184
- console.log("buffer Keys", result);
185
+ const result = chain.map((v) => v.identity);
185
186
  return result
186
187
  }
187
188
 
@@ -2,8 +2,7 @@ import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
2
2
  import { CircleCache } from '../programs/line-on-globe/circle';
3
3
  import { BufferOrchestrator, BufferManager } from "../util/account";
4
4
  import { ChainListMap } from "./chain-list-map";
5
- import { keyMethod } from "./util";
6
-
5
+ import { keyMethod } from './util';
7
6
  // TODO: Add update buffer and update text mehods on add, delete, update methods
8
7
 
9
8
 
@@ -29,9 +28,9 @@ export class CircleLineChainPlugin {
29
28
  constructor(id, { textContextWriterInjectionMap = new Map() } = {}) {
30
29
  this.id = id;
31
30
  this._textContextWriterInjectionMap = textContextWriterInjectionMap;
32
- this._textContextWriterInjectionMap.forEach((writer) => writer.keyAdaptor = (v, i, c, probs) => keyMethod(probs.chainKey, v.key));
31
+ this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, probs) => v.identity));
33
32
  this._opacity = 1;
34
- this._chainListMap = new ChainListMap();
33
+ this._chainListMap = new ChainListMap(keyMethod);
35
34
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
36
35
  }
37
36
 
@@ -107,7 +106,6 @@ export class CircleLineChainPlugin {
107
106
  * @typedef chain
108
107
  * @property {string} chainKey
109
108
  * @property {Array<node>} nodes
110
- *
111
109
  * @typedef {Object} node
112
110
  * @property {string} key
113
111
  * @property {number} long
@@ -126,7 +124,7 @@ export class CircleLineChainPlugin {
126
124
  });
127
125
  }
128
126
  this._reconstructChains(chainKeys);
129
- this._insertTexts(chainKeys, textWriterIDs);
127
+ this._updateTexts(chainKeys, textWriterIDs);
130
128
  }
131
129
 
132
130
 
@@ -138,7 +136,7 @@ export class CircleLineChainPlugin {
138
136
  updateChainProperties(chainKey, propertyMap, { textWriterIDs = [] } = {}) {
139
137
  this._chainListMap.updateChainProperties(chainKey, propertyMap);
140
138
  this._reconstructChains([chainKey]);
141
- if (textWriterIDs) this._insertTexts([chainKey], textWriterIDs);
139
+ if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
142
140
  }
143
141
 
144
142
  // ---- insertBulk family
@@ -172,7 +170,7 @@ export class CircleLineChainPlugin {
172
170
  chainKeysToConstruct.push(chainKey);
173
171
  }
174
172
  this._reconstructChains(chainKeysToConstruct);
175
- if (textWriterIDs) this._insertTexts(chainKeysToConstruct, textWriterIDs);
173
+ if (textWriterIDs) this._updateTexts(chainKeysToConstruct, textWriterIDs);
176
174
  }
177
175
 
178
176
  /**
@@ -181,20 +179,19 @@ export class CircleLineChainPlugin {
181
179
  * @param {*} chainKey
182
180
  * @param {*} theNodeKeyFront | node key of the next node, null places to the last
183
181
  */
184
- addNode(node, chainKey, { theNodeKeyFront = null, textContextIDs = [] } = {}) {
182
+ addNode(node, chainKey, { theNodeKeyFront = null, textWriterIDs = [] } = {}) {
185
183
  // TODO: if before object is null update the last two elements of the chain only.
186
- console.log("addNode", node, chainKey, theNodeKeyFront);
187
184
  this._chainListMap.addNode(node, chainKey, theNodeKeyFront);
188
- if (textContextIDs) this._insertTexts([chainKey], textContextIDs);
185
+ if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
189
186
  this._reconstructChains([chainKey]);
190
187
 
191
188
  }
192
189
 
193
190
 
194
191
 
195
- updateNodeCoordinates(node, chainKey, { textContextIDs = [] } = {}) {
192
+ updateNodeCoordinates(node, chainKey, { textWriterIDs = [] } = {}) {
196
193
  this._chainListMap.updateNode(node, chainKey);
197
- if (textContextIDs) this._insertTexts([chainKey], textContextIDs);
194
+ if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
198
195
  this._reconstructChains([chainKey]);
199
196
  }
200
197
 
@@ -219,9 +216,7 @@ export class CircleLineChainPlugin {
219
216
  for (const chainKey of chainKeys) {
220
217
  bufferKeys.push(...this._chainListMap.deleteChainAndReturnChainKeys(chainKey));
221
218
  }
222
- console.log("delete chain keys", chainKeys);
223
- console.log("deletechains bufferKeys", bufferKeys);
224
- this._insertTexts(chainKeys, this._textContextWriterInjectionMap.keys());
219
+ this._updateTexts(chainKeys, this._textContextWriterInjectionMap.keys());
225
220
  this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
226
221
  this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
227
222
  }
@@ -231,7 +226,7 @@ export class CircleLineChainPlugin {
231
226
  *
232
227
  * @param {Array<{key, nodeKeys:[]} keysAndNodes
233
228
  */
234
- deleteNodes(keysAndNodes) {
229
+ deleteNodes(keysAndNodes, { textWriterIDs = [] } = {}) {
235
230
  const bufferKeys = [];
236
231
  const chainKeysToReconstuct = [];
237
232
  keysAndNodes.forEach(({ chainKey, nodeKeys }) => {
@@ -240,13 +235,14 @@ export class CircleLineChainPlugin {
240
235
  });
241
236
  this._reconstructChains(chainKeysToReconstuct);
242
237
  this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
238
+ if (textWriterIDs) this._updateTexts(chainKeysToReconstuct, textWriterIDs)
243
239
  this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
244
240
  }
245
241
 
246
242
 
247
243
  // implicit
248
244
 
249
- _insertTexts(chainKeys, textWriterIDs) {
245
+ _updateTexts(chainKeys, textWriterIDs) {
250
246
  const textWriters = textWriterIDs.map((v) => this._textContextWriterInjectionMap.get(v));
251
247
  chainKeys.forEach((chainKey) => {
252
248
  this._chainListMap.textUpdate(chainKey, textWriters);
@@ -276,7 +272,7 @@ export class CircleLineChainPlugin {
276
272
  lat: v.lat,
277
273
  targetLong: array[i + 1].long,
278
274
  targetLat: array[i + 1].lat,
279
- key: keyMethod(probs.chainKey, v.key)
275
+ key: v.identity
280
276
  }
281
277
  }
282
278
  const bulkData = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.4.1-a",
3
+ "version": "0.5.0",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -14,6 +14,9 @@ const defaultStyle = {
14
14
  zMode: CSZMode.Z_GROUND_PERVERTEX,
15
15
  }
16
16
 
17
+ /**
18
+ * keyAdaptor should be set but higher context since it nows key methods and key method might be implicit to user
19
+ */
17
20
  export class ContextTextWriter2 {
18
21
  constructor(globe, { style = null, doDraw = true, textAdaptor = null, coordinatesAdaptor = null, keyAdaptor = null, opacityAdaptor = null } = {}) {
19
22
  this.globe = globe;
@@ -32,6 +35,9 @@ export class ContextTextWriter2 {
32
35
  }
33
36
  }
34
37
 
38
+ setKeyAdaptor(adaptor) {
39
+ this.keyAdaptor = adaptor;
40
+ }
35
41
 
36
42
  setDoDraw(bool) {
37
43
  this.doDraw = bool;
File without changes