Skip to content

Commit

Permalink
Some changes to test Atom's new commit thing!
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerryliu committed Jun 26, 2017
1 parent f2e109f commit c0f7798
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ bool Graph::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) {
return true;
}

bool Graph::update() {
const unsigned int Graph::scale_val(unsigned int raw_val) const {
const unsigned int scaled_val =
graph_y_start + graph_height -
((double)raw_val / Device::sensor_max_vals[type]) * graph_height;
return scaled_val;
}

const bool Graph::update() {
// update values
for (unsigned int i = 0; i < sensor_readings.size(); i++) {
const unsigned int raw_val =
(sensor_readings[i].cur_val >= 0) ? sensor_readings[i].cur_val : 0;
const unsigned int scaled_val =
graph_y_start + graph_height -
(double)raw_val / Device::sensor_max_vals[type] * graph_height;
const unsigned int scaled_val = scale_val(raw_val);
raw_vals[i].push_front(raw_val);
scaled_vals[i].push_front(scaled_val);
if (scaled_vals[i].size() > ticks + 1) {
Expand All @@ -56,8 +61,8 @@ bool Graph::update() {
// Refresh window
auto win = get_window();
if (win) {
Gdk::Rectangle r(0, 0, get_allocation().get_width(),
get_allocation().get_height());
Gdk::Rectangle r(graph_x_start, graph_y_start, graph_x_start + width,
graph_y_start + height);
win->invalidate_rect(r, false);
}
return true;
Expand All @@ -71,9 +76,7 @@ void Graph::check_resize() {
for (auto orig_y_it = raw_vals[i].begin(),
norm_y_it = scaled_vals[i].begin();
orig_y_it != raw_vals[i].end(); orig_y_it++, norm_y_it++) {
*norm_y_it =
graph_y_start + graph_height -
(double)(*orig_y_it) / Device::sensor_max_vals[type] * graph_height;
*norm_y_it = scale_val(*orig_y_it);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Graph : public Gtk::DrawingArea {
vector<Device::sensor_reading> sensor_readings;
vector<Gdk::RGBA> &m_colors;
bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override;
bool update();
const unsigned int scale_val (unsigned int raw_val) const;
const bool update();
void check_resize();
void draw_title(const Cairo::RefPtr<Cairo::Context> &cr);
void draw_graph_grid(const Cairo::RefPtr<Cairo::Context> &cr);
Expand Down

0 comments on commit c0f7798

Please sign in to comment.