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 id="app">
 <button @click="visible =! visible"> 
  <span v-if="visible"> Hide Config </span>
  <span v-else="visible"> Show Config </span> 
 </button>
 <div id="container">
  <div id="config" v-if="visible">
   <code>
   <span> size = {{ size }} </span> <br>
   <span> topHeight = {{ topHeight }} </span> <br/>
   <span> bottomHeight = {{ bottomHeight }} </span> <br/>
   <hr/>
   <span> width = {{ width }} </span> <br/>
   <span> halfSize = {{ halfSize }} </span> <br/>
   <hr/>
   <span> radius = {{ radius }} </span> <br/>
   <span> distance = {{ distance }} </span> <br/>
   <hr/>
   </code>
   <div class="item" v-for="(node, index) in itemArray">
    {{ node }}
    <button @click="removeItem(index)"> x </button>
   </div>
   <div class="action">
    <input v-model="inputVal" />
    <button @click="addItem"> Add </button>
   </div>
  </div>
  <svg xmlns="http://www.w3.org/2000/svg" :view-box.camel="viewbox">
   <g>
    <g v-for="(item, i) in itemArray">
     
     <text :x="calculateXPos(i)" :y="bottomHeight+45"> 
      <!-- {{ item }}  -->
       x={{calculateXPos(i)}}
     </text>
     
     <path :d="'M' + halfSize + ','         + (topHeight+radius) +' '+
                'C' + halfSize + ','         + halfSize +' '+    
                      calculateXPos(i) + ',' + halfSize +' '+ 
                      calculateXPos(i) + ',' + bottomHeight" 
     />
     
     <circle fill="#AE8EE9" 
              r="10" 
              :cx="calculateXPos(i)" 
              :cy="bottomHeight+15"> 
     </circle>
    </g>
   </g>
   
   <!-- Clipping Code Starts -->
   <defs>
    <mask id="svg-mask">
     <circle :r="radius" 
             :cx="halfSize" 
             :cy="topHeight" 
             fill="white"/>
    </mask>
   </defs>
   
   <image mask="url(#svg-mask)" 
          :x="(halfSize-radius)" 
          :y="(topHeight-radius)"
          :height="topHeight" 
          :width="topHeight"
          xlink:href="https://s3-ap-southeast-2.amazonaws.com/kruties-diagrams/misc/guardians-of-the-galaxy.jpg">
    
   </image>
   <!-- Clipping Code Ends -->

   <circle class="circle"
           :r="radius"
           :cx="halfSize"
           :cy="topHeight">
   </circle>
   
   <text class="title" 
         :x="halfSize" 
         :y="topHeight/4"> 
    {{ title }} 
   </text> 
   
  </svg>
 </div>
</div>
              
            
!

CSS

              
                body {
  background: #fff;
}
.item {
  stroke: #CCC;
  stroke-width: 5;
}
path {
  stroke: #AE8EE9;
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
}
text {
  font-size: 20px;
  text-anchor: middle;
}
#container {
  display: flex;
  height: 100vh;
  justify-content: center;
  border: 2px solid #B2EBF2;
  border-radius: 10px;
}
#config {
  padding: 10px;
  margin: 5px;
  height: fit-content;
  background: #D1C4E9;
  border-radius: 5px;
}
svg {
  width: 100%;
  height: 100%;
}

.title {
  font-size: 40px;
}
.clip-svg {
  clip-path: url(#myClip);
}
#config button {
 float: right;
}
.item {
 border-bottom: 1px dashed rgba(0,0,0,0.5);
 padding: 5px;
}
.action {
 padding: 10px;
}
input, button {
 margin-bottom: 3px;
}
.circle {
  stroke-width: 5;
  stroke: #AE8EE9;
  fill: none;
}
              
            
!

JS

              
                new Vue({
 el: "#app",
 data() {
  return {
   title: "Guardians of the Galaxy",
   size: 1000,
   inputVal: "",
   itemArray: [
    "Starlord",
    "Gamora",
    "Groot",
    "Rocket",
    "Drax",
    // "Yondu",
    // "Nebula",
    // "Korath",
   ],
   visible: false
  };
 },
 computed: {
  topHeight() {
   // 20% of the size
   return this.size * 0.2;
  },
  bottomHeight() {
   // 80% of the size
   return this.size * 0.8;
  },
  width() {
   return this.size;
  },
  halfSize() {
   return this.size * 0.5;
  },
  distance() {
   // distance between two array items on the horizon
   return Math.round(this.width / this.itemArray.length);
  },
  radius() {
    return (this.topHeight*0.5)
  },
  viewbox() {
   return "0 0 " + this.size + " " + this.size;
  }
 },
 methods: {
  addItem() {
   this.itemArray.push(this.inputVal);
   this.inputVal = "";
  },
  removeItem(i) {
   return this.itemArray.splice(i, 1);
  },
  calculateXPos(i) {
   // new values for x2 and x3
   let x = this.distance * i + this.distance * 0.5;
   return Math.round(x);
  }
 }
});

              
            
!
999px

Console