Total Complexity | 9 |
Complexity/F | 1.8 |
Lines of Code | 63 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | const { JGFGraph } = require('./jgfGraph'); |
||
2 | |||
3 | /** |
||
4 | * JGF Container (main class) of zero or more JGF graphs |
||
5 | */ |
||
6 | class JGFContainer { |
||
7 | |||
8 | /** |
||
9 | * Constructor |
||
10 | * @param {*} singleGraph true for single-graph mode, false for multi-graph mode |
||
11 | */ |
||
12 | constructor(singleGraph = true) { |
||
13 | this._graphs = []; |
||
14 | this.isSingleGraph = singleGraph; |
||
15 | |||
16 | if (singleGraph) { |
||
17 | this.addEmptyGraph(); |
||
18 | } |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * Returns all graphs, in Multi-Graph mode |
||
23 | */ |
||
24 | get graphs() { |
||
25 | if (this.isSingleGraph) { |
||
26 | throw new Error('Cannot call graphs() in Single-Graph mode') |
||
27 | } |
||
28 | |||
29 | return this._graphs; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Returns the graph, in Single-Graph mode |
||
34 | */ |
||
35 | get graph() { |
||
36 | if (!this.isSingleGraph) { |
||
37 | throw new Error('Cannot call graph() in Multi-Graph mode') |
||
38 | } |
||
39 | |||
40 | return this._graphs[0]; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Returns true if the container is in Multi-Graph mode |
||
45 | */ |
||
46 | get isMultiGraph() { |
||
47 | return !this.isSingleGraph; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Adds an empty graph |
||
52 | */ |
||
53 | addEmptyGraph() { |
||
54 | let graph = new JGFGraph(); |
||
55 | this._graphs.push(graph); |
||
56 | |||
57 | return graph; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | module.exports = { |
||
62 | JGFContainer, |
||
63 | }; |