Skip to content

Commit 80fa8f4

Browse files
committed
feat: update chart_plot
- added a "rebuild" input to chart_plot for ggplot_chart objects. This allows modification of slots after build and retains the changes for plotting e.g. adding a column to C$data Also: - ggplot_chart now exposes slots as outputs - removed broken import from ggplot_chart
1 parent 1037f57 commit 80fa8f4

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

R/ggplot_chart_class.R

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#' # Create a ggplot chart (not typically called directly)
2020
#' gc = ggplot_chart()
2121
#' @rdname ggplot_chart
22-
#' @include chart_class.R layer_entity_class.R struct_preset_class.R typed_list_class.R global_preset_registry.R
22+
#' @include chart_class.R layer_entity_class.R struct_preset_class.R typed_list_class.R
2323
ggplot_chart = function(...) {
2424
# new object
2525
out = new_struct('ggplot_chart', ...)
@@ -45,7 +45,8 @@ ggplot_chart = function(...) {
4545
description = 'A list of plot aesthetics and their mapping to the data',
4646
value = NULL,
4747
type = c('typed_list.uneval', 'uneval', 'NULL')
48-
)
48+
),
49+
.outputs = c('data','layers','mapping')
4950
)
5051
)
5152

@@ -64,13 +65,26 @@ setMethod(f = "chart_build",
6465
#' @export
6566
setMethod(f = "chart_plot",
6667
signature = c("ggplot_chart", 'DatasetExperiment'),
67-
definition = function(obj, dobj) {
68-
# Build the chart
69-
obj = chart_build(obj, dobj)
68+
definition = function(obj, dobj, rebuild = NULL) {
69+
# Determine whether to rebuild based on rebuild parameter and data state
70+
should_rebuild = FALSE
71+
72+
if (!is.null(rebuild)) {
73+
# If rebuild parameter is explicitly set, use it
74+
should_rebuild = rebuild
75+
} else {
76+
# Default behavior: only rebuild if data is empty (not already built)
77+
should_rebuild = (nrow(obj@data) == 0)
78+
}
7079

80+
# Build the chart if needed
81+
if (should_rebuild) {
82+
obj = chart_build(obj, dobj)
83+
}
84+
7185
# Create the ggplot object
7286
p = ggplot2::ggplot(data = obj@data, mapping = obj@mapping@value)
73-
87+
7488
# Add all layers (geoms, stats, scales, themes, labels, facets, etc.)
7589
if (length(obj@layers) > 0) {
7690
for (i in seq_along(obj@layers)) {
@@ -80,7 +94,7 @@ setMethod(f = "chart_plot",
8094
}
8195
}
8296
}
83-
97+
8498
return(p)
8599
}
86100
)

man/ggplot_chart.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)