Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@ jobs:
python -m pip install --upgrade pip
python -m pip install flake8 pytest coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Check format is Black
uses: psf/black@stable
- uses: astral-sh/ruff-action@v3
with:
src: "./easychart"
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
test:
runs-on: ubuntu-latest
strategy:
Expand Down
17 changes: 16 additions & 1 deletion easychart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@
import easychart.extensions as ext
import easychart.rendering

__version__ = "0.1.32"
__version__ = "0.1.33"

__all__ = [
"new",
"heatmap",
"plot",
"render",
"Chart",
"Plot",
"Grid",
"config",
"datasets",
"themes",
"colormaps",
"ext",
]


def new(
Expand Down
16 changes: 8 additions & 8 deletions easychart/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class Config(easytree.dict):
defaults = {
"stylesheets": [],
"scripts": [
"https://code.highcharts.com/stock/highstock.js",
"https://code.highcharts.com/highcharts-more.js",
"https://code.highcharts.com/modules/heatmap.js",
"https://code.highcharts.com/modules/exporting.js",
"https://code.highcharts.com/modules/offline-exporting.js",
"https://code.highcharts.com/modules/export-data.js",
"https://code.highcharts.com/modules/annotations.js",
"https://code.highcharts.com/modules/accessibility.js",
"https://cdn.jsdelivr.net/npm/highcharts/highstock.js",
"https://cdn.jsdelivr.net/npm/highcharts/highcharts-more.js",
"https://cdn.jsdelivr.net/npm/highcharts/modules/heatmap.js",
"https://cdn.jsdelivr.net/npm/highcharts/modules/exporting.js",
"https://cdn.jsdelivr.net/npm/highcharts/modules/offline-exporting.js",
"https://cdn.jsdelivr.net/npm/highcharts/modules/export-data.js",
"https://cdn.jsdelivr.net/npm/highcharts/modules/annotations.js",
"https://cdn.jsdelivr.net/npm/highcharts/modules/accessibility.js",
],
"theme": None,
"rendering": {
Expand Down
2 changes: 2 additions & 0 deletions easychart/extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .racechart import racechart

__all__ = ["racechart"]
6 changes: 4 additions & 2 deletions easychart/extensions/racechart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ def render(self, *, theme=None):
}
)

return IPython.display.HTML(f"""
return IPython.display.HTML(
f"""
<iframe
style="border:0;outline:none;width:{easychart.internals.Size(easychart.config.rendering.container.width)};max-width:{easychart.internals.Size(easychart.config.rendering.container.get("max-width", "100%"))}"
onload='javascript:(function(o){{o.style.height=o.contentWindow.document.body.scrollHeight+"px";}}(this));'
srcdoc="{html.escape(template)}">
</iframe>
""")
"""
)
2 changes: 2 additions & 0 deletions easychart/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
from .grid import Grid
from .plot import Plot
from .series import Series

__all__ = ["Chart", "Grid", "Plot", "Series"]
8 changes: 6 additions & 2 deletions easychart/models/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,11 +1265,15 @@ def export(self, filename, *, theme=None, scale=2, throttle=None, **kwargs):
)

if res.status_code == 429:
raise Exception(textwrap.dedent("""
raise Exception(
textwrap.dedent(
"""
The export server responded with HTTP code 429, which means you are making too many export requests in too short a period of time.

Please increase the throttle value, or manually set a time.sleep between each export request.
"""))
"""
)
)

if res.status_code != 200:
raise Exception(
Expand Down
6 changes: 4 additions & 2 deletions easychart/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import easychart.themes
import easychart.internals

from . import utils

from jinja2 import Environment, FileSystemLoader

# create the environment
Expand All @@ -33,8 +35,8 @@ def render(charts) -> str:
**{
"plots": simplejson.dumps([plot.serialize() for plot in grid.plots]),
"theme": simplejson.dumps(easychart.themes.get(grid.theme)),
"scripts": easychart.config.scripts,
"stylesheets": easychart.config.stylesheets,
"scripts": utils.deduplicate(easychart.config.scripts),
"stylesheets": utils.deduplicate(easychart.config.stylesheets),
}
)

Expand Down
21 changes: 21 additions & 0 deletions easychart/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Iterable, List, TypeVar, Hashable

T = TypeVar("T", bound=Hashable)


def deduplicate(lst: Iterable[T]) -> List[T]:
"""
Return a deduplicated list of items, in the order of the
original list

Parameters
----------
lst : iterable
Iterable of hashable values

Returns
-------
list
"""
seen: set[T] = set()
return [x for x in lst if not (x in seen or seen.add(x))]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="easychart",
version="0.1.32",
version="0.1.33",
author="david.schenck@outlook.com",
author_email="david.schenck@outlook.com",
description="Highcharts meets python in your Jupyter notebook",
Expand Down
1 change: 0 additions & 1 deletion tests/unit-tests/extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
import easychart


Expand Down
28 changes: 28 additions & 0 deletions tests/unit-tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest

from easychart.utils import deduplicate


def test_deduplicate_ints():
data = [1, 2, 2, 3, 1]
assert deduplicate(data) == [1, 2, 3]


def test_deduplicate_tuples_and_order():
data = [(1, 2), (1, 2), (2,)]
assert deduplicate(data) == [(1, 2), (2,)]


def test_deduplicate_generator_preserves_order():
gen = (x for x in [3, 1, 3, 2])
assert deduplicate(gen) == [3, 1, 2]


def test_deduplicate_empty():
assert deduplicate([]) == []


def test_deduplicate_unhashable_raises_typeerror():
# Passing unhashable elements (lists) should raise at runtime
with pytest.raises(TypeError):
deduplicate([[1], [1]])
Loading