Having trouble with zoom functionality when attempting to drag a rectangle over a d3 series chart

I am having trouble implementing zoom functionality by dragging a rectangle over my series plot to specify the zoom interval. Here is the link to my plunkr:

http://plnkr.co/edit/isaHzvCO6fTNlXpE18Yt?p=preview

When I draw a rectangle over the chart using the mouse, the new chart extends beyond the boundaries of the X and Y axes. I initially believed that my group under the svg would handle the bounds of the series (path), but it seems I was wrong. Despite examining it closely for a while, I couldn't find a solution. Please disregard the angular aspect of the plunkr. I suspect the issue lies somewhere in the following code:

//Build series group
                        var series = svgGroup.selectAll(".series")
                            .data(data)
                            .enter().append("g")
                            .attr("class", "series");
                        //Build each series using the line function
                        series.append("path")
                            .attr("class", "line")
                            .attr("d", function (d) {
                                return line(d.series);
                            })
                            .attr("id", function (d) {
                                //While generating the id for each series, map series name to the path element.
                                //This is useful later on for dealing with legend clicks to enable/disable plots
                                legendMap[d.name] = this;
                                //Build series id
                                return buildPathId(d.name);
                            })
                            .style("stroke", function (d) {
                                //Use series name to get the color for plotting
                                return colorFcn(d.name);

                            })
                            .style("stroke-width", "1px")
                            .style("fill", "none");

Any assistance on this matter would be greatly appreciated.

Thank you kindly.

Answer №1

There may be an issue with the method renderChartWithinSpecifiedInterval when it comes to handling large values as parameters.

For example, in line 130, the max_x value being passed seems to be a very high number like time seconds.

var svg = renderChartWithinSpecifiedInterval(min_X, max_X, min_Y, max_Y, false);
max_X and min_X have values such as 1415171404335
min_Y is 0, max_Y is 100    

However, during the dragDrop operation in line 192:

function gEnd(d,i){
    svg.selectAll(".zoom-rect").remove();
    var svgGp = svg.select("g");
    var groupTransform = d3.transform(svgGp.attr("transform"));
    var xOffset = groupTransform.translate[0];
    var yOffset = groupTransform.translate[1];
    var xBegin = Math.min(xStart,xDyn) - xOffset;
    var xEnd = Math.max(xStart,xDyn) - xOffset;
    var yBegin = Math.min(yStart,yDyn)  - yOffset;
    var yEnd =  Math.max(yStart,yDyn)  - yOffset;
    renderChartWithinSpecifiedInterval(xBegin, xEnd, yBegin, yEnd, true);
    //It appears that here the parameter values are all in pixels
    like xBegin = 100, xEnd = 200
}

I hope this information helps clarify the situation!

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

Is it necessary to display a div if the chosen Datatables row contains a span?

Currently, I am dealing with a table that has attachments, but for illustration purposes, I'm using a copyright icon. My challenge lies in displaying or hiding the .newImage block based on whether the row contains a span element (copyright icon) when ...

How to recycle a texture in three.js?

Within my software, I come across numerous instances where I create geometries, each with its own meshing preferences (double-sided or not? Lambert or basic material?). Despite these variations, they all share the same texture. My goal is to load this comm ...

When dynamically loading content with ajax, dynamic content fails to function properly

Currently, I am attempting to incorporate dynamic content loading after the user logs in by utilizing $.ajax. Here is how it's being done: $.ajax({ url: "functions.php", type: "GET", data: login_info, datatype: 'html', a ...

How to incorporate the onkeyup event within the append function for input elements in JavaScript

var tvalue = []; function add_purchase(value){ if (value in tvalue) { return 0; }else{ tvalue.push(value); } var obj = document.getElementById('item'); var item = obj.options[obj.selectedIndex].text; ...

My JavaScript array is not working with the stringify function

I am trying to encode my JavaScript array into JSON using stringify. Here is the code: params["margin_left"] = "fd"; params["text"] = "df"; params["margin_to_delete"] = "df"; console.info(params); When I check the output in Chrome console, it shows: [m ...

Ways to specify an unused parameter within a function

As I work on my code, I encounter the need to separate the key and value from a request params object in order to validate the value using ObjectID. To achieve this, I decided to iterate over an array of entries and destructure the key and value for testin ...

Using Meteor: Sharing a variable among all methods in Meteor

Just dipped my toes into the world of Meteor and managed to create a simple turn-based multiplayer game. When player 2 joins the game, I update the Game collection using a Meteor.method. However, when I try to retrieve that update in another Meteor.method ...

What is the best way to utilize URL parameters to dynamically update a component's state within a class component

I am currently working on a React component that is making calls to two different API URLs, and the fetch operations are functioning as expected. However, I would like to utilize the URL handle structure, which looks like localhost://site/coins/[handle], a ...

The unique filter in AngularJS ng-repeat is malfunctioning

I'm attempting to utilize the following distinct filter <ng-repeat="item in allItems | distinct:'itemName'" value="{{item.itemName}}">{{item.itemName}}> However, I'm encountering an error like this, Error: [$injector:unpr ...

The nested try/catch block is failing to execute within the catch block

Here is a code snippet with nested try/catch blocks: static async myEx(){ return 'hello'; } static async myfunc() { try{ Logger.info('test1'); } catch(error){ Logger.info('test2'); try{ Logger.info('test3&ap ...

Is there a way to post an array of MongoDB documents embedded in req.body?

How can I send the data from req.body to this MongoDB model using a POST request to '/add'? const QuestionSchema = new mongoose.Schema({ description: String, alternatives: [{ text: { type: String, ...

Avoid duplicating the use of the same controller in a page to prevent mirroring each other

I have implemented MVC partial controls on my page twice to handle search functionality. Each partial control has its own controller for searching, resulting in my page having two controllers with the same name. <div ng-app="app" ng-controller="MainCon ...

Angular Material JS offers a feature called a "combined dropdown selection" that allows

Is it feasible to create a user interface that resembles the one shown in the screenshot using AngularJS Material (v1.1.8)? Check out this UI for reference. ...

Having trouble running Selenium through Protractor on Firefox following the Angular 2 update

Following the upgrade from Angular JS 1.4.x to Angular 2, encountering issues running Selenium tests through grunt-protractor-runner on Firefox. Once AngularJS is loaded, an unexpected error pops up: D:\...\node_modules\grunt-protractor-ru ...

Incorporate parent state changes in React Router using the Route component

I have a unique layout on my page consisting of a step progress bar at the top (similar to this example). In the center of the page, there is content that changes depending on which step is currently active. To handle the steps, I utilize a fixed component ...

Steps for inserting a menu item into a Material UI Card

Below is an example I'm working with: https://codesandbox.io/s/material-ui-card-styling-example-lcup6?fontsize=14 I am trying to add additional menu options such as Edit and Delete to the three dots menu link, but so far I have not been successful. ...

Interested in integrating server side JavaScript with your Android application?

Running a simple web page on a Raspberry Pi to toggle the board's LED with the click of a button. The button triggers a JavaScript function that controls the LED. Now, I want to be able to call this script from a button in an Android application... B ...

The calendar on the datetime picker is malfunctioning and not displaying any dates

The date and time picker feature appears to be malfunctioning on my website. I suspect it may be due to a conflict between the full calendar and gull admin theme that I am using. I have attempted various solutions but nothing seems to be working. How can ...

Create an AngularJs user registration form that includes a "confirm password" field to ensure that the passwords entered match each other

After finding the AngularJS user registration form at , I realized it only asks for the password once. To enhance this, I want to include a "repeat password" field and ensure that both passwords match. What could I be doing wrong in my attempt? <div ...

Filtering server-side components in Next.js to create a customized list

Having been accustomed to the previous architecture of Next.js, I embarked on a new project where I am exploring the use of server and client components in the latest architecture. Specifically, I have a page dedicated to displaying race results in a tabl ...