Skip to content

take title for plot from Daru::DataFrame #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gnuplotrb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rubocop', '~> 0.29'
spec.add_development_dependency 'codeclimate-test-reporter'
spec.add_development_dependency 'chunky_png'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'daru'
end
5 changes: 5 additions & 0 deletions lib/gnuplotrb/plot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def parse_datasets_array(datasets)
when Hamster::Vector
datasets[0]
when (defined?(Daru) ? Daru::DataFrame : nil)
set_name_from_daru_dataframe(datasets[0])
Hamster::Vector.new(datasets[0].map { |ds| dataset_from_any(ds) })
else
Hamster::Vector.new(datasets.map { |ds| dataset_from_any(ds) })
Expand All @@ -295,5 +296,9 @@ def parse_datasets_array(datasets)
def new_with_options(options)
self.class.new(@datasets, options)
end

def set_name_from_daru_dataframe(dataframe)
self.title = dataframe.name unless title
end
end
end
41 changes: 32 additions & 9 deletions spec/plot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
@title = 'Awesome spec'
@formula = %w(sin(x) cos(x) exp(-x))
@options = { title: @title, term: 'dumb' }
@df = Daru::DataFrame.new(
Build: [312, 630, 315, 312],
Test: [525, 1050, 701, 514],
Deploy: [215, 441, 370, 220]
)
end

it 'should be created out of sequence of datasets' do
Expand All @@ -38,10 +33,38 @@
expect(plot.title).to eql(@title)
end

it 'should be created out of Daru::DataFrame' do
p = Plot.new(@df)
expect(p).to be_an_instance_of(Plot)
expect(p.datasets.size).to be_eql(3)
context 'creation out of Daru::DataFrame' do
let(:df) do
Daru::DataFrame.new(
{
Build: [312, 630, 315, 312],
Test: [525, 1050, 701, 514],
Deploy: [215, 441, 370, 220]
},
index: [0, 1, 2, 3],
name: 'Dummy DataFrame'
)
end

subject { Plot.new(df) }

it { is_expected.to be_an_instance_of Plot }

it 'creates datasets for each column except index' do
expect(subject.datasets.size).to be 3
end

it 'takes name for plot from DataFrame' do
expect(subject.title).to eql(df.name)
end

context 'with title option given' do
subject { Plot.new(df, title: 'Not a DataFrame') }

it "uses title option instead of DataFrame name" do
expect(subject.title).not_to eql(df.name)
end
end
end
end

Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'simplecov'
require 'codeclimate-test-reporter'
require 'digest'
require 'chunky_png'
require 'digest/md5'
Expand Down