Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move js functions to charts.js - Modify jQuery calls to use getJSON and remove host and port name from URLs - add restful services for showing charts; add charts.clj to send required JSON (for charts)
- Loading branch information
Showing
10 changed files
with
1,118 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
function createOptionTag (name, description) { | ||
var nameDesc = description + ' - ' + name; | ||
return '<option value="' + name + '">' + nameDesc + '</option>'; | ||
}; | ||
|
||
function showError (xhr) { | ||
$('#returnJson').html('Error: ' + xhr.status + ' ' + xhr.statusText); | ||
alert('error'); | ||
}; | ||
|
||
function populateColumns (data) { | ||
$.each(data, function(i, row) { | ||
if (i !== 0) | ||
$('#columnsSelect').append(createOptionTag(row.name, row.description)); | ||
}); | ||
}; | ||
|
||
function populateYear () { | ||
for (var year=2002; year<2012; year++) { | ||
$('#yearSelect').append('<option>'+year+'</option>'); | ||
} | ||
}; | ||
|
||
function renderChart (data) { | ||
// FusionCharts.setCurrentRenderer('javascript'); | ||
var myChart = new FusionCharts("js/Column3D.swf", | ||
"myChartId", "400", "300", "0", "1" ); | ||
myChart.setJSONData(data); | ||
myChart.render("chartContainer"); | ||
}; | ||
|
||
$(function() { | ||
// sufficient to wait for dom ready | ||
// no need to use $(document).ready(function() {} | ||
$.getJSON('/qa/def', populateColumns).error(showError); | ||
populateYear(); | ||
}); | ||
|
||
$(function() { | ||
$('#drawChartButton').click( | ||
function() { | ||
var baseUrl = '/qa/charts/period/'; | ||
var year = $('#yearSelect').val(); | ||
var cols = $('#columnsSelect').val() || []; | ||
var url = baseUrl + year + '/column/' + cols.join(''); | ||
|
||
$.getJSON(url, renderChart).error(showError); | ||
}); | ||
}); | ||
|
||
// $(function() { | ||
// $(document).ready(function() { | ||
// $.ajax({ | ||
// url: '/qa/def', | ||
// timeout: 5000, | ||
// type: 'GET', | ||
// dataType: 'json', | ||
// success: function(data) { | ||
// populateColumns(data); | ||
// }, | ||
// error: function (xhr) { | ||
// showError(xhr); | ||
// $('#returnJson').html('Error: ' + xhr.status + ' ' + xhr.statusText); | ||
// alert('error'); | ||
// } | ||
// }); | ||
// populateYear(); | ||
// }); | ||
// }); | ||
|
||
// $(function() { | ||
// $('#drawChartButton').click( | ||
// function() { | ||
// var baseUrl = '/qa/charts/period/'; | ||
// var year = $('#yearSelect').val(); | ||
// var cols = $('#columnsSelect').val() || []; | ||
// var url = baseUrl + year + '/column/' + cols.join(''); | ||
// var s = ""; | ||
|
||
// $.ajax({ | ||
// url: url, | ||
// timeout: 5000, | ||
// type: 'GET', | ||
// dataType: 'json', | ||
// success: function(data) { | ||
// renderChart(data); | ||
// }, | ||
// error: function (xhr) { | ||
// $('#returnJson').html('Error: ' + xhr.status + ' ' + xhr.statusText); | ||
// alert('error'); | ||
// } | ||
// }); | ||
// }); | ||
// }); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns adultcareqa.charts | ||
(:refer-clojure :exclude [replace]) | ||
(:use [clojure.string :as str])) | ||
|
||
(defn- get-label-value [row] | ||
(let [month-year (:Date row) | ||
month (join (take (if (= (count month-year) 6) 2 1) month-year)) | ||
val (:RP_N1 row)] | ||
(hash-map :label (str "Month " month) :value val))) | ||
|
||
(defn get-charts-map | ||
"Returns a map, which can be easily converted to the | ||
JSON representation as expected by Fusion charts." | ||
[caption x-axis-name y-axis-name data-array] | ||
{ | ||
:chart { | ||
:caption caption | ||
:xAxisName x-axis-name | ||
:yAxisName y-axis-name | ||
} | ||
:data (map #(get-label-value %) data-array) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters