Skip to content

Commit 4d9b000

Browse files
authored
feat(style)!: refactor how to build the overlay style (#245)
BREAKING CHANGE: `create_font`, `create_fill` and `create_stroke` functions are internal functions. `create_style` has been renamed in `create_overlay_style`, and now, we use only this function to create the style of an overlay.
1 parent 081786a commit 4d9b000

14 files changed

Lines changed: 366 additions & 334 deletions

NAMESPACE

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(bpmnVisualizationROutput)
4-
export(create_fill)
5-
export(create_font)
64
export(create_overlay)
7-
export(create_stroke)
8-
export(create_style)
5+
export(create_overlay_style)
96
export(display)
107
export(overlay_edge_position)
118
export(overlay_shape_position)

R/bpmnVisualizationR.R

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,38 @@
3838
#' # Load the BPMN file
3939
#' bpmn_file <- system.file("examples/Order_Management.bpmn", package = "bpmnVisualizationR")
4040
#'
41-
#' # Display the BPMN diagram
41+
#' # Example 1: Display the BPMN diagram
4242
#' bpmnVisualizationR::display(bpmn_file, width='auto', height='auto')
4343
#'
44-
#' # Display the BPMN diagram featuring overlays with their default positions and styles
44+
#' # Example 2: Display the BPMN diagram featuring overlays with their default positions and styles
4545
#' overlays <- list(
4646
#' bpmnVisualizationR::create_overlay("start_event_1_1", "42"),
4747
#' bpmnVisualizationR::create_overlay("sequence_flow_1_1", "42"),
4848
#' bpmnVisualizationR::create_overlay("task_1_1", "9"),
4949
#' bpmnVisualizationR::create_overlay("sequence_flow_1_2", "8"),
5050
#' bpmnVisualizationR::create_overlay("call_activity_1_1", "7")
5151
#' )
52+
#'
5253
#' bpmnVisualizationR::display(
5354
#' bpmn_file,
5455
#' overlays,
5556
#' width='auto',
5657
#' height='auto'
5758
#' )
5859
#'
59-
#' # Display the BPMN diagram featuring overlays using custom styles and positions
60-
#' taskStyle <- bpmnVisualizationR::create_style(
61-
#' font = bpmnVisualizationR::create_font(color = 'DarkSlateGray', size = 23),
62-
#' fill = bpmnVisualizationR::create_fill(color = 'MistyRose'),
63-
#' stroke = bpmnVisualizationR::create_stroke(color = 'Red')
60+
#' # Example 3: Display the BPMN diagram featuring overlays using custom styles and positions
61+
#' taskStyle <- bpmnVisualizationR::create_overlay_style(
62+
#' font_color = 'DarkSlateGray',
63+
#' font_size = 23,
64+
#' fill_color = 'MistyRose',
65+
#' stroke_color = 'Red'
6466
#' )
6567
#'
66-
#' flowStyle <- bpmnVisualizationR::create_style(
67-
#' font = bpmnVisualizationR::create_font(color = 'WhiteSmoke', size = 19),
68-
#' fill = bpmnVisualizationR::create_fill(color = 'Teal'),
69-
#' stroke = bpmnVisualizationR::create_stroke(color = 'SpringGreen')
68+
#' flowStyle <- bpmnVisualizationR::create_overlay_style(
69+
#' font_color = 'WhiteSmoke',
70+
#' font_size = 19,
71+
#' fill_color = 'Teal',
72+
#' stroke_color = 'SpringGreen'
7073
#' )
7174
#'
7275
#' overlays <- list(
@@ -78,13 +81,15 @@
7881
#' )
7982
#' bpmnVisualizationR::display(bpmn_file, overlays, width='auto', height='auto')
8083
#'
81-
#' # Display the BPMN diagram featuring overlays, but exclude their default styles and positions
84+
#' # Example 4: Display the BPMN diagram featuring overlays,
85+
#' # but exclude their default styles and positions
8286
#' overlays <- list(
8387
#' bpmnVisualizationR::create_overlay("start_event_1_1", "42", position = "middle-left"),
8488
#' bpmnVisualizationR::create_overlay("sequence_flow_1_1", "42", flowStyle, "end"),
8589
#' bpmnVisualizationR::create_overlay("task_1_1", "9", taskStyle, "bottom-right"),
8690
#' bpmnVisualizationR::create_overlay("sequence_flow_1_2", "8", position = 'start')
8791
#' )
92+
#'
8893
#' bpmnVisualizationR::display(
8994
#' bpmn_file,
9095
#' overlays,

R/funs.R

Lines changed: 105 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,62 @@
33
#' @description
44
#' To specify the position when creating an overlay object that will be attached to BPMN \code{Shape} elements in the diagram.
55
#'
6-
#' \code{overlay_shape_position} includes the following positions:
7-
#'
8-
#' - \code{"top-left"}
9-
#' - \code{"top-right"}
10-
#' - \code{"top-center"}
11-
#' - \code{"bottom-left"}
12-
#' - \code{"bottom-right"}
13-
#' - \code{"bottom-center"}
14-
#' - \code{"middle-left"}
15-
#' - \code{"middle-right"}
16-
#'
6+
#' @details
177
#' Use these constants as the \code{position} argument in the \code{\link{create_overlay}} function.
188
#'
9+
#' @section Positions:
10+
#' \itemize{
11+
#' \item{\code{top-left}}{}
12+
#' \item{\code{top-right}}{}
13+
#' \item{\code{top-center}}{}
14+
#' \item{\code{bottom-left}}{}
15+
#' \item{\code{bottom-right}}{}
16+
#' \item{\code{bottom-center}}{}
17+
#' \item{\code{middle-left}}{}
18+
#' \item{\code{middle-right}}{}
19+
#' }
20+
#'
21+
#' @seealso
22+
#' \code{\link{create_overlay}}
23+
#'
24+
#' @examples
25+
#' # Create an overlay at the top-left corner of a shape
26+
#' overlay <- create_overlay(elementId = 1, label = "My label", position = overlay_shape_position[1])
27+
#'
1928
#' @export
20-
overlay_shape_position <- c("top-left", "top-right", "top-center", "bottom-left", "bottom-right", "bottom-center", "middle-left", "middle-right")
29+
overlay_shape_position <-
30+
c(
31+
"top-left",
32+
"top-right",
33+
"top-center",
34+
"bottom-left",
35+
"bottom-right",
36+
"bottom-center",
37+
"middle-left",
38+
"middle-right"
39+
)
2140

2241
#' @title The overlay positions on \code{Edge}
2342
#'
2443
#' @description
2544
#' To specify the position when creating an overlay object that will be attached to BPMN \code{Edge} elements in the diagram.
45+
#'
46+
#' @details
47+
#' Use these constants as the \code{position} argument in the \code{\link{create_overlay}} function.
2648
#'
27-
#' \code{overlay_edge_position} includes the following positions:
28-
#' - \code{"start"}
29-
#' - \code{"end"}
30-
#' - \code{"middle"}
49+
#' @section Positions:
50+
#' \itemize{
51+
#' \item{\code{start}}{}
52+
#' \item{\code{end}}{}
53+
#' \item{\code{middle}}{}
54+
#' }
3155
#'
32-
#' Use these constants as the \code{position} argument in the \code{\link{create_overlay}} function.
56+
#' @seealso
57+
#' \code{\link{create_overlay}}
58+
#'
59+
#' @examples
60+
#' # Create an overlay at the starting point of an edge
61+
#' overlay <- create_overlay(elementId = 1, label = "My label", position = overlay_edge_position[1])
3362
#'
3463
#' @export
3564
overlay_edge_position <- c("start", "end", "middle")
@@ -47,36 +76,42 @@ overlay_edge_position <- c("start", "end", "middle")
4776
#' @param elementId The bpmn element id to which the overlay will be attached
4877
#' @param label 'HTML' element to use as an overlay
4978
#' @param style The style of the overlay.
50-
#' Use \code{\link{create_style}} function to create the style object of an overlay and be aware of the `enableDefaultOverlayStyle` parameter in the \code{\link{display}} function.
79+
#' Use \code{\link{create_overlay_style}} function to create the style object of an overlay and be aware of the `enableDefaultOverlayStyle` parameter in the \code{\link{display}} function.
5180
#' @param position The position of the overlay
5281
#' If the bpmn element where the overlay will be attached is a Shape, use \code{\link{overlay_shape_position}}.
5382
#' Otherwise, use \code{\link{overlay_edge_position}}.
5483
#'
5584
#' @returns An overlay object
5685
#'
5786
#' @examples
58-
#' # Create an overlay with shape position "top-left"
87+
#' # Example 1: Create an overlay with shape position "top-left"
88+
#' overlay_style <- create_overlay_style(
89+
#' font_color = 'DarkSlateGray',
90+
#' font_size = 23,
91+
#' fill_color = 'MistyRose',
92+
#' stroke_color = 'Red'
93+
#' )
94+
#'
5995
#' overlay <- create_overlay(
60-
#' "my-element-id",
61-
#' "My Overlay Label",
62-
#' create_style(
63-
#' font = create_font(color = 'DarkSlateGray', size = 23),
64-
#' fill = create_fill(color = 'MistyRose'),
65-
#' stroke = create_stroke(color = 'Red')
66-
#' ),
67-
#' overlay_shape_position[1]
96+
#' "my-shape-id",
97+
#' "My Overlay Label",
98+
#' style = overlay_style,
99+
#' position = overlay_shape_position[1]
100+
#' )
101+
#'
102+
#' # Example 2: Create an overlay with edge position "end"
103+
#' overlay_style <- create_overlay_style(
104+
#' font_color = 'DarkSlateGray',
105+
#' font_size = 23,
106+
#' fill_color = 'MistyRose',
107+
#' stroke_color = 'Red'
68108
#' )
69109
#'
70-
#' # Create an overlay with edge position "end"
71110
#' overlay <- create_overlay(
72-
#' "my-edge-id",
73-
#' "My Overlay Label",
74-
#' create_style(
75-
#' font = create_font(color = 'DarkSlateGray', size = 23),
76-
#' fill = create_fill(color = 'MistyRose'),
77-
#' stroke = create_stroke(color = 'Red')
78-
#' ),
79-
#' overlay_edge_position[2]
111+
#' "my-edge-id",
112+
#' "My Overlay Label",
113+
#' style = overlay_style,
114+
#' position = overlay_edge_position[2]
80115
#' )
81116
#'
82117
#' @export
@@ -102,49 +137,52 @@ create_overlay <- function(elementId, label, style = NULL, position = NULL) {
102137

103138
#' @title Create the style of an overlay
104139
#'
105-
#' @name create_style
140+
#' @name create_overlay_style
106141
#' @description
107142
#' When adding an overlay to an existing element in a diagram, it's possible to customize its style.
108143
#'
109144
#' Refer to the \code{style} parameter in the \code{\link{create_overlay}} function for more information.
110145
#'
111146
#' Use this function to create the correct style structure for an overlay.
112147
#'
113-
#' @param font The font style of the overlay
114-
#' Use \code{\link{create_font}} function to create the font style object for the overlay.
115-
#' @param fill The fill style of the overlay
116-
#' Use \code{\link{create_fill}} function to create the fill style object for the overlay.
117-
#' @param stroke The stroke style of the overlay
118-
#' Use \code{\link{create_stroke}} function to create the stroke style object for the overlay.
148+
#' @param font_color The font color of the overlay. Use all HTML color names or HEX codes.
149+
#' @param font_size The font size of the overlay. Specify a number in px.
150+
#' @param fill_color The color of the background of the overlay. Use all HTML color names or HEX codes.
151+
#' @param stroke_color The color of the stroke of the overlay. Use all HTML color names or HEX codes.
152+
#' If you don't want to display a stroke, you can set the color to:
153+
#' - \code{transparent},
154+
#' - the same value as for the \code{fill_color}. This increases the \code{padding}/\code{margin}.
119155
#'
120156
#' @returns The style object of the overlay
121157
#'
122158
#' @export
123-
create_style <- function(font = NULL, fill = NULL, stroke = NULL) {
159+
create_overlay_style <- function(font_color = NULL,
160+
font_size = NULL,
161+
fill_color = NULL,
162+
stroke_color = NULL) {
124163
ret <-
125164
.not_null_list(
126-
font = font,
127-
fill = fill,
128-
stroke = stroke
165+
font = create_font(color = font_color, size = font_size),
166+
fill = create_fill(fill_color),
167+
stroke = create_stroke(stroke_color)
129168
)
130169
}
131170

132-
#' @title Create the font style of an overlay
171+
#' @title Internal function to create the font style of an overlay or a 'BPMN' element
133172
#'
134173
#' @name create_font
135174
#' @description
136-
#' When adding an overlay to an existing element in a diagram, it's possible to customize its font style.
137-
#'
138-
#' Refer to the \code{font} parameter in the \code{\link{create_style}} function for more information.
139-
#'
140-
#' Use this function to create the correct font structure for an overlay.
175+
#' - Overlay:
176+
#' When adding an overlay to an existing element in a diagram, it's possible to customize its font style.
177+
#' Refer to the \code{font} parameter in the \code{\link{create_overlay_style}} function for more information.
178+
#' Use this function to create the correct font structure for an overlay.
141179
#'
142180
#' @param color The color of the font of the overlay
143181
#' @param size The size of the font of the overlay
144182
#'
145183
#' @returns The font style object of the overlay
146184
#'
147-
#' @export
185+
#' @noRd
148186
create_font <- function(color = NULL, size = NULL) {
149187
ret <-
150188
.not_null_list(
@@ -153,51 +191,49 @@ create_font <- function(color = NULL, size = NULL) {
153191
)
154192
}
155193

156-
#' @title Create the fill style of an overlay
194+
#' @title Internal function to create the fill style of an overlay or a 'BPMN' element
157195
#'
158196
#' @name create_fill
159197
#' @description
160-
#' When adding an overlay to an existing element in a diagram, it's possible to customize how it is filled.
161-
#'
162-
#' Refer to the \code{fill} parameter in the \code{\link{create_style}} function for more information.
163-
#'
164-
#' Use this function to create the correct fill structure for an overlay.
198+
#' - Overlay:
199+
#' When adding an overlay to an existing element in a diagram, it's possible to customize how it is filled.
200+
#' Refer to the \code{fill} parameter in the \code{\link{create_overlay_style}} function for more information.
201+
#' Use this function to create the correct fill structure for an overlay.
165202
#'
166203
#' @param color The color of the background of the overlay
167204
#'
168205
#' @returns The fill style object of the overlay
169206
#'
170-
#' @export
207+
#' @noRd
171208
create_fill <- function(color) {
172209
ret <-
173210
.not_null_list(
174211
color = color
175212
)
176213
}
177214

178-
#' @title Create the stroke style of an overlay
215+
#' @title Internal function to create the stroke style of an overlay or a 'BPMN' element
179216
#'
180217
#' @name create_stroke
181218
#' @description
182-
#' When adding an overlay to an existing element in a diagram, it's possible to customize its stroke. style.
183-
#'
184-
#' Refer to the \code{stroke.} parameter in the \code{\link{create_style}} function for more information.
185-
#'
186-
#' Use this function to create the correct stroke structure for an overlay.
219+
#' - Overlay:
220+
#' When adding an overlay to an existing element in a diagram, it's possible to customize its stroke. style.
221+
#' Refer to the \code{stroke.} parameter in the \code{\link{create_overlay_style}} function for more information.
222+
#' Use this function to create the correct stroke structure for an overlay.
187223
#'
188224
#' @param color The color of the stroke of the overlay
189225
#'
190226
#' @returns The stroke style object of the overlay
191227
#'
192-
#' @export
228+
#' @noRd
193229
create_stroke <- function(color) {
194230
ret <-
195231
.not_null_list(
196232
color = color
197233
)
198234
}
199235

200-
#' @description Internal fun to build the 'htmlwidget' content
236+
#' @description Internal function to build the 'htmlwidget' content
201237
#'
202238
#' @inheritParams display
203239
#' @returns A list

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ bpmnVisualizationR::display(bpmn_file, overlays)
115115
### Style an overlay
116116

117117
```r
118-
font <- bpmnVisualizationR::create_font(color = 'WhiteSmoke', size = 19)
119-
fill <- bpmnVisualizationR::create_fill(color = 'Teal')
120-
stroke <- bpmnVisualizationR::create_stroke(color = 'SpringGreen')
118+
style <- bpmnVisualizationR::create_overlay_style(
119+
font_color = 'WhiteSmoke',
120+
font_size = 19,
121+
fill_color = 'Teal',
122+
stroke_color = 'SpringGreen'
123+
)
121124

122-
style <- bpmnVisualizationR::create_style(font, fill, stroke)
123125
overlay <- bpmnVisualizationR::create_overlay("bpmn_element_id_1", "42", style, "middle-right")
124126
```
125127

@@ -143,10 +145,11 @@ library(shiny)
143145

144146
displayBpmn <- function() {
145147
bpmn_file <- system.file("examples/Travel_Booking.bpmn", package = "bpmnVisualizationR")
146-
style <- bpmnVisualizationR::create_style(
147-
font = bpmnVisualizationR::create_font(color = 'Black', size = 25),
148-
fill = bpmnVisualizationR::create_fill(color = 'MediumSpringGreen'),
149-
stroke = bpmnVisualizationR::create_stroke(color = 'MediumSpringGreen')
148+
style <- bpmnVisualizationR::create_overlay_style(
149+
font_color = 'Black',
150+
font_size = 25,
151+
fill_color = 'MediumSpringGreen',
152+
stroke_color = 'MediumSpringGreen'
150153
)
151154
overlays <- list(bpmnVisualizationR::create_overlay("_6-203", "9", style, "bottom-right"))
152155
bpmnVisualizationR::display(bpmn_file, overlays)

0 commit comments

Comments
 (0)