Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
  <link rel="stylesheet" href="styles.css">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&display=swap" rel="stylesheet">
  <title>Percentage Visualization Tool</title>
</head>

<body>
  <div class="container">
    <h2>Create your own datavisualisation with icons</h2>
    <ul class="inputList">
      <li>
        <label for="percentageInput">Enter highlighted percentage (1-100):</label>
        <input type="number" id="percentageInput" min="1" max="100" value="50" oninput="updateOutputs()">
      </li>
    </ul>
    <div class="flex-container">
      <div class="flex-column">
        <!-- Content for the first column -->
        <h3>Highlight <output id="selectedPercentageOutput"></output><br />
        </h3>
        <ul class="inputList">
          <li>

            <div class="icon-row">
              <label for="percentageIcon">Select Icon:</label>
              <div id="selectedPercentageIcon"></div>
            </div>

            <select id="percentageIcon" onchange="updateSelectedIcon('selectedPercentageIcon', this.value)">
              <option value="fas fa-user">Person</option>
              <option value="fas fa-circle">Circle</option>
              <option value="fas fa-female">Female</option>
              <option value="fas fa-male">Male</option>
              <option value="fa-solid fa-user">Person</option>
              <option value="fa-brands fa-apple">Apple</option>
              <option value="fa-solid fa-cookie-bite">Cookie</option>
              <option value="fa-solid fa-wheelchair-move">Wheelchair</option>
              <option value="fa-solid fa-user-doctor">Doctor</option>
              <option value="fa-solid fa-user-graduate">Graduate</option>
              <option value="fa-solid fa-person-running">Running Person</option>
              <option value="fa-solid fa-face-smile">Smiling Face</option>
              <option value="fa-solid fa-virus">Virus</option>
              <option value="fa-solid fa-lungs">Lungs</option>
              <option value="fa-solid fa-heart-pulse">Heart Pulse</option>
              <option value="fa-solid fa-bacterium">Bacterium</option>
              <option value="fa-solid fa-earth-europe">Earth Europe</option>
              <option value="fa-solid fa-fish-fins">Fish Fins</option>
              <option value="fa-solid fa-droplet">Drop</option>
              <option value="fa-solid fa-dove">Bird</option>
            </select>
          </li>

          <li>
            <label for="percentageColor">Select Color:</label>
            <input type="color" id="percentageColor" value="#009999">
          </li>
        </ul>
      </div>

      <div class="flex-column">
        <!-- Content for the second column -->
        <h3>Default <output id="complementPercentageOutput"></output></h3>
        <ul class="inputList">
          <li>
            <div class="icon-row">
              <label for="defaultIcon">Select Icon:</label>
              <div id="selectedDefaultIcon"></div>
            </div>
            <select id="defaultIcon" onchange="updateSelectedIcon('selectedDefaultIcon', this.value)">

              <option value="fas fa-user">Person</option>
              <option value="fas fa-circle">Circle</option>
              <option value="fas fa-female">Female</option>
              <option value="fas fa-male">Male</option>
              <option value="fa-solid fa-user">Person</option>
              <option value="fa-brands fa-apple">Apple</option>
              <option value="fa-solid fa-cookie-bite">Cookie</option>
              <option value="fa-solid fa-wheelchair-move">Wheelchair</option>
              <option value="fa-solid fa-user-doctor">Doctor</option>
              <option value="fa-solid fa-user-graduate">Graduate</option>
              <option value="fa-solid fa-person-running">Running Person</option>
              <option value="fa-solid fa-face-smile">Smiling Face</option>
              <option value="fa-solid fa-virus">Virus</option>
              <option value="fa-solid fa-lungs">Lungs</option>
              <option value="fa-solid fa-heart-pulse">Heart Pulse</option>
              <option value="fa-solid fa-bacterium">Bacterium</option>
              <option value="fa-solid fa-earth-europe">Earth Europe</option>
              <option value="fa-solid fa-fish-fins">Fish Fins</option>
              <option value="fa-solid fa-droplet">Drop</option>
              <option value="fa-solid fa-dove">Bird</option>

            </select>
          </li>
          <li>

            <label for="defaultColor">Select Color:</label>
            <input type="color" id="defaultColor" value="#777777">
          </li>
        </ul>
      </div>
    </div>
    <ul class="inputList">

    </ul>

    <button onclick="generateVisualization()" class="ls-button"><i class="fa-solid fa-image"></i> UPDATE Visualization</button>
    <button onclick="downloadImage()" class="ls-button">Download Image <i class="fas fa-download"></i></button>
    <div class="separator"></div>

    <div class="box-visualization">
      <div id="visualizationGrid"></div>
    </div>
  </div>

  <script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
  <script src="script.js"></script>
</body>

</html>
              
            
!

CSS

              
                body {
  font-family: Poppins, sans-serif;
  font-size: 16px;
  font-weight: 400;
  background-color: #f0f5f4;
}

li {
  list-style-type: none;
  margin-left: -35px;
  padding: 5px 10px;
  /*background-color: #e1f2f2;*/
  margin-bottom: 8px;
}

.container {
  max-width: 600px;
  margin: 0px auto;
}
.separator {
  padding-top: 40px;
}
#selectedDefaultIcon .fas,
#selectedPercentageIcon .fas {
  float: right;
  font-size: 20px;
}

.icon-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 40px;
}

#visualizationGrid i {
  font-size: 35px;
  max-width: 100%; /* Ensure the icon doesn't exceed the container width */
  max-height: 100%; /* Ensure the icon doesn't exceed the container height */
}

/* Styling for the visualization grid */
#visualizationGrid {
  display: grid;
  margin: 0 auto;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  padding: 20px;
  background-color: transparent;
}
.box-visualization {
  border: 1px solid #ddd;
}

#visualizationGrid div {
  width: 100%;
  height: 0;
  padding-bottom: 90%; /* Maintain a square aspect ratio for each icon */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Add your own styles for a better visual appearance */
.flex-container {
  gap: 20px;
  display: flex;
}

.flex-column {
  flex: 1;
  padding: 15px;
  box-sizing: border-box;
  background-color: #fff;
}

.flex-column h3 {
  padding-left: 14px;
}

/* Adjustments for smaller screens */
@media (max-width: 600px) {
  .flex-container {
    flex-direction: column;
  }
}

/* Style the button */
.ls-button {
  background-color: #6304c1;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s;
  font-family: Poppins, sans-serif;
  margin: 20px;
}

/* Add a hover state for the button */
.ls-button:hover {
  background-color: #00427d;
}

/* Style the input selection boxes */
input[type="number"],
input[type="color"],
select {
  width: 100%;
  padding: 10px;
  margin: 5px 0;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-sizing: border-box;
}

/* Style the drop-down arrow for select elements */
select {
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg fill="%23333" height="24" width="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z" /></svg>');
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* Add hover state for the drop-down arrow */
select:hover {
  border-color: #009999;
}

/* Add focus state for the input selection boxes */
input[type="number"]:focus,
input[type="color"]:focus,
select:focus {
  outline: none;
  border-color: #009999;
  box-shadow: 0 0 5px rgba(0, 153, 153, 0.5);
}
input[type="color"] {
  width: 100%;
  padding: 0px;
}

input,
select {
  font-size: 16px;
}

              
            
!

JS

              
                // Include the html2canvas library
const html2canvasScript = document.createElement("script");
html2canvasScript.src =
  "https://html2canvas.hertzen.com/dist/html2canvas.min.js";
document.head.appendChild(html2canvasScript);

// Include your main script
const mainScript = document.createElement("script");
mainScript.src = "script.js";
document.head.appendChild(mainScript);

// Call any function after the scripts are loaded
mainScript.onload = function () {
  generateVisualization();
};

// Rest of your script.js file
function generateVisualization() {
  // Retrieve user inputs
  const percentageInput = document.getElementById("percentageInput");
  const defaultIcon = document.getElementById("defaultIcon").value;
  const percentageIcon = document.getElementById("percentageIcon").value;
  const defaultColor =
    document.getElementById("defaultColor").value || "#cccccc"; // Set default color for default icon
  const percentageColor =
    document.getElementById("percentageColor").value || "#009999"; // Set default color for percentage icon

  // Calculate the colors for default and percentage icons
  const percentage = parseInt(percentageInput.value);

  // Generate the visualization grid
  const visualizationGrid = document.getElementById("visualizationGrid");
  visualizationGrid.innerHTML = ""; // Clear previous content

  for (let row = 0; row < 10; row++) {
    for (let col = 0; col < 10; col++) {
      const color =
        row * 10 + col < percentage ? percentageColor : defaultColor;
      const iconDiv = document.createElement("div");
      iconDiv.style.color = color;
      iconDiv.innerHTML = `<i class="${
        row * 10 + col < percentage ? percentageIcon : defaultIcon
      }"></i>`;
      visualizationGrid.appendChild(iconDiv);
    }
  }
}

function downloadImage() {
  const visualizationGrid = document.getElementById("visualizationGrid");

  // Use html2canvas to capture the visualizationGrid
  html2canvas(visualizationGrid, {
    backgroundColor: null, // Set background to transparent
    scale: 2 // Adjust the scale if needed
  }).then((canvas) => {
    // Create a temporary link element
    const link = document.createElement("a");
    // Set the href attribute to the canvas data URL
    link.href = canvas.toDataURL();
    // Set the download attribute with a desired filename
    link.download = "icon-visualisation_The-Online-Scientist.png";
    // Simulate a click on the link to trigger the download
    link.click();
  });
}

function updateSelectedIcon(containerId, selectedIcon) {
  const iconContainer = document.getElementById(containerId);
  iconContainer.innerHTML = `<i class="${selectedIcon}"></i>`;
}
function updateSelectedIcon(containerId, selectedIcon) {
  const iconContainer = document.getElementById(containerId);
  iconContainer.innerHTML = `<i class="${selectedIcon}"></i>`;
}

// Initial call to set the default icon for the selectedPercentageIcon
updateSelectedIcon(
  "selectedPercentageIcon",
  document.getElementById("percentageIcon").value
);

updateSelectedIcon(
  "selectedDefaultIcon",
  document.getElementById("defaultIcon").value
);

function updateSelectedIcon(containerId, selectedIcon) {
  const iconContainer = document.getElementById(containerId);
  iconContainer.innerHTML = `<i class="${selectedIcon}"></i>`;
}

function updateOutputs() {
  const percentageInput = document.getElementById("percentageInput");
  const selectedPercentageOutput = document.getElementById(
    "selectedPercentageOutput"
  );
  const complementPercentageOutput = document.getElementById(
    "complementPercentageOutput"
  );

  selectedPercentageOutput.textContent = `${percentageInput.value}%`;
  const complementPercentage = 100 - parseInt(percentageInput.value, 10);
  complementPercentageOutput.textContent = `${complementPercentage}%`;
}

window.onload = function () {
  generateVisualization();
  updateOutputs();
};

              
            
!
999px

Console