Difficulty with Pomodoro clock's canvas ring function not working as expected

Hey everyone, good evening. I've been struggling with a particular section of code for quite some time now and could really use some help. When you check out the constructor at this.drawArc and then look into the prototype, I've printed a couple of things to the console. It's clear that this.count has a value logged, but strangely, this.drawArc does not seem to be registering any values. While this.minutes and this.toSeconds are functioning properly as the timer starts, why is drawArc failing to capture the values? Interestingly enough, the status ring was working perfectly fine before being placed in the constructor, but now it refuses to acknowledge any values. I have included a link to a JSFiddle below.

Some points to note: please bear in mind that this is an incomplete version - currently, you need to refresh the page if you wish to enter a new value in the input field. Once an input is given (the small circle above the button), hovering over the canvas (larger circle) will display the countdown. The hover functionality is added for those users who prefer just the visual representation of the status ring without the ticking clock. Any suggestions or ideas would be greatly appreciated. Thank you for your assistance in advance.
https://jsfiddle.net/asthewaterfalls/szn0mch1/9/

function Pomodoro(userInput) {
    this.minutes = userInput; 
    this.toSeconds = 60 * this.minutes;//seconds - actual
    this.cout = this.toSeconds; //for timer
    this.seconds = 0; //display
    this.count = 0; //for status ring 
    this.circleStart = Math.PI * 1.5;
    this.drawArc = (2 / this.toSeconds) * this.count;
}

Pomodoro.prototype.statusRing = function () {
    if(this.count <= this.toSeconds) {
        dom.canv.beginPath(); 
        dom.canv.arc(125, 125, 121, this.circleStart, Math.PI * (1.5 + this.drawArc), false);
        dom.canv.stroke();
        this.count++;
        console.log(this.count, this.drawArc);
        const timeout = setTimeout(() => this.statusRing(), 1000 );
    }
};

Answer №1

After reviewing your fiddle, I managed to add some animation to the blue ring encircling the clock with just a few tweaks. I did not verify the ratios or angles.

I transformed drawArg into a function that calculates using the current value as an argument and this.toSeconds as the maximum value:

this.drawArc = function(arg){ return (2 / this.toSeconds) * arg; };

In addition, I invoked the function in dom.conv.arc():

dom.canv.arc(/*...*/, Math.PI * (1.5 + this.drawArc(this.count)), /*...*/);

Here is the complete example:

function Pomodoro(userInput) {
    this.minutes = userInput;
    this.toSeconds = 60 * this.minutes;//seconds - actual
    this.cout = this.toSeconds; //for timer
    this.seconds = 0; //display
    this.count = 0; //for status ring 
    this.circleStart = Math.PI * 1.5;
    this.drawArc = function(arg){ return (2 / this.toSeconds) * arg; };
}

Pomodoro.prototype.statusRing = function () {
    if(this.count <= this.toSeconds) {
        dom.canv.beginPath(); 
        dom.canv.arc(125, 125, 121, this.circleStart, Math.PI * (1.5 + this.drawArc(this.count)), false);
        dom.canv.stroke();
        this.count++;
        console.log(this.count, this.drawArc);
        const timeout = setTimeout(() => this.statusRing(), 1000 );

    }
};

If you have any feedback on this solution, please feel free to share it ;)

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

Using JavaScript and HTML, showcase the capital city of a country along with its corresponding continent

As a newcomer to this platform, I am excited to share a code snippet that I have created using HTML and JavaScript. The code generates a textbox in an HTML page where users can type the name of a country. Upon inputting the country's name, the code dy ...

Is there a way in JavaScript to format an array's output so that numbers are displayed with only two decimal places?

function calculateTipAmount(bill) { var tipPercent; if (bill < 50 ) { tipPercent = .20; } else if (bill >= 50 && bill < 200){ tipPercent = .15; } else { tipPercent = .10; } return tipPercent * bill; } var bills = ...

Having trouble initiating npm?

I am currently learning Angular2, and I encountered some issues when trying to initiate the npm server by running npm start in the project's directory. Here are the errors I received: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Can the month dropdown in react-datepicker be modified to display numbers instead of names?

Here is the code I have: <DatePicker selected={value?.toDate()} onChange={(date) => this.handleMonthChange(date)} inline showMonthYearPicker dateFormat={this.props.formatString} /> I am seeking to modify it so that instead of d ...

tips for adding text to an input field after it has been submitted

Is there a way to automatically add text to an input field after the user has entered their information? For example, if a user types "youtube.com" into a search bar, could the input then apply ""? ...

Tips for showing all percentages on a Google PieChart

I'm currently encountering two issues. How can I ensure that the entire legend is visible below the graph? Sometimes, when the legend is too large, three dots are added at the end. Another problem I am facing involves pie charts. Is there a way to d ...

The table element fails to display in IE11 due to a rendering issue, displaying the error message: "Render error - TypeError: Object does not support the property or method 'entries'"

As someone new to web app development, I am currently working on a project that involves using Vue cli and antd components, with the additional challenge of ensuring compatibility with IE11. However, I have encountered an issue where IE11 does not render ...

Leverage vuejs' this.$refs to work with multiple elements at once

I am working with 4 select elements: <div class="form-row"> <div class="form-group col-3"> <label for="stateSelect">Status</label> <select v-model ...

Troubleshooting the Angular Fullstack + CORS issue: "XMLHttpRequest cannot load

I've been wracking my brain trying to figure this out. Utilizing the yeoman generator angular-fullstack, I created a simple Angular app on a NodeJS server with Express. The app makes remote service calls, so there are no API server side calls within ...

How to pass event data when clicking on a div using React

I'm curious about how the onClick event flows in React when clicking on a div. In my application, there's a ParentComponent that renders a ChildComponent which generates a div for each item in the props.options array. I have a couple of questio ...

Building multiple files in React allows developers to divide their code

Can a React/Redux application be split into modules during webpack build? For example, having a set of components for users and another set for invoices. I want webpack to generate users.js and invoices.js that can be imported into index.html. If I make ch ...

What is the best way to interact with a checkbox that has a label using Selenium in Node.js?

My HTML document contains multiple checkbox classes with different texts for each checkbox name. Here is a snippet of the HTML code: <div class="col-md-12 syllabus-div-1"> <h4 class="vertical-spacing">Coaching<i class="fa fa-graduation- ...

Creating interactive PDF files using ReactJS

Is there a way to create a PDF using React that supports styling and allows the content to be hidden on the page? I need to have a link in my app that, when clicked, generates a PDF and opens it in a new tab. I've tried out various packages but none s ...

Is there a way for me to confirm that I am receiving the 401 error when fetching data?

When using an async function to fetch data, how can one determine if a 401 error occurred during the data retrieval process? The code example is as follows: async function getBilling(url, id, date) { let header = { method: 'GE ...

Is it possible to import multiple versions of a JavaScript file using HTML and JavaScript?

After extensive research, I am starting to think that using multiple versions of the same JavaScript library on a single page is not possible (without utilizing jquery Can I use multiple versions of jQuery on the same page?, which I am not). However, I wan ...

React Error: Unable to Call function this.state.Data.map

I'm encountering an issue with mapping objects in ReactJS. Even though I am able to fetch data, when I try to map it, I receive the following error: this.state.Data.map is not a function Here's the code snippet: import React, { Component } fro ...

Executing numerous GET requests with varying parameters in AngularJS

Update: My apologies to those who answered, it turns out that the code was correct, but requests were being intercepted and losing all parameters. I am attempting to send repeated HTTP GET requests to a REST API based on the response, using the solution I ...

Verify if the header value corresponds

How can I validate the header value in a Node.js application? I want to restrict access to a certain route only if the user includes a specific header and its value matches what is expected. For instance, let's say the route requires a header like Acc ...

What is the best way to create a promise in a basic redux action creator?

My function add does not return any promises to the caller. Here's an example: let add = (foo) => {this.props.save(foo)}; In another part of my application, I want to wait for add() to finish before moving on to something else. However, I know t ...

What is the reason this switch statement functions only with one case?

Why is the switch statement not functioning properly? It seems to correctly identify the values and match them with the appropriate case, but it only works when there is a single case remaining. If there are multiple cases to choose from, nothing happens. ...