grafica ending and then redrawing lines on same layer

edited March 2017 in Library Questions

How can I add a bunch of points to a grafica layer and have it cut off at certain point, but then have it start drawing lines again later. This all has the be on the same plot layer. To help visualize my question look at this simple code:

import grafica.*;

GPlot plot;

GPointsArray myArray = new GPointsArray(0);

void setup() {
  size(500, 500);

  plot = new GPlot(this, 0, 0, 500, 500);

  myArray.add(0, 0);
  myArray.add(1, 1);
  myArray.add(2, 2);
  myArray.add(3, 3);
  myArray.add(4, 4);
  myArray.add(5, 5);

  plot.setPoints(myArray);
  plot.defaultDraw();
}

It creates this graph:

line

I need it to appear like this by "ending" the line at (2,2) and then start drawing again at (3,3):

line2

I'm sure there's an easy way to pull this off that i'm not seeing...I imported a large data set and manually creating new layers for each cut off point seems unrealistic.

Answers

  • edited March 2017

    I imported a large data set and manually creating new layers for each cut off point seems unrealistic.

    This confuses me. There must be something about your data that I'm not understanding from your example.

    How do you know where these "certain point" cut-points should be if they aren't in your data set? If they are in your data set, why not just use them to generate layers?

  • edited March 2017

    @jeremydouglass My dataset displays the top 5 people for each time period. Depending on the period new people come in/out. Here's an example JSON:

        {"timeline": [
            {
                "x": 1,
                "people": [
                    {"Name": "Bob", "y": 8},
                    {"Name": "May", "y": 7},
                    {"Name": "Joe", "y": 4},
                    {"Name": "Larry", "y": 2},
                    {"Name": "Jamie", "y": 2}
                ]
            },
            {
                "x": 2,
                "people": [
                    {"Name": "Bob", "y": 12},
                    {"Name": "Joe", "y": 9},
                    {"Name": "May", "y": 8},
                    {"Name": "Larry", "y": 5},
                    {"Name": "Aaron", "y": 4}
                ]
            },
            {
                "x": 3,
                "people": [
                    {"Name": "Bob", "y": 21},
                    {"Name": "Joe", "y": 19},
                    {"Name": "May", "y": 16},
                    {"Name": "Larry", "y": 11},
                    {"Name": "Aaron", "y": 9}
                ]
            },
            {
                "x": 4,
                "people": [
                    {"Name": "May", "y": 32},
                    {"Name": "Bob", "y": 29},
                    {"Name": "Joe", "y": 22},
                    {"Name": "Larry", "y": 19},
                    {"Name": "Jamie", "y": 14}
                ]
            }
        ]}
    

    Notice how "Jamie" was in the first object, but fell out of the list until the very last one and re-appeared.

    The the graph will come out looking like in this video where people appear on the graph and end at certain times.

    I hope that makes sense...thanks for your help

  • Answer ✓

    Ok I figured this out. Adding a NaN as a point will make grafica cut the line. So the solution to my first example would look like this:

    myArray.add(0, 0);
    myArray.add(1, 1);
    myArray.add(2, 2);
    myArray.add(Float.NaN, Float.NaN);
    myArray.add(3, 3);
    myArray.add(4, 4);
    myArray.add(5, 5);
    
  • Great. Thxs for sharing your answer.

    Kf

Sign In or Register to comment.