@jbrowse/plugin-alignments 2.4.1 → 2.4.2
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/dist/AlignmentsFeatureDetail/AlignmentsFeatureDetail.d.ts +4 -4
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js +88 -126
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js.map +1 -1
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureFlags.d.ts +6 -0
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureFlags.js +44 -0
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureFlags.js.map +1 -0
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureSuppAligns.d.ts +6 -0
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureSuppAligns.js +37 -0
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureSuppAligns.js.map +1 -0
- package/dist/AlignmentsFeatureDetail/index.d.ts +1 -1
- package/dist/AlignmentsFeatureDetail/util.d.ts +8 -0
- package/dist/AlignmentsFeatureDetail/util.js +27 -0
- package/dist/AlignmentsFeatureDetail/util.js.map +1 -0
- package/dist/LinearAlignmentsDisplay/components/AlignmentsDisplay.js +2 -2
- package/dist/LinearAlignmentsDisplay/components/AlignmentsDisplay.js.map +1 -1
- package/dist/LinearAlignmentsDisplay/models/model.d.ts +1 -1
- package/dist/LinearAlignmentsDisplay/models/model.js.map +1 -1
- package/dist/LinearPileupDisplay/model.d.ts +27 -26
- package/dist/LinearReadArcsDisplay/model.d.ts +11 -19
- package/dist/LinearReadCloudDisplay/model.d.ts +11 -19
- package/dist/LinearSNPCoverageDisplay/models/model.d.ts +20 -22
- package/dist/MismatchParser/index.js +2 -2
- package/dist/MismatchParser/index.js.map +1 -1
- package/dist/PileupRenderer/PileupRenderer.d.ts +1 -1
- package/dist/PileupRenderer/PileupRenderer.js +1 -1
- package/dist/PileupRenderer/PileupRenderer.js.map +1 -1
- package/dist/SNPCoverageRenderer/SNPCoverageRenderer.js +1 -1
- package/dist/SNPCoverageRenderer/SNPCoverageRenderer.js.map +1 -1
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureDetail.d.ts +4 -4
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js +88 -126
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js.map +1 -1
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureFlags.d.ts +6 -0
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureFlags.js +38 -0
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureFlags.js.map +1 -0
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureSuppAligns.d.ts +6 -0
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureSuppAligns.js +31 -0
- package/esm/AlignmentsFeatureDetail/AlignmentsFeatureSuppAligns.js.map +1 -0
- package/esm/AlignmentsFeatureDetail/index.d.ts +1 -1
- package/esm/AlignmentsFeatureDetail/util.d.ts +8 -0
- package/esm/AlignmentsFeatureDetail/util.js +22 -0
- package/esm/AlignmentsFeatureDetail/util.js.map +1 -0
- package/esm/LinearAlignmentsDisplay/components/AlignmentsDisplay.js +2 -2
- package/esm/LinearAlignmentsDisplay/components/AlignmentsDisplay.js.map +1 -1
- package/esm/LinearAlignmentsDisplay/models/model.d.ts +1 -1
- package/esm/LinearAlignmentsDisplay/models/model.js.map +1 -1
- package/esm/LinearPileupDisplay/model.d.ts +27 -26
- package/esm/LinearReadArcsDisplay/model.d.ts +11 -19
- package/esm/LinearReadCloudDisplay/model.d.ts +11 -19
- package/esm/LinearSNPCoverageDisplay/models/model.d.ts +20 -22
- package/esm/MismatchParser/index.js +2 -2
- package/esm/MismatchParser/index.js.map +1 -1
- package/esm/PileupRenderer/PileupRenderer.d.ts +1 -1
- package/esm/PileupRenderer/PileupRenderer.js +1 -1
- package/esm/PileupRenderer/PileupRenderer.js.map +1 -1
- package/esm/SNPCoverageRenderer/SNPCoverageRenderer.js +1 -1
- package/esm/SNPCoverageRenderer/SNPCoverageRenderer.js.map +1 -1
- package/package.json +2 -2
- package/src/AlignmentsFeatureDetail/AlignmentsFeatureDetail.tsx +109 -183
- package/src/AlignmentsFeatureDetail/AlignmentsFeatureFlags.tsx +62 -0
- package/src/AlignmentsFeatureDetail/AlignmentsFeatureSuppAligns.tsx +51 -0
- package/src/AlignmentsFeatureDetail/__snapshots__/index.test.tsx.snap +3 -2
- package/src/AlignmentsFeatureDetail/util.ts +27 -0
- package/src/LinearAlignmentsDisplay/components/AlignmentsDisplay.tsx +2 -2
- package/src/LinearAlignmentsDisplay/models/model.tsx +1 -1
- package/src/MismatchParser/index.ts +2 -2
- package/src/PileupRenderer/PileupRenderer.ts +0 -1
- package/src/SNPCoverageRenderer/SNPCoverageRenderer.ts +1 -1
- package/dist/NestedFrequencyTable.d.ts +0 -14
- package/dist/NestedFrequencyTable.js +0 -94
- package/dist/NestedFrequencyTable.js.map +0 -1
- package/esm/NestedFrequencyTable.d.ts +0 -14
- package/esm/NestedFrequencyTable.js +0 -91
- package/esm/NestedFrequencyTable.js.map +0 -1
- package/src/NestedFrequencyTable.ts +0 -113
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
// see perf results on object.keys vs for-in loop
|
|
5
|
-
// https://jsperf.com/object-keys-vs-hasownproperty/55
|
|
6
|
-
class NestedFrequencyTable {
|
|
7
|
-
constructor(initialData = {}) {
|
|
8
|
-
this.categories = { ...initialData };
|
|
9
|
-
}
|
|
10
|
-
// get the sum of all the category counts
|
|
11
|
-
total() {
|
|
12
|
-
// calculate total if necessary
|
|
13
|
-
let t = 0;
|
|
14
|
-
for (const k in this.categories) {
|
|
15
|
-
const v = this.categories[k];
|
|
16
|
-
t += v.total ? v.total() : v;
|
|
17
|
-
}
|
|
18
|
-
return t;
|
|
19
|
-
}
|
|
20
|
-
// decrement the count for the given category
|
|
21
|
-
decrement(slotName, amount) {
|
|
22
|
-
if (!amount) {
|
|
23
|
-
amount = 1;
|
|
24
|
-
}
|
|
25
|
-
slotName = slotName ? slotName.toString() : 'default';
|
|
26
|
-
if (this.categories[slotName]) {
|
|
27
|
-
this.categories[slotName] = Math.max(0, this.categories[slotName] - amount);
|
|
28
|
-
return this.categories[slotName];
|
|
29
|
-
}
|
|
30
|
-
return 0;
|
|
31
|
-
}
|
|
32
|
-
// increment the count for the given category
|
|
33
|
-
increment(slotName, amount) {
|
|
34
|
-
if (!amount) {
|
|
35
|
-
amount = 1;
|
|
36
|
-
}
|
|
37
|
-
slotName = slotName ? slotName.toString() : 'default';
|
|
38
|
-
this.categories[slotName] = (this.categories[slotName] || 0) + amount;
|
|
39
|
-
return this.categories[slotName];
|
|
40
|
-
}
|
|
41
|
-
// get the value of the given category. may be a number or a
|
|
42
|
-
// frequency table.
|
|
43
|
-
get(slotName) {
|
|
44
|
-
return this.categories[slotName] || 0;
|
|
45
|
-
}
|
|
46
|
-
// get a given category as a frequency table
|
|
47
|
-
getNested(path) {
|
|
48
|
-
if (typeof path === 'string') {
|
|
49
|
-
path = path.split('/');
|
|
50
|
-
}
|
|
51
|
-
if (path.length === 0) {
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
const slotName = path[0].toString();
|
|
55
|
-
let slot = this.categories[slotName];
|
|
56
|
-
if (!slot || !slot.categories) {
|
|
57
|
-
this.categories[slotName] = new NestedFrequencyTable(slot ? { default: slot + 0 } : {});
|
|
58
|
-
}
|
|
59
|
-
slot = this.categories[slotName];
|
|
60
|
-
if (path.length > 1) {
|
|
61
|
-
return slot.getNested(path.slice(1));
|
|
62
|
-
}
|
|
63
|
-
return slot;
|
|
64
|
-
}
|
|
65
|
-
toString() {
|
|
66
|
-
return this.total()
|
|
67
|
-
.toPrecision(6)
|
|
68
|
-
.toString()
|
|
69
|
-
.replace(/\.?0+$/, '');
|
|
70
|
-
}
|
|
71
|
-
valueOf() {
|
|
72
|
-
return this.total();
|
|
73
|
-
}
|
|
74
|
-
// iterate through the categories and counts, call like:
|
|
75
|
-
//
|
|
76
|
-
// tbl.forEach( function( count, categoryName ) {
|
|
77
|
-
// // do something
|
|
78
|
-
// }, this );
|
|
79
|
-
//
|
|
80
|
-
forEach(func, ctx) {
|
|
81
|
-
if (ctx) {
|
|
82
|
-
for (const slotName in this.categories) {
|
|
83
|
-
func.call(ctx, this.categories[slotName], slotName);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
for (const slotName in this.categories) {
|
|
88
|
-
func(this.categories[slotName], slotName);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.default = NestedFrequencyTable;
|
|
94
|
-
//# sourceMappingURL=NestedFrequencyTable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NestedFrequencyTable.js","sourceRoot":"","sources":["../src/NestedFrequencyTable.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,iDAAiD;AACjD,sDAAsD;AACtD,MAAqB,oBAAoB;IAGvC,YAAY,WAAW,GAAG,EAAE;QAC1B,IAAI,CAAC,UAAU,GAAG,EAAE,GAAG,WAAW,EAAE,CAAA;IACtC,CAAC;IAED,yCAAyC;IACzC,KAAK;QACH,+BAA+B;QAC/B,IAAI,CAAC,GAAG,CAAC,CAAA;QAET,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;YAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;YAC5B,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAC7B;QAED,OAAO,CAAC,CAAA;IACV,CAAC;IAED,6CAA6C;IAC7C,SAAS,CAA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AAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAA;aAC1C;SACF;IACH,CAAC;CACF;AA7GD,uCA6GC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default class NestedFrequencyTable {
|
|
2
|
-
categories: {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
};
|
|
5
|
-
constructor(initialData?: {});
|
|
6
|
-
total(): number;
|
|
7
|
-
decrement(slotName: string, amount: number): any;
|
|
8
|
-
increment(slotName: string, amount: number): any;
|
|
9
|
-
get(slotName: string): any;
|
|
10
|
-
getNested(path: string | string[]): any;
|
|
11
|
-
toString(): string;
|
|
12
|
-
valueOf(): number;
|
|
13
|
-
forEach(func: Function, ctx: any): void;
|
|
14
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
// see perf results on object.keys vs for-in loop
|
|
3
|
-
// https://jsperf.com/object-keys-vs-hasownproperty/55
|
|
4
|
-
export default class NestedFrequencyTable {
|
|
5
|
-
constructor(initialData = {}) {
|
|
6
|
-
this.categories = { ...initialData };
|
|
7
|
-
}
|
|
8
|
-
// get the sum of all the category counts
|
|
9
|
-
total() {
|
|
10
|
-
// calculate total if necessary
|
|
11
|
-
let t = 0;
|
|
12
|
-
for (const k in this.categories) {
|
|
13
|
-
const v = this.categories[k];
|
|
14
|
-
t += v.total ? v.total() : v;
|
|
15
|
-
}
|
|
16
|
-
return t;
|
|
17
|
-
}
|
|
18
|
-
// decrement the count for the given category
|
|
19
|
-
decrement(slotName, amount) {
|
|
20
|
-
if (!amount) {
|
|
21
|
-
amount = 1;
|
|
22
|
-
}
|
|
23
|
-
slotName = slotName ? slotName.toString() : 'default';
|
|
24
|
-
if (this.categories[slotName]) {
|
|
25
|
-
this.categories[slotName] = Math.max(0, this.categories[slotName] - amount);
|
|
26
|
-
return this.categories[slotName];
|
|
27
|
-
}
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
// increment the count for the given category
|
|
31
|
-
increment(slotName, amount) {
|
|
32
|
-
if (!amount) {
|
|
33
|
-
amount = 1;
|
|
34
|
-
}
|
|
35
|
-
slotName = slotName ? slotName.toString() : 'default';
|
|
36
|
-
this.categories[slotName] = (this.categories[slotName] || 0) + amount;
|
|
37
|
-
return this.categories[slotName];
|
|
38
|
-
}
|
|
39
|
-
// get the value of the given category. may be a number or a
|
|
40
|
-
// frequency table.
|
|
41
|
-
get(slotName) {
|
|
42
|
-
return this.categories[slotName] || 0;
|
|
43
|
-
}
|
|
44
|
-
// get a given category as a frequency table
|
|
45
|
-
getNested(path) {
|
|
46
|
-
if (typeof path === 'string') {
|
|
47
|
-
path = path.split('/');
|
|
48
|
-
}
|
|
49
|
-
if (path.length === 0) {
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
const slotName = path[0].toString();
|
|
53
|
-
let slot = this.categories[slotName];
|
|
54
|
-
if (!slot || !slot.categories) {
|
|
55
|
-
this.categories[slotName] = new NestedFrequencyTable(slot ? { default: slot + 0 } : {});
|
|
56
|
-
}
|
|
57
|
-
slot = this.categories[slotName];
|
|
58
|
-
if (path.length > 1) {
|
|
59
|
-
return slot.getNested(path.slice(1));
|
|
60
|
-
}
|
|
61
|
-
return slot;
|
|
62
|
-
}
|
|
63
|
-
toString() {
|
|
64
|
-
return this.total()
|
|
65
|
-
.toPrecision(6)
|
|
66
|
-
.toString()
|
|
67
|
-
.replace(/\.?0+$/, '');
|
|
68
|
-
}
|
|
69
|
-
valueOf() {
|
|
70
|
-
return this.total();
|
|
71
|
-
}
|
|
72
|
-
// iterate through the categories and counts, call like:
|
|
73
|
-
//
|
|
74
|
-
// tbl.forEach( function( count, categoryName ) {
|
|
75
|
-
// // do something
|
|
76
|
-
// }, this );
|
|
77
|
-
//
|
|
78
|
-
forEach(func, ctx) {
|
|
79
|
-
if (ctx) {
|
|
80
|
-
for (const slotName in this.categories) {
|
|
81
|
-
func.call(ctx, this.categories[slotName], slotName);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
for (const slotName in this.categories) {
|
|
86
|
-
func(this.categories[slotName], slotName);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=NestedFrequencyTable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NestedFrequencyTable.js","sourceRoot":"","sources":["../src/NestedFrequencyTable.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,iDAAiD;AACjD,sDAAsD;AACtD,MAAM,CAAC,OAAO,OAAO,oBAAoB;IAGvC,YAAY,WAAW,GAAG,EAAE;QAC1B,IAAI,CAAC,UAAU,GAAG,EAAE,GAAG,WAAW,EAAE,CAAA;IACtC,CAAC;IAED,yCAAyC;IACzC,KAAK;QACH,+BAA+B;QAC/B,IAAI,CAAC,GAAG,CAAC,CAAA;QAET,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;YAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;YAC5B,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAC7B;QAED,OAAO,CAAC,CAAA;IACV,CAAC;IAED,6CAA6C;IAC7C,SAAS,CAAC,QAAgB,EAAE,MAAc;QACxC,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,GAAG,CAAC,CAAA;SACX;QAED,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;QAErD,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC7B,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,GAAG,CAClC,CAAC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AAE,OAAO,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAClC,CAAA;SACF;QACD,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QAEhC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;SACrC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,EAAE;aAChB,WAAW,CAAC,CAAC,CAAC;aACd,QAAQ,EAAE;aACV,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;IAED,wDAAwD;IACxD,EAAE;IACF,mDAAmD;IACnD,uBAAuB;IACvB,eAAe;IACf,EAAE;IACF,OAAO,CAAC,IAAc,EAAE,GAAQ;QAC9B,IAAI,GAAG,EAAE;YACP,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE;gBACtC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAA;aACpD;SACF;aAAM;YACL,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE;gBACtC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAA;aAC1C;SACF;IACH,CAAC;CACF"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
// see perf results on object.keys vs for-in loop
|
|
3
|
-
// https://jsperf.com/object-keys-vs-hasownproperty/55
|
|
4
|
-
export default class NestedFrequencyTable {
|
|
5
|
-
public categories: { [key: string]: any }
|
|
6
|
-
|
|
7
|
-
constructor(initialData = {}) {
|
|
8
|
-
this.categories = { ...initialData }
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// get the sum of all the category counts
|
|
12
|
-
total() {
|
|
13
|
-
// calculate total if necessary
|
|
14
|
-
let t = 0
|
|
15
|
-
|
|
16
|
-
for (const k in this.categories) {
|
|
17
|
-
const v = this.categories[k]
|
|
18
|
-
t += v.total ? v.total() : v
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return t
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// decrement the count for the given category
|
|
25
|
-
decrement(slotName: string, amount: number) {
|
|
26
|
-
if (!amount) {
|
|
27
|
-
amount = 1
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
slotName = slotName ? slotName.toString() : 'default'
|
|
31
|
-
|
|
32
|
-
if (this.categories[slotName]) {
|
|
33
|
-
this.categories[slotName] = Math.max(
|
|
34
|
-
0,
|
|
35
|
-
this.categories[slotName] - amount,
|
|
36
|
-
)
|
|
37
|
-
return this.categories[slotName]
|
|
38
|
-
}
|
|
39
|
-
return 0
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// increment the count for the given category
|
|
43
|
-
increment(slotName: string, amount: number) {
|
|
44
|
-
if (!amount) {
|
|
45
|
-
amount = 1
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
slotName = slotName ? slotName.toString() : 'default'
|
|
49
|
-
|
|
50
|
-
this.categories[slotName] = (this.categories[slotName] || 0) + amount
|
|
51
|
-
return this.categories[slotName]
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// get the value of the given category. may be a number or a
|
|
55
|
-
// frequency table.
|
|
56
|
-
get(slotName: string) {
|
|
57
|
-
return this.categories[slotName] || 0
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// get a given category as a frequency table
|
|
61
|
-
getNested(path: string | string[]) {
|
|
62
|
-
if (typeof path === 'string') {
|
|
63
|
-
path = path.split('/')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (path.length === 0) {
|
|
67
|
-
return this
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const slotName = path[0].toString()
|
|
71
|
-
let slot = this.categories[slotName]
|
|
72
|
-
if (!slot || !slot.categories) {
|
|
73
|
-
this.categories[slotName] = new NestedFrequencyTable(
|
|
74
|
-
slot ? { default: slot + 0 } : {},
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
slot = this.categories[slotName]
|
|
78
|
-
|
|
79
|
-
if (path.length > 1) {
|
|
80
|
-
return slot.getNested(path.slice(1))
|
|
81
|
-
}
|
|
82
|
-
return slot
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
toString() {
|
|
86
|
-
return this.total()
|
|
87
|
-
.toPrecision(6)
|
|
88
|
-
.toString()
|
|
89
|
-
.replace(/\.?0+$/, '')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
valueOf() {
|
|
93
|
-
return this.total()
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// iterate through the categories and counts, call like:
|
|
97
|
-
//
|
|
98
|
-
// tbl.forEach( function( count, categoryName ) {
|
|
99
|
-
// // do something
|
|
100
|
-
// }, this );
|
|
101
|
-
//
|
|
102
|
-
forEach(func: Function, ctx: any) {
|
|
103
|
-
if (ctx) {
|
|
104
|
-
for (const slotName in this.categories) {
|
|
105
|
-
func.call(ctx, this.categories[slotName], slotName)
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
for (const slotName in this.categories) {
|
|
109
|
-
func(this.categories[slotName], slotName)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|