const properties = [
{
id: 0,
property_for : ['Rent', 'Sale', 'investment']
},
{
id: 1,
property_for : ['Sale', 'investment']
},
{
id: 2,
property_for : ['investment']
},
{
id: 3,
property_for : ['Rent']
},
{
id: 4,
property_for : ['Sale']
},
{
id: 5,
property_for : ['Rent', 'Sale']
},
{
id: 6,
property_for : ['Rent', 'investment']
}
];
function createColorY(property) {
const propClasses = {
'000': '#242F3E', // none
'001': '#FF00F7', // investment (magenta)
'010': '#FFC400', // rent (orange)
'100': '#00E5FF', // sale (cyan)
'011': '#FF0056', // investment + rent (burdengy)
'101': '#8077D5', // investment + sale (purple)
'110': '#80ED80', // rent + sale (green)
'111': '#FFFFFF' // investment + rent + sale (white)
};
const scaffold = {
sale: false,
rent: false,
investment: false
}
for (let item of property.property_for) {
scaffold[item.toLowerCase()] = true;
}
return propClasses[`${Number(scaffold.sale)}${Number(scaffold.rent)}${Number(scaffold.investment)}`];
}
createColorY(properties[5])
////////////////
function createColor2(items) {
const scaffold = { sale: '00', rent: '00', investment: '00' };
for (let i of items.property_for) {
scaffold[i.toLowerCase()] = 'ff';
}
return `#${scaffold.sale}${scaffold.rent}${scaffold.investment}`;
}
createColor2(properties[5])
/////////////
function createColor3(items) {
let scaffold = 0x000000;
items.property_for.map(i => i.toLowerCase()).forEach(i => scaffold |= i == 'sale' ? 0xff0000 : i == 'rent' ? 0x00ff00 : i == 'investment' ? 0x0000ff : 0x000000);
return `#${scaffold.toString(16).padStart(6, 0)}`;
}
createColor3(properties[4])
/////////////
const createHexColor = items => `#${items.property_for.map(i => i.toLowerCase()).reduce((i, j) => i | (j == 'sale' ? 0xff0000 : j == 'rent' ? 0x00ff00 : j == 'investment' ? 0x0000ff : 0), 0).toString(16).padStart(6, 0)}`;
createHexColor(properties[3])
// not functional
function createCustomColor(items) {
switch (createHexColor(items)) {
case 0x000000: return 'black'
case 0xff0000: return 'red'
case 0x00ff00: return 'orange'
case 0x0000ff: return 'yellow'
case 0xffff00: return 'green'
case 0xff00ff: return 'blue'
case 0x00ffff: return 'indigo'
case 0xffffff: return 'violet'
}
}
createCustomColor(properties[3])