Skip to content

Commit

Permalink
Use a mulitiselect to select series
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuracj committed Apr 28, 2012
1 parent 6281b4f commit 7fc055f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 49 deletions.
68 changes: 23 additions & 45 deletions js/tbl_chart.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
var chart_xaxis_idx = -1;
var chart_series;
var chart_series_index = -1;
var chart_data;
var temp_chart_title;
var y_values_text;

$(function() {
var currentChart = null;
chart_series = 'columns';
chart_series = $('select[name="chartSeries"]').val();
// If no series is selected null is returned.
// In such case nitialize chart_series to empty array.
if (chart_series == null) {
chart_series = new Array();
}
chart_xaxis_idx = $('select[name="chartXAxis"]').val();
y_values_text = $('input[name="yaxis_label"]').val();

Expand Down Expand Up @@ -89,16 +93,16 @@ $(function() {
});

$('select[name="chartXAxis"]').change(function() {
chart_xaxis_idx = this.value;
chart_xaxis_idx = $(this).val();
var xaxis_title = $(this).children('option:selected').text();
$('input[name="xaxis_label"]').val(xaxis_title);
currentSettings.xAxis.title.text = xaxis_title;
drawChart();
});
$('select[name="chartSeries"]').change(function() {
chart_series = this.value;
chart_series_index = this.selectedIndex;
if (chart_series_index != 0) {
chart_series = $(this).val();

if (chart_series.length == 1) {
$('span.span_pie').show();
var yaxis_title = $(this).children('option:selected').text();
} else {
Expand Down Expand Up @@ -161,9 +165,7 @@ function isColumnNumeric(columnName)
var first = true;
var isNumeric = false;
$('select[name="chartSeries"] option').each(function() {
if (first) {
first = false;
} else if ($(this).val() == columnName) {
if ($(this).val() == columnName) {
isNumeric = true;
return false;
}
Expand Down Expand Up @@ -195,55 +197,31 @@ function PMA_queryChart(data, passedSettings)
case 'line':
case 'bar':
case 'pie':
if (chart_series == 'columns') {
var j = 0;
for (var i = 0, l = columnNames.length; i<l; i++) {
if (! isColumnNumeric(columnNames[i])) {
continue;
}
if (i != chart_xaxis_idx) {
series[j] = new Object();
series[j].data = new Array();
series[j].name = columnNames[i];

$.each(data, function(key, value) {
var floatVal;
if (value[columnNames[i]] != null) {
floatVal = parseFloat(value[columnNames[i]]);
} else {
floatVal = null;
}
series[j].data.push({
name: value[columnNames[chart_xaxis_idx]],
y: floatVal
});
if (j == 0 && ! xaxis.categories[value[columnNames[chart_xaxis_idx]]]) {
xaxis.categories.push(value[columnNames[chart_xaxis_idx]]);
}
});
j++;
}
var j = 0;
for (var i = 0; i < columnNames.length; i++) {
if (! isColumnNumeric(columnNames[i]) || $.inArray(columnNames[i], chart_series) == -1) {
continue;
}
} else {
series[0] = new Object();
series[0].data = new Array();
series[0].name = chart_series;
series[j] = new Object();
series[j].data = new Array();
series[j].name = columnNames[i];

$.each(data, function(key, value) {
var floatVal;
if (value[chart_series] != null) {
floatVal = parseFloat(value[chart_series]);
if (value[columnNames[i]] != null) {
floatVal = parseFloat(value[columnNames[i]]);
} else {
floatVal = null;
}
series[0].data.push({
series[j].data.push({
name: value[columnNames[chart_xaxis_idx]],
y: floatVal
});
if (! xaxis.categories[value[columnNames[chart_xaxis_idx]]]) {
if (j == 0 && ! xaxis.categories[value[columnNames[chart_xaxis_idx]]]) {
xaxis.categories.push(value[columnNames[chart_xaxis_idx]]);
}
});
j++;
}
break;
}
Expand Down
11 changes: 7 additions & 4 deletions tbl_chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
foreach ($keys as $idx => $key) {
if ($yaxis == -1 && (($idx == count($data[0]) - 1) || preg_match("/(date|time)/i", $key))) {
echo '<option value="' . htmlspecialchars($idx) . '" selected="selected">' . htmlspecialchars($key) . '</option>';
$yaxis=$idx;
$yaxis = $idx;
} else {
echo '<option value="' . htmlspecialchars($idx) . '">' . htmlspecialchars($key) . '</option>';
}
Expand All @@ -117,13 +117,16 @@
?>
</select><br />
<label for="select_chartSeries"><?php echo __('Series:'); ?></label>
<select name="chartSeries" id="select_chartSeries">
<option value="columns"><?php echo __('The remaining columns'); ?></option>
<select name="chartSeries" id="select_chartSeries" multiple="multiple">
<?php
$numeric_types = array('int', 'real', 'year', 'bit');
foreach ($keys as $idx => $key) {
if (in_array($fields_meta[$idx]->type, $numeric_types)) {
echo '<option>' . htmlspecialchars($key) . '</option>';
if ($idx == $yaxis) {
echo '<option value"' . htmlspecialchars($key) . '">' . htmlspecialchars($key) . '</option>';
} else {
echo '<option value"' . htmlspecialchars($key) . '" selected="selected">' . htmlspecialchars($key) . '</option>';
}
}
}
?>
Expand Down

0 comments on commit 7fc055f

Please sign in to comment.