Difficulty adding extra arguments to a function

I am currently working on a function in d3 that aims to evaluate the "time" of my data and determine if it falls within specific time intervals. This will then allow me to filter the data accordingly.

//begin with a function that checks if the time for each data point is within specified time intervals
function timeInterval(data, start, end) {
    var time = data.Time

    if (start <= time <= end) {           
        return "inline";
    } else {
        return "none";
    };   
 }

//set the visibility of points to either inline or none based on time interval
function updateTime(value) {
d3.selectAll(".events")
    .style("display", timeInterval("20:00", "24:00"));    
}


//Toggle update function when radio button is selected
d3.selectAll("#timeFilterRadioButton").on("change", function() {
updateTime()
});

My issue arises when attempting to call timeInterval with the start and end parameters. The problem occurs when I try to input

timeInterval("20:00", "24:00")
, as it results in an undefined time variable. Surprisingly, omitting any parameters allows the function to execute successfully:

 function updateTime(value) {
     d3.selectAll(".events")
        .style("display", timeInterval); //when calling timeInterval like this, the console.log shows the data's time property  
 }

Can anyone assist in identifying where my mistake lies?

Answer №1

To fetch the information, simply employ an anonymous function and encapsulate your timeInterval function inside it:

function updateClock(data) {
    d3.selectAll(".events")
        .style("display", function(d) {
            //your data is here---^
            return timeInterval(d, "20:00", "24:00")
            //apply it here-------^
        });
};

Unrelated, but consider this:

if (begin <= current <= finish)

This will yield a result of true for all instances where begin <= current time, irrespective of the finish.

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

Guide to making control bar fade out when video is paused on video.js

Is there a way for the control bar to automatically disappear when the video is paused? Thank you in advance! ...

What is the method for including an inner wrapper around an element in Angular?

Is there a way to create an Angular directive that adds an inner wrapper to a DOM element without replacing the inner content? I have tried implementing one, but it seems to be replacing instead of wrapping the content. (view example) Here is the HTML sni ...

What is the JQuery code to select a checkbox and display an input field?

I have created a function that retrieves a JSON response, and the data from this response is displayed in the input fields. This is a table. When I click the edit button, it sends a request to the master_get_items file and receives the response. Table sn ...

Input ENTER triggered JSON path loading

Upon clicking "enter", I am looking to display the description corresponding to the title. To achieve this, I have defined a variable to store the path of the description: var descri = json.query.results.channel.item.map(function (item) { return item. ...

Using an integer variable to iterate a string within a function in Python

Being a complete novice, I've tried delving into several related topics but I just can't seem to grasp it. My goal is to write a function that will iterate through the string s exactly "n" times. s="hello" n=2 When I use s[::n] it works fine ...

What is the best way to halt the current event handler thread's execution when another event is triggered that calls the same handler at

One of the functions in my code filters and sorts contents of a select dropdown based on input text entered by the user. The function filterSort() is triggered on each keyup event from the input field. Code $(inputTextField).keyup(function() { / ...

Tips for implementing Papa Parse to parse CSV files using JavaScript

I've been exploring their API without much luck. My goal is to extract data from CSV files that are sent to the client upon server entry. Here's the code snippet I attempted: // Attempting to parse local CSV file Papa.parse("data/premier leagu ...

Tips for sending JSON data through the POST method on an Android device

I have a URL and parameter called "data": URL: http://www.xxxx.ru/mobile-api-v1/query/ data={«type":1,"body":{"sortType":0,"categoryId":0,"count":50,"authorId":0,"lastId":0}} What is the correct way to include the key "data="? I keep getting an error mes ...

Send a JSONArray using Volley and fetch a StringresponseData

I am new to android development and currently exploring the use of volley for networking. I have a query regarding sending a JSONArray via a POST request using volley and expecting a String response. After downloading the volley files from Github, I found ...

Unable to retrieve the ID from JSON using the QueryParamqq

I need to retrieve two IDs (id and manufacturer_id) from two different tables. Everything works fine, but if I change the parameter value of id=661 in the URL: http://localhost:9999/TestJersey/rest/test/getID?id=661&manufacturer_id=1 An error occurs a ...

Is there a way to modify the domain of an iFrame's scr based on the parent window's URL?

Is there a way to dynamically change the scr="" attribute of an iFrame based on the current URL of the window? The goal is to have different values for the scr attribute depending on the parent window's URL. For example, if the parent window's UR ...

The build process encountered an error due to the absence of ESLint configuration after the import

Having recently worked on a Vue project created using Vue CLI, I found that eslint was also included in the project. Although I haven't utilized eslint much up to this point, I understand that it is beneficial for catching stylistic errors, semantic e ...

What is the best method to reset numerous select boxes within a form using jQuery?

What is the best way to reset multiple select boxes within a dynamically generated form using jQuery? There are several select boxes that may have selected options The select boxes are not known in advance as they are generated dynamically Some option ta ...

Is combining Nuxt 3 with WP REST API, Pinia, and local storage an effective approach for user authentication?

My current project involves utilizing NUXT 3 for the frontend and integrating Wordpress as the backend. The data is transmitted from the backend to the frontend through the REST API. The application functions as a content management system (CMS), with all ...

Is there a way to access the original query string without it being automatically altered by the browser?

I'm currently encountering an issue with query strings. When I send an activation link via email, the link contains a query string including a user activation token. Here's an example of the link: http://localhost:3000/#/activation?activation_cod ...

Could you provide the parameters for the next() function in Express?

Working with Express.js to build an API has been a game-changer for me. I've learned how to utilize middlewares, handle requests and responses, navigate through different middleware functions... But there's one thing that keeps boggling my mind, ...

Struggling to find the right strategy for obtaining real-time data while implementing customized filters

After spending a week scratching my head and experimenting with different approaches, I'm hoping to find some help here... I am working on an application that needs to provide real-time data to the client. I initially considered using Server-Sent-Eve ...

What is the process for executing mocha tests within a web browser?

Am I the only one who thinks that their documentation lacks proper instructions on running tests in the browser? Do I really need to create the HTML file they mention in the example? How can I ensure that it runs the specific test cases for my project? I ...

Looking to create a GitHub example in Fiddle but running into issues with getting the result?

I've been working on an example on Fiddle, but it's not functioning as expected. I want to implement i18next so that the text changes when the user switches languages. After searching for a solution, I came across this GitHub repository: https:// ...

Expanding the width of a Datatables within a Bootstrap modal

While working on my modal, I encountered an issue with the width of Datatables. Despite trying to adjust it to fit the modal size, it appears like this: Below is the jQuery code calling the Datatables: function retrieveTags(){ var identifier = $(&a ...