Skip to content

Commit

Permalink
add auto scale toggle function
Browse files Browse the repository at this point in the history
  • Loading branch information
TetsuakiBaba committed Jun 3, 2019
1 parent 66ad835 commit 1200146
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified Example/.DS_Store
Binary file not shown.
Binary file modified Example/bin/.DS_Store
Binary file not shown.
38 changes: 29 additions & 9 deletions src/ofxGraph.cpp
Expand Up @@ -16,7 +16,6 @@ void ofxGraph::saveSettings()
xml_settings.setValue("settings:y", r.y);
xml_settings.setValue("settings:w", r.width);
xml_settings.setValue("settings:h", r.height);

xml_settings.saveFile(ofToDataPath("ofxGraph/"+name+".xml"));
}
void ofxGraph::setup(int _x, int _y, int _w, int _h)
Expand All @@ -39,7 +38,7 @@ void ofxGraph::setup(int _x, int _y, int _w, int _h)
slider_bufsize.addListener(this, &ofxGraph::setMaxLengthOfData);
button_clear.addListener(this, &ofxGraph::clear);

panel_size.set(100, 16);
panel_size.set(120, 16);
panel.setup();
panel.setSize(panel_size.x, panel_size.y);
panel.setDefaultHeight(panel_size.y);
Expand All @@ -51,7 +50,8 @@ void ofxGraph::setup(int _x, int _y, int _w, int _h)
panel.add(toggle_pause.setup("Pause", false));
panel.add(toggle_no_draw.setup("No draw", false));
panel.add(button_clear.setup("Clear"));

panel.add(toggle_auto_scale.setup("Auto Scale", false));
panel.add(slider_scale.setup("Y-Max", 1.0, 1.0, 1000.0));
min_height = panel.getHeight()+20;
min_width = panel.getWidth()+100;

Expand All @@ -61,6 +61,8 @@ void ofxGraph::setup(int _x, int _y, int _w, int _h)
void ofxGraph::setup(string _name)
{
setup(ofRandom(300)+200, ofRandom(200)+200, 500, 250);
scale = 1.0;
toggle_auto_scale = true;
setName(_name);
}

Expand Down Expand Up @@ -109,11 +111,17 @@ void ofxGraph::setColor(ofColor _color)
toggle_no_draw.setBackgroundColor(c_background);
toggle_no_draw.setFillColor(c_fill);

toggle_auto_scale.setTextColor(c_text);
toggle_auto_scale.setBackgroundColor(c_background);
toggle_auto_scale.setFillColor(c_fill);

panel.setTextColor(c_text);
panel.setFillColor(c_fill);
panel.setBackgroundColor(c_background);
panel.setHeaderBackgroundColor(c_background);




}
void ofxGraph::saveCSV()
Expand Down Expand Up @@ -352,7 +360,7 @@ void ofxGraph::basicOperation(ofxPanel _panel)
flg_inside_r_expand = false;
}

// dragg operation
// Mouse drag operation
if( flg_mouse_dragged && flg_inside_pressed == true){

// Expand
Expand Down Expand Up @@ -412,6 +420,13 @@ void ofxGraph::setLabel(vector<string>_label)
label.clear();
label = _label;
}

void ofxGraph::setAutoScale(bool _is_auto_scale, float _scale)
{
toggle_auto_scale = _is_auto_scale;
slider_scale = _scale;
}

void ofxGraph::draw()
{

Expand All @@ -428,13 +443,18 @@ void ofxGraph::draw()
for( int j = 0; j < plotdata.size(); j++ ){
if( plotdata[j].size() > 0 ){

if( max_data > fabs(min_data) ){
rate = max_data;
if( toggle_auto_scale ){
if( max_data > fabs(min_data) ){
rate = max_data;
}
else{
rate = min_data;
}
rate = fabs(rate);
}
else{
rate = min_data;
rate = slider_scale;
}
rate = fabs(rate);

if( toggle_no_draw == false ){
ofSetColor(color[j%10]);
Expand Down Expand Up @@ -462,7 +482,7 @@ void ofxGraph::draw()
}
x = 0.0;
}

ofSetColor(color[0]);



Expand Down
5 changes: 5 additions & 0 deletions src/ofxGraph.h
Expand Up @@ -29,6 +29,7 @@ class ofxGraph{
void setName(string _name);
void setPosition(float _x, float _y);
void setColor(ofColor _color);
void setAutoScale(bool _is_auto_scale, float _scale);
void setSize(float _w, float _h);
void clear();
void saveSettings();
Expand All @@ -52,7 +53,9 @@ class ofxGraph{
bool flg_inside_r_data = false;
bool flg_inside_r_expand = false;
bool flg_inside_r_gui = false;
bool is_auto_scale = true;

float scale;

vector<float> data;
vector<vector<float>> plotdata;
Expand Down Expand Up @@ -81,6 +84,8 @@ class ofxGraph{
ofxButton button_clear;
ofxToggle toggle_pause;
ofxToggle toggle_no_draw;
ofxToggle toggle_auto_scale;
ofxFloatSlider slider_scale;
int grid;
};

Expand Down

0 comments on commit 1200146

Please sign in to comment.