Skip to content

Commit

Permalink
plotly trace_explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
i1es committed Mar 15, 2023
1 parent 746be51 commit c82dd2d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
61 changes: 45 additions & 16 deletions R/trace_explorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,59 @@ trace_explorer.eventlog <- function(log,
}

if(raw_data)
return(temp)
return(temp)
else {

if(length(unique(temp$event_classifier)) > 26) {
scale_fill <- ggplot2::scale_fill_discrete
}

temp %>%
ggplot(aes(rank_event, as.factor(trace_id))) +
geom_tile(aes(fill = event_classifier), color = "white") +
facet_grid(facets,scales = "free", space = "free") +
scale_y_discrete(breaks = NULL) +
labs(y = "Traces", x = "Activities") +
scale_fill(name = "Activity") +
theme_light() +
theme(strip.background = element_rect(color = "white"),
strip.text.y = element_text(angle = 0),
strip.text = element_text(size = 11)) -> p
temp %>%
group_by(trace_id) %>%
mutate(trace_length = max(rank_event)) %>%
ungroup() %>%
ggplot(aes(rank_event, as.factor(trace_id))) +
geom_tile(aes(fill = event_classifier,
text = paste0("Activity: ", event_classifier, "\n",
"Trace length: ", trace_length, "\n",
"Frequency: ", "\n",
" - relative: ", facets_rel, "\n",
" - absolute: ", facets_abs, "\n",
" - cumulative: ", facets_cum), color = "white"),

color = "white") +
facet_grid(facets, scales = "free", space = "free") + # switch = "y"
scale_y_discrete() +
scale_x_continuous() +
labs(y = "Traces", x = "Activities") +
scale_fill(name = "Activity") +
theme_light() -> p

if (plotly) {
p +
theme(strip.background = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.x = element_text(size = 6),
axis.ticks.x = element_blank(),
strip.text.y = element_text(angle = 0)) -> p
}
else{
p +
theme(strip.background = element_rect(color = "white"),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.x = element_text(size = 6),
axis.ticks.x = element_blank(),
strip.text.y = element_text(angle = 0),
strip.text = element_text(size = 11)) -> p
}

if(show_labels)
p + geom_text(aes(label = abbreviate_labels(abbreviate, event_classifier)),
color = "white",
fontface = "bold",
size = label_size) -> p
p + geom_text(aes(label = abbreviate_labels(abbreviate, event_classifier)),
color = "white",
fontface = "bold",
size = label_size) -> p
}

return_plotly(p, plotly)
Expand Down
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ if_start <- function(node, true, false) {
# Return a plotly instead of ggplot2 if plotly == TRUE
return_plotly <- function(p, plotly) {
if (plotly) {
return(ggplotly(p))
return(
ggplotly(p, tooltip = c("text")) %>% layout(legend = list(orientation = "h", # show entries horizontally
xanchor = "center", # use center of legend as anchor
x = 0.5,
title = "")))
} else {
return(p)
}
Expand Down

0 comments on commit c82dd2d

Please sign in to comment.