highcharts-for-python / highcharts-stock Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for the Highcharts Stock data visualization library.
Home Page: https://stock-docs.highchartspython.com
License: Other
Python wrapper for the Highcharts Stock data visualization library.
Home Page: https://stock-docs.highchartspython.com
License: Other
Add support for simplified form of .from_pandas()
in line with highcharts-for-python/highcharts-core#103
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.
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:
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')),
]
Add support for simplified form of .from_csv()
in line with highcharts-for-python/highcharts-core#105
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
.
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:
<script/>
tags that are strictly necessary for the visualization - if a module is not needed, then it should not be included<script/>
tags for inclusion in a <head/>
location<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).The FlagSeries
series type is missing its .data
property.
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 = ...)
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:
.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..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.Given the recent release of Highcharts Stock (JS) v.11.4, Highcharts Stock for Python needs to be updated to align with it.
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]]
There seems to be an issue with FlagDataCollection
serialization, specifically the JS literal is being serialized without being trimmed. This is causing downstream conflicts when rendering.
Add support for SeriesBase.convert_to()
in line with highcharts-for-python/highcharts-core#107
pyproject.toml
requirements.txt
requirements.dev.txt
requirements.travis.txt
Highcharts Stock for Python needs to be updated to reflect changes introduced by Highcharts Stock (JS) v11.
Describe the bug
chart.display(global_options=global_options) causes Javascript Error: missing ) after argument list
output
To Reproduce
Steps to reproduce the behavior:
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:
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
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.
Add support for the DataPointCollection
class added in highcharts-for-python/highcharts-core#92
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.