@@ -92,14 +92,9 @@ ScaleDiscretePosition <- ggproto("ScaleDiscretePosition", ScaleDiscrete,
9292 }
9393 },
9494
95- # If range not available from discrete range, implies discrete scale been
96- # used with purely continuous data, so construct limits accordingly
9795 get_limits = function (self ) {
9896 if (self $ is_empty()) return (c(0 , 1 ))
99-
100- dis_limits <- function (x ) seq.int(floor(min(x )), ceiling(max(x )), by = 1L )
101-
102- self $ limits %|| % self $ range $ range %|| % dis_limits(self $ range_c $ range )
97+ self $ limits %|| % self $ range $ range %|| % integer()
10398 },
10499
105100 is_empty = function (self ) {
@@ -120,16 +115,21 @@ ScaleDiscretePosition <- ggproto("ScaleDiscretePosition", ScaleDiscrete,
120115 },
121116
122117 dimension = function (self , expand = c(0 , 0 )) {
123- disc_range <- c(1 , length(self $ get_limits()))
124- disc <- expand_range(disc_range , 0 , expand [2 ], 1 )
125-
126- # if no data was trained (i.e. range_c is infinite) return disc range
127- if (any(is.infinite(self $ range_c $ range ))) {
128- return (disc )
118+ c_range <- self $ range_c $ range
119+ d_range <- self $ range $ range
120+
121+ if (self $ is_empty()) {
122+ c(0 , 1 )
123+ } else if (is.null(d_range )) { # only continuous
124+ expand_range(c_range , expand [1 ], 0 , 1 )
125+ } else if (is.null(c_range )) { # only discrete
126+ expand_range(c(1 , length(d_range )), 0 , expand [2 ], 1 )
127+ } else { # both
128+ range(
129+ expand_range(c_range , expand [1 ], 0 , 1 ),
130+ expand_range(c(1 , length(d_range )), 0 , expand [2 ], 1 )
131+ )
129132 }
130-
131- cont <- expand_range(self $ range_c $ range , expand [1 ], 0 , expand [2 ])
132- range(disc , cont )
133133 },
134134
135135 clone = function (self ) {
0 commit comments