import { Graph }        from "./Graph";
import { Series }       from "./Series";
import { Axes }         from "./Axes";
import { m }            from "hslayout";
import { DataSet }      from "hsdatab";

const root = window.document.createElement("div");
    
let series:DataSet = {
    colNames:['time', 'volume', 'costs'],
    rows:[[-1,  0.2,  0.3], [0.2, 0.7, 0.2], [0.4, 0.1, 0.3],
          [0.6, 0.05, 0.1], [0.8, 0.3, 0.5], [1,   0.2, 0.4]]
};
     
function 
(series:DataSet, titlex:string, titley:string) {
    return m.mount(root, { view:() => { 
        return m(Graph, {cfgFn: (cfg:any) => {
            cfg.chart.title.xpos = titlex;
            cfg.chart.title.ypos = titley;
            cfg.axes.primary.x.title.text = 'time';
            cfg.axes.primary.y.scale.type = Axes.type.linear;
            cfg.series.data      = [series];
            cfg.series.series    = [
                { x:'time', y:'volume', l:'volume', type:'marker' },
            ];
            cfg.series.series[0].style.marker.shape = Series.marker.circle;
       }});
    }});
}
 
Series.defaultStyle.line.width = 6;
Series.defaultStyle.bar.width  = 20;
Series.defaultStyle.bar.offset = 25;
Series.defaultColors[0] = 'rgba(255, 0, 0, 0.5)';
Series.defaultColors[1] = 'rgba(0, 255, 0, 0.5)';
 
describe('Chart', () => {
    describe('start top', () => {
        beforeAll(() => mount(series, 'start', 'top'));
        it('should plot', () => 
            expect(root).toMatchSnapshot()
        );
    });
    describe('middle top', () => {
        beforeAll(() => mount(series, 'middle', 'top'));
        it('should plot', () => 
            expect(root).toMatchSnapshot()
        );
    });
    describe('end top', () => {
        beforeAll(() => mount(series, 'end', 'top'));
        it('should plot', () => 
            expect(root).toMatchSnapshot()
        );
    });
    describe('start center', () => {
        beforeAll(() => mount(series, 'start', 'center'));
        it('should plot', () => 
            expect(root).toMatchSnapshot()
        );
    });
    describe('start bottom', () => {
        beforeAll(() => mount(series, 'start', 'bottom'));
        it('should plot', () => 
            expect(root).toMatchSnapshot()
        );
    });
});
mount