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

Add line and scatter as new graphs #72

Closed
wants to merge 5 commits into from
Closed
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
13 changes: 12 additions & 1 deletion rd_ui/app/scripts/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@

$scope.tabs = [{'key': 'table', 'name': 'Table'}, {'key': 'chart', 'name': 'Chart'},
{'key': 'pivot', 'name': 'Pivot Table'}, {'key': 'cohort', 'name': 'Cohort'}];


$scope.chartType = 'line';
$scope.chartTypes = [
{value: 'line', name: 'Line'},
{value: 'bar', name: 'Bar'},
{value: 'scatter', name: 'Scattered Plot'}
];

$scope.updateChartType = function() {
$scope.$broadcast('chart-type-changed', $scope.chartType);
};

$scope.lockButton = function (lock) {
$scope.queryExecuting = lock;
};
Expand Down
11 changes: 10 additions & 1 deletion rd_ui/app/scripts/ng-highchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ angular.module('highchart', [])
// Making sure that the DOM is ready before creating the chart element, so it gets proper width.
$timeout(function(){
scope.chart = new Highcharts.Chart(newSettings);


//Update chart type when type changes
scope.$on('chart-type-changed', function(event, type){
_.each(scope.chart.series, function(s){
s.update({
'type': type
});
});
});

//Update when charts data changes
scope.$watch(function () {
return (scope.series && scope.series.length) || 0;
Expand Down
50 changes: 41 additions & 9 deletions rd_ui/app/scripts/query_fiddle/renderers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var renderers = angular.module('redash.renderers', []);
var defaultChartOptions = {
"title": {
"text": null
title: {
text: null
},
"tooltip": {
tooltip: {
valueDecimals: 2,
formatter: function () {
if (moment.isMoment(this.x)) {
Expand Down Expand Up @@ -68,12 +68,39 @@ var defaultChartOptions = {
enabled: false
},
plotOptions: {
"column": {
"stacking": "normal",
"pointPadding": 0,
"borderWidth": 1,
"groupPadding": 0,
"shadow": false
column: {
stacking: "normal",
pointPadding: 0,
borderWidth: 1,
groupPadding: 0,
shadow: false
},
line: {
dataLabels: {
enabled: true
}
},
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x} cm, {point.y} kg'
}
}
},
"series": []
Expand All @@ -98,6 +125,11 @@ renderers.directive('chartRenderer', function () {
} else {
$scope.chartSeries.splice(0, $scope.chartSeries.length);

var stacking = null;
if ($scope.stacking() === undefined) {
stacking = 'normal';
}

_.each($scope.queryResult.getChartData(), function (s) {
$scope.chartSeries.push(_.extend(s, {'stacking': 'normal'}, $scope.options));
});
Expand Down
1 change: 0 additions & 1 deletion rd_ui/app/scripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
if (series[seriesName] == undefined) {
series[seriesName] = {
name: seriesName,
type: 'column',
data: []
}
}
Expand Down
6 changes: 6 additions & 0 deletions rd_ui/app/styles/redash.css
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,10 @@ to add those CSS styles here. */
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}

/* Charts */
.chart-tab span {
display:block;
padding:10px;
}
5 changes: 4 additions & 1 deletion rd_ui/app/views/queryfiddle.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ <h3 class="panel-title">
<div class="row" ng-show="queryResult.getStatus() == 'done'">
<rd-tabs tabs-collection='tabs' selected-tab='selectedTab'></rd-tabs>

<div ng-show="selectedTab.key == 'chart'" class="col-lg-12">
<div ng-show="selectedTab.key == 'chart'" class="col-lg-12 chart-tab">
<span class="">
Graph type: <select ng-model="chartType" ng-options="c.value as c.name for c in chartTypes" ng-change="updateChartType()"></select>
</span>
<chart-renderer query-result="queryResult"></chart-renderer>
</div>

Expand Down