Feature: pivots are now regular visualizations that can be *saved*.

This commit is contained in:
Arik Fraimovich
2016-02-14 15:17:52 +02:00
parent d21e2a79cc
commit e3420acd4b
5 changed files with 80 additions and 28 deletions

View File

@@ -15,12 +15,13 @@
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"strict": false,
"trailing": true,
"smarttabs": true,
"globals": {
"angular": false,
"_": false,
"$": false,
"currentUser": false
}
}

View File

@@ -4,7 +4,6 @@ angular.module('redash', [
'redash.controllers',
'redash.filters',
'redash.services',
'redash.renderers',
'redash.visualization',
'plotly',
'plotly-chart',

View File

@@ -40,6 +40,19 @@
}
}]);
directives.directive('hashLink', ['$location', function($location) {
return {
restrict: 'A',
scope: {
'hash': '@'
},
link: function (scope, element) {
var basePath = $location.path().substring(1);
element[0].href = basePath + "#" + scope.hash;
}
};
}]);
directives.directive('rdTab', ['$location', function ($location) {
return {
restrict: 'E',

View File

@@ -1,29 +1,64 @@
var renderers = angular.module('redash.renderers', []);
(function() {
var module = angular.module('redash.visualization');
renderers.directive('pivotTableRenderer', function () {
module.directive('pivotTableRenderer', function () {
return {
restrict: 'E',
scope: {
queryResult: '='
},
template: "",
replace: false,
link: function($scope, element, attrs) {
$scope.$watch('queryResult && queryResult.getData()', function (data) {
if (!data) {
return;
}
restrict: 'E',
scope: {
queryResult: '=',
visualization: '='
},
template: "",
replace: false,
link: function($scope, element) {
$scope.$watch('queryResult && queryResult.getData()', function (data) {
if (!data) {
return;
}
if ($scope.queryResult.getData() == null) {
} else {
// We need to give the pivot table its own copy of the data, because its change
// it which interferes with other visualizations.
var data = $.extend(true, [], $scope.queryResult.getData());
$(element).pivotUI(data, {
renderers: $.pivotUtilities.renderers
}, true);
if ($scope.queryResult.getData() === null) {
} else {
// We need to give the pivot table its own copy of the data, because it changes
// it which interferes with other visualizations.
data = $.extend(true, [], $scope.queryResult.getRawData());
var options = {
renderers: $.pivotUtilities.renderers,
onRefresh: function(config) {
var configCopy = $.extend(true, {}, config);
//delete some values which are functions
delete configCopy.aggregators;
delete configCopy.renderers;
//delete some bulky default values
delete configCopy.rendererOptions;
delete configCopy.localeStrings;
if ($scope.visualization) {
$scope.visualization.options = configCopy;
}
});
}
}
});
}
};
if ($scope.visualization) {
$.extend(options, $scope.visualization.options);
}
$(element).pivotUI(data, options, true);
}
});
}
};
});
module.config(['VisualizationProvider', function (VisualizationProvider) {
var editTemplate = '<div/>';
var defaultOptions = {
};
VisualizationProvider.registerVisualization({
type: 'PIVOT',
name: 'Pivot Table',
renderTemplate: '<pivot-table-renderer visualization="visualization" query-result="queryResult"></pivot-table-renderer>',
editorTemplate: editTemplate,
defaultOptions: defaultOptions
});
}]);
})();

View File

@@ -240,7 +240,11 @@
</div>
</div>
<pivot-table-renderer ng-show="selectedTab == 'pivot'" query-result="queryResult"></pivot-table-renderer>
<div ng-show="selectedTab == 'pivot'">
<h3>
Pivot tables are now regular visualization, which you can create from the <a hash="add" hash-link>"New Visualization" tab</a> and <strong>save</strong>.
</h3>
</div>
<div ng-show="selectedTab == vis.id" ng-repeat="vis in query.visualizations">
<visualization-renderer visualization="vis" query-result="queryResult"></visualization-renderer>