Skip to content
Snippets Groups Projects
Commit d93b2791 authored by Lillian Gray's avatar Lillian Gray
Browse files

Added readme for main.js functions #9

parent f11891a3
Branches
No related merge requests found
# main.js functions
### non-function
* creates several global variables
* `lineChartData`, `dashboard`, `controlWrapper`, and `chartWrapper` hold chart objects generated by the Google Charts API
* `endDate` and `startDate` reference the positions of the range control under the chart
* `URLComponents` references the URL path for permalink creation and parsing
### onAPILoad
* called when GoogleAPI finishes loading in `index.html`
* calls `getData` and then passes the returned data into initializeLineChart when `getData` finishes
### getData
* fetches data for chart from text file `raw_line_chart.txt` generated by `data_gen.py`
### initializeLineChart(data)
* called by onAPILoad
* creates chart using Google Charts API with initial options
* options that change such as visible columns are declared in drawLineChart
* after setting initial options, calls `drawLineChart`
### disableLoadingScreen
* hides loading icon, called in `initializeLineChart` once chart is ready
### flipAndRedraw(which)
* toggles if a building is shown in the chart
* `which` refers to the index of the building in `whichBuildings` to be toggled
* calls `drawLineChart` for chart to be redrawn with different visible columns/buildings
### handleTotalOptions(totalVisible)
* adds or removes options needed for Total which involves a second y-axis
* called by `initializeLineChart` if total is enabled, and called by flipAndRedraw(which) if total is flipped
### drawLineChart
* sets options for columns and colors in the chart and control bar and then draws the chart
* should be called anytime chart settings are changed to apply the changes
* called by `initializeLineChart`, `flipAndRedraw`, and `$(window).resize()`
### changeDashboard(button)
* changes view within dashboard div between chart, how to use page, and about page
* called by `index.html` when a button is clicked to change the view
### $(window).resize()
* if user changes the window size the chart is redrawn to be the right size
* this does not affect site speed because the Google Charts API `draw()` function doesn't redraw the chart from scratch, and considers only the aspects of the chart that has changed
### showSeriesOptions(el)
* called if series menu is clicked in `index.html`, toggles that menu `el` being shown
### parsePermalink
* if site was loaded using a permalink, modifies `startDate`, `endDate`, and `whichBuildings`
### parseDate(urlArg)
* called by `parsePermalink`
* takes a date string `urlArg` and returns that date as a date object
### parseInts(strArray)
* called by `parsePermalink`
* takes a string of integers and returns them as an array of integers
### genPermalink
* generates a permalink and copies it
* called in `index.html` when the Get Permalink button is clicked
### downloadCSV(el)
* prepares and then downloads a csv file based on what is currently shown in the chart
* only downloads data from the currently enabled buildings between `startDate` and `endDate`
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment