testing colors
This commit is contained in:
parent
be0ea5263c
commit
bdd0aaaba2
@ -1,5 +1,4 @@
|
|||||||
import utils from "./utils.js"
|
import utils from './utils.js'
|
||||||
|
|
||||||
|
|
||||||
let unknown_color = '#c0b1b1' // color for unknown power output of the station
|
let unknown_color = '#c0b1b1' // color for unknown power output of the station
|
||||||
const colors = [
|
const colors = [
|
||||||
@ -16,20 +15,34 @@ const error_color = '#ff1414'
|
|||||||
const max_out_legit_power = 400
|
const max_out_legit_power = 400
|
||||||
|
|
||||||
const colorUtils = {
|
const colorUtils = {
|
||||||
|
colors,
|
||||||
/**
|
/**
|
||||||
* trouver une couleur correspondant
|
* trouver une couleur correspondant
|
||||||
*/
|
*/
|
||||||
getColor : (feature) =>{
|
getColor: (feature) => {
|
||||||
|
|
||||||
let outputPower = utils.guessOutputPowerFromFeature(feature)
|
let outputPower = utils.guessOutputPowerFromFeature(feature)
|
||||||
feature.properties.tags.has_output_of_irve_specified = outputPower
|
feature.properties.tags.has_output_of_irve_specified = outputPower
|
||||||
if (outputPower) {
|
if (outputPower) {
|
||||||
|
|
||||||
if(outputPower> max_out_legit_power){
|
if (outputPower > max_out_legit_power) {
|
||||||
return error_color;
|
return error_color
|
||||||
|
}
|
||||||
|
let index = 0
|
||||||
|
// index = Math.min(Math.floor(outputPower / 10), colors.length - 1)
|
||||||
|
if (outputPower >= 300) {
|
||||||
|
index = 5
|
||||||
|
} else if (outputPower >= 200) {
|
||||||
|
index = 4
|
||||||
|
} else if (outputPower >= 100) {
|
||||||
|
index = 3
|
||||||
|
} else if (outputPower >= 50) {
|
||||||
|
index = 2
|
||||||
|
} else if (outputPower >= 20) {
|
||||||
|
index = 1
|
||||||
|
} else if (outputPower >= 0) {
|
||||||
|
index = 0
|
||||||
}
|
}
|
||||||
let index = Math.min(Math.floor(outputPower / 10), colors.length - 1)
|
|
||||||
|
|
||||||
return colors[index]
|
return colors[index]
|
||||||
}
|
}
|
||||||
// autrement, sans puissance max trouvée, on met la couleur des indéfinis
|
// autrement, sans puissance max trouvée, on met la couleur des indéfinis
|
||||||
|
@ -37,16 +37,16 @@ function setRandomView(){
|
|||||||
}
|
}
|
||||||
function setCoordinatesOfLeafletMapFromQueryParameters() {
|
function setCoordinatesOfLeafletMapFromQueryParameters() {
|
||||||
// Récupère les paramètres de l'URL
|
// Récupère les paramètres de l'URL
|
||||||
console.log('window.location', window.location.href, window)
|
// console.log('window.location', window.location.href, window)
|
||||||
const urlParams = new URLSearchParams(window.location.href);
|
const urlParams = new URLSearchParams(window.location.href);
|
||||||
|
|
||||||
console.log('urlParams', urlParams)
|
// console.log('urlParams', urlParams)
|
||||||
// Récupère les coordonnées et le zoom à partir des paramètres de l'URL
|
// Récupère les coordonnées et le zoom à partir des paramètres de l'URL
|
||||||
const lat = urlParams.get('lat');
|
const lat = urlParams.get('lat');
|
||||||
const lng = urlParams.get('lng');
|
const lng = urlParams.get('lng');
|
||||||
const zoom = urlParams.get('zoom');
|
const zoom = urlParams.get('zoom');
|
||||||
|
|
||||||
console.log('lat,lng,zoom', lat, lng, zoom) // Vérifie si les paramètres sont présents et valides
|
// console.log('lat,lng,zoom', lat, lng, zoom) // Vérifie si les paramètres sont présents et valides
|
||||||
if (lat && lng && zoom) {
|
if (lat && lng && zoom) {
|
||||||
// Initialise la carte avec les coordonnées et le zoom récupérés
|
// Initialise la carte avec les coordonnées et le zoom récupérés
|
||||||
map = map.setView([lat, lng], zoom);
|
map = map.setView([lat, lng], zoom);
|
||||||
|
@ -40,6 +40,56 @@ describe('testing on features', () => {
|
|||||||
let color = colorUtils.getColor(featureWithBadOutput)
|
let color = colorUtils.getColor(featureWithBadOutput)
|
||||||
expect(color).toEqual('#ff1414')
|
expect(color).toEqual('#ff1414')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('finds first color for 3 kW', () => {
|
||||||
|
let localFeature = Object.create(featureWithOutput)
|
||||||
|
localFeature.properties.tags['socket:type2:output'] = "3 kW"
|
||||||
|
let outputFound = utils.guessOutputPowerFromFeature(featureWithOutput)
|
||||||
|
expect(outputFound).toEqual(3)
|
||||||
|
let color = colorUtils.getColor(localFeature)
|
||||||
|
expect(color).toEqual(colorUtils.colors[0])
|
||||||
|
})
|
||||||
|
it('finds 2nd color for 20 kW', () => {
|
||||||
|
let localFeature = Object.create(featureWithOutput)
|
||||||
|
localFeature.properties.tags['socket:type2:output'] = "20 kW"
|
||||||
|
let outputFound = utils.guessOutputPowerFromFeature(featureWithOutput)
|
||||||
|
expect(outputFound).toEqual(20)
|
||||||
|
let color = colorUtils.getColor(localFeature)
|
||||||
|
expect(color).toEqual(colorUtils.colors[1])
|
||||||
|
})
|
||||||
|
it('finds 3nd color for 50 kW', () => {
|
||||||
|
let localFeature = Object.create(featureWithOutput)
|
||||||
|
localFeature.properties.tags['socket:type2:output'] = "50 kW"
|
||||||
|
let outputFound = utils.guessOutputPowerFromFeature(featureWithOutput)
|
||||||
|
expect(outputFound).toEqual(50)
|
||||||
|
let color = colorUtils.getColor(localFeature)
|
||||||
|
expect(color).toEqual(colorUtils.colors[2])
|
||||||
|
})
|
||||||
|
it('finds 3nd color for 100 kW', () => {
|
||||||
|
let localFeature = Object.create(featureWithOutput)
|
||||||
|
localFeature.properties.tags['socket:type2:output'] = "100 kW"
|
||||||
|
let outputFound = utils.guessOutputPowerFromFeature(featureWithOutput)
|
||||||
|
expect(outputFound).toEqual(100)
|
||||||
|
let color = colorUtils.getColor(localFeature)
|
||||||
|
expect(color).toEqual(colorUtils.colors[3])
|
||||||
|
})
|
||||||
|
it('finds 4nd color for 200 kW', () => {
|
||||||
|
let localFeature = Object.create(featureWithOutput)
|
||||||
|
localFeature.properties.tags['socket:type2:output'] = "200 kW"
|
||||||
|
let outputFound = utils.guessOutputPowerFromFeature(featureWithOutput)
|
||||||
|
expect(outputFound).toEqual(200)
|
||||||
|
let color = colorUtils.getColor(localFeature)
|
||||||
|
expect(color).toEqual(colorUtils.colors[4])
|
||||||
|
})
|
||||||
|
it('finds 4nd color for 300 kW', () => {
|
||||||
|
let localFeature = Object.create(featureWithOutput)
|
||||||
|
localFeature.properties.tags['socket:type2:output'] = "300 kW"
|
||||||
|
let outputFound = utils.guessOutputPowerFromFeature(featureWithOutput)
|
||||||
|
expect(outputFound).toEqual(300)
|
||||||
|
let color = colorUtils.getColor(localFeature)
|
||||||
|
expect(color).toEqual(colorUtils.colors[5])
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user