Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <h1>How unique am I?</h1>
  <p>
    Type "How unique am I?" in the textfield below. Compare against others and yourself.
  </p>

  <input id="tester" placeholder="How unique am I?"/>

  <div><button id="clearButton">Clear/Reset</button>
    <button id="saveButton">Save & Compare</button>
  </div>
  <br />
  <div class="myChartContainer">
    <canvas id="myChart" width="500" height="100"></canvas>
    <canvas id="person1Chart" width="500" height="100"></canvas>
  </div>
</div>
              
            
!

CSS

              
                .container{
  font-family: "Roboto";
  color: #333;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.myChartContainer{
  width: 1000px
}
input{
  font-size: 1.5em;
    padding: 0.5em;
}

button{
  all: unset;
  padding: 1em 2em 1em 2em;
  margin: 1em;
  background-color: #0568f6;
  border-radius: 5px;
  color: white;
  cursor: pointer;
}
button:hover{
   background-color: #333;
}
              
            
!

JS

              
                var lastkeyaction = null;
var breaks = [];
var holds = [];
var runs = 0;
const person1 = [
  [{'type':'Hold','value':76.4799999888055},{'type':'Break','value':158.24000001884997},{'type':'Hold','value':64.94000001111999},{'type':'Break','value':54.63999998755753},{'type':'Hold','value':73.64000001689419},{'type':'Break','value':63.91500000609085},{'type':'HoldSpace','value':95.79499997198582},{'type':'Break','value':55.26500003179535},{'type':'Hold','value':88.06499995989725},{'type':'Break','value':103.6850000382401},{'type':'Hold','value':82.27999997325242},{'type':'Break','value':142.3300000024028},{'type':'Hold','value':71.72499998705462},{'type':'Break','value':40.12499999953434},{'type':'Hold','value':63.62000002991408},{'type':'Break','value':49.149999977089465},{'type':'Hold','value':71.03500002995133},{'type':'Break','value':41.47499997634441},{'type':'Hold','value':87.09500002441928},{'type':'Break','value':54.804999963380396},{'type':'HoldSpace','value':121.44000001717359},{'type':'Break','value':24.369999999180436},{'type':'Hold','value':64.05500002438203},{'type':'Break','value':215.0149999652058},{'type':'Hold','value':88.76000001328066},{'type':'Break','value':158.59000000637025},{'type':'HoldSpace','value':74.495000008028},{'type':'Break','value':125.49000000581145},{'type':'Hold','value':73.40999995358288},{'type':'Break','value':183.10500000370666},{'type':'Hold','value':88.37500005029142}],
  [{'type':'Hold','value':74.58999997470528},{'type':'Break','value':150.16499999910593},{'type':'Hold','value':72.52500002505258},{'type':'Break','value':31.164999993052334},{'type':'Hold','value':64.89999999757856},{'type':'Break','value':31.85000002849847},{'type':'HoldSpace','value':95.3449999797158},{'type':'Break','value':31.819999974686652},{'type':'Hold','value':88.92500004731119},{'type':'Break','value':119.19999995734543},{'type':'Hold','value':81.05500001693144},{'type':'Break','value':127.09500000346452},{'type':'Hold','value':79.7199999797158},{'type':'Break','value':40.48500000499189},{'type':'Hold','value':79.75999999325722},{'type':'Break','value':23.665000044275075},{'type':'Hold','value':80.16999997198582},{'type':'Break','value':55.41500000981614},{'type':'Hold','value':80.56500001111999},{'type':'Break','value':24.214999983087182},{'type':'HoldSpace','value':106.77000001305714},{'type':'Break','value':69.90999996196479},{'type':'Hold','value':64.11000003572553},{'type':'Break','value':63.13999998383224},{'type':'Hold','value':112.38499998580664},{'type':'Break','value':15.959999989718199},{'type':'HoldSpace','value':71.66500005405396},{'type':'Break','value':105.76999996555969},{'type':'Hold','value':70.46499999705702},{'type':'Break','value':400.6550000049174},{'type':'Hold','value':71.18500000797212}]
];

const data = {
  labels: ["Typing"],
  datasets: []
};
const type = "bar";
const options = {
  indexAxis: "y",
  plugins: {
    legend: {
      position: "none"
    },
    tooltip: {
      // Disable the on-canvas tooltip
      enabled: false
    }
  },
  scales: {
    x: {
      stacked: true
    },
    y: {
      stacked: true
    }
  }
};

var myChart = new Chart(document.getElementById("myChart"), {
  type,
  data,
  options
});

var person1dataset = [];
person1[0].forEach((entry) => {
  if (entry.type == "Hold") {
    person1dataset.push({
      label: "Hold",
      data: [entry.value, 0],
      backgroundColor: "#1f78b4"
    });
  } else if (entry.type == "HoldSpace") {
    person1dataset.push({
      label: "HoldSpace",
      data: [entry.value, 0],
      backgroundColor: "#b2df8a"
    });
  } else {
    person1dataset.push({
      label: "Break",
      data: [entry.value, 0],
      backgroundColor: "#eee"
    });
  }
});
person1[1].forEach((entry, k) => {
  if (entry.type == "Hold") {
    person1dataset.push({
      label: "Hold",
      data: [0, entry.value],
      backgroundColor: "#1f78b4"
    });
  } else if (entry.type == "HoldSpace") {
    person1dataset.push({
      label: "HoldSpace",
      data: [0, entry.value],
      backgroundColor: "#b2df8a"
    });
  } else {
    person1dataset.push({
      label: "Break",
      data: [0, entry.value],
      backgroundColor: "#eee"
    });
  }
});

var person1Chart = new Chart(document.getElementById("person1Chart"), {
  type,
  data: {
    labels: ["Typing V1", "Typing V2"],
    datasets: person1dataset
  },
  options
});

document.getElementById("tester").addEventListener("keydown", function (event) {
  if (
    event.repeat ||
    event.code == "ShiftLeft" ||
    event.code == "ShiftRight" ||
    event.code == "ControlLeft" ||
    event.code == "ControlRight" ||
    event.code == "AltLeft" ||
    event.code == "AltRight" ||
    event.code == "CapsLock"
  ) {
    return;
  }
  if(event.code == "Enter"){
    save();
    return
  }
  var timenow = performance.now();
  if (lastkeyaction) {
    breaks.push(timenow - lastkeyaction);
    myChart.data.datasets.push({
      label: "Break",
      data: [timenow - lastkeyaction],
      backgroundColor: "#eee"
    });
    myChart.update();
  }
  lastkeyaction = timenow;
});

document.getElementById("tester").addEventListener("keyup", function (event) {
  if (
    event.repeat ||
    event.code == "ShiftLeft" ||
    event.code == "ShiftRight" ||
    event.code == "ControlLeft" ||
    event.code == "ControlRight" ||
    event.code == "AltLeft" ||
    event.code == "AltRight" ||
    event.code == "CapsLock" ||
    event.code == "Enter"
  ) {
    return;
  }
  if (event.code == "Backspace" && document.getElementById("tester").value.length == 0){
    clear()
    return
  }
  var timenow = performance.now();
  if (lastkeyaction) {
    holds.push(timenow - lastkeyaction);
    myChart.data.datasets.push({
      label: event.code == "Space" ? "HoldSpace" : "Hold",
      data: [timenow - lastkeyaction],
      backgroundColor: event.code == "Space" ? "#b2df8a" : "#1f78b4"
    });
    myChart.update();
    lastkeyaction = timenow;
  }
});

document
  .getElementById("clearButton")
  .addEventListener("click", function (event) {
    clear()
  });

function clear() {
  var converteddataset = [];
    myChart.data.datasets.forEach((dataset) =>
      converteddataset.push({ type: dataset.label, value: dataset.data[0] })
    );
    holds = [];
    breaks = [];
    lastkeyaction = null;
    document.getElementById("tester").value = "";
    myChart.data.datasets = [];
    myChart.update();
}


document
  .getElementById("saveButton")
  .addEventListener("click", function (event) {
  save()
  });


function save() {
  /*var converteddataset = [];
    myChart.data.datasets.forEach((dataset) =>
      converteddataset.push({ type: dataset.label, value: dataset.data[0] })
    );
  console.log(JSON.stringify(converteddataset))*/
  person1Chart.data.datasets.forEach((dataset) => dataset.data.unshift(0));
  myChart.data.datasets.forEach((dataset) => person1Chart.data.datasets.push(dataset))
  runs= runs+1
  const runname = "Run "+runs
    person1Chart.data.labels.unshift(runname);
    holds = [];
    breaks = [];
    lastkeyaction = null;
    document.getElementById("tester").value = "";
    myChart.data.datasets = [];
    myChart.update();
  person1Chart.update();
}
              
            
!
999px

Console