Skip to content
Snippets Groups Projects
README.md 3.99 KiB
Newer Older
# main.js functions
### non-function
* creates several global variables
* `lineChartData`, `dashboard`, `controlWrapper`, and `chartWrapper` hold chart objects generated by the Google Charts API
    - `lineChartData` holds a DataView which contains the data and visible columns for the chart. More information [here](https://developers.google.com/chart/interactive/docs/reference#DataView).
    - `dashboard` holds a Dashboard, which defines the element the chart and date range control are held in. More information [here](https://developers.google.com/chart/interactive/docs/gallery/controls).
    - `controlWrapper` holds a ControlWrapper, which defines the options for the date range control below the chart, which is called a ChartRangeFilter by the API. More information on control wrappers [here](https://developers.google.com/chart/interactive/docs/gallery/controls) and more information on the ChartRangeFilter [here](https://developers.google.com/chart/interactive/docs/gallery/controls#chartrangefilter_1).
    - `chartWrapper` holds a ChartWrapper, which wraps the chart so it can be connected to the ControlWrapper using the Dashboard. It also holds the chart options and the type of chart. More information [here](https://developers.google.com/chart/interactive/docs/reference#chartwrapperobject).
* `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`