Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temporal line chart annotations #402

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

khasinski
Copy link

@khasinski khasinski commented Jun 10, 2022

I'd like to propose an annotations mechanism which allows overlaying data on top of the line charts with a temporal axis.

The main use case is to keep a log of events (whether they are points in time or ranges) and to see the effect of those events on multiple metrics we track in Blazer. A good example would be to track deployments, a marketing campaign duration or holidays and overlay them on top of revenue or visits data.

Here is an example:

blazer.yml

    annotations:
      deployments:
        SELECT created_at, name FROM deployments # datetime + string, results in a vertical line + label
      holidays:
        SELECT min_date, max_date, name FROM holidays # two dates + string, results in a colored range box

Result
image

Developed together with @twratajczak

Fixes #403

@khasinski
Copy link
Author

khasinski commented Jun 13, 2022

I've added the ability to override colors, even though it requires extending Blazer::Annotations and setting it with Blazer.annotations. This might be used to easily mark for example weekends with a light gray. Helpful if the data has a cyclical nature.

Here is an example of that (to be put in a rails initializer)

class CustomAnnotations < Blazer::Annotations
  def call(result)
    min, max = result.rows.map(&:first).minmax
    super + weekends(min, max)
  end

  private

  def weekends(min, max)
    (min.to_date..max.to_date).select(&:on_weekend?).each_slice(2).map do |weekend|
      {
        min_date: weekend[0],
        max_date: weekend[1].end_of_day,
        label: "", # Empty labels are not rendered
        color: "#FAFAFA",
      }
    end
  end
end

Blazer.annotations = CustomAnnotations

Results in (notice that it works with existing annotations):

image

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.

[Idea] Add time graphs annotations
1 participant