@dra2020/baseclient 1.0.162 → 1.0.163

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.
@@ -0,0 +1 @@
1
+ export * from './control';
@@ -0,0 +1,4 @@
1
+ export interface Control {
2
+ isCanceled: () => boolean;
3
+ statusUpdate: (complete: number, total: number) => void;
4
+ }
@@ -1,3 +1,4 @@
1
1
  import * as G from '../geo/all';
2
- export declare function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap): any;
3
- export declare function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection): any;
2
+ import { Control } from '../control/all';
3
+ export declare function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap, control?: Control): any;
4
+ export declare function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection, control?: Control): any;
@@ -5,9 +5,12 @@ export declare class Elapsed {
5
5
  tDur: any;
6
6
  constructor(bStart?: boolean);
7
7
  start(): void;
8
+ restart(): void;
8
9
  end(): void;
9
10
  ms(): number;
11
+ mscur(): number;
10
12
  nano(): number;
13
+ nanocur(): number;
11
14
  }
12
15
  export declare class MultiTimer {
13
16
  _overall: Elapsed;
package/lib/all/all.ts CHANGED
@@ -29,3 +29,5 @@ import * as DataFlow from '../dataflow/all';
29
29
  export { DataFlow }
30
30
  import * as Detail from '../detail/all';
31
31
  export { Detail }
32
+ import * as Control from '../control/all';
33
+ export { Control }
@@ -0,0 +1 @@
1
+ export * from './control';
@@ -0,0 +1,4 @@
1
+ export interface Control {
2
+ isCanceled: () => boolean,
3
+ statusUpdate: (complete: number, total: number) => void,
4
+ }
package/lib/geo/geo.ts CHANGED
@@ -11,13 +11,17 @@ export type HideMap = { [id: string]: boolean };
11
11
 
12
12
  // Tracing/debugging aid
13
13
  let metrics: { [action: string]: { count: number, total: number } } = {};
14
+ const MinRecordTotal = 500;
14
15
 
15
16
  function record(action: string, total: number): void
16
17
  {
17
- if (metrics[action] === undefined)
18
- metrics[action] = { count: 0, total: 0 };
19
- metrics[action].count++;
20
- metrics[action].total += total;
18
+ if (total > MinRecordTotal)
19
+ {
20
+ if (metrics[action] === undefined)
21
+ metrics[action] = { count: 0, total: 0 };
22
+ metrics[action].count++;
23
+ metrics[action].total += total;
24
+ }
21
25
  }
22
26
 
23
27
  export function dumpMetrics(): void
@@ -25,6 +29,7 @@ export function dumpMetrics(): void
25
29
  Object.keys(metrics).forEach(action => {
26
30
  console.log(`G.${action}: count: ${metrics[action].count}, total: ${metrics[action].total}`);
27
31
  });
32
+ metrics = {};
28
33
  }
29
34
 
30
35
  export function hidemapConcat(...args: HideMap[]): HideMap
package/lib/poly/mapto.ts CHANGED
@@ -4,6 +4,7 @@ import * as PP from './polypack';
4
4
  import * as PL from './polylabel';
5
5
  import * as BB from './boundbox';
6
6
  import { polyContainsPoint } from './pointinpoly';
7
+ import { Control } from '../control/all';
7
8
 
8
9
  function setLabels(c: G.GeoFeatureCollection): void
9
10
  {
@@ -33,7 +34,7 @@ function setLabels(c: G.GeoFeatureCollection): void
33
34
  //
34
35
  // The return value is an object that maps the block feature ids to the district feature id.
35
36
  //
36
- export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap): any
37
+ export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap, control?: Control): any
37
38
  {
38
39
  let map: any = {};
39
40
 
@@ -43,7 +44,11 @@ export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids
43
44
  let aDistricts: number[] = fs.map(f => P.polyArea(f));
44
45
 
45
46
  // Walk over blocks, mapping centroid to district
46
- Object.keys(centroids).forEach(blockid => {
47
+ let canceled = false;
48
+ let keys = Object.keys(centroids);
49
+ keys.forEach((blockid: string, k: number) => {
50
+ canceled = canceled || control?.isCanceled();
51
+ if (canceled) return;
47
52
  let x = centroids[blockid].x;
48
53
  let y = centroids[blockid].y;
49
54
 
@@ -67,12 +72,14 @@ export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids
67
72
  iLow = fIn[i];
68
73
  map[blockid] = fs[iLow].properties.id;
69
74
  }
75
+
76
+ if (control) control.statusUpdate(k, keys.length);
70
77
  });
71
78
 
72
- return map;
79
+ return canceled ? undefined : map;
73
80
  }
74
81
 
75
- export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection): any
82
+ export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection, control?: Control): any
76
83
  {
77
84
  // Cache labelx, labely if necessary
78
85
  setLabels(blocks);
@@ -82,5 +89,5 @@ export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatur
82
89
  centroids[f.properties.id] = { x: f.properties.labelx, y: f.properties.labely }
83
90
  });
84
91
 
85
- return polyMapToByCentroid(districts, centroids);
92
+ return polyMapToByCentroid(districts, centroids, control);
86
93
  }
package/lib/util/util.ts CHANGED
@@ -25,6 +25,12 @@ export class Elapsed
25
25
  if (this.tDur) this.tDur = undefined;
26
26
  }
27
27
 
28
+ restart(): void
29
+ {
30
+ if (this.tStart === undefined) this.start();
31
+ delete this.tDur;
32
+ }
33
+
28
34
  end(): void
29
35
  {
30
36
  if (this.tStart === undefined) this.start();
@@ -43,6 +49,13 @@ export class Elapsed
43
49
  return this.tDur;
44
50
  }
45
51
 
52
+ mscur(): number
53
+ {
54
+ let ms = this.ms();
55
+ this.restart();
56
+ return ms;
57
+ }
58
+
46
59
  nano(): number
47
60
  {
48
61
  if (this.tDur === undefined) this.end();
@@ -51,6 +64,13 @@ export class Elapsed
51
64
  else
52
65
  return this.tDur * 1000000;
53
66
  }
67
+
68
+ nanocur(): number
69
+ {
70
+ let nano = this.nano();
71
+ this.restart();
72
+ return nano;
73
+ }
54
74
  }
55
75
 
56
76
  export class MultiTimer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.162",
3
+ "version": "1.0.163",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",
@@ -1,3 +0,0 @@
1
- export declare var ColorTable: {
2
- [key: string]: string[];
3
- };
@@ -1,3 +0,0 @@
1
- export declare var ColorTable: {
2
- [key: string]: string[];
3
- };