daru 0.1.3.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +2 -1
- data/.rspec_formatter.rb +33 -0
- data/.rubocop.yml +26 -2
- data/History.md +38 -0
- data/README.md +22 -13
- data/Rakefile +50 -2
- data/benchmarks/csv_reading.rb +22 -0
- data/daru.gemspec +9 -2
- data/lib/daru.rb +36 -4
- data/lib/daru/accessors/array_wrapper.rb +6 -1
- data/lib/daru/accessors/dataframe_by_row.rb +10 -2
- data/lib/daru/accessors/gsl_wrapper.rb +1 -3
- data/lib/daru/accessors/nmatrix_wrapper.rb +9 -0
- data/lib/daru/category.rb +935 -0
- data/lib/daru/core/group_by.rb +29 -38
- data/lib/daru/core/merge.rb +186 -145
- data/lib/daru/core/query.rb +22 -11
- data/lib/daru/dataframe.rb +976 -885
- data/lib/daru/date_time/index.rb +166 -166
- data/lib/daru/date_time/offsets.rb +66 -77
- data/lib/daru/formatters/table.rb +54 -0
- data/lib/daru/helpers/array.rb +40 -0
- data/lib/daru/index.rb +476 -73
- data/lib/daru/io/io.rb +66 -45
- data/lib/daru/io/sql_data_source.rb +33 -62
- data/lib/daru/iruby/helpers.rb +38 -0
- data/lib/daru/iruby/templates/dataframe.html.erb +52 -0
- data/lib/daru/iruby/templates/dataframe_mi.html.erb +58 -0
- data/lib/daru/iruby/templates/multi_index.html.erb +12 -0
- data/lib/daru/iruby/templates/vector.html.erb +27 -0
- data/lib/daru/iruby/templates/vector_mi.html.erb +36 -0
- data/lib/daru/maths/arithmetic/dataframe.rb +16 -18
- data/lib/daru/maths/arithmetic/vector.rb +4 -6
- data/lib/daru/maths/statistics/dataframe.rb +8 -15
- data/lib/daru/maths/statistics/vector.rb +120 -98
- data/lib/daru/monkeys.rb +12 -40
- data/lib/daru/plotting/gruff.rb +3 -0
- data/lib/daru/plotting/gruff/category.rb +49 -0
- data/lib/daru/plotting/gruff/dataframe.rb +91 -0
- data/lib/daru/plotting/gruff/vector.rb +57 -0
- data/lib/daru/plotting/nyaplot.rb +3 -0
- data/lib/daru/plotting/nyaplot/category.rb +34 -0
- data/lib/daru/plotting/nyaplot/dataframe.rb +187 -0
- data/lib/daru/plotting/nyaplot/vector.rb +46 -0
- data/lib/daru/vector.rb +694 -421
- data/lib/daru/version.rb +1 -1
- data/profile/_base.rb +23 -0
- data/profile/df_to_a.rb +10 -0
- data/profile/filter.rb +13 -0
- data/profile/joining.rb +13 -0
- data/profile/sorting.rb +12 -0
- data/profile/vector_each_with_index.rb +9 -0
- data/spec/accessors/wrappers_spec.rb +2 -4
- data/spec/categorical_spec.rb +1734 -0
- data/spec/core/group_by_spec.rb +52 -2
- data/spec/core/merge_spec.rb +63 -2
- data/spec/core/query_spec.rb +236 -80
- data/spec/dataframe_spec.rb +1373 -79
- data/spec/date_time/data_spec.rb +3 -5
- data/spec/date_time/index_spec.rb +154 -17
- data/spec/date_time/offsets_spec.rb +3 -4
- data/spec/fixtures/empties.dat +2 -0
- data/spec/fixtures/strings.dat +2 -0
- data/spec/formatters/table_formatter_spec.rb +99 -0
- data/spec/helpers_spec.rb +8 -0
- data/spec/index/categorical_index_spec.rb +168 -0
- data/spec/index/index_spec.rb +283 -0
- data/spec/index/multi_index_spec.rb +570 -0
- data/spec/io/io_spec.rb +31 -4
- data/spec/io/sql_data_source_spec.rb +0 -1
- data/spec/iruby/dataframe_spec.rb +172 -0
- data/spec/iruby/helpers_spec.rb +49 -0
- data/spec/iruby/multi_index_spec.rb +37 -0
- data/spec/iruby/vector_spec.rb +107 -0
- data/spec/math/arithmetic/dataframe_spec.rb +71 -13
- data/spec/math/arithmetic/vector_spec.rb +8 -10
- data/spec/math/statistics/dataframe_spec.rb +3 -5
- data/spec/math/statistics/vector_spec.rb +45 -55
- data/spec/monkeys_spec.rb +32 -9
- data/spec/plotting/dataframe_spec.rb +386 -0
- data/spec/plotting/vector_spec.rb +230 -0
- data/spec/shared/vector_display_spec.rb +215 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/vector_spec.rb +905 -138
- metadata +143 -11
- data/.rubocop_todo.yml +0 -44
- data/lib/daru/plotting/dataframe.rb +0 -104
- data/lib/daru/plotting/vector.rb +0 -38
- data/spec/daru_spec.rb +0 -58
- data/spec/index_spec.rb +0 -375
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Deshmukh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: backports
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: reportbuilder
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -17,7 +31,7 @@ dependencies:
|
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '1.4'
|
20
|
-
type: :
|
34
|
+
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
@@ -31,7 +45,7 @@ dependencies:
|
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: 1.1.1
|
34
|
-
type: :
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
@@ -122,6 +136,20 @@ dependencies:
|
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '3.4'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec-its
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
154
|
name: awesome_print
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,6 +290,62 @@ dependencies:
|
|
262
290
|
- - ">="
|
263
291
|
- !ruby/object:Gem::Version
|
264
292
|
version: 0.40.0
|
293
|
+
- !ruby/object:Gem::Dependency
|
294
|
+
name: ruby-prof
|
295
|
+
requirement: !ruby/object:Gem::Requirement
|
296
|
+
requirements:
|
297
|
+
- - ">="
|
298
|
+
- !ruby/object:Gem::Version
|
299
|
+
version: '0'
|
300
|
+
type: :development
|
301
|
+
prerelease: false
|
302
|
+
version_requirements: !ruby/object:Gem::Requirement
|
303
|
+
requirements:
|
304
|
+
- - ">="
|
305
|
+
- !ruby/object:Gem::Version
|
306
|
+
version: '0'
|
307
|
+
- !ruby/object:Gem::Dependency
|
308
|
+
name: simplecov
|
309
|
+
requirement: !ruby/object:Gem::Requirement
|
310
|
+
requirements:
|
311
|
+
- - ">="
|
312
|
+
- !ruby/object:Gem::Version
|
313
|
+
version: '0'
|
314
|
+
type: :development
|
315
|
+
prerelease: false
|
316
|
+
version_requirements: !ruby/object:Gem::Requirement
|
317
|
+
requirements:
|
318
|
+
- - ">="
|
319
|
+
- !ruby/object:Gem::Version
|
320
|
+
version: '0'
|
321
|
+
- !ruby/object:Gem::Dependency
|
322
|
+
name: nokogiri
|
323
|
+
requirement: !ruby/object:Gem::Requirement
|
324
|
+
requirements:
|
325
|
+
- - ">="
|
326
|
+
- !ruby/object:Gem::Version
|
327
|
+
version: '0'
|
328
|
+
type: :development
|
329
|
+
prerelease: false
|
330
|
+
version_requirements: !ruby/object:Gem::Requirement
|
331
|
+
requirements:
|
332
|
+
- - ">="
|
333
|
+
- !ruby/object:Gem::Version
|
334
|
+
version: '0'
|
335
|
+
- !ruby/object:Gem::Dependency
|
336
|
+
name: gruff
|
337
|
+
requirement: !ruby/object:Gem::Requirement
|
338
|
+
requirements:
|
339
|
+
- - ">="
|
340
|
+
- !ruby/object:Gem::Version
|
341
|
+
version: '0'
|
342
|
+
type: :development
|
343
|
+
prerelease: false
|
344
|
+
version_requirements: !ruby/object:Gem::Requirement
|
345
|
+
requirements:
|
346
|
+
- - ">="
|
347
|
+
- !ruby/object:Gem::Version
|
348
|
+
version: '0'
|
265
349
|
description: |
|
266
350
|
Daru (Data Analysis in RUby) is a library for analysis, manipulation and visualization
|
267
351
|
of data. Daru works seamlessly accross interpreters and leverages interpreter-specific
|
@@ -277,8 +361,8 @@ extra_rdoc_files: []
|
|
277
361
|
files:
|
278
362
|
- ".gitignore"
|
279
363
|
- ".rspec"
|
364
|
+
- ".rspec_formatter.rb"
|
280
365
|
- ".rubocop.yml"
|
281
|
-
- ".rubocop_todo.yml"
|
282
366
|
- ".travis.yml"
|
283
367
|
- CONTRIBUTING.md
|
284
368
|
- Gemfile
|
@@ -287,6 +371,7 @@ files:
|
|
287
371
|
- README.md
|
288
372
|
- Rakefile
|
289
373
|
- benchmarks/TradeoffData.csv
|
374
|
+
- benchmarks/csv_reading.rb
|
290
375
|
- benchmarks/dataframe_creation.rb
|
291
376
|
- benchmarks/duplicating.rb
|
292
377
|
- benchmarks/group_by.rb
|
@@ -319,6 +404,7 @@ files:
|
|
319
404
|
- lib/daru/accessors/gsl_wrapper.rb
|
320
405
|
- lib/daru/accessors/mdarray_wrapper.rb
|
321
406
|
- lib/daru/accessors/nmatrix_wrapper.rb
|
407
|
+
- lib/daru/category.rb
|
322
408
|
- lib/daru/core/group_by.rb
|
323
409
|
- lib/daru/core/merge.rb
|
324
410
|
- lib/daru/core/query.rb
|
@@ -327,23 +413,43 @@ files:
|
|
327
413
|
- lib/daru/date_time/offsets.rb
|
328
414
|
- lib/daru/exceptions.rb
|
329
415
|
- lib/daru/extensions/rserve.rb
|
416
|
+
- lib/daru/formatters/table.rb
|
417
|
+
- lib/daru/helpers/array.rb
|
330
418
|
- lib/daru/index.rb
|
331
419
|
- lib/daru/io/io.rb
|
332
420
|
- lib/daru/io/sql_data_source.rb
|
421
|
+
- lib/daru/iruby/helpers.rb
|
422
|
+
- lib/daru/iruby/templates/dataframe.html.erb
|
423
|
+
- lib/daru/iruby/templates/dataframe_mi.html.erb
|
424
|
+
- lib/daru/iruby/templates/multi_index.html.erb
|
425
|
+
- lib/daru/iruby/templates/vector.html.erb
|
426
|
+
- lib/daru/iruby/templates/vector_mi.html.erb
|
333
427
|
- lib/daru/maths/arithmetic/dataframe.rb
|
334
428
|
- lib/daru/maths/arithmetic/vector.rb
|
335
429
|
- lib/daru/maths/statistics/dataframe.rb
|
336
430
|
- lib/daru/maths/statistics/vector.rb
|
337
431
|
- lib/daru/monkeys.rb
|
338
|
-
- lib/daru/plotting/
|
339
|
-
- lib/daru/plotting/
|
432
|
+
- lib/daru/plotting/gruff.rb
|
433
|
+
- lib/daru/plotting/gruff/category.rb
|
434
|
+
- lib/daru/plotting/gruff/dataframe.rb
|
435
|
+
- lib/daru/plotting/gruff/vector.rb
|
436
|
+
- lib/daru/plotting/nyaplot.rb
|
437
|
+
- lib/daru/plotting/nyaplot/category.rb
|
438
|
+
- lib/daru/plotting/nyaplot/dataframe.rb
|
439
|
+
- lib/daru/plotting/nyaplot/vector.rb
|
340
440
|
- lib/daru/vector.rb
|
341
441
|
- lib/daru/version.rb
|
442
|
+
- profile/_base.rb
|
443
|
+
- profile/df_to_a.rb
|
444
|
+
- profile/filter.rb
|
445
|
+
- profile/joining.rb
|
446
|
+
- profile/sorting.rb
|
447
|
+
- profile/vector_each_with_index.rb
|
342
448
|
- spec/accessors/wrappers_spec.rb
|
449
|
+
- spec/categorical_spec.rb
|
343
450
|
- spec/core/group_by_spec.rb
|
344
451
|
- spec/core/merge_spec.rb
|
345
452
|
- spec/core/query_spec.rb
|
346
|
-
- spec/daru_spec.rb
|
347
453
|
- spec/dataframe_spec.rb
|
348
454
|
- spec/date_time/data_spec.rb
|
349
455
|
- spec/date_time/index_spec.rb
|
@@ -351,21 +457,34 @@ files:
|
|
351
457
|
- spec/extensions/rserve_spec.rb
|
352
458
|
- spec/fixtures/bank2.dat
|
353
459
|
- spec/fixtures/countries.json
|
460
|
+
- spec/fixtures/empties.dat
|
354
461
|
- spec/fixtures/matrix_test.csv
|
355
462
|
- spec/fixtures/music_data.tsv
|
356
463
|
- spec/fixtures/repeated_fields.csv
|
357
464
|
- spec/fixtures/sales-funnel.csv
|
358
465
|
- spec/fixtures/scientific_notation.csv
|
359
466
|
- spec/fixtures/stock_data.csv
|
467
|
+
- spec/fixtures/strings.dat
|
360
468
|
- spec/fixtures/test_xls.xls
|
361
|
-
- spec/
|
469
|
+
- spec/formatters/table_formatter_spec.rb
|
470
|
+
- spec/helpers_spec.rb
|
471
|
+
- spec/index/categorical_index_spec.rb
|
472
|
+
- spec/index/index_spec.rb
|
473
|
+
- spec/index/multi_index_spec.rb
|
362
474
|
- spec/io/io_spec.rb
|
363
475
|
- spec/io/sql_data_source_spec.rb
|
476
|
+
- spec/iruby/dataframe_spec.rb
|
477
|
+
- spec/iruby/helpers_spec.rb
|
478
|
+
- spec/iruby/multi_index_spec.rb
|
479
|
+
- spec/iruby/vector_spec.rb
|
364
480
|
- spec/math/arithmetic/dataframe_spec.rb
|
365
481
|
- spec/math/arithmetic/vector_spec.rb
|
366
482
|
- spec/math/statistics/dataframe_spec.rb
|
367
483
|
- spec/math/statistics/vector_spec.rb
|
368
484
|
- spec/monkeys_spec.rb
|
485
|
+
- spec/plotting/dataframe_spec.rb
|
486
|
+
- spec/plotting/vector_spec.rb
|
487
|
+
- spec/shared/vector_display_spec.rb
|
369
488
|
- spec/spec_helper.rb
|
370
489
|
- spec/support/database_helper.rb
|
371
490
|
- spec/vector_spec.rb
|
@@ -414,10 +533,10 @@ specification_version: 4
|
|
414
533
|
summary: Data Analysis in RUby
|
415
534
|
test_files:
|
416
535
|
- spec/accessors/wrappers_spec.rb
|
536
|
+
- spec/categorical_spec.rb
|
417
537
|
- spec/core/group_by_spec.rb
|
418
538
|
- spec/core/merge_spec.rb
|
419
539
|
- spec/core/query_spec.rb
|
420
|
-
- spec/daru_spec.rb
|
421
540
|
- spec/dataframe_spec.rb
|
422
541
|
- spec/date_time/data_spec.rb
|
423
542
|
- spec/date_time/index_spec.rb
|
@@ -425,21 +544,34 @@ test_files:
|
|
425
544
|
- spec/extensions/rserve_spec.rb
|
426
545
|
- spec/fixtures/bank2.dat
|
427
546
|
- spec/fixtures/countries.json
|
547
|
+
- spec/fixtures/empties.dat
|
428
548
|
- spec/fixtures/matrix_test.csv
|
429
549
|
- spec/fixtures/music_data.tsv
|
430
550
|
- spec/fixtures/repeated_fields.csv
|
431
551
|
- spec/fixtures/sales-funnel.csv
|
432
552
|
- spec/fixtures/scientific_notation.csv
|
433
553
|
- spec/fixtures/stock_data.csv
|
554
|
+
- spec/fixtures/strings.dat
|
434
555
|
- spec/fixtures/test_xls.xls
|
435
|
-
- spec/
|
556
|
+
- spec/formatters/table_formatter_spec.rb
|
557
|
+
- spec/helpers_spec.rb
|
558
|
+
- spec/index/categorical_index_spec.rb
|
559
|
+
- spec/index/index_spec.rb
|
560
|
+
- spec/index/multi_index_spec.rb
|
436
561
|
- spec/io/io_spec.rb
|
437
562
|
- spec/io/sql_data_source_spec.rb
|
563
|
+
- spec/iruby/dataframe_spec.rb
|
564
|
+
- spec/iruby/helpers_spec.rb
|
565
|
+
- spec/iruby/multi_index_spec.rb
|
566
|
+
- spec/iruby/vector_spec.rb
|
438
567
|
- spec/math/arithmetic/dataframe_spec.rb
|
439
568
|
- spec/math/arithmetic/vector_spec.rb
|
440
569
|
- spec/math/statistics/dataframe_spec.rb
|
441
570
|
- spec/math/statistics/vector_spec.rb
|
442
571
|
- spec/monkeys_spec.rb
|
572
|
+
- spec/plotting/dataframe_spec.rb
|
573
|
+
- spec/plotting/vector_spec.rb
|
574
|
+
- spec/shared/vector_display_spec.rb
|
443
575
|
- spec/spec_helper.rb
|
444
576
|
- spec/support/database_helper.rb
|
445
577
|
- spec/vector_spec.rb
|
data/.rubocop_todo.yml
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-05-06 16:48:54 +0300 using RuboCop version 0.39.0.
|
4
|
-
# The point is for the user to remove these configuration records
|
5
|
-
# one by one as the offenses are removed from the code base.
|
6
|
-
# Note that changes in the inspected code, or installation of new
|
7
|
-
# versions of RuboCop, may require this file to be generated again.
|
8
|
-
|
9
|
-
# Offense count: 66
|
10
|
-
Metrics/AbcSize:
|
11
|
-
Max: 110
|
12
|
-
|
13
|
-
# Offense count: 6
|
14
|
-
Metrics/BlockNesting:
|
15
|
-
Max: 6
|
16
|
-
|
17
|
-
# Offense count: 6
|
18
|
-
# Configuration parameters: CountComments.
|
19
|
-
Metrics/ClassLength:
|
20
|
-
Max: 1400
|
21
|
-
|
22
|
-
# Offense count: 26
|
23
|
-
Metrics/CyclomaticComplexity:
|
24
|
-
Max: 22
|
25
|
-
|
26
|
-
# Offense count: 273
|
27
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
28
|
-
# URISchemes: http, https
|
29
|
-
Metrics/LineLength:
|
30
|
-
Max: 164
|
31
|
-
|
32
|
-
# Offense count: 81
|
33
|
-
# Configuration parameters: CountComments.
|
34
|
-
Metrics/MethodLength:
|
35
|
-
Max: 100
|
36
|
-
|
37
|
-
# Offense count: 3
|
38
|
-
# Configuration parameters: CountComments.
|
39
|
-
Metrics/ModuleLength:
|
40
|
-
Max: 419
|
41
|
-
|
42
|
-
# Offense count: 22
|
43
|
-
Metrics/PerceivedComplexity:
|
44
|
-
Max: 28
|
@@ -1,104 +0,0 @@
|
|
1
|
-
module Daru
|
2
|
-
module Plotting
|
3
|
-
module DataFrame
|
4
|
-
# Plots a DataFrame with Nyaplot on IRuby using the given options. Yields
|
5
|
-
# the corresponding Nyaplot::Plot object and the Nyaplot::Diagram object
|
6
|
-
# to the block, if it is specified. See the nyaplot docs for info on how to
|
7
|
-
# further use these objects.
|
8
|
-
#
|
9
|
-
# Detailed instructions on use of the plotting API can be found in the
|
10
|
-
# notebooks whose links you can find in the README.
|
11
|
-
#
|
12
|
-
# == Options
|
13
|
-
#
|
14
|
-
# * +:type+ - Type of plot. Can be :scatter, :bar, :histogram, :line or :box.
|
15
|
-
# * +:x+ - Vector to be used for X co-ordinates.
|
16
|
-
# * +:y+ - Vector to be used for Y co-ordinates.
|
17
|
-
#
|
18
|
-
# == Usage
|
19
|
-
# # Simple bar chart
|
20
|
-
# df = Daru::DataFrame.new({a:['A', 'B', 'C', 'D', 'E'], b:[10,20,30,40,50]})
|
21
|
-
# df.plot type: :bar, x: :a, y: :b
|
22
|
-
def plot opts={}
|
23
|
-
options = {
|
24
|
-
type: :scatter
|
25
|
-
}.merge(opts)
|
26
|
-
|
27
|
-
plot = Nyaplot::Plot.new
|
28
|
-
types = extract_option :type, options
|
29
|
-
|
30
|
-
diagram =
|
31
|
-
case
|
32
|
-
when !([:scatter, :bar, :line, :histogram] & types).empty?
|
33
|
-
if single_diagram? options
|
34
|
-
add_single_diagram plot, options
|
35
|
-
else
|
36
|
-
add_multiple_diagrams plot, options
|
37
|
-
end
|
38
|
-
when types.include?(:box)
|
39
|
-
numeric = only_numerics(clone: false).dup_only_valid
|
40
|
-
|
41
|
-
plot.add_with_df(
|
42
|
-
numeric.to_nyaplotdf,
|
43
|
-
:box, *numeric.vectors.to_a
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
yield(plot, diagram) if block_given?
|
48
|
-
|
49
|
-
plot.show
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def single_diagram? options
|
55
|
-
options[:x] and options[:x].is_a?(Symbol)
|
56
|
-
end
|
57
|
-
|
58
|
-
def add_single_diagram plot, options
|
59
|
-
args = [
|
60
|
-
to_nyaplotdf,
|
61
|
-
options[:type],
|
62
|
-
options[:x]
|
63
|
-
]
|
64
|
-
|
65
|
-
args << options[:y] if options[:y]
|
66
|
-
|
67
|
-
plot.add_with_df(*args)
|
68
|
-
end
|
69
|
-
|
70
|
-
def add_multiple_diagrams plot, options
|
71
|
-
types = extract_option :type, options
|
72
|
-
x_vecs = extract_option :x, options
|
73
|
-
y_vecs = extract_option :y, options
|
74
|
-
|
75
|
-
diagrams = []
|
76
|
-
nyaplot_df = to_nyaplotdf
|
77
|
-
total = x_vecs.size
|
78
|
-
types = types.size < total ? types*total : types
|
79
|
-
|
80
|
-
(0...total).each do |i|
|
81
|
-
diagrams << plot.add_with_df(
|
82
|
-
nyaplot_df,
|
83
|
-
types[i],
|
84
|
-
x_vecs[i],
|
85
|
-
y_vecs[i]
|
86
|
-
)
|
87
|
-
end
|
88
|
-
|
89
|
-
diagrams
|
90
|
-
end
|
91
|
-
|
92
|
-
def extract_option opt, options
|
93
|
-
if options[opt]
|
94
|
-
o = options[opt]
|
95
|
-
o.is_a?(Array) ? o : [o]
|
96
|
-
else
|
97
|
-
arr = options.keys
|
98
|
-
arr.keep_if { |a| a =~ Regexp.new("\\A#{opt}") }.sort
|
99
|
-
arr.map { |a| options[a] }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end if Daru.has_nyaplot?
|
data/lib/daru/plotting/vector.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module Daru
|
2
|
-
module Plotting
|
3
|
-
module Vector
|
4
|
-
# Plots a Vector with Nyaplot on IRuby using the given options. Yields the
|
5
|
-
# plot object (Nyaplot::Plot) and the diagram object (Nyaplot::Diagram)
|
6
|
-
# to the block, which can be used for setting various options as per the
|
7
|
-
# Nyaplot API.
|
8
|
-
#
|
9
|
-
# == Options
|
10
|
-
# type (:scatter, :bar, :histogram), title, x_label, y_label, color(true/false)
|
11
|
-
#
|
12
|
-
# == Usage
|
13
|
-
# vector = Daru::Vector.new [10,20,30,40], [:one, :two, :three, :four]
|
14
|
-
# vector.plot(type: :bar) do |plot|
|
15
|
-
# plot.title "My first plot"
|
16
|
-
# plot.width 1200
|
17
|
-
# end
|
18
|
-
def plot opts={}
|
19
|
-
options = {
|
20
|
-
type: :scatter
|
21
|
-
}.merge(opts)
|
22
|
-
|
23
|
-
x_axis = options[:type] == :scatter ? Array.new(@size) { |i| i } : @index.to_a
|
24
|
-
plot = Nyaplot::Plot.new
|
25
|
-
diagram =
|
26
|
-
if [:box, :histogram].include? options[:type]
|
27
|
-
plot.add(options[:type], @data.to_a)
|
28
|
-
else
|
29
|
-
plot.add(options[:type], x_axis, @data.to_a)
|
30
|
-
end
|
31
|
-
|
32
|
-
yield plot, diagram if block_given?
|
33
|
-
|
34
|
-
plot.show
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end if Daru.has_nyaplot?
|