Skip to content

Commit db1c93f

Browse files
committed
Rubocop auto correct
1 parent 499f50d commit db1c93f

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

lib/gr/plot.rb

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ def set_viewport(kind, subplot)
282282
GR.restorestate
283283
end
284284

285-
if %i[polar polarhist polarheatmap nonuniformpolarheatmap].include? kind
286-
xmin, xmax, ymin, ymax = viewport
287-
xcenter = 0.5 * (xmin + xmax)
288-
ycenter = 0.5 * (ymin + ymax)
289-
r = 0.5 * [xmax - xmin, ymax - ymin].min
290-
GR.setviewport(xcenter - r, xcenter + r, ycenter - r, ycenter + r)
291-
end
285+
return unless %i[polar polarhist polarheatmap nonuniformpolarheatmap].include? kind
286+
287+
xmin, xmax, ymin, ymax = viewport
288+
xcenter = 0.5 * (xmin + xmax)
289+
ycenter = 0.5 * (ymin + ymax)
290+
r = 0.5 * [xmax - xmin, ymax - ymin].min
291+
GR.setviewport(xcenter - r, xcenter + r, ycenter - r, ycenter + r)
292292
end
293293

294294
def set_window(kind)
@@ -957,12 +957,11 @@ def plot_data(_figure = true)
957957
when :heatmap, :nonuniformheatmap
958958
case z
959959
when Array
960-
if z.all? { |zi| zi.size = z[0].size }
961-
w = z.size
962-
h = z[0].size
963-
else
964-
raise
965-
end
960+
raise unless z.all? { |zi| zi.size = z[0].size }
961+
962+
w = z.size
963+
h = z[0].size
964+
966965
when ->(obj) { narray?(obj) }
967966
w, h = z.shape
968967
else
@@ -972,11 +971,11 @@ def plot_data(_figure = true)
972971
cmin, cmax = kvs[:crange]
973972
levels = kvs[:levels] || 256
974973
data = z.flatten.to_a.map { |i| normalize_color(i, cmin, cmax) } # NArray -> Array
975-
if kind == :heatmap
974+
if kind == :heatmap && !ENV['GR_SCALE_FACTOR']
976975
rgba = data.map { |v| to_rgba(v, cmap) }
977976
GR.drawimage(0.5, w + 0.5, h + 0.5, 0.5, w, h, rgba)
978977
else
979-
colors = data.map { |i| (1000 + i * 255).round }
978+
colors = data.map { |i| (i.nan? ? 1256 : 1000 + i * 255).round }
980979
GR.nonuniformcellarray(x, y, w, h, colors)
981980
end
982981
colorbar(0, levels)
@@ -1065,8 +1064,7 @@ def plot_data(_figure = true)
10651064

10661065
when :shade
10671066
xform = kvs[:xform] || 5
1068-
if x.to_a.include? Float::NAN # FIXME: Ruby is different from Julia?
1069-
# How to check NArray?
1067+
if (x.respond_to?(:isnan) && x.isnan.any?) || (x.is_a?(Array) && x.include?(Float::NAN))
10701068
GR.shadelines(x, y, xform: xform)
10711069
else
10721070
GR.shadepoints(x, y, xform: xform)
@@ -1088,13 +1086,13 @@ def plot_data(_figure = true)
10881086

10891087
draw_legend if %i[line step scatter stem].include?(kind) && kvs.has_key?(:labels)
10901088

1091-
if kvs[:update]
1092-
GR.updatews
1093-
# if GR.isinline()
1094-
# restore_context()
1095-
# return GR.show()
1096-
# end
1097-
end
1089+
return unless kvs[:update]
1090+
1091+
GR.updatews
1092+
# if GR.isinline()
1093+
# restore_context()
1094+
# return GR.show()
1095+
# end
10981096

10991097
# flag && restore_context()
11001098
end
@@ -1333,9 +1331,9 @@ def minmax(kind)
13331331
zmin, zmax = fix_minmax(zmin, zmax)
13341332

13351333
# kvs[:xlim], kvs[:ylim], kvs[:zlim] is supposed to be Array or Range
1336-
kvs[:xrange] = [(kvs[:xlim]&.first || xmin), (kvs[:xlim]&.last || xmax)]
1337-
kvs[:yrange] = [(kvs[:ylim]&.first || ymin), (kvs[:ylim]&.last || ymax)]
1338-
kvs[:zrange] = [(kvs[:zlim]&.first || zmin), (kvs[:zlim]&.last || zmax)]
1334+
kvs[:xrange] = [kvs[:xlim]&.first || xmin, kvs[:xlim]&.last || xmax]
1335+
kvs[:yrange] = [kvs[:ylim]&.first || ymin, kvs[:ylim]&.last || ymax]
1336+
kvs[:zrange] = [kvs[:zlim]&.first || zmin, kvs[:zlim]&.last || zmax]
13391337

13401338
if kvs.has_key?(:clim)
13411339
c0, c1 = kvs[:clim]

0 commit comments

Comments
 (0)