cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <figure>
  <svg viewBox="0 0 100 20" preserveAspectRatio="xMidYMid">
  <g id="loading">
    <text y=50% x=50% font-size="2" text-anchor="middle">Fetching bug info</text>
  </g>
  </svg>
  <figcaption></figcaption>
</figure>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Libre+Baskerville:400italic);

* {
  box-sizing: border-box;  
}

body {
    background-color: rgba(10,20,0,0.03);
}

figcaption {
  padding: 0.5em 5em 0.5em 0.5em;
  display: inline-block;
  background-color: #03A9F4;
  color: #FFF;
  font-style: italic;
  font-family: 'Libre Baskerville', serif;
  border-radius: 0 0.5em 0.5em 0;
}

figcaption::before {
  content: '~ '
}

figcaption a, figcaption a:visited {
  color: inherit;
}

svg {
  margin: 0;
  width: 100vw;
  height: 200px;
}

.bug-line {
  cursor: pointer;
  animation: .2s linear appears;
}

@keyframes appears {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
            
          
!
            
              var COLORS = ["rgb(244, 67, 54)","rgb(233, 30, 99)","rgb(156, 39, 176)","rgb(103, 58, 183)","rgb(63, 81, 181)","rgb(33, 150, 243)","rgb(3, 169, 244)","rgb(0, 188, 212)","rgb(0, 150, 136)","rgb(76, 175, 80)","rgb(139, 195, 74)","rgb(255, 193, 7)","rgb(255, 152, 0)","rgb(255, 87, 34)","rgb(121, 85, 72)","rgb(96, 125, 139)"];
var userColor = {};

var svg = document.querySelector('svg');
const FIRST_WEEKDAY = new Date('2016-01-04');
const MS_A_DAY = 1000 * 60 * 60 * 24;
const BUGZILLA_API_URL = 'https://bugzilla.mozilla.org/rest/';
const BUG_ID = 1227477;
const EMAIL = "chevobbe.nicolas@gmail.com";

document.querySelector('figcaption').innerHTML =`<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=${BUG_ID}">Bug ${BUG_ID}</a>`;

var myHeaders = new Headers();
myHeaders.append('Accept', 'application/json');
var fetchParams = {
  mode: 'cors',
  method: 'GET',
  headers: myHeaders
};
var bugDetail = fetch(`${BUGZILLA_API_URL}bug/${BUG_ID}`,fetchParams)
.then((response) => response.json());
var bugHistory = fetch(`${BUGZILLA_API_URL}bug/${BUG_ID}/history`, fetchParams)
.then((response) => response.json());

Promise.all([bugDetail, bugHistory]).then(function(results){
  console.log(results);
  var bugData = results[0].bugs[0];
  bugData.history = results[1].bugs[0].history;
  console.log(bugData);
  drawBug(bugData);
})
.catch((e) => console.error(e))
 
function drawBug(bug){
    var bugColor = '#FFECB4';
  console.log(svg);
    var y = 20;
    var assignDate = null;
    bug.history.some(function(activity){
      var hasAssignement = activity.changes.some(function(change){
        return (change.field_name === 'assigned_to' && change.added === EMAIL);
      });
      if(hasAssignement === true){
        assignDate = new Date(activity.when);
        return true;
      }
    });
    bug.assign_time = assignDate.getTime();
  
    var endDate = new Date();
    if(bug.cf_last_resolved){
      endDate = (new Date(bug.cf_last_resolved));
    } 

    function getPositionFromDate(date){
      var dateTime = date.getTime();
      var length = svg.getAttribute('viewBox').split(' ')[2];
      var padding = 5;
      var a = (endDate.getTime() - bug.assign_time)/(length-(padding*2));
      return padding + ((dateTime - bug.assign_time ) / a);
    }
  
    var holidaysStart = (new Date('2016-01-16'));
    var holidaysEnd = (new Date('2016-01-23'));
  
    var holdayGroup = document.createElementNS("http://www.w3.org/2000/svg", "g");
  
    var holidaysRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
    holidaysRect.setAttribute('title', 'Ski Holidays'); 
    holidaysRect.setAttribute('x', getPositionFromDate(holidaysStart)); 
    holidaysRect.setAttribute('y', y / 4);
    holidaysRect.setAttribute('rx', y / 10);
    holidaysRect.setAttribute('ry', y / 10);
    holidaysRect.setAttribute('width', getPositionFromDate(holidaysEnd) - getPositionFromDate(holidaysStart));
    holidaysRect.setAttribute('height', y / 2);
    holidaysRect.setAttribute('fill', '#77B6EC');
    holidaysRect.setAttribute('fill-opacity', 0.8);
    holdayGroup.appendChild(holidaysRect);
  
    var holidaysText = document.createElementNS("http://www.w3.org/2000/svg", "text");
    holidaysText.textContent = 'HOLIDAYS';
    holidaysText.setAttribute('x', getPositionFromDate(holidaysStart) + ((getPositionFromDate(holidaysEnd) - getPositionFromDate(holidaysStart))/2));
    holidaysText.setAttribute('y', y - (y / 6) );
    holidaysText.setAttribute('text-anchor','middle');
  holidaysText.setAttribute('font-size',2);
  holidaysText.setAttribute('fill', '#77B6EC');
    holdayGroup.appendChild(holidaysText);
  
    svg.appendChild(holdayGroup);
  
  
    var bugGroup = document.createElementNS("http://www.w3.org/2000/svg", "g");
    bugGroup.classList.add('bug-line'); 
  
    var assignLine = document.createElementNS("http://www.w3.org/2000/svg", "line");
    assignLine.setAttribute('x1', getPositionFromDate(new Date(bug.assign_time))); 
    assignLine.setAttribute('y1', y/2);
    assignLine.setAttribute('x2', getPositionFromDate(endDate));
    assignLine.setAttribute('y2', y/2);
    assignLine.setAttribute('stroke', bugColor);
    assignLine.setAttribute('stroke-opacity', 0.75);
    assignLine.setAttribute('stroke-width', 4);
    assignLine.setAttribute('stroke-linecap', 'round');
    bugGroup.appendChild(assignLine);
  
    if(bug.cf_last_resolved){
      var endCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
      endCircle.setAttribute('cx',getPositionFromDate(new Date(bug.cf_last_resolved)));
      endCircle.setAttribute('cy', y/2);
      endCircle.setAttribute('r', 1.5);
      endCircle.setAttribute('fill', '#B2A47D');
      endCircle.setAttribute('title',`RESOLVED ${bug.cf_last_resolved}`)
      bugGroup.appendChild(endCircle);
    }
  
    var bugLine = document.createElementNS("http://www.w3.org/2000/svg", "line");
    bugLine.setAttribute('title', `Bug ${bug.id} - ${bug.summary}`); 
    bugLine.setAttribute('x1', getPositionFromDate(new Date(bug.assign_time)));
    bugLine.setAttribute('y1', y/2);
    bugLine.setAttribute('x2', getPositionFromDate(endDate)); 
    bugLine.setAttribute('y2', y/2);
    bugLine.setAttribute('stroke', '#B2A47D');
    bugLine.setAttribute('stroke-width', 0.5);
    bugLine.setAttribute('stroke-linecap', 'round');
    bugGroup.appendChild(bugLine);
  
    bug.history.forEach(function(historyEntry, idx){
      if(! userColor[historyEntry.who]){
        userColor[historyEntry.who] = COLORS.shift();
      }
      var entryColor = userColor[historyEntry.who];
      var entryCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
      var entryDate = new Date(historyEntry.when);
      entryCircle.setAttribute('cx',getPositionFromDate(entryDate));
      entryCircle.setAttribute('cy', y/2);
      entryCircle.setAttribute('r', 1);
      entryCircle.setAttribute('fill', entryColor);
      entryCircle.setAttribute('title', `${historyEntry.when} - ${historyEntry.who} : ${historyEntry.changes.map((item) => (item.field_name + " " + item.added)).join(' - ')}`); 
      bugGroup.appendChild(entryCircle);
    });
  svg.querySelector('#loading').remove();
  svg.appendChild(bugGroup);
  console.log((bug.assign_time - FIRST_WEEKDAY.getTime()) / MS_A_DAY)
  for(var i = 0; i <= (bug.assign_time - FIRST_WEEKDAY.getTime()) / MS_A_DAY ; i++){
    var weekLine = document.createElementNS("http://www.w3.org/2000/svg", "line");
    var firstWeekDay = new Date(FIRST_WEEKDAY.getTime() + ( i * MS_A_DAY * 7));
    console.log(i,new Date(FIRST_WEEKDAY.getTime() + ( i * MS_A_DAY * 7)))
    weekLine.setAttribute('x1', getPositionFromDate(firstWeekDay)); 
    weekLine.setAttribute('y1', 0);
    weekLine.setAttribute('x2', getPositionFromDate(firstWeekDay));
    weekLine.setAttribute('y2', y);
    weekLine.setAttribute('stroke', 'black');
    weekLine.setAttribute('stroke-opacity', 0.3);
    weekLine.setAttribute('stroke-width', 0.1);
    svg.appendChild(weekLine);
    
    var weekText = document.createElementNS("http://www.w3.org/2000/svg", "text");
    weekText.textContent = '-Week #'+ (i +1);
    weekText.setAttribute('x', getPositionFromDate(firstWeekDay));
    weekText.setAttribute('y', 2 );
    weekText.setAttribute('font-size',1.5);
    weekText.setAttribute('fill', '#888');
    svg.insertBefore(weekText, svg.firstChild);
  }
  
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console