Skip to content

Instantly share code, notes, and snippets.

@russbiggs
Last active June 12, 2019 17:41
Show Gist options
  • Save russbiggs/508e3edca3e4deb82ea2cd07f71b8616 to your computer and use it in GitHub Desktop.
Save russbiggs/508e3edca3e4deb82ea2cd07f71b8616 to your computer and use it in GitHub Desktop.
compliance Triangle Chart
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
svg text {
font-family: 'Roboto', sans-serif;
}
.top {
fill:lightgray;
stroke: black;
stroke-width: 2px;
}
.top--compliance {
fill: #66a61e;
}
.top--non-compliance {
fill: #d95f02;
}
.middle {
fill: lightgray;
stroke: black;
stroke-width: 2px;
}
.middle--non-compliance {
fill:#d95f02;
}
.middle--compliance {
fill:#66a61e;
}
.bottom {
fill:lightgray;
stroke: black;
stroke-width: 2px;
}
.bottom--non-compliance {
fill:#d95f02;
}
.bottom--compliance {
fill:#66a61e;
}
</style>
</head>
<body>
<div>
<svg width="240" height="240" class="svg1"></svg>
<svg width="240" height="240" class="svg2"></svg>
<svg width="240" height="240" class="svg3"></svg>
<svg width="240" height="240" class="svg4"></svg>
<svg width="240" height="240" class="svg5"></svg>
<svg width="240" height="240" class="svg6"></svg>
</div>
<script>
var classes = [
['bottom--non-compliance', 'middle--non-compliance','top--non-compliance', 'Primary Non-Compliance'],
['bottom--compliance', 'middle--non-compliance','top--non-compliance', 'Secondary Non-Compliance'],
['bottom--compliance', 'middle--compliance','top--non-compliance', 'Operational Non-Compliance'],
['bottom--compliance', 'middle--compliance','top--compliance', 'Operational Compliance'],
['bottom--compliance', 'middle','top', 'Primary Compliance'],
['bottom--compliance', 'middle--compliance','top', 'Secondary Compliance']
]
for (let i = 1; i < 7; i++) {
var svg = document.querySelector(`.svg${i}`);
var bottomTriangle = document.createElementNS('http://www.w3.org/2000/svg', 'polygon');
bottomTriangle.setAttribute('points',"100 15, 200 200, 0 200")
bottomTriangle.classList.add('bottom', classes[i-1][0]);
svg.appendChild(bottomTriangle)
var middleTriangle = document.createElementNS('http://www.w3.org/2000/svg', 'polygon');
middleTriangle.setAttribute('points',"100 15, 200 200, 0 200")
middleTriangle.classList.add('middle',classes[i-1][1]);
middleTriangle.setAttribute('transform', `translate(${200/6}, 5) scale(0.6666,0.6666)`)
svg.appendChild(middleTriangle)
var topTriangle = document.createElementNS('http://www.w3.org/2000/svg', 'polygon');
topTriangle.setAttribute('points',"100 15, 200 200, 0 200");
topTriangle.setAttribute('transform', `translate(${200/3}, 10) scale(0.3333,0.3333)`)
topTriangle.classList.add('top', classes[i-1][2]);
svg.appendChild(topTriangle)
var text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
text.textContent = classes[i-1][3];
text.setAttribute('y', 220);
svg.appendChild(text);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment