Skip to content

Customization

You can customize your plots by editing the base_plot_design object.

from google_calendar_analytics.authentication.auth import CalendarAuth
from datetime import datetime
from google_calendar_analytics.analytics import AnalyzerFacade
from googleapiclient.discovery import build, Resource  # type: ignore
from google_calendar_analytics.visualization.visual_design import base_plot_design
import asyncio

creds = CalendarAuth(
    token_path="./token.json",
    credentials_path="./credentials.json",
).get_credentials()

start_time = datetime(2023, 3, 1)
end_time = datetime(2023, 3, 30)

base_plot_design.transparency = 0.8
base_plot_design.grid_width = 0.2
base_plot_design.grid_color = "white"
base_plot_design.line_shape = "spline"
base_plot_design.rgb_line_color = "rgb(0, 255, 0)"

base_plot_design.dark_theme = True
base_plot_design.show_title = False
base_plot_design.show_legend = False


async def main():
    async with AnalyzerFacade(creds=creds) as analyzer:
        coroutines = []
        coroutines.append(analyzer.analyze_one(start_time, end_time, event_name="Programming", plot_type="Line", style_class=dark_plot_design))

        result = await asyncio.gather(*coroutines)
        for plot in result:
            plot.show()

if __name__ == "__main__":
    asyncio.run(main())

Also, you can create many design objects and use them in your code.

from google_calendar_analytics.visualization.visual_design import VisualDesign

sunny_design = VisualDesign(
    transparency=0.5,
    grid_width=0.1,
    grid_color="white",
    line_shape="spline",
    rgb_line_color="rgb(0, 255, 0)",
    dark_theme=False,
    show_title=False,
    show_legend=False,
)

rainy_design = VisualDesign(
    transparency=0.5,
    grid_width=0.1,
    grid_color="white",
    line_shape="spline",
    rgb_line_color="rgb(0, 0, 255)",
    dark_theme=True,
    show_title=False,
    show_legend=False,
)

async def main():
    async with AnalyzerFacade(creds=creds) as analyzer:
        coroutines = []
        coroutines.append(analyzer.analyze_one(start_time, end_time, event_name="Programming", plot_type="Line", style_class=sunny_design))
        coroutines.append(analyzer.analyze_one(start_time, end_time, event_name="Programming", plot_type="Line", style_class=rainy_design))

        result = await asyncio.gather(*coroutines)
        for plot in result:
            plot.show()

Plot design

Available plot design variables:

A class that represents the visual design of the plots.

Source code in google_calendar_analytics/visualization/visual_design.py
@dataclass
class VisualDesign:
    """
    A class that represents the visual design of the plots.
    """

    grid_color: str = None  # type: ignore
    font_color: str = None  # type: ignore
    rgb_colors: tuple = pastel_palette

    rgb_line_color: str = "rgb(255, 0, 0)"
    line_shape: str = "linear"

    grid_width: float = 0.1
    transparency: float = 1.0
    line_width: float = 2.0

    width: int = 800
    height: int = 400

    dark_theme: bool = False
    show_grid: bool = True
    show_title: bool = True
    show_legend: bool = True
    show_xaxis_title: bool = True
    show_yaxis_title: bool = True

    def __post_init__(self):
        """
        Check if the line_shape parameter is a valid line shape.
        """
        valid_shapes = ("linear", "spline", "hv", "vh", "hvh", "vhv")
        if self.line_shape not in valid_shapes:
            raise ValueError(
                f"Invalid line_shape: {self.line_shape}. Valid options are: {valid_shapes}"
            )

__post_init__()

Check if the line_shape parameter is a valid line shape.

Source code in google_calendar_analytics/visualization/visual_design.py
def __post_init__(self):
    """
    Check if the line_shape parameter is a valid line shape.
    """
    valid_shapes = ("linear", "spline", "hv", "vh", "hvh", "vhv")
    if self.line_shape not in valid_shapes:
        raise ValueError(
            f"Invalid line_shape: {self.line_shape}. Valid options are: {valid_shapes}"
        )

title: Plot design

Plot types

You can choose from the following plot types:

Bar

img

Line

img

MultyLine

img

Pie

img

Restrictions

Note that not all plot types have the max_events variable available. If you want to limit the number of events to be analyzed, you should use the Bar, Pie plot type instead of Line or MultyLine.

Also, you can't use analyze_many method with Line or MultyLine plot types because these plots are not suitable for multiple events.