From ef8768431af786297b635f939b803abe45baa211 Mon Sep 17 00:00:00 2001 From: iseessel Date: Wed, 24 Jan 2018 19:48:06 -0500 Subject: [PATCH 1/5] [IMPAC-745] Separated multiple update calls into one create call --- src/components/chart/chart.directive.coffee | 2 +- .../chart-threshold.component.coffee | 14 +++++++- .../accounts-cash-projection.directive.coffee | 27 +++++++++----- ...accounts-class-comparison.directive.coffee | 1 - .../highcharts-factory.svc.coffee | 35 ++++++------------- 5 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/components/chart/chart.directive.coffee b/src/components/chart/chart.directive.coffee index 10b84b25..cbad37f5 100644 --- a/src/components/chart/chart.directive.coffee +++ b/src/components/chart/chart.directive.coffee @@ -46,7 +46,7 @@ angular $log.error(error) (chartData) -> userAgent = $window.navigator.userAgent - + # Previously, this hack was only for Safari, # then we activated it for chrome after release of version 51, # now it becomes the default behaviour as IE11 has shown some unstability in the display of charts diff --git a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee index d5d4cad2..b9fca9b2 100644 --- a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee +++ b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee @@ -67,6 +67,13 @@ module.component('chartThreshold', { , 100) return + validAlertAmmount = (target) -> + ImpacKpisSvc.validateKpiTargets(target) + + handleInvalidAlertAmount = -> + toastr.error("Please choose a number one or greater.", 'Error') + ctrl.cancelCreateKpi() + ctrl.saveKpi = -> return if ctrl.loading ctrl.loading = true @@ -74,10 +81,14 @@ module.component('chartThreshold', { params.targets[ctrl.kpi.watchables[0]] = [{ "#{ctrl.kpiTargetMode}": parseFloat(ctrl.draftTarget.value) }] - return unless ImpacKpisSvc.validateKpiTargets(params.targets) + + if !validAlertAmmount(params.targets) + return handleInvalidAlertAmount() + promise = if ctrl.isEditingKpi ImpacKpisSvc.update(getKpi(), params, false).then( (kpi)-> + # Remove old threshold from chart ctrl.chart.removeThreshold(kpi.id) angular.extend(getKpi(), kpi) @@ -92,6 +103,7 @@ module.component('chartThreshold', { ) promise.then( (kpi)-> + ctrl.onComplete($event: { kpi: kpi }) if _.isFunction(ctrl.onComplete) ).finally(-> ctrl.cancelCreateKpi() diff --git a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee b/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee index 40172fa7..d39719a6 100644 --- a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee +++ b/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee @@ -194,9 +194,21 @@ module.controller('WidgetAccountsCashProjectionCtrl', ($scope, $q, $filter, $tim # Executed after the widget and its settings are initialised and ready w.format = -> # Instantiate and render chart - options = - chartType: 'line' + legendOptions = + legend: + useHTML: true + labelFormatter: legendFormatter + + callBackOptions = chartOnClickCallbacks: [] + plotOptions: + series: + events: + click: onClickBar + legendItemClick: onClickLegend + + formattingOptions = + chartType: 'line' currency: w.metadata.currency showToday: true showLegend: true @@ -204,16 +216,15 @@ module.controller('WidgetAccountsCashProjectionCtrl', ($scope, $q, $filter, $tim defaults: w.metadata.xAxis callback: onZoom + options = angular.merge(legendOptions, callBackOptions, formattingOptions) + $scope.chart ||= new HighchartsFactory($scope.chartId(), w.content.chart, options) - $scope.chart.render(w.content.chart, options) - # Add events callbacks to chart object - $scope.chart.addCustomLegend(legendFormatter) - $scope.chart.addSeriesEvent('click', onClickBar) - $scope.chart.addSeriesEvent('legendItemClick', onClickLegend) + $scope.chart.render(w.content.chart, options) - # Notifies parent element that the chart is ready to be displayed $scope.chartDeferred.notify($scope.chart) + # Notifies parent element that the chart is ready to be displayed + $scope.widgetDeferred.resolve(settingsPromises) ) diff --git a/src/components/widgets/accounts-class-comparison/accounts-class-comparison.directive.coffee b/src/components/widgets/accounts-class-comparison/accounts-class-comparison.directive.coffee index 5de0f59b..98a08edd 100644 --- a/src/components/widgets/accounts-class-comparison/accounts-class-comparison.directive.coffee +++ b/src/components/widgets/accounts-class-comparison/accounts-class-comparison.directive.coffee @@ -35,7 +35,6 @@ module.controller('WidgetAccountsClassComparisonCtrl', ($scope, $q, $filter, Cha w.initContext = -> $scope.isDataFound = angular.isDefined(w.content) && !_.isEmpty(w.content.summary) && !_.isEmpty(w.content.companies) if $scope.isDataFound - $scope.timePeriodInfoParams.histParams = w.metadata && w.metadata.hist_parameters $scope.classifications = _.map(w.content.summary, (summary) -> klass = summary.classification { diff --git a/src/services/highcharts-factory/highcharts-factory.svc.coffee b/src/services/highcharts-factory/highcharts-factory.svc.coffee index 30387801..297b6a0d 100644 --- a/src/services/highcharts-factory/highcharts-factory.svc.coffee +++ b/src/services/highcharts-factory/highcharts-factory.svc.coffee @@ -5,6 +5,10 @@ angular templates = line: Object.freeze get: (series = [], options = {})-> + seriesEvents = if options.plotOptions then options.plotOptions.series.events else {} + useHTML = if options.legend then options.legend.useHTML else false + labelFormatter = if options.legend then options.legend.labelFormatter else false + zoomingOptions = _.get(options, 'withZooming') xAxisOptions = if zoomingOptions? { @@ -13,13 +17,15 @@ angular max: _.get(zoomingOptions.defaults, 'max') min: _.get(zoomingOptions.defaults, 'min') } - chart: type: 'line' zoomType: 'x' spacingTop: 20 events: click: (event)-> _.each(_.get(options, 'chartOnClickCallbacks', []), (cb)-> cb(event)) + plotOptions: + series: + events: seriesEvents title: null credits: enabled: false @@ -28,6 +34,8 @@ angular layout: 'vertical' align: 'left' verticalAlign: 'middle' + useHTML: useHTML + labelFormatter: labelFormatter xAxis: xAxisOptions yAxis: title: null @@ -56,10 +64,8 @@ angular @data = data if _.isObject(data) angular.extend(@options, options) chartConfig = angular.merge({}, @template(), @formatters(), @todayMarker()) - if _.isEmpty(@hc) - @hc = Highcharts.stockChart(@id, chartConfig) - else - @hc.update(chartConfig) + #It is faster to create a new stockChart than to update an existing one. + @hc = Highcharts.stockChart(@id, chartConfig) return @ template: -> @@ -129,23 +135,4 @@ angular addThresholdEvent: (thresholdSerie, eventName, callback)-> return unless thresholdSerie? && eventName? && _.isFunction(callback) Highcharts.addEvent(thresholdSerie, eventName, (_event)-> callback(thresholdSerie)) - - # Extend default chart formatters to add custom legend img icon - addCustomLegend: (formatterCallback, useHTML = true) -> - @hc.legend.update({ - useHTML: useHTML - labelFormatter: formatterCallback - }) - - # Adds events to series objects - addSeriesEvent: (eventName, callback) -> - return if _.isEmpty(@hc) - eventHash = {} - eventHash[eventName] = callback - @hc.update({ - plotOptions: - series: - events: eventHash - }) - @hc ) From 70b9847d0eb7650275d46d28f313920d6e500444 Mon Sep 17 00:00:00 2001 From: iseessel Date: Fri, 26 Jan 2018 12:03:36 -0500 Subject: [PATCH 2/5] [IMPAC-745] Refactored Highcharts Factory to use setter methods --- .../chart-threshold.component.coffee | 9 +- .../accounts-cash-balance.directive.coffee | 34 +++--- .../accounts-cash-projection.directive.coffee | 40 +++---- .../highcharts-factory.svc.coffee | 110 +++++++++++------- 4 files changed, 101 insertions(+), 92 deletions(-) diff --git a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee index b9fca9b2..60d9207d 100644 --- a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee +++ b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee @@ -67,9 +67,6 @@ module.component('chartThreshold', { , 100) return - validAlertAmmount = (target) -> - ImpacKpisSvc.validateKpiTargets(target) - handleInvalidAlertAmount = -> toastr.error("Please choose a number one or greater.", 'Error') ctrl.cancelCreateKpi() @@ -82,13 +79,12 @@ module.component('chartThreshold', { "#{ctrl.kpiTargetMode}": parseFloat(ctrl.draftTarget.value) }] - if !validAlertAmmount(params.targets) + unless ImpacKpisSvc.validateKpiTargets(params.targets) return handleInvalidAlertAmount() promise = if ctrl.isEditingKpi ImpacKpisSvc.update(getKpi(), params, false).then( (kpi)-> - # Remove old threshold from chart ctrl.chart.removeThreshold(kpi.id) angular.extend(getKpi(), kpi) @@ -103,7 +99,6 @@ module.component('chartThreshold', { ) promise.then( (kpi)-> - ctrl.onComplete($event: { kpi: kpi }) if _.isFunction(ctrl.onComplete) ).finally(-> ctrl.cancelCreateKpi() @@ -133,7 +128,7 @@ module.component('chartThreshold', { onChartNotify = (chart)-> ctrl.chart = chart return unless validateHistParameters() - ctrl.chart.options.chartOnClickCallbacks.push(onChartClick) + ctrl.chart.settings.chartOnClickCallbacks.push(onChartClick) _.each buildThresholdsFromKpis(), (threshold)-> thresholdSerie = ctrl.chart.findThreshold(threshold.kpiId) thresholdSerie = ctrl.chart.addThreshold(threshold) unless thresholdSerie? diff --git a/src/components/widgets/accounts-cash-balance/accounts-cash-balance.directive.coffee b/src/components/widgets/accounts-cash-balance/accounts-cash-balance.directive.coffee index 6bc66080..b214fb59 100644 --- a/src/components/widgets/accounts-cash-balance/accounts-cash-balance.directive.coffee +++ b/src/components/widgets/accounts-cash-balance/accounts-cash-balance.directive.coffee @@ -4,11 +4,16 @@ module.controller('WidgetAccountsCashBalanceCtrl', ($scope, $q, $timeout, $filte w = $scope.widget # Define settings - # -------------------------------------- + # ------------------------------------- $scope.orgDeferred = $q.defer() settingsPromises = [$scope.orgDeferred.promise] + # Setup Highcharts Options + # ------------------------------------- + getPeriod = -> + w.metadata? && w.metadata.hist_parameters? && w.metadata.hist_parameters.period || 'MONTHLY' + # Widget specific methods # -------------------------------------- w.initContext = -> @@ -46,9 +51,6 @@ module.controller('WidgetAccountsCashBalanceCtrl', ($scope, $q, $timeout, $filte return '#000' unless serie serie.color - getPeriod = -> - w.metadata? && w.metadata.hist_parameters? && w.metadata.hist_parameters.period || 'MONTHLY' - getSerieByAccount = (series, account)-> _.find(series, (serie)-> (serie.id || serie.options && serie.options.id) == account.id) @@ -79,19 +81,23 @@ module.controller('WidgetAccountsCashBalanceCtrl', ($scope, $q, $timeout, $filte # Called after initContext - draws the chart using HighCharts w.format = -> - options = - chartType: 'line' - currency: w.metadata.currency - period: getPeriod() - showToday: true - showLegend: false - withZooming: + $timeout -> + _highChartOptions = + chartType: 'line' + currency: w.metadata.currency + period: getPeriod() + showToday: true + showLegend: false + + # Add Custom Highchart Options. + $scope.chart = new HighchartsFactory($scope.chartId(), w.content.chart.series, _highChartOptions) + $scope.chart.addXAxisOptions({ defaults: w.metadata.xAxis callback: onZoom + }) + $scope.chart.removeLegend() - $timeout -> - $scope.chart ||= new HighchartsFactory($scope.chartId(), w.content.chart, options) - $scope.chart.render(w.content.chart, options) + $scope.chart.render() # Widget is ready: can trigger the "wait for settings to be ready" # -------------------------------------- diff --git a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee b/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee index d39719a6..7db8a22f 100644 --- a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee +++ b/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee @@ -193,37 +193,25 @@ module.controller('WidgetAccountsCashProjectionCtrl', ($scope, $q, $filter, $tim # Executed after the widget and its settings are initialised and ready w.format = -> - # Instantiate and render chart - legendOptions = - legend: - useHTML: true - labelFormatter: legendFormatter - - callBackOptions = - chartOnClickCallbacks: [] - plotOptions: - series: - events: - click: onClickBar - legendItemClick: onClickLegend - - formattingOptions = + _highChartOptions = chartType: 'line' + chartOnClickCallbacks: [] currency: w.metadata.currency showToday: true - showLegend: true - withZooming: - defaults: w.metadata.xAxis - callback: onZoom - - options = angular.merge(legendOptions, callBackOptions, formattingOptions) - $scope.chart ||= new HighchartsFactory($scope.chartId(), w.content.chart, options) - - $scope.chart.render(w.content.chart, options) - - $scope.chartDeferred.notify($scope.chart) + # Add custom options to the chart before render. + $scope.chart = new HighchartsFactory($scope.chartId(), w.content.chart.series, _highChartOptions) + $scope.chart.addCustomLegend(legendFormatter) + $scope.chart.addSeriesEvent('click', onClickBar) + $scope.chart.addSeriesEvent('legendItemClick', onClickLegend) + $scope.chart.addXAxisOptions(({ + defaults: w.metadata.xAxis + callback: onZoom + })) + + $scope.chart.render() # Notifies parent element that the chart is ready to be displayed + $scope.chartDeferred.notify($scope.chart) $scope.widgetDeferred.resolve(settingsPromises) diff --git a/src/services/highcharts-factory/highcharts-factory.svc.coffee b/src/services/highcharts-factory/highcharts-factory.svc.coffee index 297b6a0d..d0ccac9a 100644 --- a/src/services/highcharts-factory/highcharts-factory.svc.coffee +++ b/src/services/highcharts-factory/highcharts-factory.svc.coffee @@ -4,45 +4,22 @@ angular templates = line: Object.freeze - get: (series = [], options = {})-> - seriesEvents = if options.plotOptions then options.plotOptions.series.events else {} - useHTML = if options.legend then options.legend.useHTML else false - labelFormatter = if options.legend then options.legend.labelFormatter else false - - zoomingOptions = _.get(options, 'withZooming') - xAxisOptions = if zoomingOptions? - { - events: - setExtremes: zoomingOptions.callback - max: _.get(zoomingOptions.defaults, 'max') - min: _.get(zoomingOptions.defaults, 'min') - } chart: type: 'line' zoomType: 'x' spacingTop: 20 - events: - click: (event)-> _.each(_.get(options, 'chartOnClickCallbacks', []), (cb)-> cb(event)) - plotOptions: - series: - events: seriesEvents - title: null - credits: - enabled: false legend: - enabled: _.get(options, 'showLegend', true) + enabled: true layout: 'vertical' align: 'left' verticalAlign: 'middle' - useHTML: useHTML - labelFormatter: labelFormatter - xAxis: xAxisOptions + title: null + credits: + enabled: false yAxis: title: null startOnTick: true minPadding: 0 - series: series - rangeSelector: buttons: [ { type: 'month', count: 4, text: 'def.' }, { type: 'month', count: 1, text: '1m' }, @@ -51,28 +28,26 @@ angular { type: 'year', count: 1, text: '1y' }, { type: 'all', text: 'All' } ] - selected: (if _.get(xAxisOptions, 'min') then null else 0) todayUTC = moment().startOf('day').add(moment().utcOffset(), 'minutes') class Chart - constructor: (@id, @data = {}, @options = {})-> - @_template = templates[@options.chartType] + constructor: (@id, @series = {}, @settings = {})-> + # Setup the basic options for highcharts. + template = templates[@settings.chartType] + formatters = @formatters(@settings.currency) + todayMarker = @todayMarker(@settings) + series = { series: @series } + @options = angular.merge({}, series, template, formatters, todayMarker) return - render: (data, options)-> - @data = data if _.isObject(data) - angular.extend(@options, options) - chartConfig = angular.merge({}, @template(), @formatters(), @todayMarker()) - #It is faster to create a new stockChart than to update an existing one. - @hc = Highcharts.stockChart(@id, chartConfig) + render: () -> + # Options are already populated in the constructor, and through the options setter methods. + # It is faster to create a new stockChart than to update an existing one when data changes. + @hc = Highcharts.stockChart(@id, @options) return @ - template: -> - @_template.get(@data.series, @options) - - formatters: -> - currency = @options.currency + formatters: (currency) -> xAxis: labels: formatter: -> @@ -92,11 +67,11 @@ angular name = _.startCase _.trim name.toLowerCase().replace(/\s*projected\s*/, ' ') "#{date}
#{name}: #{amount}" - todayMarker: -> - return {} unless @options.showToday + todayMarker: (showToday, markerColor = 'rgba(0, 85, 255, 0.2)') -> + return {} unless showToday xAxis: plotLines: [{ - color: _.get(@options, 'todayMarkerColor', 'rgba(0, 85, 255, 0.2)') + color: markerColor value: todayUTC.unix() * 1000 width: 1 label: @@ -110,7 +85,7 @@ angular addThreshold: (thresholdOptions)-> return if _.isEmpty(@hc) # Initialize data matrix - data = angular.copy @data.series[0].data + data = angular.copy @series[0].data for vector in data # When in the past, set y-axis value at null if !thresholdOptions.fullLengthThresholds && moment(vector[0]) < todayUTC @@ -135,4 +110,49 @@ angular addThresholdEvent: (thresholdSerie, eventName, callback)-> return unless thresholdSerie? && eventName? && _.isFunction(callback) Highcharts.addEvent(thresholdSerie, eventName, (_event)-> callback(thresholdSerie)) + + addCustomLegend: (labelFormatter, useHTML = true, showLegend = true) -> + legend = + legend: + labelFormatter: labelFormatter + useHTML: useHTML + enabled: showLegend + angular.merge(@options, legend) + + removeLegend: () -> + legend = + legend: + enabled: false + angular.merge(@options, legend) + + addSeriesEvent: (eventName, callback) -> + eventHash = {} + eventHash[eventName] = callback + plotOptions = + plotOptions: + series: + events: eventHash + angular.merge(@options, plotOptions) + + addOnClickCallbacks: (chartOnClickCallbacks = []) -> + click = (event) -> _.each(chartOnClickCallbacks, (cb) -> cb(event)) + onClickCallBacks = + chart: + events: + click: click + angular.merge(@options, onClickCallBacks) + + addXAxisOptions: (zoomingOptions) -> + xAxisOptions = if zoomingOptions? + events: + setExtremes: zoomingOptions.callback + max: _.get(zoomingOptions.defaults, 'max') + min: _.get(zoomingOptions.defaults, 'min') + + xAxis = + xAxis: xAxisOptions + rangeSelector: + selected: (if _.get(xAxisOptions, 'min') then null else 0) + + angular.merge(@options, xAxis) ) From fb0bbd78bfba190d27c76c0ad8e8315a4330e4b4 Mon Sep 17 00:00:00 2001 From: Isaac Seessel Date: Tue, 20 Feb 2018 15:12:43 -0500 Subject: [PATCH 3/5] [IMPAC-745] Changed ui for failed update --- .../chart-threshold.component.coffee | 2 +- ...accounts-class-comparison.directive.coffee | 1 + .../highcharts-factory.svc.coffee | 62 +++++++++---------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee index 60d9207d..7dffd99d 100644 --- a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee +++ b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee @@ -69,7 +69,7 @@ module.component('chartThreshold', { handleInvalidAlertAmount = -> toastr.error("Please choose a number one or greater.", 'Error') - ctrl.cancelCreateKpi() + ctrl.loading = false ctrl.saveKpi = -> return if ctrl.loading diff --git a/src/components/widgets/accounts-class-comparison/accounts-class-comparison.directive.coffee b/src/components/widgets/accounts-class-comparison/accounts-class-comparison.directive.coffee index 98a08edd..5de0f59b 100644 --- a/src/components/widgets/accounts-class-comparison/accounts-class-comparison.directive.coffee +++ b/src/components/widgets/accounts-class-comparison/accounts-class-comparison.directive.coffee @@ -35,6 +35,7 @@ module.controller('WidgetAccountsClassComparisonCtrl', ($scope, $q, $filter, Cha w.initContext = -> $scope.isDataFound = angular.isDefined(w.content) && !_.isEmpty(w.content.summary) && !_.isEmpty(w.content.companies) if $scope.isDataFound + $scope.timePeriodInfoParams.histParams = w.metadata && w.metadata.hist_parameters $scope.classifications = _.map(w.content.summary, (summary) -> klass = summary.classification { diff --git a/src/services/highcharts-factory/highcharts-factory.svc.coffee b/src/services/highcharts-factory/highcharts-factory.svc.coffee index d0ccac9a..c8d57ed8 100644 --- a/src/services/highcharts-factory/highcharts-factory.svc.coffee +++ b/src/services/highcharts-factory/highcharts-factory.svc.coffee @@ -4,30 +4,30 @@ angular templates = line: Object.freeze - chart: - type: 'line' - zoomType: 'x' - spacingTop: 20 - legend: - enabled: true - layout: 'vertical' - align: 'left' - verticalAlign: 'middle' + chart: + type: 'line' + zoomType: 'x' + spacingTop: 20 + legend: + enabled: true + layout: 'vertical' + align: 'left' + verticalAlign: 'middle' + title: null + credits: + enabled: false + yAxis: title: null - credits: - enabled: false - yAxis: - title: null - startOnTick: true - minPadding: 0 - buttons: [ - { type: 'month', count: 4, text: 'def.' }, - { type: 'month', count: 1, text: '1m' }, - { type: 'month', count: 3, text: '3m' }, - { type: 'month', count: 6, text: '6m' }, - { type: 'year', count: 1, text: '1y' }, - { type: 'all', text: 'All' } - ] + startOnTick: true + minPadding: 0 + buttons: [ + { type: 'month', count: 4, text: 'def.' }, + { type: 'month', count: 1, text: '1m' }, + { type: 'month', count: 3, text: '3m' }, + { type: 'month', count: 6, text: '6m' }, + { type: 'year', count: 1, text: '1y' }, + { type: 'all', text: 'All' } + ] todayUTC = moment().startOf('day').add(moment().utcOffset(), 'minutes') @@ -36,15 +36,15 @@ angular # Setup the basic options for highcharts. template = templates[@settings.chartType] formatters = @formatters(@settings.currency) - todayMarker = @todayMarker(@settings) + todayMarker = @todayMarker(@settings.showToday, @settings.markerColor) series = { series: @series } - @options = angular.merge({}, series, template, formatters, todayMarker) + @highChartOptions = angular.merge({}, series, template, formatters, todayMarker) return render: () -> # Options are already populated in the constructor, and through the options setter methods. # It is faster to create a new stockChart than to update an existing one when data changes. - @hc = Highcharts.stockChart(@id, @options) + @hc = Highcharts.stockChart(@id, @highChartOptions) return @ formatters: (currency) -> @@ -117,13 +117,13 @@ angular labelFormatter: labelFormatter useHTML: useHTML enabled: showLegend - angular.merge(@options, legend) + angular.merge(@highChartOptions, legend) removeLegend: () -> legend = legend: enabled: false - angular.merge(@options, legend) + angular.merge(@highChartOptions, legend) addSeriesEvent: (eventName, callback) -> eventHash = {} @@ -132,7 +132,7 @@ angular plotOptions: series: events: eventHash - angular.merge(@options, plotOptions) + angular.merge(@highChartOptions, plotOptions) addOnClickCallbacks: (chartOnClickCallbacks = []) -> click = (event) -> _.each(chartOnClickCallbacks, (cb) -> cb(event)) @@ -140,7 +140,7 @@ angular chart: events: click: click - angular.merge(@options, onClickCallBacks) + angular.merge(@highChartOptions, onClickCallBacks) addXAxisOptions: (zoomingOptions) -> xAxisOptions = if zoomingOptions? @@ -154,5 +154,5 @@ angular rangeSelector: selected: (if _.get(xAxisOptions, 'min') then null else 0) - angular.merge(@options, xAxis) + angular.merge(@highChartOptions, xAxis) ) From d66bf5f814dea5c0a840da0682d8e8319ceeed9f Mon Sep 17 00:00:00 2001 From: Isaac Seessel Date: Wed, 21 Feb 2018 16:31:23 -0500 Subject: [PATCH 4/5] [Impac-745] Fixed #chartOnClickCallbacks --- .../highcharts-factory.svc.coffee | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/services/highcharts-factory/highcharts-factory.svc.coffee b/src/services/highcharts-factory/highcharts-factory.svc.coffee index c8d57ed8..6130e24c 100644 --- a/src/services/highcharts-factory/highcharts-factory.svc.coffee +++ b/src/services/highcharts-factory/highcharts-factory.svc.coffee @@ -37,8 +37,11 @@ angular template = templates[@settings.chartType] formatters = @formatters(@settings.currency) todayMarker = @todayMarker(@settings.showToday, @settings.markerColor) + # We need onClickCallbacks pointing to settings.onClickCallbacks, so that + # we can push functions into it after this code is run. + onClickCallbacks = @onClickCallbacks(@settings.chartOnClickCallbacks) series = { series: @series } - @highChartOptions = angular.merge({}, series, template, formatters, todayMarker) + @highChartOptions = angular.merge({}, series, template, formatters, todayMarker, onClickCallbacks) return render: () -> @@ -134,13 +137,11 @@ angular events: eventHash angular.merge(@highChartOptions, plotOptions) - addOnClickCallbacks: (chartOnClickCallbacks = []) -> + onClickCallbacks: (chartOnClickCallbacks) -> click = (event) -> _.each(chartOnClickCallbacks, (cb) -> cb(event)) - onClickCallBacks = - chart: - events: - click: click - angular.merge(@highChartOptions, onClickCallBacks) + chart: + events: + click: click addXAxisOptions: (zoomingOptions) -> xAxisOptions = if zoomingOptions? From dae9eb7f7ae9e0b0d7fd5db78d17d499c79def01 Mon Sep 17 00:00:00 2001 From: Isaac Seessel Date: Mon, 26 Feb 2018 12:05:09 -0500 Subject: [PATCH 5/5] [IMPAC-745] Refactor #addOnClickCallback API --- .../chart-threshold.component.coffee | 2 +- .../accounts-cash-projection.directive.coffee | 1 - .../highcharts-factory.svc.coffee | 13 ++++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee index 7dffd99d..6eed97c6 100644 --- a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee +++ b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee @@ -128,7 +128,7 @@ module.component('chartThreshold', { onChartNotify = (chart)-> ctrl.chart = chart return unless validateHistParameters() - ctrl.chart.settings.chartOnClickCallbacks.push(onChartClick) + ctrl.chart.addOnClickCallback(onChartClick) _.each buildThresholdsFromKpis(), (threshold)-> thresholdSerie = ctrl.chart.findThreshold(threshold.kpiId) thresholdSerie = ctrl.chart.addThreshold(threshold) unless thresholdSerie? diff --git a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee b/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee index 7db8a22f..107f9dc4 100644 --- a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee +++ b/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee @@ -195,7 +195,6 @@ module.controller('WidgetAccountsCashProjectionCtrl', ($scope, $q, $filter, $tim w.format = -> _highChartOptions = chartType: 'line' - chartOnClickCallbacks: [] currency: w.metadata.currency showToday: true diff --git a/src/services/highcharts-factory/highcharts-factory.svc.coffee b/src/services/highcharts-factory/highcharts-factory.svc.coffee index 6130e24c..69cf6494 100644 --- a/src/services/highcharts-factory/highcharts-factory.svc.coffee +++ b/src/services/highcharts-factory/highcharts-factory.svc.coffee @@ -37,8 +37,6 @@ angular template = templates[@settings.chartType] formatters = @formatters(@settings.currency) todayMarker = @todayMarker(@settings.showToday, @settings.markerColor) - # We need onClickCallbacks pointing to settings.onClickCallbacks, so that - # we can push functions into it after this code is run. onClickCallbacks = @onClickCallbacks(@settings.chartOnClickCallbacks) series = { series: @series } @highChartOptions = angular.merge({}, series, template, formatters, todayMarker, onClickCallbacks) @@ -137,11 +135,16 @@ angular events: eventHash angular.merge(@highChartOptions, plotOptions) - onClickCallbacks: (chartOnClickCallbacks) -> - click = (event) -> _.each(chartOnClickCallbacks, (cb) -> cb(event)) + onClickCallbacks: (chartOnClickCallbacks = []) -> + # We need onClickCallbacks pointing to settings.onClickCallbacks, so that we can add callbacks to the settings later on. + @settings.chartOnClickCallbacks = chartOnClickCallbacks + click = (event) -> _.each(@settings.chartOnClickCallbacks, (cb) -> cb(event)) chart: events: - click: click + click: click.bind(@) + + addOnClickCallback: (event) -> + @settings.chartOnClickCallbacks.push(event) addXAxisOptions: (zoomingOptions) -> xAxisOptions = if zoomingOptions?