Skip to content

Business intelligence made simple

Updated chartkick.js

Andrew Kane6032e16e7828
diff --git a/app/assets/javascripts/blazer/chartkick.js b/app/assets/javascripts/blazer/chartkick.js
index b316744a..0c14f51b 100644
--- a/app/assets/javascripts/blazer/chartkick.js
+++ b/app/assets/javascripts/blazer/chartkick.js
@@ -243,6 +243,10 @@
return a[0].getTime() - b[0].getTime();
}
+ function sortByNumber(a, b) {
+ return a - b;
+ }
+
function loadAdapters() {
if (!HighchartsAdapter && "Highcharts" in window) {
var HighchartsAdapter = new function () {
@@ -889,6 +893,8 @@
var series = chart.data;
+ var sortedLabels = [];
+
var i, j, s, d, key, rows = [];
for (i = 0; i < series.length; i++) {
s = series[i];
@@ -900,9 +906,16 @@
rows[key] = new Array(series.length);
}
rows[key][i] = toFloat(d[1]);
+ if (sortedLabels.indexOf(key) === -1) {
+ sortedLabels.push(key);
+ }
}
}
+ if (detectType) {
+ sortedLabels.sort(sortByNumber);
+ }
+
var rows2 = [];
for (var j = 0; j < series.length; j++) {
rows2.push([]);
@@ -910,25 +923,25 @@
var day = true;
var value;
- for (i in rows) {
- if (rows.hasOwnProperty(i)) {
- if (detectType) {
- value = new Date(toFloat(i));
- // TODO make this efficient
- day = day && isDay(value);
- if (!dayOfWeek) {
- dayOfWeek = value.getDay();
- }
- week = week && isWeek(value, dayOfWeek);
- month = month && isMonth(value);
- year = year && isYear(value);
- } else {
- value = i;
- }
- labels.push(value);
- for (var j = 0; j < series.length; j++) {
- rows2[j].push(rows[i][j])
+ var k;
+ for (k = 0; k < sortedLabels.length; k++) {
+ i = sortedLabels[k];
+ if (detectType) {
+ value = new Date(toFloat(i));
+ // TODO make this efficient
+ day = day && isDay(value);
+ if (!dayOfWeek) {
+ dayOfWeek = value.getDay();
}
+ week = week && isWeek(value, dayOfWeek);
+ month = month && isMonth(value);
+ year = year && isYear(value);
+ } else {
+ value = i;
+ }
+ labels.push(value);
+ for (var j = 0; j < series.length; j++) {
+ rows2[j].push(rows[i][j])
}
}
@@ -981,7 +994,7 @@
if (step && timeDiff > 0) {
var unitStepSize = Math.ceil(timeDiff / step / (chart.element.offsetWidth / 100.0));
if (week) {
- unitStepSize = Math.round(unitStepSize / 7.0) * 7;
+ unitStepSize = Math.ceil(unitStepSize / 7.0) * 7;
}
options.scales.xAxes[0].time.unitStepSize = unitStepSize;
}
diff --git a/app/views/blazer/queries/run.html.erb b/app/views/blazer/queries/run.html.erb
index 579dd843..03fd333b 100644
--- a/app/views/blazer/queries/run.html.erb
+++ b/app/views/blazer/queries/run.html.erb
@@ -30,7 +30,7 @@
<% chart_options = {id: chart_id, min: nil} %>
<% series_library = {} %>
<% @columns.keys.select { |k| k.downcase == "target" }.each do |key| %>
- <% series_library[key] = {pointStyle: "line", hitRadius: 10, borderColor: "#109618", pointBackgroundColor: "#109618", backgroundColor: "#109618"} %>
+ <% series_library[key] = {pointStyle: "line", hitRadius: 5, borderColor: "#109618", pointBackgroundColor: "#109618", backgroundColor: "#109618"} %>
<% end %>
<% if blazer_maps? && @markers.any? %>
<div id="map" style="height: <%= @only_chart ? 300 : 500 %>px;"></div>