Source code for QuteChartjs.charts

from typing import Any, Callable, Dict

from property_manager import cached_property

from QuteChartjs.common import DataNode
from QuteChartjs.core import RootNode
from QuteChartjs.internals import QWebEnginePage, QUuid


[docs]class ChartjsNode(RootNode): def __init__(self, id_: str, type_: str, page: "QWebEnginePage") -> None: super().__init__(f"chart_{QUuid.createUuid().toString(QUuid.Id128)}") self._id = id_ self._type = type_ self._page = page self._create_chart() def _create_chart(self): script = """ var ctx = document.getElementById("{{id}}").getContext('2d'); var {{chart}} = new Chart(ctx, { type: "{{type}}" });""" self.execute(script, kwargs=dict(id=self.id, type=self.type)) @property def id(self) -> str: return self._id @property def type(self) -> str: return self._type
[docs] @cached_property def data(self) -> "DataNode": return DataNode(self)
[docs] def execute( self, script: str, *, callback: Callable[[Any], None] = None, kwargs: Dict[str, Any] = None, synchronous: bool = False, ) -> None: kwargs = kwargs or {} kwargs["chart"] = self.fullname() super().execute( script, callback=callback, kwargs=kwargs, synchronous=synchronous )