Skip to content

Commit

Permalink
Merge pull request elastic#7931 from ppisljar/fix/legendPosition
Browse files Browse the repository at this point in the history
Ability to set the position of legends
  • Loading branch information
ppisljar authored Aug 21, 2016
2 parents 0eae35b + 313eb21 commit 0d1762c
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core_plugins/kbn_vislib_vis_types/public/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function HistogramVisType(Private) {
shareYAxis: true,
addTooltip: true,
addLegend: true,
legendPosition: 'right',
smoothLines: false,
scale: 'linear',
interpolate: 'linear',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<div>
<div class="vis-option-item" ng-if="vis.params.addLegend">
<label>
Legend Position
<select
class="form-control"
ng-model="vis.params.legendPosition"
ng-options="position for position in ['top', 'left', 'right', 'bottom']"
>
</select>
</label>
</div>
<div class="vis-option-item">
<label>
<input type="checkbox" ng-model="vis.params.addTooltip">
Expand Down
1 change: 1 addition & 0 deletions src/core_plugins/kbn_vislib_vis_types/public/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function HistogramVisType(Private) {
shareYAxis: true,
addTooltip: true,
addLegend: true,
legendPosition: 'right',
scale: 'linear',
mode: 'stacked',
times: [],
Expand Down
1 change: 1 addition & 0 deletions src/core_plugins/kbn_vislib_vis_types/public/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function HistogramVisType(Private) {
shareYAxis: true,
addTooltip: true,
addLegend: true,
legendPosition: 'right',
showCircles: true,
smoothLines: false,
interpolate: 'linear',
Expand Down
1 change: 1 addition & 0 deletions src/core_plugins/kbn_vislib_vis_types/public/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function HistogramVisType(Private) {
shareYAxis: true,
addTooltip: true,
addLegend: true,
legendPosition: 'right',
isDonut: false
},
editor: pieTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

.collapsible-sidebar {
.flex-parent(0, 0, auto);
margin-right: 10px;
}

.visualization-options {
Expand Down
31 changes: 31 additions & 0 deletions src/ui/public/vislib/styles/_legend.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ visualize-legend {
flex-direction: row;
padding-top: 5px;

.vis-container--legend-left & {
flex-direction: row-reverse;
}
.vis-container--legend-right & {
flex-direction: row;
}
.vis-container--legend-top & {
flex-direction: column-reverse;
width: 100%;
padding-left: 25px;
}
.vis-container--legend-bottom & {
flex-direction: column;
width: 100%;
padding-left: 25px;
}

.header {
cursor: pointer;
width: 15px;
Expand All @@ -30,6 +47,11 @@ visualize-legend {
color: @sidebar-hover-color;
}

.vis-container--legend-top &,
.vis-container--legend-bottom & {
text-align: center;
}

padding-right: 5px;
font-size: 14px;
}
Expand All @@ -54,6 +76,15 @@ visualize-legend {
text-align: left;

flex-direction: column;

.vis-container--legend-top &,
.vis-container--legend-bottom & {
width: auto;

.legend-value {
display: inline-block;
}
}
}

.legend-ul.hidden {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/visualize/visualize.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h4>No results found</h4>
</div>
<div class="item bottom"></div>
</div>
<div div ng-hide="showNoResultsMessage()" class="vis-container">
<div div ng-hide="showNoResultsMessage()" class="vis-container {{getVisContainerClasses()}}">
<div
ng-style="loadingStyle"
ng-class="{ loading: vis.type.requiresSearch && searchSource.activeFetchCount > 0 }"
Expand Down
11 changes: 11 additions & 0 deletions src/ui/public/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ uiModules
return Boolean(requiresSearch && isZeroHits && shouldShowMessage);
};

const legendPositionToVisContainerClassMap = {
top: 'vis-container--legend-top',
bottom: 'vis-container--legend-bottom',
left: 'vis-container--legend-left',
right: 'vis-container--legend-right',
};

$scope.getVisContainerClasses = function () {
return legendPositionToVisContainerClassMap[$scope.vis.params.legendPosition];
};

$scope.spy = {};
$scope.spy.mode = ($scope.uiState) ? $scope.uiState.get('spy.mode', {}) : {};

Expand Down
13 changes: 13 additions & 0 deletions src/ui/public/visualize/visualize.less
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ visualize {
-webkit-transition: opacity 0.01s;
transition: opacity 0.01s;

&.vis-container--legend-left {
flex-direction: row-reverse;
}
&.vis-container--legend-right {
flex-direction: row;
}
&.vis-container--legend-top {
flex-direction: column-reverse;
}
&.vis-container--legend-bottom {
flex-direction: column;
}

&.spy-only {
display: none;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/visualize/visualize_legend.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="legend-col-wrapper" ng-if="labels.length">
<div ng-click="toggleLegend()" class="legend-toggle">
<i class="legend-icon fa" ng-class="open ? 'fa-chevron-circle-right' : 'fa-chevron-circle-left'"></i>
<i class="legend-icon fa {{getToggleLegendClasses()}}"></i>
</div>
<ul class="legend-ul" ng-show="open">

Expand Down
17 changes: 17 additions & 0 deletions src/ui/public/visualize/visualize_legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ uiModules.get('kibana')
$scope.uiState.set('vis.legendOpen', $scope.open);
};

$scope.getToggleLegendClasses = function () {
switch ($scope.vis.params.legendPosition) {
case 'top':
return $scope.open ? 'fa-chevron-circle-up' : 'fa-chevron-circle-down';
break;
case 'bottom':
return $scope.open ? 'fa-chevron-circle-down' : 'fa-chevron-circle-up';
break;
case 'left':
return $scope.open ? 'fa-chevron-circle-left' : 'fa-chevron-circle-right';
break;
case 'right':
default:
return $scope.open ? 'fa-chevron-circle-right' : 'fa-chevron-circle-left';
}
};

$scope.filter = function (legendData, negate) {
clickHandler({point: legendData, negate: negate});
};
Expand Down

0 comments on commit 0d1762c

Please sign in to comment.