D3 Treemap- recursive rectangles are unexpectedly missing

I'm currently working on replicating a D3 zoomable treemap to gain a better understanding of D3 functionality. The original treemap can be found here:

TL;DR: My issue is that I am only able to see the first two children of the JSON object, but not the grandchildren and beyond. When I click on one of the children, instead of being redirected to '' (like in the original Ohio State treemap), an empty HTML document opens in my browser.

Debugging Efforts: In my console, I've stored the value of the JSON from 'zoomabletreemap.json' as 'treemap', and can access attributes like 'treemap.children[0].children'. But when I attempt to output these same children using console.log statements in my script, I receive 'undefined' for each child node below.

/* write children rectangles */

Additional details are shown below comparing expected versus actual output which clearly indicates there may be some overriding behavior occurring that removes the sub-nodes. I have compared my code with the source through to identify any significant differences, but none were spotted. Can someone guide me on identifying the error?

Here's a JS Fiddle link that presents the issue:

http://jsfiddle.net/gvcJ6/

The related HTML and JS script can be seen below:

<!DOCTYPE html>
<!-- Placeholders -->

The mentioned file 'zoomabletreemap.json' contains the following structure:

{
 "name": "Sitemap",
 "children": [
 <!-- Data goes here -->
 ]
}

Answer №1

After some experimentation, I decided to transition from the most recent version of D3.js to version 2. So, I replaced the code I originally obtained from the D3 website:

<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>

...with this updated version:

<script src="http://d3js.org/d3.v2.min.js" charset="utf-8"></script>

The change proved to be successful and everything worked smoothly!

Answer №2

Encountered a similar issue but managed to find a solution here:

Check out this helpful resource as well: http://jsfiddle.net/sreebabu/65ypcpg9/

Just make a simple change from "children" to "_children"

For example:

function accumulate(d) {
    return (d._children = d.children)
    ? d.value = d.children.reduce(function(p, v) { return p + accumulate(v); }, 0)
    : d.value;
  }

var g = g1.selectAll("g")
      .data(d._children)   // changed from d.children to d._children
      .enter().append("g");

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

jquery and radio button technology

I am attempting to create a basic function using jquery, but it is not functioning properly. Here is the radio button in question: <input type="radio" id="price" name="shipping" class="styled" /> In the head section of my HTML, I have included the ...

The Angular controller is defined in a separate file such that the controller file is loaded before the Module file

I have made progress in the following areas: I successfully created a module using the correct convention: var myApp = angular.module('myApp', []);. I ensured to include the empty array as the second parameter. In addition, I developed some con ...

We are experiencing difficulties rendering flash messages in Expressjs with Handlebars(hbs) and express-messages using flash-connect

I'm working on an express app and I want to display flash messages when a user signs up using a form. The technologies I am utilizing include Node.js, Express.js, Handlebars(hbs), connect-flash, and express-messages. To make finding errors easier, I ...

Having difficulties deciphering a JSON object converted from PHP in JavaScript

I'm encountering issues with decoding a JSON object in PHP that was created using JSON.stringify in JavaScript. It could be due to the fact that the object contains arrays. Here is the JSON data and the code snippet: $jsonString = "{"tabLabels":["tab ...

How to jest at node_modules that provide a function?

I've been working on a typeScript program that interacts with an external API. While writing tests for this program, I've encountered challenges in properly mocking the dependency on the external API to analyze the values passed to the API itself ...

"Pausing execution of a synchronous function by using Promise.all in JavaScript to wait for multiple promises to

Currently, I have numerous synchronous functions that need to run one after the other, and these are basic ajax requests responsible for rendering HTML content to the DOM. My goal is to execute all of these synchronous functions asynchronously at the same ...

jQuery and ajax for efficient data management

My father and I are collaborating on a project that involves developing a script to fetch data once a number is entered into a form. For instance, when an ID number is inputted and ENTER or SUBMIT is clicked, the form will display relevant information. Thi ...

Utilizing Google Web Fonts in Gatsby with Custom Styled Components

While using createGlobalStyle from styled-components for global styling, everything seems to be working fine except for applying Google fonts. I have tried multiple ways but can't seem to get it to work. Here's the code snippet: import { createG ...

The inability to access a route with an authentication guard in the app controller is causing the validate function in the local strategy file to not run

While trying to access my login route in the app.controller.ts of my rest api built with Nestjs and Prisma, I encountered a 401 error response. I have been closely following the official documentation provided by Nestjs on authentication (https://docs.nest ...

Angular beautiful URLs are not functioning

I recently developed a SPA angularJS application that was working perfectly fine with normal routing using hashes (e.g. somesite.com#/something). However, I became tired of the hash routing and discovered something called "pretty urls" with $locationProvid ...

Effectively handle multiple connections from nodejs to postgres using the pg library

I need to run a script that performs multiple queries using the pg library for managing connections. However, I am facing an issue where my program stops working when the connection pool is full and does not queue future queries. I have tried setting the p ...

The JQuery function fails to execute following a successful Ajax request

I recently ran into an issue with my Ajax call. Here's the code snippet in question: $("#start-upload-btn").click(function(){ $.ajax({ type: "post", url: "", data: { newProjectName: $('#project-name') ...

Validating input parameters with a Typescript union type

Looking to determine if a string contains a specific prefix from a union type: type Prefix = "ABC" | "DEF" | "GHI" ...; const hasPrefix = (str: string): boolean => { // Goal is to compare the first 3 characters of the string // With the prefixe ...

How to retrieve the current element in AngularJS version 1.x

I have done extensive research on how to get the current element in jQuery using $(this). However, I have not been able to find a similar method in AngularJS 1.x. Here is what I have tried: angular.element(this), but it does not work as expected. Below is ...

The conversion of the value of type java.lang.String cannot be processed as requested

When I try to fetch data from a MySQL table using Android and HttpURLConnection, I encounter the following error: W/System.err: org.json.JSONException: Value br of type java.lang.String cannot be converted to JSONObject The error specifically occurs ...

The dropdown feature is malfunctioning. (Using Angular 8 and Bootstrap)

I'm encountering an issue with displaying a dropdown and its options using the bootstrap directive 'ngbDropdown'. When I follow this example from the documentation: <div ngbDropdown class="d-inline-block"> <button class="btn ...

The issue of Datatables child row not refreshing when using AJAX

I'm attempting to retrieve child row data in Datatables using AJAX: $('#myTable tbody').on('click', 'td', function () { var tr = $(this).closest('tr'); var row = myTable.row( tr ); if ( row.child.isS ...

I am having trouble getting the jsTree ajax demo to load

I am having trouble running the basic demo "ajax demo" below, as the file does not load and the loading icon continues to churn. // ajax demo $('#ajax').jstree({ 'core' : { 'data' : { ...

Can someone show me how to implement arrow functions within React components?

I am facing an issue while working on a node and react project. Whenever I use an arrow function, it shows an error stating that the function is not defined. Despite trying various tutorials and guides, I am unable to resolve this issue. Below is the snipp ...

How come the data in my handsontable isn't being submitted to the controller action?

I'm having an issue sending the data from my handsontable to my controller action. Even though the table is working correctly and the action is being called, the object is null. How can I properly post the contents of my handsontable to the controller ...