aboutsummaryrefslogtreecommitdiff
path: root/templates/index.html
blob: 75153ce0a5b7e7c749cc8cae2def36596edb2e31 (plain)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Excel2Graph</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://bootswatch.com/5/morph/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/mdbassit/Coloris@latest/dist/coloris.min.css"/>
<script src="https://cdn.jsdelivr.net/gh/mdbassit/Coloris@latest/dist/coloris.min.js"></script>
</head>
<body>
    <div class="container">
    <h1>Excel2Graph</h1>
    <p>Instructions:</p>
    <ol>
        <li>Paste Excel data into the text area below</li>
        <li>Click Process Excel Data</li>
        <li>Fill in the rest of the form</li>
        <li>Click "Generate Plot"</li>
    </ol>
<form action="/process_data" method="post" onsubmit="prepareSubmission">
    <textarea id="excelData" placeholder="Paste Excel data here" class="form-control mb-3" name="excelData"></textarea>
    <button type="button" onclick="processData()" class="btn btn-outline-primary mb-3">Process Excel Data</button>
    <div name="dataSeriesDiv" id="data-series-div">
    <div class="row mt-3 mb-3">
        <div class="col-md-2">
            <label for="xColumn-1" class="form-label">X Data Column</label>
            <select id="xColumn-1" class="form-control table-data" name="xColumn-1"></select>
        </div>
        <div class="col-md-2">
            <label for="yColumn-1" class="form-label">Y Data Column</label>
            <select id="yColumn-1" class="form-control table-data" name="yColumn-1"></select>
        </div>
        <div class="col-md-2">
            <label for="stdDevColumn-1" class="form-label" >Error Bars</label>
            <select id="stdDevColumn-1" class="form-control table-data" name="stdDevColumn-1">
                <option value="">None</option>
            </select>
        </div>
        <div class="col-md-2">
            <label for="dataSeries-1" class="form-label">Data Series Name</label>
            <input type="text" name="dataSeries-1" id="dataSeries-1" class="form-control" placeholder="Data">
        </div>
        <div class="col-md-2">
            <label for="colorPicker-1" class="form-label">Datapoint Color</label>
            <input name="colorPicker-1" class="form-control" id="colorPicker-1" name="colorPicker-1" value="#000000" data-coloris>
        </div>
    </div>
    </div>
    <button class="btn btn-outline-primary mb-4" type="button" onclick="addDataSeries()">Add Data Series</button>
    <script type="text/javascript">
        function addDataSeries() {
            let dataSeriesCount = document.getElementById('data-series-div').childElementCount;
            let dataSeriesDiv = document.getElementById('data-series-div');

            let row = document.createElement('div');
            row.classList.add('row');
            row.classList.add('mb-3');
            row.id = `dataSeriesRow-${dataSeriesCount + 1}`;

            let col1 = document.createElement('div');
            col1.classList.add('col-md-2');

            let col2 = document.createElement('div');
            col2.classList.add('col-md-2');

            let col3 = document.createElement('div');
            col3.classList.add('col-md-2');

            let col4 = document.createElement('div');
            col4.classList.add('col-md-2');

            let col5 = document.createElement('div');
            col5.classList.add('col-md-2');

            let col6 = document.createElement('div');
            col6.classList.add('col-md-2');

            let xColumn = document.createElement('select');
            xColumn.classList.add('form-control');
            xColumn.classList.add('table-data');
            xColumn.id = `xColumn-${dataSeriesCount + 1}`;
            xColumn.name = `xColumn-${dataSeriesCount + 1}`;

            let yColumn = document.createElement('select');
            yColumn.classList.add('form-control');
            yColumn.classList.add('table-data');
            yColumn.id = `yColumn-${dataSeriesCount + 1}`;
            yColumn.name = `yColumn-${dataSeriesCount + 1}`;

            let stdDevColumn = document.createElement('select');
            stdDevColumn.classList.add('form-control');
            stdDevColumn.classList.add('table-data');
            stdDevColumn.id = `stdDevColumn-${dataSeriesCount + 1}`;
            stdDevColumn.name = `stdDevColumn-${dataSeriesCount + 1}`;
            // Default to None
            let stdDevOption = document.createElement('option');
            stdDevOption.value = '';
            stdDevOption.innerHTML = 'None';
            stdDevColumn.appendChild(stdDevOption);

            let dataSeries = document.createElement('input');
            dataSeries.classList.add('form-control');
            dataSeries.id = `dataSeries-${dataSeriesCount + 1}`;
            dataSeries.name = `dataSeries-${dataSeriesCount + 1}`;
            dataSeries.placeholder = 'Data';

            let colorPicker = document.createElement('input');
            colorPicker.classList.add('form-control');
            colorPicker.id = `colorPicker-${dataSeriesCount + 1}`;
            colorPicker.name = `colorPicker-${dataSeriesCount + 1}`;
            colorPicker.value = '#000000';
            colorPicker.setAttribute('data-coloris', '');

            let removeButton = document.createElement('button');
            removeButton.classList.add('btn');
            removeButton.classList.add('btn-outline-danger');
            removeButton.classList.add('mb-3');
            removeButton.type = 'button';
            removeButton.innerHTML = 'Remove Data Series';
            removeButton.onclick = function() {
                let row = document.getElementById(`dataSeriesRow-${dataSeriesCount + 1}`);
                row.remove();
            }


            // If excel data is present, populate the column selectors
            let headersDiv = document.getElementById('headersDiv');
            if (headersDiv) {
                let headers = JSON.parse(headersDiv.innerHTML);
                headers.forEach((header, index) => {
                    let option = new Option(header, index);
                    xColumn.add(option.cloneNode(true));
                    yColumn.add(option.cloneNode(true));
                    stdDevColumn.add(option.cloneNode(true));
                });
            }

            col1.appendChild(xColumn);
            col2.appendChild(yColumn);
            col3.appendChild(stdDevColumn);
            col4.appendChild(dataSeries);
            col5.appendChild(colorPicker);
            col6.appendChild(removeButton);

            row.appendChild(col1);
            row.appendChild(col2);
            row.appendChild(col3);
            row.appendChild(col4);
            row.appendChild(col5);
            row.appendChild(col6);

            dataSeriesDiv.appendChild(row);

        }
    </script>
        <input type="hidden" name="xData" id="xData">
    <input type="hidden" name="yData" id="yData">
    <input type="hidden" name="stdDevData" id="stdDevData">
    <!--<br><br>
    <div>
            <button type="button" onclick="prepareSubmission()" class="btn btn-outline-primary">Load Data from Columns</button>
            <button type="button" class="btn btn-outline-warning">Reset Data Load</button>
    </div>-->

    <div class="row mb-3 mt-3">
        <label for="xTitle" class="form-label">X-Axis Title</label>
        <input type="text" name="xTitle" id="xTitle" class="form-control" placeholder="X-Axis">
    </div>

    <div class="row mb-3">
        <label for="yTitle" class="form-label">Y-Axis Title</label>
        <input type="text" name="yTitle" id="yTitle" class="form-control" placeholder="Y-Axis">
    </div>

    <div class="row mb-3">
    <label for="plotTitle">Plot Title</label>
    <input type="text" name="plotTitle" id="plotTitle" class="form-control">
    </div>


    <div id="constantLinesContainer">
    </div>

    <button type="button" class="btn btn-outline-primary mb-3" onclick="addConstantLine()">Add Constant Line</button>

    <div class="row mb-3">
        <div class="col">
            <div class="form-check form-switch">
            <input class="form-check-input" type="checkbox" id="calcTrendline" name="calcTrendline" checked="">
            <label class="form-check-label" for="calcTrendline">Calculate Trendline (Note: This calculates the trendline for the first data series only)</label>
            </div>
        </div>
    </div>

    <div class="row mb-3">
        <label for="trendlineEquation" class="form-label">Trendline Equation (Leave blank if you want it to be auto-calculated)</label>
        <input type="text" name="trendlineEquation" id="trendlineEquation" class="form-control" placeholder="">
    </div>

        <div class="mb-3 row">
            <label for="colorPickerPlotBackground" class="form-label">Plot Background Color</label>
            <input name="colorPickerPlotBackground" class="form-control" id="colorPickerPlotBackground" value="#ffffff" data-coloris>
        </div>
        <div class="mb-3 row">
            <label for="colorPickerTrendline" class="form-label">Trendline Color</label>
            <input name="colorPickerTrendline" class="form-control" id="colorPickerTrendline" value="#000000" data-coloris>
            </div>
    <div class="row mb-3">
        <div class="col-md-4">
            <label for="xAxisScale" class="form-label">X-Axis Scale</label>
            <select name="xAxisScale" id="xAxisScale" class="form-control">
                <option value="linear" default>Linear</option>
                <option value="log">Logarithmic</option>
                <option value="symlog">Symmetrical Logarithmic</option>
                <option value="logit">Logit</option>
            </select>
        </div>
        <div class="col-md-4">
            <label for="yAxisScale" class="form-label">Y-Axis Scale</label>
            <select name="yAxisScale" id="yAxisScale" class="form-control">
                <option value="linear" default>Linear</option>
                <option value="log">Logarithmic</option>
                <option value="symlog">Symmetrical Logarithmic</option>
                <option value="logit">Logit</option>
            </select>
        </div>
    </div>
    <input type="submit" value="Generate Plot" class="btn btn-primary mb-3">
</form>
<div id="tableContainer" class="mt-3 mb-3"></div>

<script type="text/javascript">
    // add change handler for textarea and execute processData function
    //document.getElementById('excelData').addEventListener('change', processData);


    function prepareSubmission() {
    const data = document.getElementById('excelData').value;
    const rows = data.split('\n').map(row => row.split('\t'));

    // Assuming first row contains headers
    const headers = rows.shift();
    populateColumnSelectors(headers);

    // Prepare data for submission
    const xIndex = document.getElementById('xColumn').value;
    const yIndex = document.getElementById('yColumn').value;
    const stdDevIndex = document.getElementById('stdDevColumn').value;

    const xData = rows.map(row => row[xIndex]);
    const yData = rows.map(row => row[yIndex]);
    const stdDevData = stdDevIndex ? rows.map(row => row[stdDevIndex]) : [];

    document.getElementById('xData').value = JSON.stringify(xData);
    document.getElementById('yData').value = JSON.stringify(yData);
    document.getElementById('stdDevData').value = JSON.stringify(stdDevData);

    // Optionally, create and display table for review before submission
    createTable(rows, headers);
}


    function processData() {
    const data = document.getElementById('excelData').value;
    const rows = data.split('\n').map(row => row.split('\t'));

    // Assuming first row contains headers
    const headers = rows.shift();
    populateColumnSelectors(headers);

    // Create and display table
    createTable(rows, headers);

    // Create hidden div with headers data
    const headersDiv = document.createElement('div');
    headersDiv.id = 'headersDiv';
    headersDiv.classList.add('d-none');
    headersDiv.innerHTML = JSON.stringify(headers);
    document.body.appendChild(headersDiv);
}

function populateColumnSelectors(headers) {
    const xColumnSelect = document.getElementById('xColumn');
    const yColumnSelect = document.getElementById('yColumn');
    const stdDevSelect = document.getElementById('stdDevColumn');

    /*
    headers.forEach((header, index) => {
        let option = new Option(header, index);
        xColumnSelect.add(option.cloneNode(true));
        yColumnSelect.add(option.cloneNode(true));
        stdDevSelect.add(option.cloneNode(true));
    });
    */

    // Fill all data series

    var allSelect = document.getElementsByClassName('table-data');
    console.log(allSelect)

    for (var i = 0; i < allSelect.length; i++) {
        for (var j = 0; j < headers.length; j++) {
            let option = new Option(headers[j], j);
            allSelect[i].add(option.cloneNode(true));
        }
    }

}

function createTable(data, headers) {
    let table = '<table contenteditable="true" class="table">';
    table += '<tr>' + headers.map(header => `<th scope="col">${header}</th>`).join('') + '</tr>';
    data.forEach(row => {
        table += '<tr>' + row.map(cell => `<td>${cell}</td>`).join('') + '</tr>';
    });
    table += '</table>';

    document.getElementById('tableContainer').innerHTML = table;
}

    let constantLineCount = 0;

    function addConstantLine() {
    const container = document.getElementById('constantLinesContainer');
    const line = document.createElement('div');
    line.innerHTML = `
    <div class="row mb-3">
            <div class="col-md-4">
        <label for="constantLine${constantLineCount}">Constant Line (y=)</label>
        <input type="text" name="constantLine${constantLineCount}" id="constantLine${constantLineCount}" class="form-control">
            </div>
            <div class="col-md-4">
            <label for="constantLineLabel${constantLineCount}">Line Title</label>
        <input type="text" name="constantLineLabel${constantLineCount}" id="constantLineLabel${constantLineCount}" class="form-control">
            </div>
            <div class="col-md-4">
            <button type="button" class="btn btn-outline-danger mb-3 mt-4" onclick="this.parentElement.parentElement.remove()">Remove Constant Line</button>
            </div>
    </div>
    `;
    container.appendChild(line);
    constantLineCount++;
}


// You should add more JavaScript for handling editing and validation
</script>

<style type="text/css">
textarea {
    width: 100%;
    height: 150px;
}
select {
    margin: 5px;
}
table {
    border-collapse: collapse;
    width: 100%;
}
th, td {
    border: 1px solid black;
    padding: 5px;
    text-align: left;
}

</style>
    </div>

</body>
</html>