Source code for energytrackr.plot.builtin_plots.evolution_plot
"""EvolutionPlot module with commit-zoom selector and fixed y-axis."""from__future__importannotationsfromdataclassesimportdataclass,fieldfromtypingimportAnyfrombokeh.modelsimportColumnDataSourcefrombokeh.plottingimportfigurefromenergytrackr.plot.builtin_plots.mixinsimportFontMixin,SingleCommitZoomMixin,draw_additional_objectsfromenergytrackr.plot.builtin_plots.registryimportregister_plotfromenergytrackr.plot.core.contextimportContextfromenergytrackr.plot.core.interfacesimportBasePlot,Configurable
[docs]@dataclass(frozen=True)classEvolutionPlotConfig:"""Configuration for EvolutionPlot, including how wide the zoom box is."""template:str="templates/base_plot.html"objects:list[str]=field(default_factory=list)zoom_window:int=5# number of commits on each side to show
[docs]@register_plotclassEvolutionPlot(SingleCommitZoomMixin,FontMixin,BasePlot,Configurable[EvolutionPlotConfig]):"""Energy-per-commit evolution plot with commit zoom and fixed y-axis."""def__init__(self,**params:dict[str,Any])->None:"""Initialize with optional `zoom_window` parameter. Args: **params: Arbitrary configuration parameters for EvolutionPlotConfig. """super().__init__(EvolutionPlotConfig,**params)def_make_sources(self,ctx:Context)->dict[str,ColumnDataSource]:# noqa: PLR6301x=ctx.stats["x_indices"]y=ctx.stats["medians"]return{"median":ColumnDataSource({"x":x,"y":y})}def_draw_glyphs(self,fig:figure,sources:dict[str,ColumnDataSource],ctx:Context)->None:fig.line("x","y",source=sources["median"],color="black",legend_label="Median")draw_additional_objects(self.config.objects,fig,ctx)def_configure(self,fig:figure,ctx:Context)->None:"""Apply fonts, axis labels, and freeze the y-axis to initial full-data range."""super()._configure(fig,ctx)# labelsfig.xaxis[0].axis_label="Commit (oldest → newest)"fig.yaxis[0].axis_label=f"Median {ctx.energy_fields[0]} (J)"def_title(self,ctx:Context)->str:# noqa: PLR6301# Custom title including fieldreturnf"Energy Consumption - {ctx.energy_fields[0]}"def_key(self,ctx:Context)->str:# noqa: ARG002, PLR6301# Store under 'Evolution'return"Evolution"