I am trying to create some kind of heat map for the network I'm working on. I wanted to use the hive for this because it looks fancy and gives me more freedom to use.
if I found this site where I figured out how to use hexagons with pure CSS. but these were highly dependent lines and offsets. My entire user interface is powered by KnockoutJS and has a dynamic number of PCs on the network at any given time. (mostly docker containers go up or down).
Clusters can vary from 1 to n + 1 nodes.
I looked at this site: CSS Hexagon and found several solutions for managing hexagons, but all of them are REALLY limited in their dynamic use.
This is the assigned code:
<div class="panel-body> {{noescape "<!-- ko foreach: { data: vm.dash().nodes, as: 'node' } -->" }} <span class="flex-span" data-bind="attr: { 'id': node.id }, css: { up: node.Status == 2, down: node.Status != 2 }">⬢</span> {{noescape "<!-- /ko -->"}} </div>
Based on this, it will give a hexagon color that points up / down
I hacked a knockout script with my idea of โโflexbox, but I really don't understand flexbox, so it obviously doesn't work: Fiddle
#container { max-width:400px; max-height:400px; } .hex:before { content: " "; width: 0; height: 0; border-bottom: 30px solid #6C6; border-left: 52px solid transparent; border-right: 52px solid transparent; position: absolute; top: -30px; flex-shrink: 1; flex-grow:1; flex-basis: 130px; } .hex { margin-top: 30px; width: 104px; height: 60px; background-color: #6C6; position: relative; float:left; margin-bottom:30px; flex-shrink: 1; flex-grow:1; flex-basis: 130px; } .hex:after { content: ""; width: 0; position: absolute; bottom: -30px; border-top: 30px solid #6C6; border-left: 52px solid transparent; border-right: 52px solid transparent; flex-shrink: 1; flex-grow:1; flex-basis: 130px; }
<div id="container"> <div class=hex></div> <div class=hex></div> <div class=hex></div> <div class=hex></div> <div class=hex></div> <div class=hex></div> <div class=hex></div> <div class=hex></div> <div class=hex></div> <div class=hex></div> </div>
The issues I am facing are as follows:
- How to scale these divs dynamically regardless of number and occupy maximum space.
- How to use a pure CSS solution to make sure that all even "lines" are offset by half the hexagon.
!! UPDATE !!
So, I added the concept of predefined lines: fiddle I'm still looking for a way to make the line offset dependent on the width of the ".hex" class. and have a hex class scale with the number of elements. but I think the grid itself looks really good.
source share