Browse Source
Goodbye, old friend :-( That heatmap thingy took several revisions and lots fo hard work, but it just didn't work out :-( :-( :'(pull/65/head
11 changed files with 4763 additions and 4794 deletions
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
"use strict"; |
||||
|
||||
import chroma from 'chroma-js'; |
||||
|
||||
import marker_svg from '../marker-embed.svg'; |
||||
import gradients from './Gradients.mjs'; |
||||
|
||||
class MarkerGenerator { |
||||
constructor() { |
||||
|
||||
} |
||||
|
||||
marker_default() { |
||||
return marker_svg.replace("{{colour_a}}", "#1975c8") |
||||
.replace("{{colour_b}}", "#5ea6d5") |
||||
.replace("{{colour_dark}}", "#2e6d99"); |
||||
} |
||||
|
||||
marker(value, type) { |
||||
let col = this.get_colour(value, type); |
||||
let result = marker_svg.replace(/\{\{colour_a\}\}/g, col.darken(0.25).hex()) |
||||
.replace(/\{\{colour_b\}\}/g, col.brighten(0.25).hex()) |
||||
.replace(/\{\{colour_dark\}\}/g, col.darken(1)) |
||||
.replace(/\{\{id_grad\}\}/g, `marker-grad-${btoa(`${type}-${value}`).replace(/\+/g, "-").replace(/\//g, "_")}`); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* Fetches the colour for a given value of a given type. |
||||
* Currently a gradient is not used - i.e. a value is coloured according to |
||||
* the last threshold it crossed in the associated gradient definition. |
||||
* TODO: Calculate the gradient instead. |
||||
* @param {number} value The value to calculate the colour for. |
||||
* @param {string} type The type of measurement value we're working with. Determines the gradient to use. |
||||
* @return {chroma} The calculated colour. |
||||
*/ |
||||
get_colour(value, type) { |
||||
if(typeof gradients[type] == "undefined") { |
||||
console.warn(`[MarkerGenerator] Warning: Unknown gradient type '${type}', using unknown instead.`); |
||||
type = "unknown"; |
||||
} |
||||
return gradients[type].chroma(value); |
||||
} |
||||
} |
||||
|
||||
export default MarkerGenerator; |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
"use strict"; |
||||
|
||||
import Config from './Config.mjs'; |
||||
|
||||
import GetFromUrl from './Helpers/GetFromUrl.mjs'; |
||||
|
||||
class ReadingsData { |
||||
constructor() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Fetches the data from all currently active devices at a given datetime |
||||
* and for a given reading type. |
||||
* @param {string} reading_type The reading type to fetch data for. |
||||
* @param {String|Date} [datetime="now"] The datetime to fetch the data for. |
||||
* @return {Promise<Map>} A promise that resolves to a Map keyed by device IDs that contains the data objects returned by the fetch-data API action. |
||||
*/ |
||||
async fetch(reading_type, datetime = "now") { |
||||
if(datetime instanceof Date) |
||||
datetime = datetime.toISOString(); |
||||
// TODO: memoize this
|
||||
let data = await this.__make_request(reading_type, datetime); |
||||
let result = new Map(); |
||||
for(let item of data) |
||||
result.set(item.device_id, item); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
async __make_request(reading_type, datetime) { |
||||
return JSON.parse(await GetFromUrl( |
||||
`${Config.api_root}?action=fetch-data&datetime=${encodeURIComponent(datetime)}&reading_type=${encodeURIComponent(reading_type)}` |
||||
)); |
||||
} |
||||
} |
||||
|
||||
export default ReadingsData; |
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.5 KiB |
Loading…
Reference in new issue