• 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 827 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, 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

Get new posts by email:

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 (24.3K Followers)
  • Twitter (5.8k 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

  • Online Dating: How to Find Your Match March 20, 2023
  • Web Design Cookbook: Logo March 19, 2023
  • How Starlink Internet Works March 17, 2023
  • The Importance of a Camera Tracking System in Virtual Production March 15, 2023
  • Understanding the Key Differences between Docker and OpenVZ March 14, 2023

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 21, 2023, https://thecustomizewindows.com/2012/08/create-animated-progress-showing-favicon-like-pie-charts/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

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

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

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

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT