GithubHelp home page GithubHelp logo

highcharts-for-python / highcharts-stock Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 1.0 12.13 MB

Python wrapper for the Highcharts Stock data visualization library.

Home Page: https://stock-docs.highchartspython.com

License: Other

Python 33.39% JavaScript 66.61%
charting charting-library data-visualization data-visualization-python highcharts stock-prices-chart time-series-data

highcharts-stock's People

Contributors

hcpchris avatar insightindustry avatar szemek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

szemek

highcharts-stock's Issues

Is Python version 3.9 or below supported?

The version currently supported is version 3.10 or above, but version 3.8 is used. Of course, virtual environments can solve this problem, but I always think that solving version issues can save a lot of time. Looking forward to your work here, thank you.

BUG RangeSelectorButton types

Describe the bug
Can't render type property on RangeSelectorButton

To Reproduce

my_chart = Chart.from_array(list_of_selected_pairs, is_stock_chart=True, options_kwargs={
        'title': {
            'text': f"{table}: {column}",
        },
        'range_selector': {
            'enabled': 'true',
            'buttons': [{
                'type': 'minute',
                'count': 60,
                'text': '1h'
            }, {
                'type': 'day',
                'count': 1,
                'text': '1d'
            }, {
                'type': 'all',
                'text': 'All'
            }],
            'selected': 2,
            'inputEnabled': 'true',
        }
    })

Expected behavior
rendered should have type attribute on buttons

Your Environment:

  • OS: [e.g. Linux, Windows, etc.]
  • Python Version: [e.g. 3.10, 3.8, 3.11]
  • Highcharts JavaScript Version: [e.g. 10.2, 10.3, etc.]

Additional context
My work around:

from highcharts_stock.options.range_selector import RangeSelectorButton

class RBHRangeSelectorButton(RangeSelectorButton):

    def _to_untrimmed_dict(self, in_cls=None) -> dict:
        untrimmed_dict = super()._to_untrimmed_dict(in_cls)
        untrimmed_dict.update(type=self.type)
        return untrimmed_dict
...

my_chart.options.range_selector.buttons = [
    (RBHRangeSelectorButton(type='minute', count='60', text='1h')),
    (RBHRangeSelectorButton(type='day', count='1', text='1d')),
    (RBHRangeSelectorButton(type='all', text='All')),
]

Support for Explicit Output of HC Defaults

In v.1.0.0, Highcharts Stock for Python outputs the JavaScript literal object where any unspecified property is serialized to a dict as None and subsequently stripped from the serialized JS object literal version. Logically, this will then apply the Highcharts default value for that property.

In v.1.x, it would be nice (to aid in debugging / diagnostics) to have an show_default_values argument in the .to_js_literal() method which if True will output the JS literal with those default values explicitly displayed, rather than stripped. By default, this argument should be False.

Needed <script/> Tags Only

In v.1.0.0, Highcharts Stock for Python will generate the full set of <script/> tags that download all of the Highcharts JS modules - whether the visualization uses that module or not.

In v.1.x, it would be good for Highcharts Stock for Python to:

  • generate the set of <script/> tags that are strictly necessary for the visualization - if a module is not needed, then it should not be included
  • expose a public method for retrieving those <script/> tags for inclusion in a <head/> location
  • expose a public method for dynamically retrieving those <script/> tags and appending them to the <head/> location based on Javascript Promises (as is used for the Jupyter Labs rendering in v.1.0.0).

One-shot Chart Creation

While a chart can be created using a single method call, in general it would make things easier to add keyword properties to Chart.__init__(...) and related factory methods that allow for "one-shot" chart creation. For example:

Chart(series = ..., data = ..., series_type = ...)

One-shot Series + Chart Creation

It should be trivially easy for a developer/data scientist to create and render a single-series chart. There are existing single-shot series creation methods, but they rely on the series then being added to an existing Chart instance. This is inefficient and overly verbose. Instead, the semantics should be simpler (pseudo-code follows):

my_series = Series(...)
chart = my_series.to_chart()

# OR

my_series = Series(...)
my_series.display()

To complete this task:

  • Series objects need a .to_chart() (instance) method that creates a chart instance populated with the single series. Default chart settings should be intelligently set or populated via keyword arguments.
  • Series objects need a .display() (instance) method that a) creates a chart instance by calling self.to_chart(), and then b) renders the chart in a Jupyter context by calling .display() on that chart.

CandlestickData fails to serialize the ``.open`` property to JS literal

NOTE: Reported on StackOverflow

It would seem that following the recent (v.1.4.0) update, that CandlestickData does not serialize proper serialization to JS literal. In particular, the .open property gets set, but when serialized to a JS literal it is serialized as null for some reason:

from highcharts_stock.chart import Chart
ohlcv = [[1665504000000, 20, 21, 19, 20, 322],
         [1665590400000, 21, 23, 21, 22, 168]]
chart = Chart.from_array(ohlcv, series_type='candlestick')

print(chart.options.series[0].data)
# Output: [CandlestickData(open = 20, close = 20, high = 21, low = 19, x = 1665504000000),
# CandlestickData(open = 21, close = 22, high = 23, low = 21, x = 1665590400000)]

js_lit = chart.to_js_literal()
print(js_lit[js_lit.find("data:"):js_lit.find(']]') + 2].replace('\n', ''))
# Output: data: [[1665504000000, null, 21, 19, 20], [1665590400000, null, 23, 21, 22]]

BUG Bug in generated JS with global options

Describe the bug
chart.display(global_options=global_options) causes Javascript Error: missing ) after argument list output

To Reproduce
Steps to reproduce the behavior:

  1. When I attempt 'to set up global options' using the following code: 'chart.display(global_options=global_options) '
  2. I receive 2 'Javascript Error: missing ) after argument list' errors

Expected behavior
I expect it to render proper JS with 2 calls -- one to set the global options, and the other to create the chart.

Your Environment:

  • OS: [e.g. Linux, Windows, etc.]
  • Python Version: [e.g. 3.10, 3.8, 3.11]
  • Highcharts JavaScript Version: [e.g. 10.2, 10.3, etc.]

Additional context
Bug may be at: highcharts_core/utility_functions.py:525
where it does not extract the function body correctly, cutting out too much at the end, and thus not closing off properly.

... my stupid work-around (i just added 3 dumb characters xxx to be lopped off by the function call):

class RBHChart(Chart):

    @classmethod
    def from_array(cls,
                   value,
                   series_type='line',
               series_kwargs=None,
                   options_kwargs=None,
                   chart_kwargs=None,
                   is_stock_chart=False):

        series_type = validators.string(series_type, allow_empty = False)
        series_type = series_type.lower()
        if series_type not in SERIES_CLASSES:
            raise errors.HighchartsValueError(f'series_type expects a valid Highcharts '
                                              f'series type. Received: {series_type}')

        series_kwargs = validators.dict(series_kwargs, allow_empty = True) or {}
        options_kwargs = validators.dict(options_kwargs, allow_empty = True) or {}
        chart_kwargs = validators.dict(chart_kwargs, allow_empty = True) or {}

        series_cls = SERIES_CLASSES.get(series_type, None)

        series = series_cls.from_array(value, series_kwargs = series_kwargs)

        options_kwargs['series'] = [series]
        chart_kwargs['is_stock_chart'] = is_stock_chart

        if is_stock_chart:
            options = HighchartsStockOptions(**options_kwargs)
        else:
            options = HighchartsOptions(**options_kwargs)

        instance = cls(**chart_kwargs)
        instance.options = options

        return instance

    def _jupyter_javascript(self,
                            global_options = None,
                            container = None,
                            random_slug = None,
                            retries = 3,
                            interval = 1000):
        original_container = self.container
        new_container = container or self.container or 'highcharts_target_div'
        if not random_slug:
            self.container = new_container
        else:
            self.container = f'{new_container}_{random_slug}'

        if global_options is not None:
            global_options = validate_types(global_options,
                                            types = (SharedStockOptions, SharedOptions))

        js_str = ''
        js_str += utility_functions.get_retryHighcharts()

        if global_options:
            js_str += '\n' + utility_functions.prep_js_for_jupyter(global_options.to_js_literal()+'xxx') + '\n'  # extra 3 chars

        js_str += utility_functions.prep_js_for_jupyter(self.to_js_literal(),
                                                        container=self.container,
                                                        random_slug=random_slug,
                                                        retries=retries,
                                                        interval=interval)

        self.container = original_container

        return js_str

Support for Styled Mode Configuration

In v.1.0.0 of Highcharts Stock for Python supports the enabling/disabling of styled mode using the appropriate options. However, any configuration of the CSS has to occur outside of the library itself.

In v.1.x (possibly v.2.0 due to the complexity of this enhancement) it would be helpful if the library also provided for the configuration of the CSS styles that are applicable if using Styled Mode.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.