From ac538c35e90904375c16245a9a5c32d38ee137bc Mon Sep 17 00:00:00 2001 From: deecay Date: Mon, 20 Feb 2017 15:09:48 +0900 Subject: [PATCH 1/3] Add: option to hide pivot table controls --- client/app/visualizations/pivot/index.js | 86 ++++++++++++------- .../pivot/pivottable-editor.html | 9 ++ 2 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 client/app/visualizations/pivot/pivottable-editor.html diff --git a/client/app/visualizations/pivot/index.js b/client/app/visualizations/pivot/index.js index e723e4d0b..2fe72dc9d 100644 --- a/client/app/visualizations/pivot/index.js +++ b/client/app/visualizations/pivot/index.js @@ -2,6 +2,9 @@ import $ from 'jquery'; import 'pivottable'; import 'pivottable/dist/pivot.css'; +import editorTemplate from './pivottable-editor.html'; + + function pivotTableRenderer() { return { restrict: 'E', @@ -12,48 +15,65 @@ function pivotTableRenderer() { template: '', replace: false, link($scope, element) { - $scope.$watch('queryResult && queryResult.getData()', (data) => { - if (!data) { - return; - } - - if ($scope.queryResult.getData() !== null) { - // 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()); - const options = { - renderers: $.pivotUtilities.renderers, - onRefresh(config) { - const configCopy = Object.assign({}, config); - // delete some values which are functions - delete configCopy.aggregators; - delete configCopy.renderers; - delete configCopy.onRefresh; - // delete some bulky default values - delete configCopy.rendererOptions; - delete configCopy.localeStrings; - - if ($scope.visualization) { - $scope.visualization.options = configCopy; - } - }, - }; - - if ($scope.visualization) { - Object.assign(options, $scope.visualization.options); + function updatePivot() { + $scope.$watch('queryResult && queryResult.getData()', (data) => { + if (!data) { + return; } - $(element).pivotUI(data, options, true); - } - }); + + if ($scope.queryResult.getData() !== null) { + // 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()); + const options = { + renderers: $.pivotUtilities.renderers, + onRefresh(config) { + const configCopy = Object.assign({}, config); + // delete some values which are functions + delete configCopy.aggregators; + delete configCopy.renderers; + delete configCopy.onRefresh; + // delete some bulky default values + delete configCopy.rendererOptions; + delete configCopy.localeStrings; + + if ($scope.visualization) { + $scope.visualization.options = configCopy; + } + }, + }; + + if ($scope.visualization) { + Object.assign(options, $scope.visualization.options); + } + $(element).pivotUI(data, options, true); + if ($scope.visualization.options.controls.enabled) { + const controls = $('.pvtAxisContainer, .pvtRenderer, .pvtVals'); + for (let i = 0; i < controls.length; i += 1) { controls[i].style.display = 'none'; } + } + } + }); + } + + $scope.$watch('queryResult && queryResult.getData()', updatePivot); + $scope.$watch('visualization.options.controls.enabled', updatePivot); }, }; } +function pivotTableEditor() { + return { + restrict: 'E', + template: editorTemplate, + }; +} + export default function (ngModule) { ngModule.directive('pivotTableRenderer', pivotTableRenderer); + ngModule.directive('pivotTableEditor', pivotTableEditor); ngModule.config((VisualizationProvider) => { - const editTemplate = '
'; + const editTemplate = ''; const defaultOptions = { }; diff --git a/client/app/visualizations/pivot/pivottable-editor.html b/client/app/visualizations/pivot/pivottable-editor.html new file mode 100644 index 000000000..696054ac3 --- /dev/null +++ b/client/app/visualizations/pivot/pivottable-editor.html @@ -0,0 +1,9 @@ +
+
+
+ + Hide Controls + +
+
+
From 081ac5f651fc7869154d3e89cb6acd6e3667adff Mon Sep 17 00:00:00 2001 From: deecay Date: Tue, 21 Feb 2017 17:18:14 +0900 Subject: [PATCH 2/3] Remove unnecessary comment line. --- client/app/visualizations/pivot/pivottable-editor.html | 1 - 1 file changed, 1 deletion(-) diff --git a/client/app/visualizations/pivot/pivottable-editor.html b/client/app/visualizations/pivot/pivottable-editor.html index 696054ac3..c573a685c 100644 --- a/client/app/visualizations/pivot/pivottable-editor.html +++ b/client/app/visualizations/pivot/pivottable-editor.html @@ -3,7 +3,6 @@
Hide Controls -
From 9f3fd021abb1fc7497b145d0238dd832c03a3206 Mon Sep 17 00:00:00 2001 From: deecay Date: Mon, 3 Apr 2017 16:25:23 +0900 Subject: [PATCH 3/3] Fix backward compatibility and resolve conflict --- client/app/visualizations/pivot/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/app/visualizations/pivot/index.js b/client/app/visualizations/pivot/index.js index 2fe72dc9d..00b1dde87 100644 --- a/client/app/visualizations/pivot/index.js +++ b/client/app/visualizations/pivot/index.js @@ -1,3 +1,4 @@ +import angular from 'angular'; import $ from 'jquery'; import 'pivottable'; import 'pivottable/dist/pivot.css'; @@ -24,7 +25,7 @@ function pivotTableRenderer() { if ($scope.queryResult.getData() !== null) { // 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()); + data = angular.copy($scope.queryResult.getData()); const options = { renderers: $.pivotUtilities.renderers, onRefresh(config) { @@ -47,7 +48,7 @@ function pivotTableRenderer() { Object.assign(options, $scope.visualization.options); } $(element).pivotUI(data, options, true); - if ($scope.visualization.options.controls.enabled) { + if (options.controls && options.controls.enabled) { const controls = $('.pvtAxisContainer, .pvtRenderer, .pvtVals'); for (let i = 0; i < controls.length; i += 1) { controls[i].style.display = 'none'; } }