css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
      <h1>Calculating a pie | umbrella chart in SVG</h1>
      <div class="wrapper"> <!-- wrapper start -->
      <div class="controller"> <!-- controller start -->
      <form id="cform">
      <label>No. of slices (<span id="myNoOfSlices" class="lblNoSlices">9 pcs</span>)</label><br>
      <input id="rns" type="range" min="1" max="60" step="1" value="9" language="javascript" onchange="fCalculatePie()" oninput="fCalculatePie()"/><br>
      <label>Radius (<span id="myRadius" class="lblRadius">180°</span>)</label><br>
      <input id="rradius" type="range" min="10" max="199" step="1" value="180" language="javascript" onchange="fCalculatePie()" oninput="fCalculatePie()"/><br>
      <label>Fill-opacity (<span id="myOpacity" class="lblOpacity">100%</span>)</label><br>
      <input id="ropacity" type="range" min="0" max="1" step="0.1" value="1" language="javascript" onchange="fCalculatePie()" oninput="fCalculatePie()"/><br>
      <label>Stroke-width (<span id="myStrokeWidth" class="lblStrokeWidth">1px</span>)</label><br>
      <input id="rstrokewidth" type="range" min="0" max="3" step="0.25" value="1" language="javascript" onchange="fCalculatePie()" oninput="fCalculatePie()"/><br> 
      <label>Stroke-color (<span id="myStrokeColor" class="lblStrokeColor">&FilledSmallSquare; hsl(0,100%,50%)</span>)</label><br>
      <input id="rstrokecolor" type="range" min="0" max="360" step="1" value="0" language="javascript" onchange="fCalculatePie()" oninput="fCalculatePie()"/><br><br>        
      <label>Rotation (off | clockwise | counterclockwise)</label><br>
      <input id="chkRotation" type="range" min="0" max="2" step="1" value="1" language="javascript" onchange="fCalculatePie()" oninput="fCalculatePie()" style="width:20%;"/>
      <label>Grid (off | on)</label><br>
      <input id="chkGrid" type="range" min="0" max="1" step="1" value="1" language="javascript" onchange="fCalculatePie()" oninput="fCalculatePie()" style="width:10%;"/>
      <label>Arc (convex | concave)</label><br>
      <input id="chkArc" type="range" min="0" max="1" step="1" value="0" language="javascript" onchange="fCalculatePie()" oninput="fCalculatePie()" style="width:10%;"/><br>
      <label id="sb" class="sb"></label>
      </div> <!-- controller end -->
        <!-- preview start -->
      <div id="preview" class="preview">
        <!-- copy from https://codepen.io/itsnorbat/full/bVYoBa -->
        <svg xmlns="http://www.w3.org/2000/svg" width="402" height="402">
          <pattern id="karo" x="0" y="0" width="20" height="20" patternUnits="userSpaceOnUse">
            <rect x="0" y="0" width="20" height="20" fill="none" stroke="#fff" stroke-width="0.5"/>
        <rect id="grid" x="0" y="0" width="401" height="401" fill="url(#karo)" stroke="#fff" stroke-width="0"/>
        <g id="piechart" class="piechart">
          <path d="M200,200L380,200 A180,180 1 0,0 337.9,315.7z" style="fill: rgb(255, 0, 0); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <path d="M200,200L337.9,315.7 A180,180 1 0,0 231.3,377.3z" style="fill: rgb(255, 170, 0); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <path d="M200,200L231.3,377.3 A180,180 1 0,0 110,355.9z" style="fill: rgb(170, 255, 0); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <path d="M200,200L110,355.9 A180,180 1 0,0 30.9,261.6z" style="fill: rgb(0, 255, 0); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <path d="M200,200L30.9,261.6 A180,180 1 0,0 30.9,138.4z" style="fill: rgb(0, 255, 170); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <path d="M200,200L30.9,138.4 A180,180 1 0,0 110,44.1z" style="fill: rgb(0, 170, 255); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <path d="M200,200L110,44.1 A180,180 1 0,0 231.3,22.7z" style="fill: rgb(0, 0, 255); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <path d="M200,200L231.3,22.7 A180,180 1 0,0 337.9,84.3z" style="fill: rgb(170, 0, 255); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <path d="M200,200L337.9,84.3 A180,180 1 0,0 380,200z" style="fill: rgb(255, 0, 170); fill-opacity: 1; stroke: rgb(255, 0, 0); stroke-width: 0px;"></path>
          <!-- <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0,200,200" to="360,200,200" begin="0s" dur="6s" repeatCount="indefinite"/> -->
        <g id="calcPie" class="piechartcw"></g>
      </div> <!-- preview end -->
        <div style="clear:both;"></div>
        <p class="myp">I uncomment the SMIL animations and replace them with CSS transforms/keyframes animations because of the intent of deprecation of SMIL in future browsers (<a href="https://www.chromestatus.com/feature/5371475380928512" target="_blank">further details</a>).</p>
        <p class="myp">Therefore I've updated the <em>addRotation</em> function to toggle between the three rotation states of the calculated pie (#calcPie).</p>
        <p class="myp2">If you like your custom pie you can select and copy the code from the following textarea but please keep in mind that the external CSS especially the animation is not included.<br>
        You can copy the classes <strong>piechartcw</strong> and <strong>piechartccw</strong> and the <strong>keyframes</strong> from the CSS in this pen to your inline or external stylesheet and your animations will work instantly.</p>
        <textarea id="svgsource" rows="4" cols="120"></textarea><br><br>
      </div> <!-- wrapper end -->
  font-family: Raleway, sans-serif;
  font-weight: 200;
  color: #fc3;
  font-weight: 500;
  color: white;
  font-style: italic;
  text-decoration: none;
  width: 100%;
  color: lightgrey;
  text-align: left;
  color: grey;
  font-style: italic;
  text-align: left;  
/* controller */
  width: 846px;
  height: 405px;
  width: 382px;
  height: 382px;
  background-color: #000;
  border: 1px solid white;
  margin-right: 40px;
  text-align: left;
  padding: 10px;
  color: lightgrey;
  width: 402px;
  height: 402px;
  background-color: #000;
  border: 0px solid white;
  color: white;
  font-weight: 500;
  color: hsl(0,100%,50%);
  color: yellow;
  opacity: 0.6;
/* using CSS instead of SMIL for the animations */
  -webkit-animation: rotatecw 15s 0s linear infinite;
          animation: rotatecw 15s 0s linear infinite;
  -webkit-animation: rotatecw 3s 0s linear infinite;
          animation: rotatecw 3s 0s linear infinite;
  -webkit-animation: rotateccw 3s 0s linear infinite;
          animation: rotateccw 3s 0s linear infinite;
/* rotation clockwise (cw) */
@-webkit-keyframes rotatecw {
  0% {
    -webkit-transform-origin: 50% 50%;
    -webkit-transform: rotate(0deg);
            transform-origin: 50% 50%;
            transform: rotate(0deg);  }
  100% {
    -webkit-transform-origin:  50% 50%;
    -webkit-transform: rotate(360deg);
            transform-origin:  50% 50%;
            transform: rotate(360deg);
/* rotation counterclockwise (ccw) */
@-webkit-keyframes rotateccw {
  0% {
    -webkit-transform-origin: 50% 50%;
    -webkit-transform: rotate(360deg);
            transform-origin: 50% 50%;
            transform: rotate(360deg);
  100% {
    -webkit-transform-origin:  50% 50%;
    -webkit-transform: rotate(0deg);
            transform-origin:  50% 50%;
            transform: rotate(0deg);
              function fCalculatePie() {
  var originX = 200;
  var originY = 200;
  var radius = document.getElementById('rradius').value;
  var nos = document.getElementById('rns').value;
  var myOpacity = document.getElementById('ropacity').value;
  var myStrokeWidth = document.getElementById('rstrokewidth').value;
  var myStrokeColor = document.getElementById('rstrokecolor').value;
  var hslStokeColor = "hsl("+myStrokeColor+", 100%, 50%)";
  var rotationonoff = document.getElementById('chkRotation').value;
  var myGrid = document.getElementById('grid');
  var gridonoff = document.getElementById('chkGrid').value;
  var acc = document.getElementById('chkArc').value;
  document.getElementById('myRadius').innerHTML = radius + '°';
  document.getElementById('myNoOfSlices').innerHTML = nos + ' pcs';
  document.getElementById('myOpacity').innerHTML = myOpacity*100 + '%';
  document.getElementById('myStrokeWidth').innerHTML = myStrokeWidth + 'px';
  document.getElementById('myStrokeColor').innerHTML = "&FilledSmallSquare; "+hslStokeColor
  document.getElementById('myStrokeColor').style.color = hslStokeColor;
  var angle = 360/nos;
  var sa = rou(angle, 10); //sa for shorten angle
  //document.getElementById('calcAngle').value = sa;
  for (var i = 0; i < nos; i++) {
    addPiece(originX, originY, radius, i*sa, ((i+1)*sa), myOpacity, hslStokeColor, myStrokeWidth, acc);
  // former version for SMIL in SVG
  } else if(rotationonoff==2){
  } else{
  csvg2ta("Norbert Mesch");

function addPiece(ox, oy, r, sa, ea, opacity, strokecolor, strokewidth, arccc){
  var myPiece = document.getElementById('calcPie');
  var newElement = document.createElementNS("http://www.w3.org/2000/svg", 'path'); //Create a path in SVG's namespace
  // starting point calculation
  var spx = ox + rou(r*Math.cos(sa * Math.PI / 180),10)*(1);
  var spy = oy + rou(r*Math.sin(sa * Math.PI / 180),10)*(1);
  // ending point calculation 
  var epx = ox + rou(r*Math.cos(ea * Math.PI / 180),10)*(1);
  var epy = oy + rou(r*Math.sin(ea * Math.PI / 180),10)*(1);
  // creating hsl color attribute
  var mycolor = "hsl("+sa+", 100%, 50%)";
  // create path element
  var myPath = "M"+ ox +","+ oy + "L"+ spx +","+ spy +" A"+r+","+r+" 1 0,"+ arccc +" "+ epx +","+ epy +"z";
  //a little bit styling
  newElement.setAttribute("d", myPath);
  newElement.style.fill = mycolor;
  newElement.style['fill-opacity'] = opacity;
  newElement.style.stroke = strokecolor;
  newElement.style['stroke-width'] = strokewidth;
  //Append the element to the DOM
/* remomes all pieces of the calculated pie */
function remAllPieces(pelem){
  var myNode = document.getElementById(pelem);
  while (myNode.firstChild) {

/* toggle between the rotation states no(0), clockwise(1) and counterclockwise(2) */
function addRotation(direction){
  //document.getElementById("sb").innerHTML = "Ausgabe: " + direction;
  }else if(direction==1){
  }else if(direction==2) {
/*function addRotation(direction){
  var myRotation = document.getElementById('calcPie');
  var newRotation = document.createElementNS("http://www.w3.org/2000/svg", 'animateTransform');
  newRotation.setAttribute("attributeType", "xml");
  newRotation.setAttribute("attributeName", "transform");
  newRotation.setAttribute("type", "rotate");
    newRotation.setAttribute("from", "0,200,200");
    newRotation.setAttribute("to", "360,200,200");
    newRotation.setAttribute("from", "360,200,200");
    newRotation.setAttribute("to", "0,200,200");    
  newRotation.setAttribute("begin", "1s");  
  newRotation.setAttribute("dur", "6s");  
  newRotation.setAttribute("repeatCount", "indefinite"); 

// function to round the number (n) with the number of decimal places (dp) e.g. 
// 10 for one decimal places 106.1 or 
// 100 for two decimal places 106.13 and so on
function rou(n,dp) {
    n = (Math.round(n * dp) / dp);
    return n;

// copy pie svg into textarea
function csvg2ta(quelle){
  var svgs = document.getElementById('preview').innerHTML;
  //document.getElementById("sb").innerHTML = svgs;
  document.getElementById('svgsource').value = svgs;
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................