-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.ts
More file actions
138 lines (98 loc) · 3.18 KB
/
classes.ts
File metadata and controls
138 lines (98 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
class Point{
constructor(private origonalValue: number){
}
}
interface Channel{
channelName: string;
point: Point;
}
class BarChannel implements Channel {
channelName: string;
point: Point;
constructor(name:string,point:Point) {
this.channelName = name;
this.point = point;
}
get getChannelName(): string{
return this.channelName;
}
}
interface Axis {
axisName: string;
channels : Array<Channel>;
}
class BarAxis implements Axis {
axisName: string;
channels : Array<BarChannel> = new Array<BarChannel>();
constructor(name:string, channels: Array<BarChannel>) {
this.axisName = name;
this.channels = channels;
}
}
interface Graph {
graphName: string;
dataAxis : Array<Axis>;
}
class BarGraph implements Graph {
graphName: string;
dataAxis:Array<BarAxis> = new Array<BarAxis>();
constructor(name : string,dataAxis:Array<BarAxis>) {
this.graphName = name;
this.dataAxis = dataAxis;
}
}
class InputManager{
owner : Grapher;
constructor (owner : Grapher){
this.owner=owner;
}
public MakeNewBarGraph( rawInput : string ) {
//check for faulty files here
this.owner.GraphRequest(rawInput);
}
}
class Grapher {
private inputManager = new InputManager(this);
private graphFactory = new GraphFactory(this);
private graphs : Array<Graph> = new Array<Graph>();
constructor() {
}
public GetInputManager(){
return this.inputManager;
}
public GraphRequest(input : string){
this.graphs.push(this.graphFactory.MakeNewGraph(input,"test"));
}
}
class GraphFactory{
constructor (owner : Grapher){
}
public MakeNewGraph(input :string, name: string) : Graph{
//known issues, this does not take into account csv files with arbitrary white space
//assumes titles at the top and side
//assumes amount of data is constant, so no colum has more data than the other for no reason or if data sets > amount of sets
let rows = input.split(/\r?\n/);//split the document into rows
let matrix : string[][];
matrix = [];
for (var i = 0; i < rows.length; i++) {//setup a 2 dimensional array of all the values
matrix[i] = [];
matrix[i] = rows[i].split(",");
}
let titles = matrix[0];
let amountOfChannels : number = rows.length ;
let amountOfAxis : number = titles.length ;
let axis : Array<BarAxis> = new Array<BarAxis>();
for (var c = 1; c < amountOfAxis ; c++) {//loop through arrays and make objects accordingly
let channels : Array<BarChannel> = new Array<BarChannel>();
for (var r = 1 ; r < amountOfChannels ; r++) {
channels.push(new BarChannel(matrix[r][0],new Point(+matrix[r][c] )))
}
axis.push(new BarAxis(matrix[0][c],channels));
}
let newGraph = new BarGraph(name,axis);
console.log(newGraph);
return newGraph;
//tested with single csv with many different values and console.log constantly checking values
}
}
let grapher = new Grapher();