Commit 18a815f7f3a375c1d68340f25ffa9678975a2370

Authored by Igor Kulikov
1 parent 9734f45e

#335: Improve flot charts tooltips layout (use columns). Improve legend layout (…

…prevent element overflow, use scrolling).
... ... @@ -546,16 +546,16 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele
546 546 var legendStyle;
547 547 switch($scope.legendConfig.position) {
548 548 case types.position.top.value:
549   - legendStyle = 'padding-bottom: 8px;';
  549 + legendStyle = 'padding-bottom: 8px; max-height: 50%; overflow-y: auto;';
550 550 break;
551 551 case types.position.bottom.value:
552   - legendStyle = 'padding-top: 8px;';
  552 + legendStyle = 'padding-top: 8px; max-height: 50%; overflow-y: auto;';
553 553 break;
554 554 case types.position.left.value:
555   - legendStyle = 'padding-right: 0px;';
  555 + legendStyle = 'padding-right: 0px; max-width: 50%; overflow-y: auto;';
556 556 break;
557 557 case types.position.right.value:
558   - legendStyle = 'padding-left: 0px;';
  558 + legendStyle = 'padding-left: 0px; max-width: 50%; overflow-y: auto;';
559 559 break;
560 560 }
561 561
... ...
... ... @@ -107,6 +107,14 @@ export default class TbFlot {
107 107 return divElement;
108 108 }
109 109
  110 + function seriesInfoDivFromInfo(seriesHoverInfo, seriesIndex) {
  111 + var units = seriesHoverInfo.units && seriesHoverInfo.units.length ? seriesHoverInfo.units : tbFlot.ctx.trackUnits;
  112 + var decimals = angular.isDefined(seriesHoverInfo.decimals) ? seriesHoverInfo.decimals : tbFlot.ctx.trackDecimals;
  113 + var divElement = seriesInfoDiv(seriesHoverInfo.label, seriesHoverInfo.color,
  114 + seriesHoverInfo.value, units, decimals, seriesHoverInfo.index === seriesIndex, null, seriesHoverInfo.tooltipValueFormatFunction);
  115 + return divElement.prop('outerHTML');
  116 + }
  117 +
110 118 if (this.chartType === 'pie') {
111 119 ctx.tooltipFormatter = function(item) {
112 120 var units = item.series.dataKey.units && item.series.dataKey.units.length ? item.series.dataKey.units : tbFlot.ctx.trackUnits;
... ... @@ -129,16 +137,42 @@ export default class TbFlot {
129 137 fontWeight: "700"
130 138 });
131 139 content += dateDiv.prop('outerHTML');
132   - for (var i = 0; i < hoverInfo.seriesHover.length; i++) {
133   - var seriesHoverInfo = hoverInfo.seriesHover[i];
134   - if (tbFlot.ctx.tooltipIndividual && seriesHoverInfo.index !== seriesIndex) {
135   - continue;
  140 + if (tbFlot.ctx.tooltipIndividual) {
  141 + var seriesHoverInfo = hoverInfo.seriesHover[seriesIndex];
  142 + if (seriesHoverInfo) {
  143 + content += seriesInfoDivFromInfo(seriesHoverInfo, seriesIndex);
  144 + }
  145 + } else {
  146 + var seriesDiv = $('<div></div>');
  147 + seriesDiv.css({
  148 + display: "flex",
  149 + flexDirection: "row"
  150 + });
  151 + const maxRows = 15;
  152 + var columns = Math.ceil(hoverInfo.seriesHover.length / maxRows);
  153 + var columnsContent = '';
  154 + for (var c = 0; c < columns; c++) {
  155 + var columnDiv = $('<div></div>');
  156 + columnDiv.css({
  157 + display: "flex",
  158 + flexDirection: "column"
  159 + });
  160 + var columnContent = '';
  161 + for (var i = c*maxRows; i < (c+1)*maxRows; i++) {
  162 + if (i == hoverInfo.seriesHover.length) {
  163 + break;
  164 + }
  165 + seriesHoverInfo = hoverInfo.seriesHover[i];
  166 + columnContent += seriesInfoDivFromInfo(seriesHoverInfo, seriesIndex);
  167 + }
  168 + columnDiv.html(columnContent);
  169 + if (c > 0) {
  170 + columnsContent += '<span style="width: 20px;"></span>';
  171 + }
  172 + columnsContent += columnDiv.prop('outerHTML');
136 173 }
137   - var units = seriesHoverInfo.units && seriesHoverInfo.units.length ? seriesHoverInfo.units : tbFlot.ctx.trackUnits;
138   - var decimals = angular.isDefined(seriesHoverInfo.decimals) ? seriesHoverInfo.decimals : tbFlot.ctx.trackDecimals;
139   - var divElement = seriesInfoDiv(seriesHoverInfo.label, seriesHoverInfo.color,
140   - seriesHoverInfo.value, units, decimals, seriesHoverInfo.index === seriesIndex, null, seriesHoverInfo.tooltipValueFormatFunction);
141   - content += divElement.prop('outerHTML');
  174 + seriesDiv.html(columnsContent);
  175 + content += seriesDiv.prop('outerHTML');
142 176 }
143 177 return content;
144 178 };
... ...