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>
  <body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.3.2/echarts.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <h3 id="title"></h3>
    <div id="main"></div>
    <button id="replay-btn">Replay</button>
  </body>
</html>

              
            
!

CSS

              
                #main {
  width: 600px;
  height: 400px;
  border: 1px solid red;
}
              
            
!

JS

              
                async function getJSON(url) {
  const response = await fetch(url);
  if (!response.ok) {
    throw response.status;
  } else {
    return await response.json();
  }
}

const baseUrl = "https://oss.x-lab.info/open_digger/github";
const repoName = "X-lab2017/open-digger";

const container = document.getElementById("main");
const chart = echarts.init(container);
const updateFrequency = 2000;
const colorMap = new Map();
const option = {
  grid: {
    top: 10,
    bottom: 30,
    left: 150,
    right: 80
  },
  xAxis: {
    max: "dataMax",
    axisLabel: {
      formatter: function (n) {
        return Math.round(n) + "";
      }
    }
  },
  yAxis: {
    type: "category",
    inverse: true,
    max: 10,
    axisLabel: {
      show: true,
      fontSize: 14,
      formatter: function (value) {
        if (!value || value.endsWith("[bot]")) return value;
        return `${value} {avatar${value.replaceAll("-", "")}|}`;
      },
      rich: null
    },
    animationDuration: 300,
    animationDurationUpdate: 300
  },
  series: [
    {
      realtimeSort: true,
      seriesLayoutBy: "column",
      type: "bar",
      itemStyle: {
        color: function (params) {
          const githubId = params.value[0];
          if (colorMap.has(githubId)) {
            return colorMap.get(githubId);
          } else {
            const randomColor =
              "#" + Math.floor(Math.random() * 16777215).toString(16);
            colorMap.set(githubId, randomColor);
            return randomColor;
          }
        }
      },
      data: null,
      encode: {
        x: 1,
        y: 0
      },
      label: {
        show: true,
        precision: 1,
        position: "right",
        valueAnimation: true,
        fontFamily: "monospace"
      }
    }
  ],
  // Disable init animation.
  animationDuration: 0,
  animationDurationUpdate: updateFrequency,
  animationEasing: "linear",
  animationEasingUpdate: "linear",
  graphic: {
    elements: [
      {
        type: "text",
        right: 60,
        bottom: 60,
        style: {
          text: null,
          font: "bolder 60px monospace",
          fill: "rgba(100, 100, 100, 0.25)"
        },
        z: 100
      }
    ]
  }
};

let playing = false;
async function play() {
  $('#title').text(repoName);
  playing = true;
  const data = await getJSON(`${baseUrl}/${repoName}/activity_details.json`);
  const months = Object.keys(data);
  let startIndex = 0;
  let startMonth = months[startIndex];

  for (let i = startIndex; i < months.length - 1; ++i) {
    (function (i) {
      setTimeout(function () {
        updateMonth(months[i + 1]);
        if (i + 1 === months.length - 1) {
          playing = false;
        }
      }, (i - startIndex) * updateFrequency);
    })(i);
  }
  function updateMonth(month) {
    const rich = {};
    data[month].forEach((item) => {
      // rich name cannot contain special characters such as '-'
      rich[`avatar${item[0].replaceAll("-", "")}`] = {
        backgroundColor: {
          image: `https://avatars.githubusercontent.com/${item[0]}?s=48&v=4`
        },
        height: 20
      };
    });
    option.yAxis.axisLabel.rich = rich;
    option.series[0].data = data[month];
    option.graphic.elements[0].style.text = month;
    chart.setOption(option);
  }
}

play();
$("#replay-btn").click(() => {
  if (playing) {
    alert("Already playing!");
    return;
  }
  play();
});

              
            
!
999px

Console