Skip to content
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
27 changes: 27 additions & 0 deletions datawrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
RangeAnnotation,
ScatterPlot,
StackedBarChart,
Table,
TextAnnotation,
Transform,
XLineAnnotation,
Expand All @@ -47,6 +48,7 @@
)
from datawrapper.charts.enums import (
ArrowHead,
BorderWidth,
ConnectorLineType,
DateFormat,
GridDisplay,
Expand All @@ -57,6 +59,7 @@
LineWidth,
NumberDivisor,
NumberFormat,
PaginationType,
PlotHeightMode,
RegressionMethod,
ReplaceFlagsType,
Expand All @@ -76,10 +79,20 @@
ValueLabelPlacement,
)
from datawrapper.charts.models import (
ColorStop,
CustomRangeMixin,
CustomTicksMixin,
GridDisplayMixin,
GridFormatMixin,
HeatMapContinuous,
HeatMapSteps,
LegendContinuous,
MiniColumn,
MiniLine,
TableBodyRow,
TableColumn,
TableRow,
TableTextStyle,
)
from datawrapper.exceptions import (
FailedRequestError,
Expand All @@ -94,13 +107,18 @@
"Datawrapper",
"get_chart",
"BaseChart",
"BorderWidth",
"Annotate",
"ColumnFormat",
"Transform",
"Describe",
"BarChart",
"BarOverlay",
"ColorStop",
"ColumnChart",
"HeatMapContinuous",
"HeatMapSteps",
"LegendContinuous",
"LineChart",
"Line",
"LineSymbol",
Expand All @@ -117,6 +135,14 @@
"MultipleColumnYRangeAnnotation",
"ScatterPlot",
"StackedBarChart",
"Table",
"TableColumn",
"TableBodyRow",
"TableRow",
"TableMiniChart",
"TableTextStyle",
"MiniLine",
"MiniColumn",
"TextAnnotation",
"RangeAnnotation",
"XRangeAnnotation",
Expand All @@ -135,6 +161,7 @@
"LineWidth",
"NumberDivisor",
"NumberFormat",
"PaginationType",
"PlotHeightMode",
"RegressionMethod",
"ReplaceFlagsType",
Expand Down
2 changes: 2 additions & 0 deletions datawrapper/chart_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def get_chart(chart_id: str, access_token: str | None = None) -> BaseChart:
MultipleColumnChart,
ScatterPlot,
StackedBarChart,
Table,
)

# Type mapping from Datawrapper API chart types to Python chart classes
Expand All @@ -60,6 +61,7 @@ def get_chart(chart_id: str, access_token: str | None = None) -> BaseChart:
"d3-bars-split": MultipleColumnChart,
"d3-scatter-plot": ScatterPlot,
"d3-bars-stacked": StackedBarChart,
"tables": Table,
}

# Fetch chart metadata to determine type
Expand Down
4 changes: 4 additions & 0 deletions datawrapper/charts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
LineWidth,
NumberDivisor,
NumberFormat,
PaginationType,
PlotHeightMode,
RegressionMethod,
ReplaceFlagsType,
Expand Down Expand Up @@ -69,6 +70,7 @@
)
from .scatter import ScatterPlot
from .stacked_bar import StackedBarChart
from .table import Table

__all__ = (
"ConnectorLine",
Expand Down Expand Up @@ -96,6 +98,7 @@
"LineWidth",
"NumberDivisor",
"NumberFormat",
"PaginationType",
"PlotHeightMode",
"RegressionMethod",
"ReplaceFlagsType",
Expand Down Expand Up @@ -140,4 +143,5 @@
"MultipleColumnYRangeAnnotation",
"ScatterPlot",
"StackedBarChart",
"Table",
)
1 change: 1 addition & 0 deletions datawrapper/charts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class BaseChart(BaseModel):
"d3-scatter-plot",
"locator-map",
"multiple-columns",
"tables",
] = Field(alias="chart-type", description="The type of datawrapper chart to create")

#
Expand Down
4 changes: 4 additions & 0 deletions datawrapper/charts/enums/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Enum classes for Datawrapper chart formatting and styling options."""

from .annos import ArrowHead, ConnectorLineType, StrokeType, StrokeWidth
from .border_width import BorderWidth
from .date_format import DateFormat
from .grid_display import GridDisplay
from .grid_label import GridLabelAlign, GridLabelPosition
Expand All @@ -9,6 +10,7 @@
from .line_width import LineWidth
from .number_divisor import NumberDivisor
from .number_format import NumberFormat
from .pagination import PaginationType
from .plot_height import PlotHeightMode
from .replace_flags import ReplaceFlagsType
from .scatter_shape import (
Expand All @@ -29,6 +31,7 @@

__all__ = [
"ArrowHead",
"BorderWidth",
"ConnectorLineType",
"DateFormat",
"GridDisplay",
Expand All @@ -39,6 +42,7 @@
"LineWidth",
"NumberDivisor",
"NumberFormat",
"PaginationType",
"PlotHeightMode",
"RegressionMethod",
"ReplaceFlagsType",
Expand Down
26 changes: 26 additions & 0 deletions datawrapper/charts/enums/border_width.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Enum for border thickness options in tables."""

from enum import Enum


class BorderWidth(str, Enum):
"""Border width options for rows and columns in tables.

Attributes:
NONE: No border
THIN: 1px thickness
MEDIUM: 2px thickness
THICK: 3px thickness

Examples:
>>> from datawrapper.charts import Table, TableHeaderRow, BorderWidth
>>> chart = Table(
... title="Country Data",
... header_style=TableHeaderRow(border_bottom=BorderWidth.THIN),
... )
"""

NONE = "none"
THIN = "1px"
MEDIUM = "2px"
THICK = "3px"
25 changes: 25 additions & 0 deletions datawrapper/charts/enums/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Enum for pagination options in charts."""

from enum import Enum


class PaginationType(str, Enum):
"""Pagination options in charts.

Controls whether pagination is enabled and where the controls sit.

Attributes:
OFF: No pagination
TOP: Pagination controls at top
BOTTOM: Pagination controls at bottom
BOTH: Pagination controls at top and bottom

Examples:
>>> from datawrapper.charts import Table, PaginationType
>>> chart = Table(title="Country Data", pagination=PaginationType.TOP)
"""

OFF = "off"
TOP = "top"
BOTTOM = "bottom"
BOTH = "both"
25 changes: 25 additions & 0 deletions datawrapper/charts/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@
YLineAnnotation,
YRangeAnnotation,
)
from .table_column import TableColumn
from .table_heatmap import (
ColorStop,
HeatMap,
HeatMapContinuous,
HeatMapSteps,
LegendContinuous,
LegendSteps,
)
from .table_mini_chart import MiniColumn, MiniLine, TableMiniChart
from .table_row import TableBodyRow, TableRow
from .table_text_style import TableTextStyle
from .text_annotations import ConnectorLine, TextAnnotation
from .transforms import ColumnFormat, ColumnFormatList, Transform

__all__ = [
"Annotate",
"AnnotationsMixin",
"ColorStop",
"ColumnFormat",
"ColumnFormatList",
"ConnectorLine",
Expand All @@ -37,11 +50,23 @@
"Describe",
"GridDisplayMixin",
"GridFormatMixin",
"HeatMap",
"HeatMapContinuous",
"HeatMapSteps",
"LegendContinuous",
"LegendSteps",
"Logo",
"MiniLine",
"MiniColumn",
"Publish",
"PublishBlocks",
"RangeAnnotation",
"Sharing",
"TableBodyRow",
"TableColumn",
"TableRow",
"TableMiniChart",
"TableTextStyle",
"TextAnnotation",
"Transform",
"Visualize",
Expand Down
Loading