diff --git a/docs/area.asciidoc b/docs/area.asciidoc index f64a5922aae51..e690e5e0d68fa 100644 --- a/docs/area.asciidoc +++ b/docs/area.asciidoc @@ -67,6 +67,7 @@ values. *Scale Y-Axis to Data Bounds*:: The default Y axis bounds are zero and the maximum value returned in the data. Check this box to change both upper and lower bounds to match the values returned in the data. *Show Tooltip*:: Check this box to enable the display of tooltips. +*Show Sum of Series*:: Show a sum of all the values in each series next to it's label in the legend [float] [[area-viewing-detailed-information]] diff --git a/docs/line.asciidoc b/docs/line.asciidoc index b83431093c94f..12c89675403b9 100644 --- a/docs/line.asciidoc +++ b/docs/line.asciidoc @@ -48,6 +48,7 @@ values. *Show Tooltip*:: Check this box to enable the display of tooltips. *Scale Y-Axis to Data Bounds*:: The default Y-axis bounds are zero and the maximum value returned in the data. Check this box to change both upper and lower bounds to match the values returned in the data. +*Show Sum of Series*:: Show a sum of all the values in each series next to it's label in the legend After changing options, click the *Apply changes* button to update your visualization, or the grey *Discard changes* button to keep your visualization in its current state. diff --git a/docs/pie.asciidoc b/docs/pie.asciidoc index f3acb2c5c322b..5277dcb56df04 100644 --- a/docs/pie.asciidoc +++ b/docs/pie.asciidoc @@ -80,6 +80,8 @@ Select the *Options* tab to change the following aspects of the table: *Donut*:: Display the chart as a sliced ring instead of a sliced pie. *Show Tooltip*:: Check this box to enable the display of tooltips. +*Show Sum of Series*:: Show a sum of all the values in each series next to it's label in the legend + After changing options, click the *Apply changes* button to update your visualization, or the grey *Discard changes* button to keep your visualization in its current state. diff --git a/docs/vertbar.asciidoc b/docs/vertbar.asciidoc index 8b9938de4a5fd..a70f10cb9d998 100644 --- a/docs/vertbar.asciidoc +++ b/docs/vertbar.asciidoc @@ -69,6 +69,8 @@ Checkboxes are available to enable and disable the following behaviors: *Show Tooltip*:: Check this box to enable the display of tooltips. *Scale Y-Axis to Data Bounds*:: The default Y axis bounds are zero and the maximum value returned in the data. Check this box to change both upper and lower bounds to match the values returned in the data. +*Show Sum of Series*:: Show a sum of all the values in each series next to it's label in the legend + [float] [[vertbar-viewing-detailed-information]] diff --git a/src/core_plugins/kbn_vislib_vis_types/public/area.js b/src/core_plugins/kbn_vislib_vis_types/public/area.js index 8ba764e50a6d8..c1fe8f70b9342 100644 --- a/src/core_plugins/kbn_vislib_vis_types/public/area.js +++ b/src/core_plugins/kbn_vislib_vis_types/public/area.js @@ -32,7 +32,8 @@ export default function HistogramVisType(Private) { }, scales: ['linear', 'log', 'square root'], modes: ['stacked', 'overlap', 'percentage', 'wiggle', 'silhouette'], - editor: areaTemplate + editor: areaTemplate, + isLegendCountSupported: true }, schemas: new Schemas([ { diff --git a/src/core_plugins/kbn_vislib_vis_types/public/controls/vislib_basic_options.html b/src/core_plugins/kbn_vislib_vis_types/public/controls/vislib_basic_options.html index 3a69041a9e7df..c20950c391c70 100644 --- a/src/core_plugins/kbn_vislib_vis_types/public/controls/vislib_basic_options.html +++ b/src/core_plugins/kbn_vislib_vis_types/public/controls/vislib_basic_options.html @@ -16,4 +16,10 @@ Show Tooltip +
+ +
diff --git a/src/core_plugins/kbn_vislib_vis_types/public/controls/vislib_basic_options.js b/src/core_plugins/kbn_vislib_vis_types/public/controls/vislib_basic_options.js index fd7f7b9eaa8e0..19f9fef752640 100644 --- a/src/core_plugins/kbn_vislib_vis_types/public/controls/vislib_basic_options.js +++ b/src/core_plugins/kbn_vislib_vis_types/public/controls/vislib_basic_options.js @@ -8,6 +8,11 @@ module.directive('vislibBasicOptions', function ($parse, $compile) { return { restrict: 'E', template: vislibBasicOptionsTemplate, - replace: true + replace: true, + link: function ($scope, $el) { + $scope.showLegendCount = legendData => { + return $scope.vis.type.params.isLegendCountSupported; + }; + } }; }); diff --git a/src/core_plugins/kbn_vislib_vis_types/public/histogram.js b/src/core_plugins/kbn_vislib_vis_types/public/histogram.js index 40099fe4c7bf0..d17779231828d 100644 --- a/src/core_plugins/kbn_vislib_vis_types/public/histogram.js +++ b/src/core_plugins/kbn_vislib_vis_types/public/histogram.js @@ -28,7 +28,8 @@ export default function HistogramVisType(Private) { }, scales: ['linear', 'log', 'square root'], modes: ['stacked', 'percentage', 'grouped'], - editor: histogramTemplate + editor: histogramTemplate, + isLegendCountSupported: true }, schemas: new Schemas([ { diff --git a/src/core_plugins/kbn_vislib_vis_types/public/line.js b/src/core_plugins/kbn_vislib_vis_types/public/line.js index 0c7830da74583..9ff391dc3e0fc 100644 --- a/src/core_plugins/kbn_vislib_vis_types/public/line.js +++ b/src/core_plugins/kbn_vislib_vis_types/public/line.js @@ -31,7 +31,8 @@ export default function HistogramVisType(Private) { yAxis: {} }, scales: ['linear', 'log', 'square root'], - editor: lineTemplate + editor: lineTemplate, + isLegendCountSupported: true }, schemas: new Schemas([ { diff --git a/src/core_plugins/kbn_vislib_vis_types/public/pie.js b/src/core_plugins/kbn_vislib_vis_types/public/pie.js index 170178cf1d153..7a2acb9a19af8 100644 --- a/src/core_plugins/kbn_vislib_vis_types/public/pie.js +++ b/src/core_plugins/kbn_vislib_vis_types/public/pie.js @@ -20,7 +20,8 @@ export default function HistogramVisType(Private) { legendPosition: 'right', isDonut: false }, - editor: pieTemplate + editor: pieTemplate, + isLegendCountSupported: true }, responseConverter: false, hierarchicalData: true, diff --git a/src/ui/public/agg_response/hierarchical/_build_split.js b/src/ui/public/agg_response/hierarchical/_build_split.js index f4eb0fdf764ab..10a0bf5160cc6 100644 --- a/src/ui/public/agg_response/hierarchical/_build_split.js +++ b/src/ui/public/agg_response/hierarchical/_build_split.js @@ -1,9 +1,25 @@ +import _ from 'lodash'; import collectKeys from 'ui/agg_response/hierarchical/_collect_keys'; import AggResponseHierarchicalTransformAggregationProvider from 'ui/agg_response/hierarchical/_transform_aggregation'; export default function biuldSplitProvider(Private) { let transformer = Private(AggResponseHierarchicalTransformAggregationProvider); + function showLabelCount(vis) { + if (!vis || !vis.params || !vis.params.addLegendCount) return false; + if (!vis.type.params.isLegendCountSupported) return false; + return true; + } + function getSize(name, children) { + let nextChildren = _.pluck(children, 'children'); + let sizes = _.pluck(children, 'size'); + let size = _.reduce(children, (sum, child) => { + if (child.children) sum += getSize(name, child.children); + if (child.name === name) sum += child.size; + return sum; + }, 0); + return size; + } return function (agg, metric, aggData) { - // Ceate the split structure + // Create the split structure let split = { label: '', slices: { children: [] } }; // Transform the aggData into splits @@ -11,6 +27,17 @@ export default function biuldSplitProvider(Private) { // Collect all the keys split.names = collectKeys(split.slices.children); + + split.labels = {}; + _.map(split.names, name => { + const size = getSize(name, split.slices.children); + if (showLabelCount(agg.vis)) { + split.labels[name] = `${name} (${size})`; + } else { + split.labels[name] = name; + } + }); + return split; }; }; diff --git a/src/ui/public/agg_response/hierarchical/_collect_keys.js b/src/ui/public/agg_response/hierarchical/_collect_keys.js index 1b9a542462c75..db2cbfa1f0825 100644 --- a/src/ui/public/agg_response/hierarchical/_collect_keys.js +++ b/src/ui/public/agg_response/hierarchical/_collect_keys.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -export default function collectKeys(children) { +export default function collectKeys(children, showCounts = false) { let nextChildren = _.pluck(children, 'children'); let keys = _.pluck(children, 'name'); return _(nextChildren) diff --git a/src/ui/public/agg_response/point_series/_get_series.js b/src/ui/public/agg_response/point_series/_get_series.js index 817ec2712d96f..71a53bc929f99 100644 --- a/src/ui/public/agg_response/point_series/_get_series.js +++ b/src/ui/public/agg_response/point_series/_get_series.js @@ -5,7 +5,21 @@ export default function PointSeriesGetSeries(Private) { let getPoint = Private(AggResponsePointSeriesGetPointProvider); let addToSiri = Private(AggResponsePointSeriesAddToSiriProvider); - return function getSeries(rows, chart) { + function showLabelCount(vis) { + if (!vis || !vis.params || !vis.params.addLegendCount) return false; + if (!vis.type.params.isLegendCountSupported) return false; + return true; + } + + function canCountMetric(siri) { + const metricType = siri.values[0].aggConfigResult.aggConfig._opts.type; + if (siri.values.length === 0) return false; + if (!siri.values[0].aggConfigResult.aggConfig) return false; + if (['count', 'cardinality', 'sum'].indexOf(metricType) === -1) return false; + return true; + } + + return function getSeries(rows, chart, vis) { let aspects = chart.aspects; let multiY = _.isArray(aspects.y); let yScale = chart.yScale; @@ -50,6 +64,16 @@ export default function PointSeriesGetSeries(Private) { }); } + series = _.map(series, siri => { + if (showLabelCount(vis) && canCountMetric(siri)) { + const count = siri.values.reduce((prev, curr) => prev + curr.y, 0); + siri.legendLabel = `${siri.label} (${count})`; + } else { + siri.legendLabel = siri.label; + } + return siri; + }); + return series; }; }; diff --git a/src/ui/public/agg_response/point_series/point_series.js b/src/ui/public/agg_response/point_series/point_series.js index 0a2ccd90729c4..83d5b262456e6 100644 --- a/src/ui/public/agg_response/point_series/point_series.js +++ b/src/ui/public/agg_response/point_series/point_series.js @@ -28,7 +28,7 @@ export default function PointSeriesProvider(Private) { setupOrderedDateXAxis(vis, chart); } - chart.series = getSeries(table.rows, chart); + chart.series = getSeries(table.rows, chart, vis); delete chart.aspects; return chart; diff --git a/src/ui/public/vislib/lib/data.js b/src/ui/public/vislib/lib/data.js index a04e53daeb9a6..56ac0f5b2df16 100644 --- a/src/ui/public/vislib/lib/data.js +++ b/src/ui/public/vislib/lib/data.js @@ -601,6 +601,7 @@ export default function DataFactory(Private) { obj.slices = self._removeZeroSlices(obj.slices); _.forEach(self.getNames(obj, columns), function (name) { + name.legendLabel = obj.labels[name.label]; names.push(name); }); }); diff --git a/src/ui/public/visualize/visualize_legend.html b/src/ui/public/visualize/visualize_legend.html index de736616df7ad..5f3daf86fc968 100644 --- a/src/ui/public/visualize/visualize_legend.html +++ b/src/ui/public/visualize/visualize_legend.html @@ -17,9 +17,9 @@ ng-click="showDetails = !showDetails" ng-class="showDetails ? 'legend-value-full' : 'legend-value-truncate'" class="legend-value-title" - tooltip="{{legendData.label}}" + tooltip="{{legendData.legendLabel}}" > - {{legendData.label}} + {{legendData.legendLabel}}
diff --git a/src/ui/public/visualize/visualize_legend.js b/src/ui/public/visualize/visualize_legend.js index fa03abe422a56..d7b748a3c16f1 100644 --- a/src/ui/public/visualize/visualize_legend.js +++ b/src/ui/public/visualize/visualize_legend.js @@ -120,9 +120,7 @@ uiModules.get('kibana') return a.concat(b); }, []); return _.compact(_.uniq(values, 'label')); - } - - + }; } }; });