controlp5 icon indicating copy to clipboard operation
controlp5 copied to clipboard

no getRange for Chart

Open jango-fx opened this issue 7 years ago • 3 comments

is there no way to retrieve the current range, to update it according to new maximum values?

jango-fx avatar Sep 21 '18 11:09 jango-fx

Hi, do you have a (runnable) example code to demonstrate the issue and the desired behaviour?

sojamo avatar Sep 22 '18 03:09 sojamo

i assumed there should be either a Chart.getRange()-method returning the range set by Chart.setRange(,) or Chart.getMin() and Chart.getMax() would return those values, but they don't seem to do so:

import controlP5.*;
ControlP5 cp5 = new ControlP5(this);
Chart myChart = cp5.addChart("dataflow").setRange(-0.5, 0.5);
println(myChart.getMin() +" / "+ myChart.getMax());

expected: -0.5 / 0.5 returns: 0 / 0

i can call setMin()/setMax() as a makeshift solution explicitly myself, though…

import controlP5.*;
ControlP5 cp5;
Chart myChart;

void setup() {
  size(300, 200);
  cp5 = new ControlP5(this);
  myChart = cp5.addChart("dataflow")
    .setPosition(50, 50)
    .setRange(-0.5, 0.5)
    .setView(Chart.LINE)
    ;

  myChart.addDataSet("incoming");
  myChart.setData("incoming", new float[100]);
}


void draw() {
  background(40);
  float val = (float) new java.util.Random().nextGaussian();
  myChart.push("incoming", val);

  float currentMin = min(myChart.getMin(), val);
  float currentMax = max(myChart.getMax(), val);
  myChart.setMin(currentMin);
  myChart.setMax(currentMax);
  myChart.setRange(currentMin, currentMax);
}

but i don't get why Chart.setRange(,) doesn't seem to access the same _myMin / _myMax as setMax() / getMax() inherited by the Controller class...

jango-fx avatar Sep 22 '18 18:09 jango-fx

Thanks for the example. Fixed in dev-2.2.7 branch

sojamo avatar Sep 26 '18 02:09 sojamo