Unique Angular Circular Progress Bar SVG Interface Customization

The circular progress bar I have created was inspired by the angular-circular-progress repository on GitHub.

This is my current progress input:

https://i.sstatic.net/nDgfO.png

I am looking to customize the end of the progress bar with a small CIRCLE and a VALUE CENTRE that shows real-time animation value based on svg movement. How can I achieve this? Your help would be greatly appreciated.

This is the expected output:

https://i.sstatic.net/ZR4Zm.png

Here is my current code snippet:

angular.module('myModule', ['angular-circular-progress'])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="http://pencil.my/assets/js/circularProgress.js"></script>

<div ng-app="myModule">
<circular-progress
    value="80"
    max="100"
    orientation="1"
    radius="100"
    stroke="10"
    base-color="#fff"
    progress-color="#f9991d"
    iterations="100"
    animation="easeInOutCubic"
></circular-progress>
  </div>

Answer №1

Have you checked out ProgressBar.js for your needs?

var bar = new ProgressBar.Circle(container, {

    color: '#aaa',
   // Make sure to adjust size accordingly to prevent clipping
   strokeWidth: 4,
   trailWidth: 1,
   easing: 'easeInOut',
   duration: 1400,
   text: {
        autoStyleContainer: false
   },
   from: { color: '#aaa', width: 1 },
   to: { color: '#333', width: 4 },
   step: function(state, circle) {
       circle.path.setAttribute('stroke', state.color);
       circle.path.setAttribute('stroke-width', state.width);

        var value = Math.round(circle.value() * 100);
        if (value === 0) {
            circle.setText(''); 
        } else {
            circle.setText(value);
        }
}

Here is a Fiddle example.

Best regards, Alex

Answer №2

To achieve a dynamic effect with your circle, consider creating a group that incorporates a transparent object the same size as your circle. Position the small circle at one edge of this group and then proceed to rotate the group around its center. The structure of the SVG code for this could resemble:

<g id="pip" transform="rotate({{360/value}}, 50, 50)">
<!--The contents inside g tag-->
</g>

This method assumes that the diameter of the circle is set at 100 units.

Answer №3

Below is a simple function that can be used to map a number ranging from 0 to 100 to x and y coordinates necessary for outlining a circular path of a circle object using canvas tools:

function drawCircle(percentage, ctx) {
  var angle = percentage / 100.0;

  var xPos = 140 * Math.cos((angle * (2 * Math.PI)) - (Math.PI * .5));
  var yPos = -140 * Math.sin((angle * (2 * Math.PI)) - (Math.PI * .5) );

  ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
  ctx.beginPath();
  ctx.arc (xPos + 150, 150 - yPos, 10, 0, 2 * Math.PI);
  ctx.stroke();
}

To witness this function in action, check out the following plunker link: https://plnkr.co/edit/ePMK7DVLB3OH15oUJzr1?p=preview

This process involves taking the input number (ranging from 0 to 100), scaling it accordingly, converting it into radians, and finally transforming these radians into Cartesian coordinates.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unusual Behavior Causing Error: 'RangeError: Invalid time value'

Currently, I am developing a straightforward timestamp API using Express. Essentially, when a user inputs a date in 'regular' format, the API displays a JSON object with both the Unix format and the normal format. Below is the pertinent section o ...

Modify the input field in the datepicker to resemble a button

How can I transform an input field into a button that looks like this https://i.sstatic.net/BDk5C.png rather than this https://i.sstatic.net/UdXoE.png? The simple switch of tag names doesn't seem to work. Any suggestions on how to achieve this? cla ...

What steps can I take to help EventListener locate a specific class if it is experiencing difficulty?

In the process of creating a responsive navigation bar, everything seems to be functioning correctly except for a small javascript error that arises in my sub menu when clicking. Despite thoroughly checking through my index, script, and style files, I am ...

The functionality of loading JSON is not working properly in ePub3

Currently, I am working on a project involving the creation of an ePub3 eBook. One of the exciting features I have successfully integrated is three.js to showcase some models. My next goal is to develop 'hotspot' elements (small cubes that users ...

Updating and Preserving Content in Angular

I've encountered an issue while working on a code that allows users to edit and save a paragraph on the screen. Currently, the editing functionality is working fine and the save() operation is successful. However, after saving, the edited paragraph do ...

What is the primary function for Express.js and Node.js 10 in Google Cloud Functions?

My Node JS version is 10 Express JS version: 4.16.1 I understand that for Node JS 8, the entry point should be "app" The generated code (from `npm install -g express-generator) www #!/usr/bin/env node /** * Module dependencies. */ var app = require( ...

What is the most effective method for utilizing JSON as a database?

For my upcoming offline mobile web app project, I am considering using JSON to mirror some of my database tables and storing the data in localStorage. (Although Web SQL Database is an option, its future-proofing capabilities are questionable.) Initially, ...

What methods can be employed to reduce additional background tasks when altering a state in a React component?

Trying out Code I experimented with creating a React exercise code that showcases a bus and its seats. Reserved seats are marked in red and cannot be selected, while the remaining seats can be chosen by clicking on them and selecting a gender from a popup ...

JavaScript on Event

My task is to develop a landing page that requires users to input a promotion code in order to proceed. There are three possible scenarios: the user enters the correct code and is redirected to another page, the user enters the wrong code and is taken to a ...

Implementing React with multiple event listeners for a single click event

One of the challenges I'm facing is with a function called playerJoin() in my React app. This function is triggered when a specific button is clicked. It sends data to the server, which then checks if the information matches what is stored. If there i ...

attempting to retrieve the selected values from within an iframe

I'm attempting to access the values of an iframe element select within a dialog on my page. In my JS file, I wrote code to access a select with the ID "firstSelectms2side__sx", but it didn't work as expected. Setting aside the iframe, I also tr ...

Is there a way to reduce the code needed by typing {{id}} instead of {{object.id}} when working with JSON in AngularJS?

There's a question that has been bothering me for a while, and I couldn't find an answer through my searches. Imagine having $scope set as $scope.object = {id:1, name:"stackoverflow"}; Now, in the HTML code, I want to simply call {{id}} ...

What are the steps to prevent Phonegap InAppBrowser from caching the URL content?

I have implemented the InAppBrowser plugin to display a web page: window.open(encodeURI('http://app.website.com'), '_self', 'location=no,toolbar=no,hidden=yes'); After changing the content of the URL, I noticed that when I r ...

JavaScript is sending a variable to a .php file, which then returns data based on the variable. The information is displayed using JavaScript and AJAX, along with triggers set using the bind('input', function

Currently, I am attempting to create a form that automatically populates some input fields when there is a change. However, I am struggling to understand how to send the #url field to my PHP script. Any insights or suggestions would be greatly appreciated. ...

Change the page using JavaScript after submission

I am currently working on incorporating Firebase authentication into a Node.js Express-based application. However, I have encountered the following error: nexttick.js:45 Uncaught TypeError: Cannot read property 'redirect' of undefined This ...

Guide on programmatically choosing an option within a variable with the help of jQuery

Imagine having a variable named html, which holds select options like this: var html = '<select>'+ '<option value="10">10</option>'+ '<option value="20">20</option>'+ ...

The statement "document.getElementById('grand_total_display').innerHTML = "Total is : $"+variable;" is causing issues in Internet Explorer versions 6 and 7

document.getElementById('grand_total_display).innerHTML = "Total is : $"+variable; seems to be causing an error specifically in IE6 and IE7 Within my HTML, I have an element <li> identified as grand_total_display which contains some existing te ...

It appears that the setup function completes its execution before the onMount function is called in Vue 3

createApp({ setup() { let price = 0 onMounted() { // axios price = axios.response } return { price } } }).mount('#app') HTML <h6 id="app" class="mb-0"> ...

Interacting with APIs in Svelte applications

I'm fairly new to utilizing Svelte and JavaScript. I've been attempting to construct a page that incorporates numerous API components from external websites, but I'm facing some challenges. I'm uncertain about where exactly to place the ...

How can a button be linked directly to a particular list item?

I currently have a HTML tag within my React application that looks something like this: <ul> <li> Item 1 <button> Delete </button> </li> <li> Item 2 <button> ...