### ----------------------------------------------------
### -- JavaScript::D3
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/01-plots-calls.rakutest
### ----------------------------------------------------
#!/usr/bin/env raku
use v6.d;

# use lib <. lib>;

use JavaScript::D3;

use Test;

plan 15;

#my @dsXY = random-tabular-dataset(12, <x y>,
#        generators => { x => { random-variate(NormalDistribution.new(30, 12), $_) },
#                        y => { random-real(400, $_) } });
my @dsXY = [{:x(18.44193433951788e0), :y(393.17809757025526e0)}, {:x(17.3810240767343e0), :y(273.73524913533555e0)}, {:x(6.74822921399435e0), :y(284.64701050256554e0)},
            {:x(33.12676277233732e0), :y(367.87025801505905e0)}, {:x(29.360113552246453e0), :y(346.41753370557103e0)}, {:x(26.14755093451985e0), :y(226.10944668510191e0)},
            {:x(18.4093226066732e0), :y(53.129912177713834e0)}, {:x(34.350674655309454e0), :y(61.078113101833374e0)}, {:x(41.136946202641894e0), :y(52.797551561648916e0)},
            {:x(61.9475390216227e0), :y(196.50927122018098e0)}, {:x(16.07845927581193e0), :y(128.69859187230782e0)}, {:x(17.33293691771654e0), :y(122.70510305598417e0)}];

#my @dsXYG = random-tabular-dataset(12, <x y group>,
#        generators => { x => { random-variate(NormalDistribution.new(30, 12), $_) },
#                        y => { random-real(400, $_) },
#                        group => <a b c d> });
my @dsXYG = [{:group("c"), :x(36.76449617736303e0), :y(208.09994227661667e0)}, {:group("d"), :x(38.26054718688302e0), :y(233.44049333827604e0)}, {:group("d"), :x(31.398379384273944e0), :y(385.38199254721275e0)},
             {:group("a"), :x(28.820495464506802e0), :y(297.0157022707852e0)}, {:group("b"), :x(26.4091338504342e0), :y(279.9478171139661e0)}, {:group("d"), :x(33.50969881911225e0), :y(245.72026529056572e0)},
             {:group("c"), :x(25.567333844254474e0), :y(331.8210516364763e0)}, {:group("b"), :x(37.23217634596619e0), :y(247.12722165664132e0)}, {:group("a"), :x(32.356841891576806e0), :y(346.19385230785167e0)},
             {:group("c"), :x(37.98089056518958e0), :y(313.74285209487294e0)}, {:group("c"), :x(15.21769308572128e0), :y(324.70401574669194e0)}, {:group("b"), :x(48.30592423079918e0), :y(87.1655519541188e0)}];

## 1
ok js-d3-list-plot((rand xx 100).List);

## 2
ok js-d3-list-plot((rand xx 100).List,
        height => 500,
        background => 'gray',
        title => 'Try it!',
        x-axis-label => 'My X',
        y-axis-label => 'My Y',
        margins => %(top => 80));

## 3
ok js-d3-list-plot(@dsXY,
        height => 500,
        background => 'gray',
        title => 'Try it!',
        x-axis-label => 'My X',
        y-axis-label => 'My Y',
        margins => %(top => 80));

## 4
ok js-d3-list-line-plot((rand xx 100).List);

## 5
ok js-d3-list-line-plot((rand xx 100).List,
        height => 500,
        background => 'gray',
        title => 'Try it!',
        x-axis-label => 'My X',
        y-axis-label => 'My Y',
        margins => %(top => 80));

## 6
ok js-d3-list-line-plot(@dsXY,
        height => 500,
        background => 'gray',
        title => 'Try it!',
        x-axis-label => 'My X',
        y-axis-label => 'My Y',
        margins => %(top => 80));


## 7
ok js-d3-list-line-plot(@dsXY,
        height => 500,
        background => 'gray',
        title => 'Try it!',
        x-axis-label => 'My X',
        y-axis-label => 'My Y',
        margins => %(top => 80));

## 8
ok js-d3-list-line-plot(@dsXYG);

## 9
my @tsRand9 = [{:date("1972-01-19"), :value(8054.176314849976e0)}, {:date("1972-11-15"), :value(11904.64512571012e0)}, {:date("1981-07-11"), :value(24649.691428781414e0)},
               {:date("1986-09-13"), :value(25482.020805707773e0)}, {:date("1991-06-19"), :value(29886.14908358724e0)}, {:date("2006-04-30"), :value(44308.25652881795e0)},
               {:date("2010-01-09"), :value(41992.17316528338e0)}, {:date("2015-04-19"), :value(43481.79162319789e0)}, {:date("2018-05-07"), :value(47036.51495100006e0)},
               {:date("2018-08-19"), :value(45503.891398953994e0)}, {:date("2020-10-28"), :value(42583.396163750265e0)}, {:date("2021-07-24"), :value(52462.731894928394e0)}];
ok js-d3-date-list-plot(@tsRand9);

## 10
my @tsRand10 = [("1973-01-11", 10362.018313698258e0), ("1973-05-05", 11628.521214949724e0), ("1976-06-01", 17113.43240089176e0), ("1980-09-26", 20001.873403108802e0),
                ("1981-11-01", 19507.50152328676e0), ("1987-09-10", 31128.076573249346e0), ("1990-04-06", 28134.826387652567e0), ("1990-04-29", 28804.388595133754e0),
                ("2000-07-17", 35179.50122305548e0), ("2006-10-29", 39306.55363070641e0), ("2012-04-22", 47916.277955902435e0), ("2021-06-23", 51032.26926024121e0)];
ok js-d3-date-list-plot(@tsRand10);

## 11
my $seq11 =((2, <88706/9185>), (1, <78683/8047>), (7, <64493/6356>), (5, <41257/4225>), (3, <74643/7457>), (4, <83245/8493>), (6, <65406/6467>)).Seq;
ok js-d3-list-plot($seq11);

## 12
ok js-d3-list-line-plot($seq11, margins => 100);

## 13
ok js-d3-list-plot(@dsXYG);

## 14
ok js-d3-list-plot(@dsXYG.map({ $_<x y group> }));

## 15
ok js-d3-list-line-plot(@dsXYG.map({ $_<x y group> }));

done-testing;


