nerdamer-prime
Version:
javascript light-weight symbolic math library
165 lines (158 loc) • 4.99 kB
HTML
<html>
<head>
<title>Nerdamer Tree Visualizer</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="./nerdamer.core.js"></script>
<style>
/* source: https://codepen.io/philippkuehn/pen/QbrOaN */
body {
font-family: sans-serif;
font-size: 15px;
}
.tree ul {
position: relative;
padding: 1em 0;
white-space: nowrap;
margin: 0 auto;
text-align: center;
}
.tree ul::after {
content: '';
display: table;
clear: both;
}
.tree li {
display: inline-block;
vertical-align: top;
text-align: center;
list-style-type: none;
position: relative;
padding: 1em 0.5em 0 0.5em;
}
.tree li::before,
.tree li::after {
content: '';
position: absolute;
top: 0;
right: 50%;
border-top: 1px solid #ababab;
width: 50%;
height: 1em;
}
.tree li::after {
right: auto;
left: 50%;
border-left: 1px solid #ababab;
}
.tree li:only-child::after,
.tree li:only-child::before {
display: none;
}
.tree li:only-child {
padding-top: 0;
}
.tree li:first-child::before,
.tree li:last-child::after {
border: 0 none;
}
.tree li:last-child::before {
border-right: 1px solid #ababab;
border-radius: 0 5px 0 0;
}
.tree li:first-child::after {
border-radius: 5px 0 0 0;
}
.tree ul ul::before {
content: '';
position: absolute;
top: 0;
left: 50%;
border-left: 1px solid #ababab;
width: 0;
height: 1em;
}
.tree li div {
border: 1px solid #ababab;
padding: 0.5em 0.75em;
text-decoration: none;
display: inline-block;
border-radius: 5px;
color: #333;
position: relative;
top: 1px;
}
.tree li div:hover,
.tree li div:hover + ul li div {
background: #90c4f4;
color: #fff;
border: 1px solid #ababab;
}
.tree li div:hover + ul li::after,
.tree li div:hover + ul li::before,
.tree li div:hover + ul::before,
.tree li div:hover + ul ul::before {
border-color: #90c4f4;
}
.tree div span {
display: inline-block;
min-width: 30px;
}
.operator {
background: #ecf7fc;
}
.function {
background: #05346a;
color: #fff ;
}
#input {
border: 2px solid #ababab;
border-radius: 3px;
padding: 5px;
color: #707070;
font-size: 18px;
width: 80%;
margin-bottom: 4px;
}
#generate {
padding: 0;
border: none;
font: inherit;
color: inherit;
cursor: pointer;
background: #ccc;
padding: 7px;
vertical-align: top;
font-size: 18px;
color: #707070;
border-radius: 3px;
margin-left: 2px;
}
</style>
</head>
<body>
<input type="text" id="input" onKeyPress="keypress(event)" /><button id="generate" onclick="generate()">
Generate
</button>
<div id="output"></div>
<script>
var output = document.getElementById('output');
var input = document.getElementById('input');
function keypress(e) {
var code = Number(e.keyCode ? e.keyCode : e.which);
if (code === 13) {
//Enter keycode
generate();
}
}
function generate() {
try {
output.innerHTML = nerdamer.htmlTree(input.value);
} catch (e) {
alert(e.message);
}
}
</script>
</body>
</html>