• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Create Animated Progress Showing Favicon Like Pie Charts

By Abhishek Ghosh August 29, 2012 7:56 am Updated on August 29, 2012

Create Animated Progress Showing Favicon Like Pie Charts

Advertisement

Create Animated Progress Showing Favicon Like Pie Charts, sounds odd but there is no way to describe this cute function that adds a virtual progress bar in Pie. Chrome, Firefox and Opera currently supports these feature and trick.

 

How Create Animated Progress Showing Favicon Like Pie Charts

 

Its quite easy to create animated progress showing favicon like Pie Charts. Basically we will just show the usage of small Open Source javascript, its alteration and how to use it. The official name is Piecon – Pie charts in your favicon. It look like this while the webpage loading :

 

Create Animated Progress Showing Favicon Like Pie Charts

Create Animated Progress Showing Favicon Like Pie Charts : Guide, Tips and Resources

 

Go to this webpage :

Advertisement

---

 

Vim
1
https://github.com/lipka/piecon

 

Download the file named piecon.js. Open it any text editor with syntax highlighting feature like Gedit, it will look like this :

 

(function(){
var Piecon = {};

var currentFavicon = null;
var originalFavicon = null;
var originalTitle = null;
var canvas = null;
var options = {};
var defaults = {
color: ‘#ff0084‘,
background: ‘#bbb‘,
shadow: ‘#fff‘,
fallback: false
};

var ua = (function () {
var agent = navigator.userAgent.toLowerCase();
return function (browser) {
return agent.indexOf(browser) !== -1;
};
}());

var browser = {
ie: ua(‘msie’),
chrome: ua(‘chrome’),
webkit: ua(‘chrome’) || ua(‘safari’),
safari: ua(‘safari’) && !ua(‘chrome’),
mozilla: ua(‘mozilla’) && !ua(‘chrome’) && !ua(‘safari’)
};

var getFaviconTag = function() {
var links = document.getElementsByTagName(‘link’);

for (var i = 0, l = links.length; i < l; i++) {
if ((links[i].getAttribute(‘rel’) || ”).match(/biconb/)) {
return links[i];
}
}

return false;
};

var removeFaviconTag = function() {
var links = document.getElementsByTagName(‘link’);
var head = document.getElementsByTagName(‘head’)[0];

for (var i = 0, l = links.length; i < l; i++) {
if (typeof(links[i]) !== ‘undefined’ && links[i].getAttribute(‘rel’) === ‘icon’) {
head.removeChild(links[i]);
}
}
};

var setFaviconTag = function(url) {
removeFaviconTag();

var link = document.createElement(‘link’);
link.type = ‘image/x-icon’;
link.rel = ‘icon’;
link.href = url;

document.getElementsByTagName(‘head’)[0].appendChild(link);
};

var getCanvas = function () {
if (!canvas) {
canvas = document.createElement(“canvas”);
canvas.width = 16;
canvas.height = 16;
}

return canvas;
};

var drawFavicon = function(percentage) {
var canvas = getCanvas();
var context = canvas.getContext(“2d”);
var percentage = percentage || 0;
var src = currentFavicon;

var faviconImage = new Image();
faviconImage.onload = function() {
context.clearRect(0, 0, 16, 16);

// Draw shadow
context.beginPath();
context.moveTo(canvas.width / 2, canvas.height / 2);
context.arc(canvas.width / 2, canvas.height / 2, Math.min(canvas.width / 2, canvas.height / 2), 0, Math.PI * 2, false);
context.fillStyle = options.shadow;
context.fill();

// Draw background
context.beginPath();
context.moveTo(canvas.width / 2, canvas.height / 2);
context.arc(canvas.width / 2, canvas.height / 2, Math.min(canvas.width / 2, canvas.height / 2) – 2, 0, Math.PI * 2, false);
context.fillStyle = options.background;
context.fill();

// Draw pie
if (percentage > 0) {
context.beginPath();
context.moveTo(canvas.width / 2, canvas.height / 2);
context.arc(canvas.width / 2, canvas.height / 2, Math.min(canvas.width / 2, canvas.height / 2) – 2, (-0.5) * Math.PI, (-0.5 + 2 * percentage / 100) * Math.PI, false);
context.lineTo(canvas.width / 2, canvas.height / 2);
context.fillStyle = options.color;
context.fill();
}

if (context) {
setFaviconTag(canvas.toDataURL());
}
};

// allow cross origin resource requests if the image is not a data:uri
// as detailed here: https://github.com/mrdoob/three.js/issues/1305
if (!src.match(/^data/)) {
faviconImage.crossOrigin = ‘anonymous’;
}

faviconImage.src = src;
};

var updateTitle = function(percentage) {
if (options.fallback) {
if (percentage > 0) {
document.title = ‘(‘ + percentage + ‘%) ‘ + originalTitle;
} else {
document.title = originalTitle;
}
}
};

Piecon.setOptions = function(custom) {
options = {};

for (var key in defaults){
options[key] = custom.hasOwnProperty(key) ? custom[key] : defaults[key];
}

return this;
};

Piecon.setProgress = function(percentage) {
if (!originalTitle) {
originalTitle = document.title;
}

if (!originalFavicon || !currentFavicon) {
var tag = getFaviconTag();
originalFavicon = currentFavicon = tag ? tag.getAttribute(‘href’) : ‘/favicon.ico’;
}

if (!isNaN(parseFloat(percentage)) && isFinite(percentage)) {
if (!getCanvas().getContext || browser.ie || browser.safari || options.fallback == true) {
// Fallback to updating the browser title if unsupported
return updateTitle(percentage);
} else if (options.fallback === ‘force’) {
updateTitle(percentage);
}

return drawFavicon(percentage);
}

return false;
};

Piecon.reset = function() {
if (originalTitle) {
document.title = originalTitle;
}

if (originalFavicon) {
currentFavicon = originalFavicon;
setFaviconTag(currentFavicon);
}
};

Piecon.setOptions(defaults);
window.Piecon = Piecon;
})();

 

The reason to write the whole code is to show the variables. The red colored text can be altered according to your choice for showing the color of the pie chart. If you read the code’s comments, you will understand it is not very difficult to change for customizing the look.

 

Save it. Now the implementation part. If you place javascript at root of your server, add this code within header tag :

 

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<span style="color: #0000ff;">&lt;!doctype html&gt; </span>
<span style="color: #0000ff;">&lt;!More Stuffs Here&gt;</span>
<span style="color: #0000ff;">&lt;head&gt;</span>
 
<span style="color: #ff00ff;">&lt;script src="piecon.js"&gt;&lt;/script&gt;</span>
<span style="color: #ff00ff;">&lt;script&gt;</span>
<span style="color: #ff00ff;">(function(){</span>
<span style="color: #ff00ff;">var count = 0;</span>
<span style="color: #ff00ff;">Piecon.setOptions({fallback: 'force'});</span>
<span style="color: #ff00ff;">var i = setInterval(function(){</span>
<span style="color: #ff00ff;">if (++count &gt; 100) { Piecon.reset(); clearInterval(i); return false; }</span>
<span style="color: #ff00ff;">Piecon.setProgress(count);</span>
<span style="color: #ff00ff;">}, 250);</span>
<span style="color: #ff00ff;">})();</span>
<span style="color: #ff00ff;">&lt;/script&gt;</span>
 
<span style="color: #0000ff;">&lt;!More Stuffs Here&gt;</span>
<span style="color: #0000ff;">&lt;/head&gt;</span>

 

So, to create animated Progress Showing Favicon Like Pie Charts, you have to add it within the header tag. Change the script src to full url in case you have you have placed it in subfolder or a CDN. You can optimize the script by minifying it after modification and saving using any online tools to minify js. We said ” virtual progress bar” in the description as its actually not related to page loading progress. It will work for any webpage including free Blogger, Hosted WordPress or any HTML webpage where javascript can be added.

 

 

Signature

 

This Article Has Been Shared 742 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Create Animated Progress Showing Favicon Like Pie Charts

  • Cloud Computing Articles – List With Description of all we have Published

    Cloud Computing Solution penetrating as business solution and in day to day usage. Here is list of all articles on Cloud computing we have published so far.

  • Internet Marketing Plan For 2012-13 with Google's Services

    Internet Marketing Plan For 2012-13 emphasizes on how the Google’s Various Free and Paid Services can be properly used to make your monetization smooth.

  • Installing Podcast Generator on Rackspace Cloud Sites

    Installing Podcast Generator on Rackspace Cloud Sites is actually quite easy. Creating a sub directory or subdomain installation for Podcast keeps it clean.

  • iPhone App for Website : Practical Tips and Technical Guide

    iPhone App for website is easy to create and publish, you need a good CDN, a preferably good cloud platform, free resource as template and some tips to start.

  • Install WordPress 3.x on openSUSE

    Install WordPress 3.x on openSUSE is obviously a bit difficult than on a REHL based or Debian based Linux distro – here is step by step guide.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Comments

  1. Avatarwww says

    September 17, 2012 at 3:16 pm

    Spot on with this write-up, I actually feel this website needs far more attention.
    I’ll probably be back again to read through more, thanks for the information!

Subscribe To Our Free Newsletter

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (21K Followers)
  • Twitter (5.3k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • IoT Home Automation: Getting Started March 9, 2021
  • Basics on Python Tornado (web server) March 8, 2021
  • What You Need to Know About Hybrid Mobile App Development March 6, 2021
  • Why Not to Use Your Host for Email Marketing March 5, 2021
  • What You Need to Know About the Microservices March 4, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "Create Animated Progress Showing Favicon Like Pie Charts," in The Customize Windows, August 29, 2012, March 9, 2021, https://thecustomizewindows.com/2012/08/create-animated-progress-showing-favicon-like-pie-charts/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2021 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy