diff --git a/app/assets/javascripts/components/pf_charts/aggregate-status-card.component.js b/app/assets/javascripts/components/pf_charts/aggregate-status-card.component.js index f2ad70b2b9eb..1e2f9fbe52a6 100644 --- a/app/assets/javascripts/components/pf_charts/aggregate-status-card.component.js +++ b/app/assets/javascripts/components/pf_charts/aggregate-status-card.component.js @@ -3,16 +3,16 @@ angular.module( 'patternfly.card' ).component('pfAggregateStatusCard', { status: '=', showTopBorder: '@?', altLayout: '@?', - layout: '@?' + layout: '@?', }, templateUrl: '/static/pf_charts/aggregate-status-card.html.haml', - controller: function () { + controller: function() { 'use strict'; var vm = this; - vm.$onInit = function () { + vm.$onInit = function() { vm.shouldShowTopBorder = (vm.showTopBorder === 'true'); vm.isAltLayout = (vm.altLayout === 'true' || vm.layout === 'tall'); vm.isMiniLayout = (vm.layout === 'mini'); }; - } + }, }); diff --git a/app/assets/javascripts/components/pf_charts/c3-chart.component.js b/app/assets/javascripts/components/pf_charts/c3-chart.component.js index 1e10c128b540..19fc2eff7f42 100644 --- a/app/assets/javascripts/components/pf_charts/c3-chart.component.js +++ b/app/assets/javascripts/components/pf_charts/c3-chart.component.js @@ -1,34 +1,35 @@ angular.module('patternfly.charts').component('pfC3Chart', { bindings: { config: '<', - getChartCallback: '<' + getChartCallback: '<', }, template: '
', - controller: c3ChartController + controller: c3ChartController, }); -c3ChartController.$inject = ['$timeout', '$attrs'] +c3ChartController.$inject = ['$timeout', '$attrs']; function c3ChartController($timeout, $attrs) { - var vm = this, prevConfig; + var vm = this; + var prevConfig; // store the chart object var chart; - vm.generateChart = function () { + vm.generateChart = function() { var chartData; // Need to deep watch changes in chart config prevConfig = angular.copy(vm.config); - $timeout(function () { + $timeout(function() { chartData = vm.config; if (chartData) { chartData.bindto = '#' + $attrs.id; // only re-generate donut pct chart if it has a threshold object // because it's colors will change based on data and thresholds - if (!chart || ($attrs.id.indexOf('donutPctChart') !== -1 && chartData.thresholds)) { + if (! chart || ($attrs.id.indexOf('donutPctChart') !== -1 && chartData.thresholds)) { chart = c3.generate(chartData); } else { - //if chart is already created, then we only need to re-load data + // if chart is already created, then we only need to re-load data chart.load(vm.config.data); } if (vm.getChartCallback) { @@ -39,9 +40,9 @@ function c3ChartController($timeout, $attrs) { }); }; - vm.$doCheck = function () { + vm.$doCheck = function() { // do a deep compare on config - if (!angular.equals(vm.config, prevConfig)) { + if (! angular.equals(vm.config, prevConfig)) { vm.generateChart(); } }; diff --git a/app/assets/javascripts/components/pf_charts/donut-chart.component.js b/app/assets/javascripts/components/pf_charts/donut-chart.component.js index 4024be357a2c..f38a20e7a7ea 100644 --- a/app/assets/javascripts/components/pf_charts/donut-chart.component.js +++ b/app/assets/javascripts/components/pf_charts/donut-chart.component.js @@ -2,115 +2,116 @@ angular.module('patternfly.charts').component('pfDonutChart', { bindings: { config: '<', data: '<', - chartHeight: '' + chartHeight: '', }, templateUrl: '/static/pf_charts/donut-chart.html.haml', - controller: donutChartController + controller: donutChartController, }); -donutChartController.$inject = ['pfUtils', '$element', '$timeout', '$log'] +donutChartController.$inject = ['pfUtils', '$element', '$timeout', '$log']; function donutChartController(pfUtils, $element, $timeout, $log) { 'use strict'; - var vm = this, prevData; + var vm = this; + var prevData; - vm.$onInit = function () { + vm.$onInit = function() { vm.donutChartId = 'donutChart'; - if (vm.config.chartId) { - vm.donutChartId = vm.config.chartId + vm.donutChartId; - } + if (vm.config.chartId) { + vm.donutChartId = vm.config.chartId + vm.donutChartId; + } vm.updateAll(); }; - vm.getDonutData = function () { - return { - type: 'donut', - columns: vm.data, - order: null, - colors: vm.config.colors - }; + vm.getDonutData = function() { + return { + type: 'donut', + columns: vm.data, + order: null, + colors: vm.config.colors, }; + }; - vm.updateAll = function () { - // Need to deep watch changes in chart data - prevData = angular.copy(vm.data); + vm.updateAll = function() { + // Need to deep watch changes in chart data + prevData = angular.copy(vm.data); vm.config = pfUtils.merge(patternfly.c3ChartDefaults().getDefaultDonutConfig(), vm.config); vm.config.tooltip = { contents: patternfly.pfDonutTooltipContents }; vm.config.data = vm.getDonutData(); vm.config.data.onclick = vm.config.onClickFn; + }; - }; - - vm.getTotal = function () { - var total = 0; - angular.forEach(vm.data, function (value) { - angular.forEach(value, function (value) { - if (!isNaN(value)) { - total += Number(value); - } - }); + vm.getTotal = function() { + var total = 0; + angular.forEach(vm.data, function(value) { + angular.forEach(value, function(value) { + if (! isNaN(value)) { + total += Number(value); + } }); - return total; - }; - - vm.getCenterLabelText = function () { - var centerLabelText; - - // default - centerLabelText = { bigText: vm.getTotal(), - smText: vm.config.donut.title}; - - if (vm.config.centerLabelFn) { - centerLabelText.bigText = vm.config.centerLabelFn(); - centerLabelText.smText = ''; - } - - return centerLabelText; - }; + }); + return total; + }; - vm.setupDonutChartTitle = function () { - var donutChartTitle, centerLabelText; + vm.getCenterLabelText = function() { + var centerLabelText; - if (angular.isUndefined(vm.chart)) { - return; - } + // default + centerLabelText = { bigText: vm.getTotal(), + smText: vm.config.donut.title}; - donutChartTitle = d3.select(vm.chart.element).select('text.c3-chart-arcs-title'); - if (!donutChartTitle) { - return; - } + if (vm.config.centerLabelFn) { + centerLabelText.bigText = vm.config.centerLabelFn(); + centerLabelText.smText = ''; + } - centerLabelText = vm.getCenterLabelText(); + return centerLabelText; + }; - // Remove any existing title. - donutChartTitle.text(''); - if (centerLabelText.bigText && !centerLabelText.smText) { - donutChartTitle.text(centerLabelText.bigText); - } else { - donutChartTitle.insert('tspan').text(centerLabelText.bigText).classed('donut-title-big-pf', true).attr('dy', 0).attr('x', 0); - donutChartTitle.insert('tspan').text(centerLabelText.smText).classed('donut-title-small-pf', true).attr('dy', 20).attr('x', 0); - } - }; + vm.setupDonutChartTitle = function() { + var donutChartTitle; + var centerLabelText; + + if (angular.isUndefined(vm.chart)) { + return; + } + + donutChartTitle = d3.select(vm.chart.element).select('text.c3-chart-arcs-title'); + if (! donutChartTitle) { + return; + } + + centerLabelText = vm.getCenterLabelText(); + + // Remove any existing title. + donutChartTitle.text(''); + if (centerLabelText.bigText && ! centerLabelText.smText) { + donutChartTitle.text(centerLabelText.bigText); + } else { + donutChartTitle.insert('tspan').text(centerLabelText.bigText).classed('donut-title-big-pf', true).attr('dy', 0).attr('x', 0); + donutChartTitle.insert('tspan').text(centerLabelText.smText).classed('donut-title-small-pf', true).attr('dy', 20).attr('x', 0); + } + }; - vm.setChart = function (chart) { + vm.setChart = function(chart) { vm.chart = chart; vm.setupDonutChartTitle(); - }; + }; - vm.$onChanges = function (changesObj) { - if (changesObj.config || changesObj.data) { - vm.updateAll(); - } - if (changesObj.chartHeight) { - vm.config.size.height = changesObj.chartHeight.currentValue; - } - }; + vm.$onChanges = function(changesObj) { + if (changesObj.config || changesObj.data) { + vm.updateAll(); + } + if (changesObj.chartHeight) { + vm.config.size.height = changesObj.chartHeight.currentValue; + } + }; - vm.$doCheck = function () { - // do a deep compare on data - if (!angular.equals(vm.data, prevData)) { - vm.updateAll(); - } - }; + vm.$doCheck = function() { + // do a deep compare on data + if (! angular.equals(vm.data, prevData)) { + vm.updateAll(); + } + }; } diff --git a/app/assets/javascripts/components/pf_charts/donut-pct-chart.component.js b/app/assets/javascripts/components/pf_charts/donut-pct-chart.component.js index 6a171a195949..2574f4504761 100644 --- a/app/assets/javascripts/components/pf_charts/donut-pct-chart.component.js +++ b/app/assets/javascripts/components/pf_charts/donut-pct-chart.component.js @@ -4,18 +4,19 @@ angular.module('patternfly.charts').component('pfDonutPctChart', { data: '<', chartHeight: '', centerLabel: '', - onThresholdChange: '&' + onThresholdChange: '&', }, templateUrl: '/static/pf_charts/donut-pct-chart.html.haml', - controller: donutPctChartController + controller: donutPctChartController, }); -donutPctChartController.$inject = ['pfUtils', '$element', '$timeout'] +donutPctChartController.$inject = ['pfUtils', '$element', '$timeout']; function donutPctChartController(pfUtils, $element, $timeout) { 'use strict'; - var vm = this, prevData; + var vm = this; + var prevData; - vm.$onInit = function () { + vm.$onInit = function() { vm.donutChartId = 'donutPctChart'; if (vm.config.chartId) { vm.donutChartId = vm.config.chartId + vm.donutChartId; @@ -24,11 +25,11 @@ function donutPctChartController(pfUtils, $element, $timeout) { vm.updateAll(); }; - vm.updateAvailable = function () { + vm.updateAvailable = function() { vm.data.available = vm.data.total - vm.data.used; }; - vm.getStatusColor = function (used, thresholds) { + vm.getStatusColor = function(used, thresholds) { var threshold = "none"; var color = pfUtils.colorPalette.blue; @@ -44,7 +45,7 @@ function donutPctChartController(pfUtils, $element, $timeout) { } } - if (!vm.threshold || vm.threshold !== threshold) { + if (! vm.threshold || vm.threshold !== threshold) { vm.threshold = threshold; vm.onThresholdChange({ threshold: vm.threshold }); } @@ -52,8 +53,9 @@ function donutPctChartController(pfUtils, $element, $timeout) { return color; }; - vm.statusDonutColor = function () { - var color, percentUsed; + vm.statusDonutColor = function() { + var color; + var percentUsed; color = { pattern: [] }; percentUsed = vm.data.used / vm.data.total * 100.0; @@ -62,9 +64,9 @@ function donutPctChartController(pfUtils, $element, $timeout) { return color; }; - vm.donutTooltip = function () { + vm.donutTooltip = function() { return { - contents: function (d) { + contents: function(d) { var tooltipHtml; if (vm.config.tooltipFn) { @@ -78,35 +80,35 @@ function donutPctChartController(pfUtils, $element, $timeout) { } return tooltipHtml; - } + }, }; }; - vm.getDonutData = function () { + vm.getDonutData = function() { return { columns: [ ['Used', vm.data.used], - ['Available', vm.data.available] + ['Available', vm.data.available], ], type: 'donut', donut: { label: { - show: false - } + show: false, + }, }, groups: [ - ['used', 'available'] + ['used', 'available'], ], - order: null + order: null, }; }; - vm.getCenterLabelText = function () { + vm.getCenterLabelText = function() { var centerLabelText; // default to 'used' info. centerLabelText = { bigText: vm.data.used, - smText: vm.config.units + ' Used' }; + smText: vm.config.units + ' Used' }; if (vm.config.centerLabelFn) { centerLabelText.bigText = vm.config.centerLabelFn(); @@ -125,7 +127,7 @@ function donutPctChartController(pfUtils, $element, $timeout) { return centerLabelText; }; - vm.updateAll = function () { + vm.updateAll = function() { // Need to deep watch changes in chart data prevData = angular.copy(vm.data); @@ -137,15 +139,16 @@ function donutPctChartController(pfUtils, $element, $timeout) { vm.config.data.onclick = vm.config.onClickFn; }; - vm.setupDonutChartTitle = function () { - var donutChartTitle, centerLabelText; + vm.setupDonutChartTitle = function() { + var donutChartTitle; + var centerLabelText; if (angular.isUndefined(vm.chart)) { return; } donutChartTitle = d3.select(vm.chart.element).select('text.c3-chart-arcs-title'); - if (!donutChartTitle) { + if (! donutChartTitle) { return; } @@ -153,7 +156,7 @@ function donutPctChartController(pfUtils, $element, $timeout) { // Remove any existing title. donutChartTitle.selectAll('*').remove(); - if (centerLabelText.bigText && !centerLabelText.smText) { + if (centerLabelText.bigText && ! centerLabelText.smText) { donutChartTitle.text(centerLabelText.bigText); } else { donutChartTitle.insert('tspan').text(centerLabelText.bigText).classed('donut-title-big-pf', true).attr('dy', 0).attr('x', 0); @@ -161,12 +164,12 @@ function donutPctChartController(pfUtils, $element, $timeout) { } }; - vm.setChart = function (chart) { + vm.setChart = function(chart) { vm.chart = chart; vm.setupDonutChartTitle(); }; - vm.$onChanges = function (changesObj) { + vm.$onChanges = function(changesObj) { if (changesObj.config || changesObj.data) { vm.updateAll(); } @@ -178,9 +181,9 @@ function donutPctChartController(pfUtils, $element, $timeout) { } }; - vm.$doCheck = function () { + vm.$doCheck = function() { // do a deep compare on data - if (!angular.equals(vm.data, prevData)) { + if (! angular.equals(vm.data, prevData)) { vm.updateAll(); } }; diff --git a/app/assets/javascripts/components/pf_charts/empty-chart.component.js b/app/assets/javascripts/components/pf_charts/empty-chart.component.js index cbd6df5a212c..d0ca8dc16996 100644 --- a/app/assets/javascripts/components/pf_charts/empty-chart.component.js +++ b/app/assets/javascripts/components/pf_charts/empty-chart.component.js @@ -1,26 +1,26 @@ angular.module('patternfly.charts').component('pfEmptyChart', { bindings: { - chartHeight: '' + chartHeight: '', }, templateUrl: '/static/pf_charts/empty-chart.html.haml', - controller: function () { + controller: function() { 'use strict'; var vm = this; - vm.setSizeStyles = function () { + vm.setSizeStyles = function() { var height = vm.chartHeight || 40; var topPadding = Math.min(Math.round((height - 40) / 2), 20); vm.sizeStyles = { height: height + 'px', - 'padding-top': topPadding + 'px' + 'padding-top': topPadding + 'px', }; }; vm.setSizeStyles(); - vm.$onChanges = function (changesObj) { + vm.$onChanges = function(changesObj) { if (changesObj.chartHeight) { vm.setSizeStyles(); } }; - } + }, }); diff --git a/app/assets/javascripts/components/pf_charts/heatmap-legend.component.js b/app/assets/javascripts/components/pf_charts/heatmap-legend.component.js index 0ae178bac729..e24acc1f6d46 100644 --- a/app/assets/javascripts/components/pf_charts/heatmap-legend.component.js +++ b/app/assets/javascripts/components/pf_charts/heatmap-legend.component.js @@ -1,48 +1,48 @@ angular.module('patternfly.charts').component('pfHeatmapLegend', { bindings: { legend: '', - legendColors: '' + legendColors: '', }, templateUrl: '/static/pf_charts/heatmap-legend.html.haml', - controller: function () { + controller: function() { 'use strict'; var vm = this; var heatmapColorPatternDefaults = ['#d4f0fa', '#F9D67A', '#EC7A08', '#CE0000']; var legendLabelDefaults = ['< 70%', '70-80%', '80-90%', '> 90%']; - vm.$onInit = function () { + vm.$onInit = function() { vm.updateAll(); }; - vm.updateAll = function () { + vm.updateAll = function() { var items = []; var index; - //Allow overriding of defaults - if (!vm.legendColors) { + // Allow overriding of defaults + if (! vm.legendColors) { vm.legendColors = heatmapColorPatternDefaults; } - if (!vm.legend) { + if (! vm.legend) { vm.legend = legendLabelDefaults; } for (index = vm.legend.length - 1; index >= 0; index--) { items.push({ text: vm.legend[index], - color: vm.legendColors[index] + color: vm.legendColors[index], }); } vm.legendItems = items; }; - vm.$onChanges = function (changesObj) { - if (changesObj.legend && !changesObj.legend.isFirstChange()) { + vm.$onChanges = function(changesObj) { + if (changesObj.legend && ! changesObj.legend.isFirstChange()) { vm.updateAll(); } - if (changesObj.legendColors && !changesObj.legendColors.isFirstChange()) { + if (changesObj.legendColors && ! changesObj.legendColors.isFirstChange()) { vm.updateAll(); } }; - } + }, }); diff --git a/app/assets/javascripts/components/pf_charts/heatmap.component.js b/app/assets/javascripts/components/pf_charts/heatmap.component.js index 89ab7a0cda1a..7e4f316125f2 100644 --- a/app/assets/javascripts/components/pf_charts/heatmap.component.js +++ b/app/assets/javascripts/components/pf_charts/heatmap.component.js @@ -14,250 +14,253 @@ angular.module('patternfly.charts').component('pfHeatmap', { clickAction: '', rangeOnHover: '', rangeHoverSize: '@', - rangeTooltips: '' + rangeTooltips: '', }, templateUrl: '/static/pf_charts/heatmap.html.haml', - controller: heatmapController + controller: heatmapController, }); heatmapController.$inject = ['$element', '$window', '$compile', '$scope', '$timeout']; function heatmapController($element, $window, $compile, $scope, $timeout) { - 'use strict'; - var vm = this, prevData; - var containerWidth, containerHeight, blockSize, numberOfRows; - - var thresholdDefaults = [0.7, 0.8, 0.9]; - var heatmapColorPatternDefaults = ['#d4f0fa', '#F9D67A', '#EC7A08', '#CE0000']; - var legendLabelDefaults = ['< 70%', '70-80%' ,'80-90%', '> 90%']; - var rangeTooltipDefaults = ['< 70%', '70-80%' ,'80-90%', '> 90%']; - var heightDefault = 200; - - var setStyles = function () { - vm.containerStyles = { - height: vm.height + 'px', - display: vm.chartDataAvailable === false ? 'none' : 'block' - }; + 'use strict'; + var vm = this; + var prevData; + var containerWidth; + var containerHeight; + var blockSize; + var numberOfRows; + var thresholdDefaults = [0.7, 0.8, 0.9]; + var heatmapColorPatternDefaults = ['#d4f0fa', '#F9D67A', '#EC7A08', '#CE0000']; + var legendLabelDefaults = ['< 70%', '70-80%', '80-90%', '> 90%']; + var rangeTooltipDefaults = ['< 70%', '70-80%', '80-90%', '> 90%']; + var heightDefault = 200; + + var setStyles = function() { + vm.containerStyles = { + height: vm.height + 'px', + display: vm.chartDataAvailable === false ? 'none' : 'block', }; + }; - var setSizes = function () { - var parentContainer = $element[0].querySelector('.heatmap-container'); - containerWidth = parentContainer.clientWidth; - containerHeight = parentContainer.clientHeight; - blockSize = determineBlockSize(); + var setSizes = function() { + var parentContainer = $element[0].querySelector('.heatmap-container'); + containerWidth = parentContainer.clientWidth; + containerHeight = parentContainer.clientHeight; + blockSize = determineBlockSize(); - if ((blockSize - vm.padding) > vm.maxSize) { - blockSize = vm.padding + vm.maxSize; + if ((blockSize - vm.padding) > vm.maxSize) { + blockSize = vm.padding + vm.maxSize; - // Attempt to square off the area, check if square fits - numberOfRows = Math.ceil(Math.sqrt(vm.data.length)); - if (blockSize * numberOfRows > containerWidth || - blockSize * numberOfRows > containerHeight) { - numberOfRows = (blockSize === 0) ? 0 : Math.floor(containerHeight / blockSize); - } - } else if ((blockSize - vm.padding) < vm.minSize) { - blockSize = vm.padding + vm.minSize; - - // Attempt to square off the area, check if square fits - numberOfRows = Math.ceil(Math.sqrt(vm.data.length)); - if (blockSize * numberOfRows > containerWidth || - blockSize * numberOfRows > containerHeight) { - numberOfRows = (blockSize === 0) ? 0 : Math.floor(containerHeight / blockSize); - } - } else { + // Attempt to square off the area, check if square fits + numberOfRows = Math.ceil(Math.sqrt(vm.data.length)); + if (blockSize * numberOfRows > containerWidth || + blockSize * numberOfRows > containerHeight) { numberOfRows = (blockSize === 0) ? 0 : Math.floor(containerHeight / blockSize); } - }; - - var determineBlockSize = function () { - var x = containerWidth; - var y = containerHeight; - var n = vm.data ? vm.data.length : 0; - var px = Math.ceil(Math.sqrt(n * x / y)); - var py = Math.ceil(Math.sqrt(n * y / x)); - var sx, sy; + } else if ((blockSize - vm.padding) < vm.minSize) { + blockSize = vm.padding + vm.minSize; - if (Math.floor(px * y / x) * px < n) { - sx = y / Math.ceil(px * y / x); - } else { - sx = x / px; + // Attempt to square off the area, check if square fits + numberOfRows = Math.ceil(Math.sqrt(vm.data.length)); + if (blockSize * numberOfRows > containerWidth || + blockSize * numberOfRows > containerHeight) { + numberOfRows = (blockSize === 0) ? 0 : Math.floor(containerHeight / blockSize); } - - if (Math.floor(py * x / y) * py < n) { - sy = x / Math.ceil(x * py / y); - } else { - sy = y / py; + } else { + numberOfRows = (blockSize === 0) ? 0 : Math.floor(containerHeight / blockSize); + } + }; + + var determineBlockSize = function() { + var x = containerWidth; + var y = containerHeight; + var n = vm.data ? vm.data.length : 0; + var px = Math.ceil(Math.sqrt(n * x / y)); + var py = Math.ceil(Math.sqrt(n * y / x)); + var sx; + var sy; + + if (Math.floor(px * y / x) * px < n) { + sx = y / Math.ceil(px * y / x); + } else { + sx = x / px; + } + + if (Math.floor(py * x / y) * py < n) { + sy = x / Math.ceil(x * py / y); + } else { + sy = y / py; + } + return Math.max(sx, sy); + }; + + var redraw = function() { + var data = vm.data; + var color = d3.scale.threshold().domain(vm.thresholds).range(vm.heatmapColorPattern); + var rangeTooltip = d3.scale.threshold().domain(vm.thresholds).range(vm.rangeTooltips); + var blocks; + var fillSize = blockSize - vm.padding; + var highlightBlock = function(block, active) { + block.style('fill-opacity', active ? 1 : 0.4); + }; + var highlightBlockColor = function(block, fillColor) { + // Get fill color from given block + var blockColor = color(block.map(function(d) { + return d[0].__data__.value; + })); + // If given color matches, apply highlight + if (blockColor === fillColor) { + block.style('fill-opacity', 1); } - return Math.max(sx, sy); }; - var redraw = function () { - var data = vm.data; - var color = d3.scale.threshold().domain(vm.thresholds).range(vm.heatmapColorPattern); - var rangeTooltip = d3.scale.threshold().domain(vm.thresholds).range(vm.rangeTooltips); - var blocks; - var fillSize = blockSize - vm.padding; - var highlightBlock = function (block, active) { - block.style('fill-opacity', active ? 1 : 0.4); - }; - var highlightBlockColor = function (block, fillColor) { - // Get fill color from given block - var blockColor = color(block.map(function (d) { + var svg = window.d3.select(vm.thisComponent); + svg.selectAll('*').remove(); + blocks = svg.selectAll('rect').data(data).enter().append('rect'); + blocks.attr('x', function(d, i) { + return Math.floor(i / numberOfRows) * blockSize; + }).attr('y', function(d, i) { + return i % numberOfRows * blockSize; + }).attr('width', fillSize).attr('height', fillSize).style('fill', function(d) { + return color(d.value); + }).attr('uib-tooltip-html', function(d, i) { // tooltip-html is throwing an exception + if (vm.rangeOnHover && fillSize <= vm.rangeHoverSize) { + return '"' + rangeTooltip(d.value) + '"'; + } + return "'" + d.tooltip + "'"; + }).attr('tooltip-append-to-body', function(d, i) { + return true; + }).attr('tooltip-animation', function(d, i) { + return false; + }); + + // Adding events + blocks.on('mouseover', function() { + var fillColor; + blocks.call(highlightBlock, false); + if (vm.rangeOnHover && fillSize <= vm.rangeHoverSize) { + // Get fill color for current block + fillColor = color(d3.select(this).map(function(d) { return d[0].__data__.value; })); - // If given color matches, apply highlight - if (blockColor === fillColor) { - block.style('fill-opacity', 1); - } - }; - - var svg = window.d3.select(vm.thisComponent); - svg.selectAll('*').remove(); - blocks = svg.selectAll('rect').data(data).enter().append('rect'); - blocks.attr('x', function (d, i) { - return Math.floor(i / numberOfRows) * blockSize; - }).attr('y', function (d, i) { - return i % numberOfRows * blockSize; - }).attr('width', fillSize).attr('height', fillSize).style('fill', function (d) { - return color(d.value); - }).attr('uib-tooltip-html', function (d, i) { //tooltip-html is throwing an exception - if (vm.rangeOnHover && fillSize <= vm.rangeHoverSize) { - return '"' + rangeTooltip(d.value) + '"'; - } - return "'" + d.tooltip + "'"; - }).attr('tooltip-append-to-body', function (d, i) { - return true; - }).attr('tooltip-animation', function (d, i) { - return false; - }); - - //Adding events - blocks.on('mouseover', function () { - var fillColor; - blocks.call(highlightBlock, false); - if (vm.rangeOnHover && fillSize <= vm.rangeHoverSize) { - // Get fill color for current block - fillColor = color(d3.select(this).map(function (d) { - return d[0].__data__.value; - })); - // Highlight all blocks matching fill color - blocks[0].forEach(function (block) { - highlightBlockColor(d3.select(block), fillColor); - }); - } else { - d3.select(this).call(highlightBlock, true); - } - }); - blocks.on('click', function (d) { - if (vm.clickAction) { - vm.clickAction(d); - } - }); - - //Compiles the tooltips - angular.forEach(angular.element(blocks), function (block) { - var el = angular.element(block); - // TODO: get heatmap tooltips to work without using $compile or $scope - $compile(el)($scope); - }); - - svg.on('mouseleave', function () { - blocks.call(highlightBlock, true); - }); - }; - - vm.updateAll = function () { - // Need to deep watch changes in chart data - prevData = angular.copy(vm.data); - - //Allow overriding of defaults - if (vm.maxBlockSize === undefined || isNaN(vm.maxBlockSize)) { - vm.maxSize = 64; - } else { - vm.maxSize = parseInt(vm.maxBlockSize); - if (vm.maxSize < 5) { - vm.maxSize = 5; - } else if (vm.maxSize > 50) { - vm.maxSize = 50; - } - } - - if (vm.minBlockSize === undefined || isNaN(vm.minBlockSize)) { - vm.minSize = 2; + // Highlight all blocks matching fill color + blocks[0].forEach(function(block) { + highlightBlockColor(d3.select(block), fillColor); + }); } else { - vm.minSize = parseInt(vm.minBlockSize); + d3.select(this).call(highlightBlock, true); } - - if (vm.blockPadding === undefined || isNaN(vm.blockPadding)) { - vm.padding = 2; - } else { - vm.padding = parseInt(vm.blockPadding); + }); + blocks.on('click', function(d) { + if (vm.clickAction) { + vm.clickAction(d); } - - if (vm.rangeHoverSize === undefined || isNaN(vm.rangeHoverSize)) { - vm.rangeHoverSize = 15; - } else { - vm.rangeHoverSize = parseInt(vm.rangeHoverSize); - } - - vm.rangeOnHover = (vm.rangeOnHover === undefined || vm.rangeOnHover) ? true : false; - - if (!vm.rangeTooltips) { - vm.rangeTooltips = rangeTooltipDefaults; + }); + + // Compiles the tooltips + angular.forEach(angular.element(blocks), function(block) { + var el = angular.element(block); + // TODO: get heatmap tooltips to work without using $compile or $scope + $compile(el)($scope); + }); + + svg.on('mouseleave', function() { + blocks.call(highlightBlock, true); + }); + }; + + vm.updateAll = function() { + // Need to deep watch changes in chart data + prevData = angular.copy(vm.data); + + // Allow overriding of defaults + if (vm.maxBlockSize === undefined || isNaN(vm.maxBlockSize)) { + vm.maxSize = 64; + } else { + vm.maxSize = parseInt(vm.maxBlockSize); + if (vm.maxSize < 5) { + vm.maxSize = 5; + } else if (vm.maxSize > 50) { + vm.maxSize = 50; } + } + + if (vm.minBlockSize === undefined || isNaN(vm.minBlockSize)) { + vm.minSize = 2; + } else { + vm.minSize = parseInt(vm.minBlockSize); + } + + if (vm.blockPadding === undefined || isNaN(vm.blockPadding)) { + vm.padding = 2; + } else { + vm.padding = parseInt(vm.blockPadding); + } + + if (vm.rangeHoverSize === undefined || isNaN(vm.rangeHoverSize)) { + vm.rangeHoverSize = 15; + } else { + vm.rangeHoverSize = parseInt(vm.rangeHoverSize); + } + + vm.rangeOnHover = (vm.rangeOnHover === undefined || vm.rangeOnHover) ? true : false; + + if (! vm.rangeTooltips) { + vm.rangeTooltips = rangeTooltipDefaults; + } + + if (! vm.thresholds) { + vm.thresholds = thresholdDefaults; + } + + if (! vm.heatmapColorPattern) { + vm.heatmapColorPattern = heatmapColorPatternDefaults; + } + + if (! vm.legendLabels) { + vm.legendLabels = legendLabelDefaults; + } + vm.height = vm.height || heightDefault; + vm.showLegend = vm.showLegend || (vm.showLegend === undefined); + vm.loadingDone = false; + + angular.element($window).on('resize', function() { + setSizes(); + redraw(); + }); - if (!vm.thresholds) { - vm.thresholds = thresholdDefaults; - } - - if (!vm.heatmapColorPattern) { - vm.heatmapColorPattern = heatmapColorPatternDefaults; - } - - if (!vm.legendLabels) { - vm.legendLabels = legendLabelDefaults; - } - vm.height = vm.height || heightDefault; - vm.showLegend = vm.showLegend || (vm.showLegend === undefined); - vm.loadingDone = false; - - angular.element($window).on('resize', function () { - setSizes(); - redraw(); - }); - - vm.thisComponent = $element[0].querySelector('.heatmap-pf-svg'); - - $timeout(function () { - setStyles(); - setSizes(); - redraw(); - }); - }; - - vm.$onChanges = function (changesObj) { - if (changesObj.chartDataAvailable && !changesObj.chartDataAvailable.isFirstChange()) { - setStyles(); - } else { - vm.updateAll(); - vm.loadingDone = true; - } - }; - - vm.$doCheck = function () { - // do a deep compare on chartData and config - if (!angular.equals(vm.data, prevData)) { - setStyles(); - if (vm.chartDataAvailable !== false) { - setSizes(); - redraw(); - } - } - }; + vm.thisComponent = $element[0].querySelector('.heatmap-pf-svg'); - vm.$postLink = function () { + $timeout(function() { setStyles(); setSizes(); redraw(); - }; + }); + }; - } + vm.$onChanges = function(changesObj) { + if (changesObj.chartDataAvailable && ! changesObj.chartDataAvailable.isFirstChange()) { + setStyles(); + } else { + vm.updateAll(); + vm.loadingDone = true; + } + }; + + vm.$doCheck = function() { + // do a deep compare on chartData and config + if (! angular.equals(vm.data, prevData)) { + setStyles(); + if (vm.chartDataAvailable !== false) { + setSizes(); + redraw(); + } + } + }; + + vm.$postLink = function() { + setStyles(); + setSizes(); + redraw(); + }; +} diff --git a/app/assets/javascripts/components/pf_charts/line-chart.component.js b/app/assets/javascripts/components/pf_charts/line-chart.component.js index 6af3788963ff..84e79b82a745 100644 --- a/app/assets/javascripts/components/pf_charts/line-chart.component.js +++ b/app/assets/javascripts/components/pf_charts/line-chart.component.js @@ -4,18 +4,19 @@ angular.module('patternfly.charts').component('pfLineChart', { chartData: '<', showXAxis: '', showYAxis: '', - setAreaChart: '' + setAreaChart: '', }, templateUrl: '/static/pf_charts/line-chart.html', - controller: lineChartController + controller: lineChartController, }); -lineChartController.$inject = ['pfUtils'] +lineChartController.$inject = ['pfUtils']; function lineChartController(pfUtils) { 'use strict'; - var vm = this, prevChartData; + var vm = this; + var prevChartData; - vm.updateAll = function () { + vm.updateAll = function() { // Need to deep watch changes in chart data prevChartData = angular.copy(vm.chartData); @@ -50,19 +51,19 @@ function lineChartController(pfUtils) { show: vm.showXAxis === true, type: 'timeseries', tick: { - format: function () { + format: function() { return ''; - } - } + }, + }, }, y: { show: vm.showYAxis === true, tick: { - format: function () { + format: function() { return ''; - } - } - } + }, + }, + }, }; /* @@ -85,15 +86,15 @@ function lineChartController(pfUtils) { /* * Convert the config data to C3 Data */ - vm.getLineData = function (chartData) { + vm.getLineData = function(chartData) { var lineData = { - type: vm.setAreaChart ? "area" : "line" + type: vm.setAreaChart ? "area" : "line", }; if (chartData && chartData.dataAvailable !== false && chartData.xData) { lineData.x = chartData.xData[0]; // Convert the chartData dictionary into a C3 columns data arrays - lineData.columns = Object.keys(chartData).map(function (key) { + lineData.columns = Object.keys(chartData).map(function(key) { return chartData[key]; }); } @@ -101,13 +102,13 @@ function lineChartController(pfUtils) { return lineData; }; - vm.$onChanges = function (changesObj) { + vm.$onChanges = function(changesObj) { vm.updateAll(); }; - vm.$doCheck = function () { + vm.$doCheck = function() { // do a deep compare on chartData - if (!angular.equals(vm.chartData, prevChartData)) { + if (! angular.equals(vm.chartData, prevChartData)) { vm.updateAll(); } }; diff --git a/app/assets/javascripts/components/pf_charts/sparkline-chart.component.js b/app/assets/javascripts/components/pf_charts/sparkline-chart.component.js index 0baaf1a8d77c..929f2a72379e 100644 --- a/app/assets/javascripts/components/pf_charts/sparkline-chart.component.js +++ b/app/assets/javascripts/components/pf_charts/sparkline-chart.component.js @@ -4,18 +4,19 @@ angular.module('patternfly.charts').component('pfSparklineChart', { chartData: '<', chartHeight: '', showXAxis: '', - showYAxis: '' + showYAxis: '', }, templateUrl: '/static/pf_charts/sparkline-chart.html.haml', - controller: sparklineChartController + controller: sparklineChartController, }); -sparklineChartController.$inject = ['pfUtils'] +sparklineChartController.$inject = ['pfUtils']; function sparklineChartController(pfUtils) { 'use strict'; - var vm = this, prevChartData; + var vm = this; + var prevChartData; - vm.updateAll = function () { + vm.updateAll = function() { // Need to deep watch changes in chart data prevChartData = angular.copy(vm.chartData); @@ -50,19 +51,19 @@ function sparklineChartController(pfUtils) { show: vm.showXAxis === true, type: 'timeseries', tick: { - format: function () { + format: function() { return ''; - } - } + }, + }, }, y: { show: vm.showYAxis === true, tick: { - format: function () { + format: function() { return ''; - } - } - } + }, + }, + }, }; // Setup the default configuration @@ -82,23 +83,23 @@ function sparklineChartController(pfUtils) { /* * Convert the config data to C3 Data */ - vm.getSparklineData = function (chartData) { + vm.getSparklineData = function(chartData) { var sparklineData = { - type: 'area' + type: 'area', }; if (chartData && chartData.dataAvailable !== false && chartData.xData && chartData.yData) { sparklineData.x = chartData.xData[0]; sparklineData.columns = [ chartData.xData, - chartData.yData + chartData.yData, ]; } return sparklineData; }; - vm.getTooltipTableHTML = function (tipRows) { + vm.getTooltipTableHTML = function(tipRows) { return '