Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add Bokeh gridplot/layout integration (Issue #40) #149

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions chartify/_core/layout/Nonnegative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import annotations

from typing import Any, TypeVar, Union

T = TypeVar("T", bound=Union[int, float])


class NonNegative():

def __init__(self, type_param: T, default: Intrinsic) -> None:
super().__init__(type_param, default=default)
10 changes: 10 additions & 0 deletions chartify/_core/layout/Nullable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

from typing import Any, TypeVar, Union

T = TypeVar("T")


class Nullable(Union[T, None]):
def __init__(self, type_param: T, default: Union[T, None] = None) -> None:
super().__init__(type_param, default=default)
26 changes: 26 additions & 0 deletions chartify/_core/layout/css.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
String: TypeAlias = str


class StyleSheet():
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)


class InlineStyleSheet(StyleSheet):

"""
Inline style sheet equivalent to ``<style type="text/css">${css}</style>``
"""

css = Required(String)


class ImportedStyleSheet(StyleSheet):

# explicit __init__ to support Init signatures
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

url = Required(String, help="""
The location of an external stylesheet.
""")
53 changes: 53 additions & 0 deletions chartify/_core/layout/layouts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'''
various kinds of layout components
'''


from typing import TypeAlias, Tuple, List, Any
from chartify import Color, Nullable

from abc import ABC, abstractmethod

from bokeh import Optional
from core import UIElement

Auto: TypeAlias = Enum(auto)
Null: TypeAlias = None
Float: TypeAlias = float
Bool: TypeAlias = bool
Int: TypeAlias = int
Str: TypeAlias = str


class LayoutDOM(UIElement):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

width: int | None = Nullable(NonNegative(int))

height: int | None = Nullable(NonNegative(int))

min_width = Nullable(NonNegative(int))

min_height = Nullable(Nonnegative(int))

margin = Nullable(Any(Int, Tuple(Int, Int), Tuple(Int, Int, Int, Int)))

width_policy = Any(Auto, Enum(SizingMode), default="auto")

height_policy = Any(Auto, Enum(SizingMode), default="auto")

aspect_ratio = Any(Null, Auto, Float)

flow_mode = Enum(FlowMode, default="block")

sizing_mode = Nullable(Enum(SizingMode))

align = Any(Auto, Enum(Align), Tuple(
Enum(Align), Enum(Align)), default="auto")

css_class = List(str)

resizable = Any(Bool, Enum(Dimensions), default=False)


9 changes: 9 additions & 0 deletions chartify/_core/layout/required.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import TypeVar

T = TypeVar("T")


class Required():

def __init__(self, type_param: T, default: Undefined) -> None:
super().__init__(type_param, default)
8 changes: 8 additions & 0 deletions chartify/_core/layout/uielement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from cssutils import cssstylesheets # to add the abstraction of stylesheets

class UIElement:

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)


32 changes: 32 additions & 0 deletions chartify/_core/layout/undefined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations


class UndefinedT:

def __deepcopy__(self) -> UndefinedT:
return self

def __str__(self) -> str:
return "Undefined"

def __repr__(self) -> str:
return "Undefined"


Undefined = UndefinedT()


class IntrinsicT:
""" Indicates usage of the intrinsic default value of a property. """

def __deepcopy__(self) -> IntrinsicT:
return self

def __str__(self) -> str:
return "Intrinsic"

def __repr__(self) -> str:
return "Intrinsic"


Intrinsic = IntrinsicType()
Loading