Насколько я могу судить по вашему коду, похоже, что вы должны просто сделать:
аю svg-прямоугольники из базы данных, используя python, я не знаю, правильный ли это путь, так как кажется, что я жестко программирую, потому что я хочу, чтобы каждый прямоугольник менял цвета в моей таблице стилей CSS. Есть ли лучший способ назвать эти прямоугольники, а не использовать ifs и elifs, потому что, если у меня есть 100 прямоугольников, что является лучшим способом сделать это. Я также добавил свою таблицу стилей
for row in c:
box_x = ((row[3]-row[1])/2 + row[1] - 0.25)
box_y = ((row[4]-row[2])/2 + row[2] - 0.25)
move1 = box_y * 2
try1 = row[1] * 2
if row[0] == 1:
print('<rect id= rectangle1 class= "rectangles" onmousemove="myFunction3()" x=',row[1],' y=',row[2],' width=',row[3]-row[1],' height=',row[4]-row[2],'><title>Owned by',row[6],'</title></rect>')
elif row[0] == 2:
print('<rect id="rectangle2" class= "rectangles" onmousemove="myFunction3()" x=',row[1],' y=',row[2],' width=',row[3]-row[1],' height=',row[4]-row[2],'><title>Owned by',row[6],'</title></rect>')
elif row[0] == 3:
print('<rect id="rectangle3" class= "rectangles" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" onmousemove="myFunction3()" x=',row[1],' y=',row[2],' width=',row[3]-row[1],' height=',row[4]-row[2],'><title>Owned by',row[6],'</title></rect>')
elif row[0] == 4:
print('<rect id="rectangle4" class= "rectangles" onmousemove="myFunction3()" x=',row[1],' y=',row[2],' width=',row[3]-row[1],' height=',row[4]-row[2],'><title>Owned by',row[6],'</title></rect>')
elif row[0] == 5:
print('<rect id="rectangle5" class= "rectangles" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" onmousemove="myFunction3()" x=',row[1],' y=',row[2],' width=',row[3]-row[1],' height=',row[4]-row[2],'><title>Owned by',row[6],'</title></rect>')
elif row[0] == 6:
print('<rect id="rectangle6" class= "rectangles" onmousemove="myFunction3()" x=',row[1],' y=',row[2],' width=',row[3]-row[1],' height=',row[4]-row[2],'><title>Owned by',row[6],'</title></rect>')
elif row[0] == 7:
print('<rect id="rectangle7" class= "rectangles" onmousemove="myFunction3()" x=',row[1],' y=',row[2],' width=',row[3]-row[1],' height=',row[4]-row[2],'><title>Owned by',row[6],'</title></rect>')
else:
print('<rect id="rectangle8" class= "rectangles" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" onmousemove="myFunction3()" x=',row[1],' y=',row[2],' width=',row[3]-row[1],' height=',row[4]-row[2],'><title>Owned by',row[6],'</title></rect>')
таблица стилей CSS
.rectangles{
fill: #ff3333;
stroke: #000000;
stroke-width: 0.1;
}
#rectangle1:hover{
stroke: #FF7F00;
stroke-width: 0.1;
fill: #A52A2A;
}
#rectangle2:hover{
stroke: #FF7F00;
stroke-width: 0.1;
fill: #A52A2A;
}
#rectangle3:hover{
stroke: #FF7F00;
stroke-width: 0.1;
fill: #006400;
}
#rectangle4:hover{
stroke: #FF7F00;
stroke-width: 0.1;
fill: #000000;
}
#rectangle5:hover{
stroke: #FF7F00;
stroke-width: 0.1;
fill: #006400;
}
#rectangle6:hover{
stroke: #FF7F00;
stroke-width: 0.1;
fill: #000000;
}
#rectangle7:hover{
stroke: #FF7F00
stroke-width: 0.1;
fill: #FFFFFF;
}
#rectangle8:hover{
stroke: #FF7F00;
stroke-width: 0.1;
fill: #FFFFFF;
}