Skip to content

Commit

Permalink
Merge pull request #510 from hroemer/master
Browse files Browse the repository at this point in the history
hjson as alternative JSON/JS decoding library
  • Loading branch information
WolfgangFahl authored Sep 7, 2022
2 parents f555d76 + 3b619ff commit 9d3aa3e
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 128 deletions.
27 changes: 6 additions & 21 deletions justpy/chartcomponents.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import hjson

from .htmlcomponents import *
import demjson3 as demjson
from addict import Dict
import itertools
from urllib.parse import quote


# TODO: May need to call chart.reflow() on resize
# TODO: Handle formatter functions, for example in dataLabels and others.
# TODO: Add support for more events like drilldown
Expand All @@ -18,7 +20,6 @@ def make_pairs_list(x_data, y_data):


class HighCharts(JustpyBaseComponent):

# Highcharts.getOptions().colors
highcharts_colors = [
"#7cb5ec",
Expand Down Expand Up @@ -195,12 +196,12 @@ def react(self, data):
pass

def load_json(self, options_string):
self.options = Dict(demjson.decode(options_string.encode("ascii", "ignore")))
self.options = Dict(hjson.loads(options_string.encode("ascii", "ignore")))
return self.options

def load_json_from_file(self, file_name):
with open(file_name, "r") as f:
self.options = Dict(demjson.decode(f.read().encode("ascii", "ignore")))
self.options = Dict(hjson.loads(f.read().encode("ascii", "ignore")))
return self.options

def convert_object_to_dict(self):
Expand All @@ -227,13 +228,11 @@ def convert_object_to_dict(self):

class HighStock(HighCharts):
def __init__(self, **kwargs):

super().__init__(**kwargs)
self.stock = True


class Histogram(HighCharts):

_options = """
{
title: {
Expand Down Expand Up @@ -282,7 +281,6 @@ def __init__(self, data, **kwargs):


class Pie(HighCharts):

_options = """
{
chart: {
Expand Down Expand Up @@ -327,7 +325,6 @@ def __init__(self, data, **kwargs):


class PieSemiCircle(HighCharts):

_options = """
{
chart: {
Expand Down Expand Up @@ -385,7 +382,6 @@ def __init__(self, data, **kwargs):


class Scatter(HighCharts):

_options = """
{
chart: {
Expand Down Expand Up @@ -454,7 +450,6 @@ def set_figure(self, fig=None):
output.close()
return self.inner_html


# --------------------------------------------------------------------
# deck.gl related objects

Expand All @@ -470,9 +465,7 @@ def set_figure(self, fig=None):
_has_pydeck = False

if _has_pydeck:

class PyDeckFrame(Iframe):

vue_type = "iframejp"

def __init__(self, **kwargs):
Expand All @@ -494,8 +487,8 @@ def convert_object_to_dict(self):
d["transition_duration"] = self.transition_duration
return d

class PyDeck(Div):

class PyDeck(Div):
vue_type = "deckgl"

def __init__(self, **kwargs):
Expand All @@ -518,15 +511,13 @@ def convert_object_to_dict(self):
d["mapbox_key"] = self.deck.mapbox_key
return d


try:
import altair as alt

_has_altair = True
except:
_has_altair = False


if _has_altair:

class AltairChart(Div):
Expand Down Expand Up @@ -559,15 +550,13 @@ def convert_object_to_dict(self):
d["options"] = self.options
return d


try:
import plotly

_has_plotly = True
except:
_has_plotly = False


if _has_plotly:

class PlotlyChart(Div):
Expand Down Expand Up @@ -599,15 +588,13 @@ def convert_object_to_dict(self):
d["config"] = self.config
return d


try:
import bokeh

_has_bokeh = True
except:
_has_bokeh = False


if _has_bokeh:

class BokehChart(Div):
Expand Down Expand Up @@ -639,15 +626,13 @@ def convert_object_to_dict(self):
d["config"] = self.config
return d


try:
import folium

_has_folium = True
except:
_has_folium = False


if _has_folium:

class FoliumChart(Div):
Expand Down
8 changes: 4 additions & 4 deletions justpy/gridcomponents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hjson

from .htmlcomponents import *
import demjson3 as demjson
from addict import Dict

try:
Expand All @@ -14,7 +15,6 @@


class AgGrid(JustpyBaseComponent):

# https://www.ag-grid.com/javascript-grid-features/

vue_type = "grid"
Expand Down Expand Up @@ -85,12 +85,12 @@ def react(self, data):
pass

def load_json(self, options_string):
self.options = Dict(demjson.decode(options_string.encode("ascii", "ignore")))
self.options = Dict(hjson.loads(options_string.encode("ascii", "ignore")))
return self.options

def load_json_from_file(self, file_name):
with open(file_name, "r") as f:
self.options = Dict(demjson.decode(f.read().encode("ascii", "ignore")))
self.options = Dict(hjson.loads(f.read().encode("ascii", "ignore")))
return self.options

def load_pandas_frame(self, df):
Expand Down
Loading

0 comments on commit 9d3aa3e

Please sign in to comment.