﻿function createChart(text1, text2) {
	return new dojo.charting.Chart(null, text1, text2);
}

function createSeries(data) {
	var
	buoyData = new dojo.collections.Store();
	buoyData.setData(data);

	var
	buoySeries = new dojo.charting.Series({
		dataSource: buoyData,
		bindings:   {x: "x", speed: "speed", direction: "direction", text: "text"},
		label:      "Viento boya 1"
	});

	return buoySeries;
}

function createPlotArea(seriesData, title, minXValue, maxXValue, width, height) {
	var
	series          = createSeries(seriesData);
	axisX           = new dojo.charting.StyledAxis();
	axisX.range     = {lower: minXValue, upper: maxXValue};
	axisX.origin    = "0";

	var
	delta           = maxXValue - minXValue,
	ratio           = height / width;
	yMaxValue       = delta * ratio / 2;

	var
	axisY           = new dojo.charting.StyledAxis();
	axisY.range     = {lower: -yMaxValue, upper: yMaxValue};
	axisY.origin    = "min";
	axisY.label     = title;
	axisY.showAxis  = false;
	axisY.verticalLabelLeftPositionFactor = 0.4;

	var
	plot = new dojo.charting.Plot(axisX, axisY);
	plot.addSeries({data: series, plotter: dojo.charting.Plotters.Wind});

	var
	plotArea1 = new dojo.charting.PlotArea();
	plotArea1.size = {width: width, height: height};
	plotArea1.padding = {top: 5, right: 5, bottom: 5, left: 12};
	plotArea1.plots.push(plot);

	return plotArea1;
}

function createDatePlotArea(seriesData, minXValue, maxXValue, width, height) {
	var
	series                    = createSeries(seriesData),
	axisX                     = new dojo.charting.DateStyledAxis(minXValue, maxXValue, seriesData);
	axisX.labelVerticalOffset = -(axisX.textSize / 2);

	var
	delta           = maxXValue - minXValue,
	ratio           = height / width;
	yMaxValue       = delta * ratio / 2;

	var
	axisY           = new dojo.charting.StyledAxis();
	axisY.range     = {lower: -yMaxValue, upper: yMaxValue};
	axisY.showAxis  = false;

	var
	plot = new dojo.charting.Plot(axisX, axisY);

	var
	plotArea1 = new dojo.charting.PlotArea();
	plotArea1.size = {width: width, height: height};
	plotArea1.padding = {top: 0, right: 5, bottom: 0, left: 12};
	plotArea1.plots.push(plot);

	return plotArea1;
}
