@barchart/portfolio-api-common 1.0.147 → 1.0.151

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.
@@ -242,6 +242,32 @@ module.exports = (() => {
242
242
  parentGroup.setExcludedItems(array.unique(excludedItems));
243
243
  }
244
244
  }, false);
245
+
246
+ if (treeDefinition.exclusionDependencies.length > 0) {
247
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
248
+ if (this._trees.hasOwnProperty(name)) {
249
+ trees.push(this._trees[name]);
250
+ }
251
+
252
+ return trees;
253
+ }, [ ]);
254
+
255
+ if (dependantTrees.length > 0) {
256
+ let excludedItems = [ ];
257
+
258
+ tree.walk((childGroup) => {
259
+ if (childGroup.excluded) {
260
+ excludedItems = excludedItems.concat(childGroup.items);
261
+ }
262
+ }, false, false);
263
+
264
+ dependantTrees.forEach((dependantTrees) => {
265
+ dependantTrees.walk((childGroup) => {
266
+ childGroup.setExcludedItems(excludedItems);
267
+ }, false, false);
268
+ });
269
+ }
270
+ }
245
271
  }));
246
272
  };
247
273
 
@@ -545,18 +545,6 @@ module.exports = (() => {
545
545
  summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrentChange))
546
546
  };
547
547
  }
548
-
549
- if (parent !== null) {
550
- const parentData = parent._dataActual;
551
-
552
- if (parentData.market !== null && !parentData.market.getIsZero()) {
553
- updates.marketPercent = updates.market.divide(parentData.market);
554
- } else {
555
- updates.marketPercent = null;
556
- }
557
- } else {
558
- updates.marketPercent = null;
559
- }
560
548
 
561
549
  actual.market = updates.market;
562
550
  actual.unrealized = updates.unrealized;
@@ -593,13 +581,14 @@ module.exports = (() => {
593
581
  }
594
582
 
595
583
  const parent = group._parent;
584
+ const excluded = group._excluded;
596
585
 
597
586
  const actual = group._dataActual;
598
587
  const format = group._dataFormat;
599
588
 
600
589
  let marketPercent;
601
590
 
602
- if (parent !== null) {
591
+ if (parent !== null && !excluded) {
603
592
  const parentData = parent._dataActual;
604
593
 
605
594
  if (parentData.market !== null && !parentData.market.getIsZero()) {
@@ -13,17 +13,23 @@ module.exports = (() => {
13
13
  * @param {Array.<PositionLevelDefinition>} definitions
14
14
  */
15
15
  class PositionTreeDefinitions {
16
- constructor(name, definitions) {
16
+ constructor(name, definitions, exclusionDependencies) {
17
17
  assert.argumentIsRequired(name, 'name', String);
18
18
  assert.argumentIsArray(definitions, 'definitions', PositionLevelDefinition, 'PositionLevelDefinition');
19
19
 
20
+ if (exclusionDependencies) {
21
+ assert.argumentIsArray(exclusionDependencies, 'exclusionDependencies', String);
22
+ }
23
+
20
24
  this._name = name;
21
25
  this._definitions = definitions;
26
+ this._exclusionDependencies = exclusionDependencies || [ ];
22
27
  }
23
28
 
24
29
  /**
25
30
  * The name of the tree.
26
31
  *
32
+ * @public
27
33
  * @returns {String}
28
34
  */
29
35
  get name() {
@@ -43,6 +49,17 @@ module.exports = (() => {
43
49
  return this._definitions;
44
50
  }
45
51
 
52
+ /**
53
+ * Returns the names of other trees which should be impacted when a
54
+ * group (from the current tree) is excluded.
55
+ *
56
+ * @public
57
+ * @return {Array.<String>}
58
+ */
59
+ get exclusionDependencies() {
60
+ return this._exclusionDependencies;
61
+ }
62
+
46
63
  toString() {
47
64
  return '[PositionTreeDefinitions]';
48
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.147",
3
+ "version": "1.0.151",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -958,6 +958,32 @@ module.exports = (() => {
958
958
  parentGroup.setExcludedItems(array.unique(excludedItems));
959
959
  }
960
960
  }, false);
961
+
962
+ if (treeDefinition.exclusionDependencies.length > 0) {
963
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
964
+ if (this._trees.hasOwnProperty(name)) {
965
+ trees.push(this._trees[name]);
966
+ }
967
+
968
+ return trees;
969
+ }, [ ]);
970
+
971
+ if (dependantTrees.length > 0) {
972
+ let excludedItems = [ ];
973
+
974
+ tree.walk((childGroup) => {
975
+ if (childGroup.excluded) {
976
+ excludedItems = excludedItems.concat(childGroup.items);
977
+ }
978
+ }, false, false);
979
+
980
+ dependantTrees.forEach((dependantTrees) => {
981
+ dependantTrees.walk((childGroup) => {
982
+ childGroup.setExcludedItems(excludedItems);
983
+ }, false, false);
984
+ });
985
+ }
986
+ }
961
987
  }));
962
988
  };
963
989
 
@@ -1765,18 +1791,6 @@ module.exports = (() => {
1765
1791
  summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrentChange))
1766
1792
  };
1767
1793
  }
1768
-
1769
- if (parent !== null) {
1770
- const parentData = parent._dataActual;
1771
-
1772
- if (parentData.market !== null && !parentData.market.getIsZero()) {
1773
- updates.marketPercent = updates.market.divide(parentData.market);
1774
- } else {
1775
- updates.marketPercent = null;
1776
- }
1777
- } else {
1778
- updates.marketPercent = null;
1779
- }
1780
1794
 
1781
1795
  actual.market = updates.market;
1782
1796
  actual.unrealized = updates.unrealized;
@@ -1813,13 +1827,14 @@ module.exports = (() => {
1813
1827
  }
1814
1828
 
1815
1829
  const parent = group._parent;
1830
+ const excluded = group._excluded;
1816
1831
 
1817
1832
  const actual = group._dataActual;
1818
1833
  const format = group._dataFormat;
1819
1834
 
1820
1835
  let marketPercent;
1821
1836
 
1822
- if (parent !== null) {
1837
+ if (parent !== null && !excluded) {
1823
1838
  const parentData = parent._dataActual;
1824
1839
 
1825
1840
  if (parentData.market !== null && !parentData.market.getIsZero()) {
@@ -2407,17 +2422,23 @@ module.exports = (() => {
2407
2422
  * @param {Array.<PositionLevelDefinition>} definitions
2408
2423
  */
2409
2424
  class PositionTreeDefinitions {
2410
- constructor(name, definitions) {
2425
+ constructor(name, definitions, exclusionDependencies) {
2411
2426
  assert.argumentIsRequired(name, 'name', String);
2412
2427
  assert.argumentIsArray(definitions, 'definitions', PositionLevelDefinition, 'PositionLevelDefinition');
2413
2428
 
2429
+ if (exclusionDependencies) {
2430
+ assert.argumentIsArray(exclusionDependencies, 'exclusionDependencies', String);
2431
+ }
2432
+
2414
2433
  this._name = name;
2415
2434
  this._definitions = definitions;
2435
+ this._exclusionDependencies = exclusionDependencies || [ ];
2416
2436
  }
2417
2437
 
2418
2438
  /**
2419
2439
  * The name of the tree.
2420
2440
  *
2441
+ * @public
2421
2442
  * @returns {String}
2422
2443
  */
2423
2444
  get name() {
@@ -2437,6 +2458,17 @@ module.exports = (() => {
2437
2458
  return this._definitions;
2438
2459
  }
2439
2460
 
2461
+ /**
2462
+ * Returns the names of other trees which should be impacted when a
2463
+ * group (from the current tree) is excluded.
2464
+ *
2465
+ * @public
2466
+ * @return {Array.<String>}
2467
+ */
2468
+ get exclusionDependencies() {
2469
+ return this._exclusionDependencies;
2470
+ }
2471
+
2440
2472
  toString() {
2441
2473
  return '[PositionTreeDefinitions]';
2442
2474
  }