noosfero | Use chartkick gem to improve the visualization of custom_form submissions. (!1316)

David Carlos gitlab at mg.gitlab.com
Thu Sep 28 18:10:44 BRT 2017


David Carlos commented on a discussion on plugins/custom_forms/lib/custom_forms_plugin/graph.rb:

> +  #    "percents" => {"foo" => 40, "bla" => 60}
> +  #   },
> +  #   {"data" => { "foo"=> 5, "test" => 7, "show_as" => "check_box"}}
> +  # ]
> +  # Each 'data' key on @query_results represents the data that will be used by
> +  # chartkick lib, to render a graph based on the show_as value. The 'percents'
> +  # key will be used to show the percentage by answer when render a pizza
> +  # chart.
> +  #
> +  # @answers_with_alternative_label have the format
> +  # [
> +  #   { "1" => {"foo" : 5}, "2" => {"bla": 7},
> +  #     "show_as" => {"show_as" => "radio"}
> +  #   },
> +  #   { "21" => {"foo" : 2}, "2" => {"test": 15},
> +  #     "show_as" => {"show_as" => "check_box"}

One of the behaviors of the Graph model is to transform `a`
```
[
  { "1" => {"foo" : 5}, "2" => {"bla": 7},
    "show_as" => {"show_as" => "radio"}
  }
]
```

to `b`
```
[
  {"data" => { "foo"=> 5, "bla" => 7, "show_as" => "radio"},
   "percents" => {"foo" => 40, "bla" => 60}
  }
]
```
To accomplish that, I iterate over each position on `a`,and for each hash element, I get it value, and merge on the final hash that will be used by chartkick. So when I get the value of `{ "1" => {"foo" : 5}`, I will have `{"foo" : 5}`. When I get the value of `"show_as" => {"show_as" => "radio"}`, I get `{"show_as" => "radio"}`. If I leave only `{"show_as" => "radio"}`, when I'm going to transform a -> b, I will have to check if the hash that I am getting the value, is not the "show_as" hash, because the value of `{"show_as" => "radio"}`, will be `radio`.

---
Reply to this email directly or view it on GitLab: https://gitlab.com/noosfero/noosfero/merge_requests/1316#note_41833292
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170928/dbf19bc2/attachment-0001.html>


More information about the Noosfero-dev mailing list