spec/plotting/nyaplot/dataframe_spec.rb in daru-0.1.5 vs spec/plotting/nyaplot/dataframe_spec.rb in daru-0.1.6
- old
+ new
@@ -33,33 +33,30 @@
it 'plots numeric vectors' do
expect(plot).to receive(:add_with_df)
.with(numerics.to_nyaplotdf, :box, :x, :y1, :y2)
.ordered
- expect(plot).to receive(:show).ordered
- data_frame.plot(type: :box)
+ expect(data_frame.plot(type: :box)).to eq plot
end
end
context 'other types' do
context 'single chart' do
it 'works with :y provided' do
expect(plot).to receive(:add_with_df)
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
.ordered
- expect(plot).to receive(:show).ordered
- data_frame.plot(type: :scatter, x: :x, y: :y1)
+ expect(data_frame.plot(type: :scatter, x: :x, y: :y1)).to eq plot
end
it 'works without :y provided' do
expect(plot).to receive(:add_with_df)
.with(data_frame.to_nyaplotdf, :scatter, :x)
.ordered
- expect(plot).to receive(:show).ordered
- data_frame.plot(type: :scatter, x: :x)
+ expect(data_frame.plot(type: :scatter, x: :x)).to eq plot
end
end
context 'multiple charts' do
it 'works with single type provided' do
@@ -67,46 +64,50 @@
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
.ordered
expect(plot).to receive(:add_with_df)
.with(data_frame.to_nyaplotdf, :scatter, :x, :y2)
.ordered
- expect(plot).to receive(:show).ordered
- data_frame.plot(type: :scatter, x: [:x, :x], y: [:y1, :y2])
+ expect(
+ data_frame.plot(type: :scatter, x: [:x, :x], y: [:y1, :y2])
+ ).to eq plot
end
it 'works with multiple types provided' do
expect(plot).to receive(:add_with_df)
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
.ordered
expect(plot).to receive(:add_with_df)
.with(data_frame.to_nyaplotdf, :line, :x, :y2)
.ordered
- expect(plot).to receive(:show).ordered
- data_frame.plot(type: [:scatter, :line], x: [:x, :x], y: [:y1, :y2])
+ expect(
+ data_frame.plot(
+ type: [:scatter, :line], x: [:x, :x], y: [:y1, :y2])
+ ).to eq plot
end
it 'works with numeric var names' do
expect(plot).to receive(:add_with_df)
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
.ordered
expect(plot).to receive(:add_with_df)
.with(data_frame.to_nyaplotdf, :line, :x, :y2)
.ordered
- expect(plot).to receive(:show).ordered
- data_frame.plot(
+ expect(
+ data_frame.plot(
type: [:scatter, :line],
# FIXME: this didn't work due to default type: :scatter opts
#type1: :scatter,
#type2: :line,
x1: :x,
x2: :x,
y1: :y1,
y2: :y2
- )
+ )
+ ).to eq plot
end
end
end
end
@@ -119,26 +120,25 @@
c: ['I', 'II', 'I', 'III', 'I', 'III', 'II']
})
end
let(:plot) { instance_double('Nyaplot::Plot') }
let(:diagram) { instance_double('Nyaplot::Diagram::Scatter') }
-
+
before do
df.to_category :c
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
allow(plot).to receive(:add_with_df).and_return(diagram)
end
-
+
it 'plots scatter plot categoried by color with a block' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:color).exactly(3).times
expect(diagram).to receive(:tooltip_contents).exactly(3).times
expect(plot).to receive :legend
expect(plot).to receive :xrange
expect(plot).to receive :yrange
- expect(plot).to receive :show
df.plot(type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :color}) do |p, d|
p.xrange [-10, 10]
p.yrange [-10, 10]
end
end
@@ -147,74 +147,85 @@
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:color).exactly(3).times
expect(diagram).to receive(:tooltip_contents).exactly(3).times
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :scatter, x: :a, y: :b,
- categorized: {by: :c, method: :color})
+ expect(
+ df.plot(
+ type: :scatter, x: :a, y: :b,
+ categorized: {by: :c, method: :color})
+ ).to eq plot
end
it 'plots scatter plot categoried by custom colors' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:color).with :red
expect(diagram).to receive(:color).with :blue
expect(diagram).to receive(:color).with :green
expect(diagram).to receive(:tooltip_contents).exactly(3).times
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :scatter, x: :a, y: :b,
- categorized: {by: :c, method: :color, color: [:red, :blue, :green]})
+ expect(df.plot(type: :scatter, x: :a, y: :b,
+ categorized: {by: :c, method: :color, color: [:red, :blue, :green]})).to eq plot
end
it 'plots scatter plot categoried by shape' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:shape).exactly(3).times
expect(diagram).to receive(:tooltip_contents).exactly(3).times
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :scatter, x: :a, y: :b,
- categorized: {by: :c, method: :shape})
+ expect(df.plot(type: :scatter, x: :a, y: :b,
+ categorized: {by: :c, method: :shape})).to eq plot
end
it 'plots scatter plot categoried by custom shapes' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:shape).with 'circle'
expect(diagram).to receive(:shape).with 'triangle-up'
expect(diagram).to receive(:shape).with 'diamond'
expect(diagram).to receive(:tooltip_contents).exactly(3).times
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :scatter, x: :a, y: :b,
- categorized: {by: :c, method: :shape, shape: %w(circle triangle-up diamond)})
+ expect(
+ df.plot(
+ type: :scatter, x: :a, y: :b,
+ categorized: {
+ by: :c, method: :shape,
+ shape: %w(circle triangle-up diamond)})
+ ).to eq plot
end
it 'plots scatter plot categoried by size' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:size).exactly(3).times
expect(diagram).to receive(:tooltip_contents).exactly(3).times
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :scatter, x: :a, y: :b,
- categorized: {by: :c, method: :size})
+ expect(df.plot(type: :scatter, x: :a, y: :b,
+ categorized: {by: :c, method: :size})).to eq plot
end
it 'plots scatter plot categoried by cusom sizes' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:size).with 100
expect(diagram).to receive(:size).with 200
expect(diagram).to receive(:size).with 300
expect(diagram).to receive(:tooltip_contents).exactly(3).times
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :scatter, x: :a, y: :b,
- categorized: {by: :c, method: :size, size: [100, 200, 300]})
+ expect(
+ df.plot(
+ type: :scatter,
+ x: :a, y: :b,
+ categorized: {
+ by: :c,
+ method: :size,
+ size: [100, 200, 300]
+ }
+ )
+ ).to eq plot
end
end
context 'line' do
let(:df) do
@@ -224,25 +235,24 @@
c: ['I', 'II', 'I', 'III', 'I', 'III', 'II']
})
end
let(:plot) { instance_double('Nyaplot::Plot') }
let(:diagram) { instance_double('Nyaplot::Diagram::Scatter') }
-
+
before do
df.to_category :c
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
allow(plot).to receive(:add_with_df).and_return(diagram)
end
-
+
it 'plots line plot categoried by color with a block' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:color).exactly(3).times
expect(plot).to receive :legend
expect(plot).to receive :xrange
expect(plot).to receive :yrange
- expect(plot).to receive :show
df.plot(type: :line, x: :a, y: :b, categorized: {by: :c, method: :color}) do |p, d|
p.xrange [-10, 10]
p.yrange [-10, 10]
end
end
@@ -250,44 +260,59 @@
it 'plots line plot categoried by color' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:color).exactly(3).times
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :line, x: :a, y: :b, categorized: {by: :c, method: :color})
+ expect(
+ df.plot(
+ type: :line, x: :a, y: :b,
+ categorized: {by: :c, method: :color}
+ )
+ ).to eq plot
end
it 'plots line plot categoried by custom colors' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:color).with :red
expect(diagram).to receive(:color).with :blue
expect(diagram).to receive(:color).with :green
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :line, x: :a, y: :b,
- categorized: {by: :c, method: :color, color: [:red, :blue, :green]})
+ expect(
+ df.plot(
+ type: :line, x: :a, y: :b,
+ categorized: {by: :c, method: :color, color: [:red, :blue, :green]}
+ )
+ ).to eq plot
end
it 'plots line plot categoried by stroke width' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:stroke_width).exactly(3).times
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :line, x: :a, y: :b, categorized: {by: :c, method: :stroke_width})
+ expect(
+ df.plot(
+ type: :line, x: :a, y: :b,
+ categorized: {by: :c, method: :stroke_width}
+ )
+ ).to eq plot
end
it 'plots line plot categoried by custom stroke widths' do
expect(plot).to receive :add_with_df
expect(diagram).to receive(:title).exactly(3).times
expect(diagram).to receive(:stroke_width).with 100
expect(diagram).to receive(:stroke_width).with 200
expect(diagram).to receive(:stroke_width).with 300
expect(plot).to receive :legend
- expect(plot).to receive :show
- df.plot(type: :line, x: :a, y: :b,
- categorized: {by: :c, method: :stroke_width, stroke_width: [100, 200, 300]})
+ expect(
+ df.plot(
+ type: :line, x: :a, y: :b,
+ categorized: {
+ by: :c, method: :stroke_width, stroke_width: [100, 200, 300]}
+ )
+ ).to eq plot
end
end
context "invalid type" do
let(:df) do