Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve flot confiuration such that it displays actual dates in the x axis #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/saulabs/reportable/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module Config
:grid => {
:show => false
},
:xaxis => {
:mode => :time
},
:series => {
:lines => {
:fill => true,
Expand Down
9 changes: 3 additions & 6 deletions lib/saulabs/reportable/report_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,9 @@ def flot_report_tag(data, options = {}, flot_options = {})
%Q{<div id="#{options[:dom_id]}" style="width:#{options[:width]}px;height:#{options[:height]}px;"></div>
<script type="text\/javascript" charset="utf-8">
$(function() {
var set = #{data.map{|d| d[1] }.to_json},
data = [];
for (var i = 0; i < set.length; i++) {
data.push([i, set[i]]);
}
$.plot($('##{options[:dom_id]}'), [data], #{flot_options.to_json});
// flot wants the x axis as a javascript timestamp, so that's the deal with the strftime below
var dataset = #{data.map{|d| [d[0].strftime("%s000"), d[1]]}.to_json};
$.plot($('##{options[:dom_id]}'), [dataset], #{flot_options.to_json});
});
</script>}
end
Expand Down