Skip to content

feat: add chartkick dependency#87

Open
jonathanloos wants to merge 6 commits intomainfrom
61-add-support-for-chartkick
Open

feat: add chartkick dependency#87
jonathanloos wants to merge 6 commits intomainfrom
61-add-support-for-chartkick

Conversation

@jonathanloos
Copy link
Contributor

  • Add chartkick gem
  • Add chartkick to importmap
  • Add chartkick as dependency in gemspec
  • Resolve comment on readme

@jonathanloos jonathanloos linked an issue Nov 16, 2023 that may be closed by this pull request
@jonathanloos jonathanloos self-assigned this Nov 16, 2023
@krsyoung
Copy link
Contributor

Thoughts on updating the README with any required steps? I didn't try it, but basically all an app needs to do to leverage chartkick as part of matey would be to do the js includes? (any css includes?)

import "chartkick"
import "Chart.bundle"

@krsyoung
Copy link
Contributor

krsyoung commented Dec 30, 2023

Question (sorry for the delay!), adding chartkick might be overly opinionated? Or maybe that is a good thing.

I'm thinking that a project may use an alternate charting library (like Apex), and they may chose to only use the text-based components.

If this is true, then adding chartkick as a gem dep is going to force them to pull an unused gem into their project (correct)? I feel like the previous approach probably resulted in poor DX but also didn't impose any optional dependency.

Again, maybe that is the stance that we want to take as chartkick is great.

@jonathanloos
Copy link
Contributor Author

@krsyoung to close the loop here, I agree that adding a hard dependency for chartkick wouldn't be the best because Matey itself isn't named accordingly. Thinking about bootstrap_form it makes sense that it has a hard requirement on bootstrap (it's in the name).

In the case of Matey, we don't have any indication that it's a hard requirement.

An approach I've been contemplating is actually leveraging slots in VCs to allow for consumers to pass their charts in, where Matey can provide the data. I'll work on an example implementation and let you know!

@jonathanloos
Copy link
Contributor Author

Looking at implementation I don't think it will work here without some additional refactoring. I was going with the idea we could approach as something like:

<%= render(Matey::ChartComponent.new) do |component| %>
    <% component.with_chart do %>
      <%# custom charting code here %>
      <%# would need access to a Matey service to put the data into charting tool %>
    <% end %>
<% end %>

But this would require each dataset available in each view component to also be exposed as a service or helper method such that the following would be possible:

<%= render(Matey::ChartComponent.new) do |component| %>
    <% component.with_chart do %>
      <%= apex_line_chart matey_helper_method(@events), @options %>
    <% end %>
<% end %>

What are your thoughts on the move? Worth it?

The opinionated "just include chartkick or apex" route would be much less work but also less flexible..

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.

Add Support for Chartkick

2 participants