Skip to content

Commit

Permalink
Merge pull request #2 from RobertoMaurizzi/upgrade-to-pydantic-2.8.2
Browse files Browse the repository at this point in the history
Upgrade to pydantic 2.8.2
  • Loading branch information
joshbrooks authored Oct 4, 2024
2 parents 451dd64 + 61064a6 commit ccd863e
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 181 deletions.
142 changes: 75 additions & 67 deletions pydacharts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,39 @@ class Layout(BaseModel):
the global options for the chart layout is defined in Chart.defaults.layout
"""

padding: Optional[Padding]
padding: Optional[Padding] = None


class Dataset(BaseModel):
label: Optional[str]
data: Optional[List[Any]]
borderColor: Optional[Union[List[RgbStr], RgbStr]]
backgroundColor: Optional[Union[List[RgbStr], RgbStr]]
showLine: Optional[bool]
hoverOffset: Optional[int]
label: Optional[str] = None
data: Optional[List[Any]] = None
borderColor: Optional[Union[List[RgbStr], RgbStr]] = None
backgroundColor: Optional[Union[List[RgbStr], RgbStr]] = None
showLine: Optional[bool] = None
hoverOffset: Optional[int] = None
# Support stacked bar charts
stack: Optional[str]
stack: Optional[str] = None
# Support rounded bars
borderWidth: Optional[int]
borderRadius: Optional[int]
borderSkipped: Optional[bool]
borderDash: Optional[List[int]]
borderWidth: Optional[int] = None
borderRadius: Optional[int] = None
borderSkipped: Optional[bool] = None
borderDash: Optional[List[int]] = None
# Support "combo chart"
type: Optional[Union[ChartType, str]]
order: Optional[int]
type: Optional[Union[ChartType, str]] = None
order: Optional[int] = None

datalabels: Optional[DataLabelsPlugin]
datalabels: Optional[DataLabelsPlugin] = None


class LineDataSet(Dataset):
showLine: Optional[bool] = True
fill: Optional[bool] = False
tension: Optional[float] = 0.1
stepped: Optional[Union[bool, StepOption]]
stepped: Optional[Union[bool, StepOption]] = None


class PieDataSet(Dataset):
...
fill: Optional[bool] = False


class Data(BaseModel):
Expand All @@ -99,11 +99,11 @@ class PieData(Data):

class Title(BaseModel):
display: bool = True
text: Optional[str]
color: Optional[RgbStr]
font: Optional[Font]
padding: Optional[Padding]
align: Optional[Literal["left", "right", "center"]]
text: Optional[str] = None
color: Optional[RgbStr] = None
font: Optional[Font] = None
padding: Optional[Padding] = None
align: Optional[Literal["left", "right", "center"]] = None


class LegendLabels(BaseModel):
Expand All @@ -114,7 +114,7 @@ class LegendLabels(BaseModel):
boxWidth: Optional[int] = Field(40, description="Width of coloured box.")
boxHeight: Optional[int] = Field(description="Height of the coloured box.")
color: Optional[Color] = Field(description="Color of label and the strikethrough.")
font: Optional[Font]
font: Optional[Font] = None
padding: Optional[int] = Field(description="Padding between rows of colored boxes.")
generateLabels: Optional[Function] = Field(
description="Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. See Legend Item for details."
Expand Down Expand Up @@ -258,30 +258,30 @@ class Tooltip(BaseModel):


class Plugins(BaseModel):
legend: Optional[Legend]
title: Optional[Title]
datalabels: Optional[Union[DataLabelsPlugin, List[DataLabelsPlugin]]]
tooltip: Optional[Tooltip]
legend: Optional[Legend] = None
title: Optional[Title] = None
datalabels: Optional[Union[DataLabelsPlugin, List[DataLabelsPlugin]]] = None
tooltip: Optional[Tooltip] = None


class Ticks(BaseModel):
"""
Namespace: options.scales[scaleId].ticks
"""

beginAtZero: Optional[bool]
beginAtZero: Optional[bool] = None
backdropColor: Optional[Color] = Field(description="Color of label backdrops.")
backdropPadding: Optional[Padding] = Field(description="Padding of label backdrop.")
callback: Optional[Function] = Field(
description="Returns the string representation of the tick value as it should be displayed on the chart.."
)
display: Optional[bool] = Field(description="If true, show tick labels.")
color: Optional[Color] = Field(description="Color of ticks.")
font: Optional[Font]
font: Optional[Font] = None
major: Optional[Dict] = Field(description="Major ticks configuration.")
padding: Optional[int] = Field(description="Sets the offset of the tick labels from the axis")
showLabelBackdrop: Optional[bool] = Field(description="If true, draw a background behind the tick labels.")
stepSize: Optional[int]
stepSize: Optional[int] = None
textStrokeColor: Optional[Color] = Field(description="The color of the stroke around the text.")
textStrokeWidth: Optional[int] = Field(description="Stroke width around the text.")
z: Optional[int] = Field(
Expand Down Expand Up @@ -352,50 +352,57 @@ class CartesianTicks(Ticks):
description='Should the defined min and max values be presented as ticks even if they are not "nice".'
)
labelOffset: Optional[int] = Field(
description="Distance in pixels to offset the label from the centre point of the tick (in the x-direction for the x-axis, and the y-direction for the y-axis). Note: this can cause labels at the edges to be cropped by the edge of the canvas"
)
maxRotation: Optional[int] = Field(
description="Maximum rotation for tick labels when rotating to condense labels. Note: Rotation doesn't occur until necessary. Note: Only applicable to horizontal scales."
)
minRotation: Optional[int] = Field(
description="Minimum rotation for tick labels. Note: Only applicable to horizontal scales."
description="Distance in pixels to offset the label from the centre point of the tick (in the x-direction for the horizontal axis, and the y-direction for the vertical axis)."
)
minRotation: Optional[int] = Field(description="Minimum rotation for tick labels, in degrees.")
maxRotation: Optional[int] = Field(description="Maximum rotation for tick labels, in degrees.")
mirror: Optional[bool] = Field(
description="Flips tick labels around axis, displaying the labels inside the chart instead of outside. Note: Only applicable to vertical scales."
description="Flips tick labels around axis, displaying the labels inside the chart instead of outside."
)
padding: Optional[int] = Field(
description="Padding between the tick label and the axis. When set on a vertical axis, this applies in the horizontal (X) direction. When set on a horizontal axis, this applies in the vertical (Y) direction."
padding: Optional[int] = Field(description="Padding between the tick label and the axis.")
showLabelBackdrop: Optional[bool] = Field(description="If true, draw a background behind the tick labels.")
textStrokeColor: Optional[Color] = Field(description="The color of the stroke around the text.")
textStrokeWidth: Optional[int] = Field(description="Stroke width around the text.")
z: Optional[int] = Field(
description="z-index of tick layer. Useful when ticks are drawn on chart area. Values <= 0 are drawn under datasets, > 0 on top."
)


class ScaleOptions(BaseModel):
display: Optional[bool] = True
beginAtZero: Optional[bool]
title: Optional[Title]
min: Optional[int]
max: Optional[int]
stacked: Optional[bool]
position: Optional[str]
beginAtZero: Optional[bool] = None
title: Optional[Title] = None
min: Optional[int] = None
max: Optional[int] = None
stacked: Optional[bool] = None
position: Optional[str] = None
offset: bool = True
ticks: Optional[Union[Ticks, CartesianTicks]]
barThickness: Optional[int]
labels: Optional[Any]
grid: Optional[Grid]
ticks: Optional[Union[Ticks, CartesianTicks]] = None
barThickness: Optional[int] = None
labels: Optional[Any] = None
grid: Optional[Grid] = None
type: Optional[str] = None


class Scales(BaseModel):
y: Optional[ScaleOptions]
x: Optional[ScaleOptions]
y: Optional[ScaleOptions] = None
x: Optional[ScaleOptions] = None
# Added for datalabels plugin
xAxes: Optional[List[ScaleOptions]]
yAxes: Optional[List[ScaleOptions]]
xAxes: Optional[List[ScaleOptions]] = None
yAxes: Optional[List[ScaleOptions]] = None
# x1, y1 represent additional
y1: Optional[ScaleOptions]
x1: Optional[ScaleOptions]
y1: Optional[ScaleOptions] = None
x1: Optional[ScaleOptions] = None
grid: Optional[Grid] = None


class Interaction(BaseModel):
intersect: Optional[bool] # False for stacked charts
intersect: Optional[bool] = None # False for stacked charts
mode: Optional[str] = Field(
description="Sets which elements appear in the interaction. See Interaction Modes for details."
)
axis: Optional[str] = "x"
includeInvisible: Optional[bool] = False


class Options(BaseModel):
Expand All @@ -418,24 +425,25 @@ class Options(BaseModel):
description="Delay the resize update by give amount of milliseconds. This can ease the resize process by debouncing update of the elements.",
)

plugins: Optional[Plugins]
scales: Optional[Scales]
elements: Optional[Elements]
indexAxis: Optional[str]
interaction: Optional[Interaction]
plugins: Optional[Plugins] = None
scales: Optional[Scales] = None
elements: Optional[Elements] = None
indexAxis: Optional[str] = None
interaction: Optional[Interaction] = None

# Bar chart option
barPercentage: Optional[float]
layout: Optional[Layout]
barPercentage: Optional[float] = None
layout: Optional[Layout] = None
stacked: Optional[bool] = False

# Doughnut chart
cutout: Optional[str]
cutout: Optional[str] = None


class Config(BaseModel):
type: Union[ChartType, str] = ChartType.line
data: Optional[Data]
options: Optional[Options]
data: Optional[Data] = None
options: Optional[Options] = None


if __name__ == "__main__":
Expand Down
61 changes: 31 additions & 30 deletions pydacharts/plugins/datalabels.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ class Align(str, Enum):
left = "left"
top = "top"

align: Optional[Align]
anchor: Optional[Anchor]
color: Optional[Color]
font: Optional[Font]
formatter: Optional[str]
offset: Optional[int]
opacity: Optional[float]
align: Optional[Align] = None
anchor: Optional[Anchor] = None
clamp: Optional[bool] = None
color: Optional[Color] = None
font: Optional[Font] = None
formatter: Optional[str] = None
offset: Optional[int] = None
opacity: Optional[float] = None

padding: Optional[int]
borderRadius: Optional[int]
backgroundColor: Optional[Color]
padding: Optional[int] = None
borderRadius: Optional[int] = None
backgroundColor: Optional[Color] = None


"""
Expand Down Expand Up @@ -73,34 +74,34 @@ class Align(str, Enum):


class DataLabelsPlugin(BaseModel):
align: Optional[Union[align, degrees]]
align: Optional[Union[align, degrees]] = None
anchor: Optional[str] = "center"
backgroundColor: Optional[DataLabelsPluginStyle]
borderColor: Optional[DataLabelsPluginStyle]
borderRadius: Optional[number]
borderWidth: Optional[number]
clamp: Optional[bool]
clip: Optional[bool]
color: Optional[DataLabelsPluginStyle]
backgroundColor: Optional[DataLabelsPluginStyle] = None
borderColor: Optional[DataLabelsPluginStyle] = None
borderRadius: Optional[number] = None
borderWidth: Optional[number] = None
clamp: Optional[bool] = None
clip: Optional[bool] = None
color: Optional[DataLabelsPluginStyle] = None
display: Optional[Union[Function, Literal[True, False, "auto"]]] = Field(
True, description="controls the visibility of labels"
)
font: Optional[Font]
formatter: Optional[Function]
labels: Optional[object]
listeners: Optional[object]
font: Optional[Font] = None
formatter: Optional[Function] = None
labels: Optional[object] = None
listeners: Optional[object] = None
offset: Optional[number] = Field(
4,
description="The offset represents the distance (in pixels) to pull the label away from the anchor point. This option is not applicable when align is 'center'. Also note that if align is 'start', the label is moved in the opposite direction. The default value is 4.",
)
opacity: Optional[number]
padding: Optional[Padding]
rotation: Optional[degrees]
textAlign: Optional[str]
textStrokeColor: Optional[DataLabelsPluginStyle]
textStrokeWidth: Optional[number]
textShadowBlur: Optional[number]
textShadowColor: Optional[Color]
opacity: Optional[number] = None
padding: Optional[Padding] = None
rotation: Optional[degrees] = None
textAlign: Optional[str] = None
textStrokeColor: Optional[DataLabelsPluginStyle] = None
textStrokeWidth: Optional[number] = None
textShadowBlur: Optional[number] = None
textShadowColor: Optional[Color] = None


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ target-version = ['py38']

[tool.poetry]
name = "pydacharts"
version = "0.1.4"
version = "0.2.0"
description = ""
authors = ["Josh Brooks <josh@catalpa.io>"]
license = "GPLv3"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.8"
pydantic = "^1.10.0"
pydantic = "^2.8"

[tool.poetry.group.dev.dependencies]
isort = "*"
Expand Down
Loading

0 comments on commit ccd863e

Please sign in to comment.