Skip to content

[IMPAC-622] threshold tooltip#393

Closed
xaun wants to merge 7 commits intomaestrano:release/v1.6.1from
xaun:feature-1.6.1/622-threshold-tooltip
Closed

[IMPAC-622] threshold tooltip#393
xaun wants to merge 7 commits intomaestrano:release/v1.6.1from
xaun:feature-1.6.1/622-threshold-tooltip

Conversation

@xaun
Copy link
Copy Markdown
Contributor

@xaun xaun commented Aug 29, 2017

@cesar-tonnoir here is the threshold tooltip rebased on top of v.1.6.1. I have applied your refactors as well.

I could not assign the switch like you wanted to in the kpi.svc:

host = switch.kpi.source
    ...

As one of the cases return $q.reject(err)

@xaun
Copy link
Copy Markdown
Contributor Author

xaun commented Aug 29, 2017

@cesar-tonnoir I have added commits to:

  • flag impac dependency in Changelog
  • clean up toastr error/success messages
  • remove outline from kpi threshold buttons when loading

@cesar-tonnoir cesar-tonnoir mentioned this pull request Sep 11, 2017
5 tasks
Copy link
Copy Markdown
Contributor

@cesar-tonnoir cesar-tonnoir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xaun
I've tried to refactor this branch and gave up after ~3 hours: the way the thresholds are added to the chart is too complex and the code is too intricate. Even if the feature seems to work, if I was to merge this branch, it would add yet another layer of complexity on something that should already be refactored.

So, before going further with the tooltips, I would like you to refactor the thresholds, taking several things into account:

  • The widget (or the threshold component) should trigger the action to attach a threshold to a Chart. Calling addTresholds() after the chart initialization, exiting if no threshold option has been set, is not the proper way to go.

  • Don't put specific code in the factory: anything related to cash, projection, etc.. even the threshold series name, should be passed as arguments. Otherwise, you are building a factory that works for a single widget.

  • The only major change since you've worked on the thresholds / tooltips is the way we handle the dates with unix timestamps. I can help you with this part, or you can stub the data and let me update it: I'm happy to give a hand on this part as long as the rest of the code is clean, with separated concerns.

Eg:

# Not ok:
constructor: (@id, @data = {}, @options = {})-> 
  @hc = Highcharts.stockChart(@id, chartConfig)
  @addThresholds()

addThresholds: (options = @options)->
  for threshold in options.thresholds
  ...

# ok:
# in widget / threshold component:
chart.addThreshold( {...}, cashProjectionSeries)

# thresholdOptions: { name, value, kpiId, color, isFullLength, withTooltip }
addThreshold: (thresholdOptions, targetSeries) ->
  ...
  s = @hc.series.add(myThresholdSeries)
  addThresholdTooltip(s, targetSeries) if thresholdOptions.withTooltip

return removePointDataLabels(@triggeredPoint) unless thresholdSerie
cashSerie = _.find(chart.series, (s)-> s.name.toLowerCase() == 'projected cash')

return removePointDataLabels(@triggeredPoint) unless thresholdSerie.options.triggered
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thresholdSerie.options.triggered always true

s.options.triggered && s.name.toLowerCase() == 'threshold kpi'
)
return removePointDataLabels(@triggeredPoint) unless thresholdSerie
cashSerie = _.find(chart.series, (s)-> s.name.toLowerCase() == 'projected cash')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code specific to cash projection widget in the chart factory

else
@hc.update(chartConfig)
@addThresholds()
@addThresholds(@hc)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addThresholds and renderThresholdTooltip should be called from the widget context

labelText = "The cash projection reaches the threshold on #{triggeredIntervalDate}"
# The first cash projection interval point below the threshold
@triggeredPoint = cashSerie.points[thresholdSerie.options.triggered_interval_index]
# Updating dataLabels have no animation, adds delay to improve UI.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very good.. can't you simply update the chart once the dataLabels object is ready?

# Remove existing thresholds
_.each(@hc.series, (s)-> s.remove() if s.name.toLowerCase().includes('threshold'))
return @hc if _.isEmpty(options.thresholds)
_.each(chart.series, (s)-> s.remove() if s.name.toLowerCase().includes('threshold'))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to remove all the existing threshold series? What if we want to define several thresholds on a chart in the future?


# Render a threshold serie dataLabel when KPI triggered
renderThresholdTooltip: (chart, options = @options)->
thresholdSerie = _.find(chart.series, (s)->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be passed as an argument

thresholdSerie = _.find(chart.series, (s)->
s.options.triggered && s.name.toLowerCase() == 'threshold kpi'
)
return removePointDataLabels(@triggeredPoint) unless thresholdSerie
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we should have @triggeredPoint as a global variable? shouldn't it remain in the method's scope?

@getApiV2KpiDataKey = (kpi)->
# Formats the kpi endpoint to select the key name
# e.g response.cash_projection = { triggered: true, ... }
# TODO: maybe the 'kpi' of endpoint 'kpis/cash_projection' should be removed?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes: I don't think the endpoint was returning kpis/something in the API v1?
Can you please align the Bolt endpoint?

@xaun xaun closed this Sep 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants