Use chroma to determine the colour to display, but we're not displaying it yet

This commit is contained in:
Starbeamrainbowlabs 2019-06-11 13:28:47 +01:00
parent b9d60c7e32
commit 4df93a3683
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 33 additions and 3 deletions

View file

@ -7,9 +7,10 @@ import Vector2 from '../Helpers/Vector2.mjs';
* @param {Vector2} point The point at which the cell is located. * @param {Vector2} point The point at which the cell is located.
*/ */
class VoronoiCell { class VoronoiCell {
constructor(in_point) { constructor(in_point, in_colour) {
this.point = in_point; this.point = in_point;
this.polygon = null; this.polygon = null;
this.colour = in_colour;
} }
} }

View file

@ -1,5 +1,9 @@
"use strict"; "use strict";
import chroma from 'chroma-js';
import Config from '../Config.mjs';
import VoronoiOverlay from './VoronoiOverlay.mjs'; import VoronoiOverlay from './VoronoiOverlay.mjs';
import VoronoiCell from './VoronoiCell.mjs'; import VoronoiCell from './VoronoiCell.mjs';
@ -35,13 +39,32 @@ class VoronoiManager {
} }
async set_data(datetime, reading_type) { async set_data(datetime, reading_type) {
this.guage.set_spec(Specs[reading_type]); this.spec = Specs[reading_type];
if(typeof this.spec.chroma == "undefined")
this.spec.chroma = chroma.scale(Object.values(this.spec.gradient))
.domain(Object.keys(this.spec.gradient));
this.guage.set_spec(this.spec);
this.guage.render(); this.guage.render();
let result = JSON.parse(await GetFromUrl( let dataset = JSON.parse(await GetFromUrl(
`${Config.api_root}?action=fetch-data&datetime=${encodeURIComponent(datetime.toISOString())}&reading_type=${encodeURIComponent(reading_type)}` `${Config.api_root}?action=fetch-data&datetime=${encodeURIComponent(datetime.toISOString())}&reading_type=${encodeURIComponent(reading_type)}`
)); ));
let result = [];
for(let row of dataset) {
let device = this.device_data.get_by_id(row.device_id);
if(typeof device.latitude != "number" || typeof device.longitude != "number")
continue;
result.push(new VoronoiCell(
new Vector2(
device.longitude,
device.latitude
),
this.spec.chroma(row.value).toString()
));
}
console.log(result); console.log(result);
} }
} }

5
package-lock.json generated
View file

@ -407,6 +407,11 @@
"color-name": "^1.0.0" "color-name": "^1.0.0"
} }
}, },
"chroma-js": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/chroma-js/-/chroma-js-2.0.3.tgz",
"integrity": "sha512-2kTvZZOFSV1O81/rm99t9vmkh9jQxsHqsRRoZevDVz/VCC3yKMyPuMK8M5yHG+UMg2tV6cRoqtZtgcD92udcBw=="
},
"class-utils": { "class-utils": {
"version": "0.3.6", "version": "0.3.6",
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",

View file

@ -19,6 +19,7 @@
"homepage": "https://github.com/sbrl/ConnectedHumber-Air-Quality-Interface#readme", "homepage": "https://github.com/sbrl/ConnectedHumber-Air-Quality-Interface#readme",
"dependencies": { "dependencies": {
"chart.js": "^2.8.0", "chart.js": "^2.8.0",
"chroma-js": "^2.0.3",
"d3-delaunay": "^4.1.5", "d3-delaunay": "^4.1.5",
"dom-create-element-query-selector": "github:hekigan/dom-create-element-query-selector", "dom-create-element-query-selector": "github:hekigan/dom-create-element-query-selector",
"iso8601-js-period": "^0.2.1", "iso8601-js-period": "^0.2.1",