Get Extent of Complicated Data Structure in D3

Viewed 190

I am trying to get the extent of my xy-data which has this nested form:

data = [
        {"points": [{"x": 0, "y": 0}, {"x": -5, "y": 100}, {"x": 300, "y": 1}, ...],
         "rgbval": "rgb(0, 0, 0)"
        },
        {"points": [{"x": 1, "y": 2}, {"x": -7000, "y": 2}, {"x": 0, "y": 0}, ...],
         "rgbval": "rgb(255, 0, 0)"
        }, 
         .
         .
         .
       ]

In the case of this sample data, the values I'm looking for are:

x_domain = [-7000, 300]
y_domain = [0, 100]

I am able to get the extent of a particular group of points using:

for i in [0...data.length]
    console.log(d3.extent(data[i].points, (d) -> d.x))  # x_domain of i_th group of points
    console.log(d3.extent(data[i].points, (d) -> d.y))  # y_domain of i_th group of points

In the sample case, this would give me two x_domains and two y_domains. I want the domains of the overall xy data.

1 Answers
Related