Skip to content

Commit 390339f

Browse files
committed
start with builder pattern
1 parent 3bc53dd commit 390339f

File tree

5 files changed

+187
-13
lines changed

5 files changed

+187
-13
lines changed

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(buildLineUp)
4+
export(buildTaggle)
35
export(lineup)
6+
export(lineupBuilder)
47
export(lineupOutput)
58
export(lineupRanking)
69
export(renderLineup)

R/lineup.R

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,43 @@
2323
defaultSlopeGraphMode = 'item',
2424
ignoreUnsupportedBrowser = FALSE
2525
)
26-
27-
.lineupImpl = function(data,
28-
width,
29-
height,
30-
elementId,
31-
options,
32-
ranking,
33-
dependencies,
34-
lineupType,
26+
#' taggle - factory for Taggle HTMLWidget
27+
#'
28+
#' @param data data frame like object i.e. also crosstalk shared data frame
29+
#' @param options LineUp options
30+
#' \describe{
31+
#' \item{filterGlobally}{whether filter within one ranking applies to all rankings (default: TRUE)}
32+
#' \item{singleSelection}{restrict to single item selection (default: FALSE}
33+
#' \item{noCriteriaLimits}{allow more than one sort and grouping criteria (default: FALSE)}
34+
#' \item{animated}{use animated transitions (default: TRUE)}
35+
#' \item{sidePanel}{show side panel (TRUE, FALSE, 'collapsed') (default: 'collapsed')}
36+
#' \item{hierarchyIndicator}{show sorting and grouping hierarchy indicator (TRUE, FALSE) (default: TRUE)}
37+
#' \item{labelRotation}{how many degrees should a label be rotated in case of narrow columns (default: 0)}
38+
#' \item{summaryHeader}{show summary histograms in the header (default: TRUE)}
39+
#' \item{overviewMode}{show overview mode in Taggle by default (default: FALSE)}
40+
#' \item{expandLineOnHover}{expand to full row height on mouse over (default: FALSE)}
41+
#' \item{defaultSlopeGraphMode}{default slope graph mode: item,band (default: 'item')}
42+
#' \item{ignoreUnsupportedBrowser}{ignore unsupported browser detection at own risk (default: FALSE)}
43+
#' \item{rowHeight}{height of a row in pixel (default: 18)}
44+
#' \item{rowPadding}{padding between two rows in pixel (default: 2)}
45+
#' \item{groupHeight}{height of an aggregated group in pixel (default: 40)}
46+
#' \item{groupPadding}{padding between two groups in pixel (default: 5)}
47+
#' }
48+
#' @param ranking ranking definition created using \code{\link{lineupRanking}}
49+
#' @param ... additional ranking definitions like 'ranking1=...' due to restrictions in converting parameters
50+
#'
51+
#' @return lineup builder objects
52+
#'
53+
#' @examples
54+
#' \dontrun{
55+
#' taggle(mtcars)
56+
#' taggle(iris)
57+
#' }
58+
#'
59+
#' @export
60+
lineupBuilder = function(data,
61+
options = c(.lineupDefaultOptions),
62+
ranking = NULL,
3563
...) {
3664
# extend with all the default options
3765
options = c(options, .lineupDefaultOptions[!(names(.lineupDefaultOptions) %in% names(options))])
@@ -73,14 +101,17 @@
73101
cols[['rowname']] = list(type = 'string', column = 'rowname', frozen = TRUE)
74102

75103
# forward options using x
76-
x = list(
104+
structure(list(
77105
data = cbind(rowname = rownames(data), data),
78106
colnames = c('rowname', colnames(data)),
79107
cols = cols,
80108
crosstalk = list(key = key, group = group),
81109
options = options,
82110
rankings = list(ranking = ranking, ...)
83-
)
111+
), class='LineUpBuilder')
112+
}
113+
114+
.buildLineUpWidget = function(x, width, height, elementId, dependencies, lineupType) {
84115
# create widget
85116
htmlwidgets::createWidget(
86117
name = lineupType,
@@ -93,6 +124,43 @@
93124
)
94125
}
95126

127+
#' lineup - factory for LineUp HTMLWidget
128+
#'
129+
#' @param x LineUpBuilder object
130+
#' @param width width of the element
131+
#' @param height height of the element
132+
#' @param elementId unique element id
133+
#' @param dependencies include crosstalk dependencies
134+
#'
135+
#' @return html lineup widget
136+
#'
137+
#' @export
138+
buildLineUp = function(x, width = '100%',
139+
height = NULL,
140+
elementId = NULL,
141+
dependencies = crosstalk::crosstalkLibs()) {
142+
.buildLineUpWidget(x, width, height, elementId, dependencies, lineupType='lineup')
143+
}
144+
145+
#' taggle - factory for Taggle HTMLWidget
146+
#'
147+
#' @param x LineUpBuilder object
148+
#' @param width width of the element
149+
#' @param height height of the element
150+
#' @param elementId unique element id
151+
#' @param dependencies include crosstalk dependencies
152+
#'
153+
#' @return html taggle widget
154+
155+
#' @export
156+
buildTaggle = function(x, width = '100%',
157+
height = NULL,
158+
elementId = NULL,
159+
dependencies = crosstalk::crosstalkLibs()) {
160+
.buildLineUpWidget(x, width, height, elementId, dependencies, lineupType='taggle')
161+
}
162+
163+
96164
#' lineup - factory for LineUp HTMLWidget
97165
#'
98166
#' @param data data frame like object i.e. also crosstalk shared data frame
@@ -139,7 +207,8 @@ lineup = function(data,
139207
ranking = NULL,
140208
dependencies = crosstalk::crosstalkLibs(),
141209
...) {
142-
.lineupImpl(data, width, height, elementId, options, ranking, dependencies, lineupType='lineup', ...)
210+
x = lineupBuilder(data, options, ranking, ...)
211+
buildLineUp(x, width, height, elementId, dependencies)
143212
}
144213

145214

@@ -189,7 +258,8 @@ taggle = function(data,
189258
ranking = NULL,
190259
dependencies = crosstalk::crosstalkLibs(),
191260
...) {
192-
.lineupImpl(data, width, height, elementId, options, ranking, dependencies, lineupType='taggle', ...)
261+
x = lineupBuilder(data, options, ranking, ...)
262+
buildTaggle(x, width, height, elementId, dependencies)
193263
}
194264

195265
#' helper function for creating a LineUp ranking definition as used by \code{\link{lineup}}

man/buildLineUp.Rd

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/buildTaggle.Rd

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/lineupBuilder.Rd

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)