@pirireis/webglobeplugins 0.6.7 → 0.6.8

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.
@@ -65,12 +65,12 @@ export default class Plugin {
65
65
  }
66
66
 
67
67
  _checkTextContextInjectionMap(textContextInjectionMap) {
68
- if (!(textContextInjectionMap instanceof Map)) throw new Error("textContextInjectionMap is not instance of Map");
68
+ if (!(textContextInjectionMap instanceof Map)) throw new TypeError("textContextInjectionMap is not instance of Map");
69
69
  textContextInjectionMap.forEach((v) => {
70
- if (typeof v !== 'object') throw new Error("textContextInjectionMap format is wrong");
71
- if (typeof v.coordsAdaptor !== 'function') throw new Error("textContextInjectionMap coordsAdaptor format is wrong");
72
- if (typeof v.textAdaptor !== 'function') throw new Error("textContextInjectionMap textAdaptor format is wrong");
73
- if (!(v.writer instanceof ContextTextWriter)) throw new Error("textContextInjectionMap writer is not instance of ContextTextWriter");
70
+ if (typeof v !== 'object') throw new TypeError("textContextInjectionMap format is wrong");
71
+ if (typeof v.coordsAdaptor !== 'function') throw new TypeError("textContextInjectionMap coordsAdaptor format is wrong");
72
+ if (typeof v.textAdaptor !== 'function') throw new TypeError("textContextInjectionMap textAdaptor format is wrong");
73
+ if (!(v.writer instanceof ContextTextWriter)) throw new TypeError("textContextInjectionMap writer is not instance of ContextTextWriter");
74
74
  })
75
75
  }
76
76
 
@@ -235,7 +235,7 @@ export default class Plugin {
235
235
  */
236
236
  insertBulk(items, textWriterInjectionSubSetIDs = []) {
237
237
  const { globe, bufferOrchestrator, bufferManagersCompMap } = this;// angleTextContext, distanceTextContext,
238
- const textWriterInjectionSubSets = textWriterInjectionSubSetIDs.map((id) => this._textContextInjectionMap.get(id));
238
+ const textWriterInjectionSubSets = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs);
239
239
  const data = []
240
240
  for (let item of items) {
241
241
  this._insertTexts(item, textWriterInjectionSubSets);
@@ -269,7 +269,7 @@ export default class Plugin {
269
269
  * @param {Array<string>} textWriterInjectionSubSetIDs | textContextInjectionMap keys to be used for writing text.
270
270
  */
271
271
  updateCoordinatesBulk(items, textWriterInjectionSubSetIDs = []) { //TODO
272
- const injectionsSubSet = textWriterInjectionSubSetIDs.map((id) => this._textContextInjectionMap.get(id));
272
+ const injectionsSubSet = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs);
273
273
  const { globe, bufferOrchestrator, bufferManagersCompMap, } = this;
274
274
  const data = []
275
275
  for (let item of items) {
@@ -285,24 +285,23 @@ export default class Plugin {
285
285
  /**
286
286
  *
287
287
  * @param {*} items some colums EXCEPT positional ones
288
- * @param {*} propertyIDs
289
- * @param {*} textWriterInjectionSubSetIDs
288
+ * @param {string} propertyIDs
289
+ * @param {string} textWriterInjectionSubSetIDs
290
290
  * Do NOT send empty data if property ID of this data is entered or NaN is loaded to the buffer, resulting in an unwanted behaviour.
291
291
  */
292
292
  updatePartial(items, propertyIDs = [], textWriterInjectionSubSetIDs = []) { // textWriterInjectionSubSetIDs = []
293
293
  if (propertyIDs.length === 0) console.warn("updatePartial is called with no target propertyIDs");
294
294
  const { _textContextInjectionMap, bufferOrchestrator, bufferManagersCompMap } = this;
295
- const writers = textWriterInjectionSubSetIDs.map((x) => _textContextInjectionMap.get(x));
295
+ const writers = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs); // TODO:filter out rgba? this might be a bug
296
296
  for (let item of items) { this._insertTexts(item, writers) }
297
297
  bufferOrchestrator.updateBulk(items, bufferManagersCompMap, propertyIDs);
298
298
  // patch to update text opacity
299
299
  for (const property of propertyIDs) {
300
300
  if (property === "rgba") {
301
- this._textContextInjectionMap.forEach((v) => {
301
+ _textContextInjectionMap.forEach((v) => {
302
302
  const { writer } = v;
303
303
  writer.updateOpacityBulk(items, (e) => e.key, (e) => e.rgba[3]);
304
304
  })
305
-
306
305
  }
307
306
  }
308
307
  this.globe.DrawRender();
@@ -407,6 +406,17 @@ export default class Plugin {
407
406
  });
408
407
  }
409
408
 
409
+ textContextInjection
410
+ _getTextWriterInjectionSubSet(textWriterIds) {
411
+ const { _textContextInjectionMap } = this;
412
+ const result = [];
413
+ for (const id of textWriterIds) {
414
+ const writerAndAdaptors = _textContextInjectionMap.get(id);
415
+ if (writerAndAdaptors === undefined) throw new Error("textContextInjection id does not exist in map:" + id);
416
+ result.push(writerAndAdaptors)
417
+ }
418
+ return result;
419
+ }
410
420
  }
411
421
 
412
422
 
@@ -46,6 +46,7 @@ export class CircleLineChainPlugin {
46
46
  textDataPreAdaptor = null
47
47
  } = {}) {
48
48
  this.id = id;
49
+ this._checkTextContextWriterInjectionMap(textContextWriterInjectionMap);
49
50
  this._textContextWriterInjectionMap = textContextWriterInjectionMap;
50
51
  this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, properties) => v.__identity__));
51
52
  this._opacity = 1;
@@ -297,7 +298,6 @@ export class CircleLineChainPlugin {
297
298
  chainKeysToReconstuct.push(chainKey);
298
299
  });
299
300
  this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
300
- // if (textWriterIDs) this._updateTexts(chainKeysToReconstuct, textWriterIDs)
301
301
  this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
302
302
  this._reconstructChains(chainKeysToReconstuct);
303
303
  this._updateTexts(chainKeysToReconstuct, textWriterIDs);
@@ -315,12 +315,23 @@ export class CircleLineChainPlugin {
315
315
  // implicit
316
316
 
317
317
  _updateTexts(chainKeys, textWriterIDs) {
318
- const textWriters = textWriterIDs.map((v) => this._textContextWriterInjectionMap.get(v));
318
+ if (textWriterIDs.length === 0) return;
319
+ const textWriters = this._getTextWriterInjectionSubSet(textWriterIDs)
319
320
  chainKeys.forEach((chainKey) => {
320
321
  this._chainListMap.textUpdate(chainKey, textWriters, this._textDataPreAdaptor);
321
322
  })
322
323
  }
323
324
 
325
+ _getTextWriterInjectionSubSet(textWriterIds) {
326
+ const { _textContextWriterInjectionMap } = this;
327
+ const result = [];
328
+ for (const id of textWriterIds) {
329
+ const w = _textContextWriterInjectionMap.get(id);
330
+ if (w === undefined) throw new Error("textContextInjection id does not exist in map:" + id);
331
+ result.push(w)
332
+ }
333
+ return result;
334
+ }
324
335
 
325
336
 
326
337
  _reconstructChains(chainKeys) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
File without changes
@@ -0,0 +1,10 @@
1
+
2
+
3
+ export const isHexColor = (hexColor) => /^#[0-9A-F]{6}$/i.test(hexColor);
4
+ export const isHexColorWithOpacity = (hexColor) => /^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(hexColor);
5
+
6
+ export const doesOwnProperties = (properties, errorMessage) => (object) => {
7
+ properties.array.forEach(element => {
8
+ if (!Object.hasOwn(object, element)) throw new TypeError(errorMessage + ' ' + element);
9
+ });
10
+ }
@@ -42,6 +42,7 @@ export class ContextTextWriter3 {
42
42
  this.style = style;
43
43
  this.doDraw = doDraw;
44
44
 
45
+ this._checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset);
45
46
 
46
47
  this.textAdaptor = textAdaptor;
47
48
  this.coordinatesAdaptor = coordinatesAdaptor;
@@ -63,6 +64,16 @@ export class ContextTextWriter3 {
63
64
  this.yOffset = yOffset;
64
65
  }
65
66
 
67
+ _checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset) {
68
+ if (textAdaptor !== null) if (!(textAdaptor instanceof Function)) throw new Error("textAdaptor is not an instance of a Function");
69
+ if (coordinatesAdaptor !== null) if (!(coordinatesAdaptor instanceof Function)) throw new Error("coordinatesAdaptor is not an instance of a Function");
70
+ if (keyAdaptor !== null) if (!(keyAdaptor instanceof Function)) throw new Error("keyAdaptor is not an instance of a Function");
71
+ if (opacityAdaptor !== null) if (!(opacityAdaptor instanceof Function)) throw new Error("opacityAdaptor is not an instance of a Function");
72
+ if (angleAdaptor !== null) if (!(angleAdaptor instanceof Function)) throw new Error("angleAdaptor is not an instance of a Function");
73
+ if (typeof xOffset !== "number") throw new Error("xOffset type is not a number");
74
+ if (typeof yOffset !== "number") throw new Error("yOffset type is not a number");
75
+ }
76
+
66
77
  setKeyAdaptor(adaptor) {
67
78
  this.keyAdaptor = adaptor;
68
79
  }
@@ -0,0 +1,12 @@
1
+ import { doesOwnProperties, isHexColor } from "../util/check/typecheck";
2
+
3
+ const fontCheckTypes = doesOwnProperties(["name", "textColor", "hollowColor", "size", "bold", "italic"], "font does not have");
4
+ const fontCheckColors = (textColor, hollowColor) => isHexColor(textColor) && isHexColor(hollowColor);
5
+
6
+ export const isTextFont = (textFont) => {
7
+ fontCheckTypes(textFont);
8
+ fontCheckColors(textFont.textColor, textFont.hollowColor);
9
+ if (!(textFont.size instanceof Number)) throw new TypeError("textFont size is not a number");
10
+
11
+ }
12
+