Skip to content

Optional EventListener on Chart.to_js_literal - #131

Merged
hcpchris merged 2 commits into
highcharts-for-python:rc-v.1.6from
ByronCook:master
Nov 7, 2023
Merged

hcpchris merged 2 commits into
highcharts-for-python:rc-v.1.6from
ByronCook:master

Conversation

@ByronCook

@ByronCook ByronCook commented Nov 2, 2023 •

Copy link
Copy Markdown
Contributor

Please ignore all the line ending diff's. (I'm guessing it's because I'm on Linux or haven't configured my Git client to ignore it)
The change is on line 512/513 and 602-608

I needed a chart which doesn't require an eventlistener as it's loaded on click using HTMX instead of JS, because I'm using HTMX, the DOMContentLoaded isn't being triggered. Using this change I can have the JS code executed immediately instead. This change also allows you to use any other EventListener by providing it as a string.

def to_js_literal(self,
                      filename = None,
                      encoding = 'utf-8',
                      careful_validation = False,
                      event_listener : str = 'DOMContentLoaded',
                      event_listener_enabled : bool = True) -> Optional[str]:
        if event_listener_enabled:
            if event_listener:
                prefix = """document.addEventListener('""" + event_listener + """', function() {\n"""
            else:
                prefix = """document.addEventListener(function() {\n"""
            suffix = """});"""
            as_str = prefix + as_str + '\n' + suffix
        else:
            as_str = as_str

@ByronCook ByronCook changed the title Optional EVentListener on Chart.to_js_literal Optional EventListener on Chart.to_js_literal Nov 2, 2023
@hcpchris
hcpchris self-requested a review November 2, 2023 12:42
@hcpchris hcpchris added the enhancement New feature or request label Nov 2, 2023
@hcpchris hcpchris modified the milestones: 1.5.1, 1.6.0 Nov 2, 2023
@hcpchris

hcpchris commented Nov 2, 2023

Copy link
Copy Markdown
Collaborator

Thanks, @ByronCook ! Definitely appreciate the PR. I'll review it shortly and hopefully merge it in for the next minor release.

@codecov

codecov Bot commented Nov 2, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (6726e8d) 88.25% compared to head (23ef54c) 88.24%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #131      +/-   ##
===========================================
- Coverage    88.25%   88.24%   -0.01%     
===========================================
  Files          209      209              
  Lines        30472    30475       +3     
  Branches      2434     2436       +2     
===========================================
  Hits         26892    26892              
- Misses        2669     2670       +1     
- Partials       911      913       +2     
Files Coverage Δ
highcharts_core/chart.py 49.65% <50.00%> (-0.35%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hcpchris
hcpchris changed the base branch from develop to rc-v.1.6 November 7, 2023 20:21

@hcpchris hcpchris left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, @ByronCook ! This PR looks good, and it's a welcome addition to the method! I'm going to merge it into the rc-v.1.6 branch that I'm using for our v.1.6 release. Before we roll v.1.6 out, there are some other things that we'll be merging in, and within this PR itself I'm also going to add some docstring details, but I definitely appreciate you filing this PR with this tweak. Thanks!

@hcpchris
hcpchris merged commit 02c15c8 into highcharts-for-python:rc-v.1.6 Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants