
\newlength{\origXLabelSep}\setlength{\origXLabelSep}{\baselineskip+1ex}
\newlength{\origYLabelSep}\setlength{\origYLabelSep}{7ex}
\newlength{\xLabelSep}\setlength{\xLabelSep}{\origXLabelSep}
\newlength{\yLabelSep}\setlength{\yLabelSep}{\origYLabelSep}

\newlength{\TempLengthA}
\setlength{\TempLengthA}{0pt}
\newlength{\TempLengthB}
\setlength{\TempLengthB}{0pt}

\newcommand{\NumDataPlotBaseline}{0}
\newcommand{\NumDataPlotDistance}{1}
% \newcommand{\xLabelRefPt}{t}
% \newcommand{\yLabelRefPt}{r}
% \newcommand{\xLabelRot}{0}
% \newcommand{\yLabelRot}{90}



% ------------------------------------------------------------------------------
% | keys for the put label commands
% ------------------------------------------------------------------------------

\define@cmdkeys[NumericDataPlot]{putxLabel}[NumDataPlotx]{
	LabelPos, LabelOption, LabelOrientation, LabelRot, LabelRefPt
}
\define@cmdkeys[NumericDataPlot]{putyLabel}[NumDataPloty]{
	LabelPos, LabelOption, LabelOrientation, LabelRot, LabelRefPt
}

\define@key[NumericDataPlot]{putxLabel}{LabelSep}[\origXLabelSep]{\setlength{\xLabelSep}{#1}}
\define@key[NumericDataPlot]{putyLabel}{LabelSep}[\origYLabelSep]{\setlength{\yLabelSep}{#1}}

\define@choicekey+[NumericDataPlot]{putxLabel}{ax}[\val\nrPutAxis]
{lower,upper}{
	\ifcase\nrPutAxis\relax
		\setkeys[NumericDataPlot]{putxLabel}{LabelRot=0, LabelRefPt=t}%
	    \renewcommand{\NumDataPlotBaseline}{\NumDataPlotyCoordMin}
        \renewcommand{\NumDataPlotDistance}{-1}
    \or
    	\setkeys[NumericDataPlot]{putxLabel}{LabelRot=0, LabelRefPt=b}%
		\renewcommand{\NumDataPlotBaseline}{\NumDataPlotyCoordMax}
		\renewcommand{\NumDataPlotDistance}{1}
    \fi
}{
	\PackageWarning{NumericPlots}
		{Axis #1 not defined. Use left or right.}
}
\define@choicekey+[NumericDataPlot]{putyLabel}{ax}[\val\nrPutAxis]
{left,right}{
	\ifcase\nrPutAxis\relax
		\setkeys[NumericDataPlot]{putyLabel}{LabelRot=90, LabelRefPt=b}%
    	\renewcommand{\NumDataPlotBaseline}{\NumDataPlotxCoordMin}
		\renewcommand{\NumDataPlotDistance}{-1}
    \or
    	\setkeys[NumericDataPlot]{putyLabel}{LabelRot=270, LabelRefPt=b}%
    	\renewcommand{\NumDataPlotBaseline}{\NumDataPlotxCoordMax}
		\renewcommand{\NumDataPlotDistance}{1}
    \fi
}{
	\PackageWarning{NumericPlots}
		{Axis #1 not defined. Use left or right.}
}

\newcommand\CheckIfColumntypeDefined[1]{%
  \providebool{tpl@coltype@#1}
  \ifcsdef{NC@find@\string#1}%
    {\setbool{tpl@coltype@#1}{true}}%
    {\ifcsdef{columntype@\string#1}
      {\setbool{tpl@coltype@#1}{true}}%
      {\setbool{tpl@coltype@#1}{false}}%
    }%
}

% ------------------------------------------------------------------------------
% | standard values for the keys
% ------------------------------------------------------------------------------


\newcommand{\StdLabelOption}{{}}

\presetkeys[NumericDataPlot]{putxLabel}{
	LabelPos=0.5, LabelOption=\StdLabelOption{},LabelOrientation=c
}{}
\presetkeys[NumericDataPlot]{putyLabel}{
	LabelPos=0.5, LabelOption=\StdLabelOption{},LabelOrientation=c 
}{}




% ==============================================================================
% ||
% || axis labels
% ||
% ==============================================================================
\newcommand{\PutLabelXaxis}[2][]{
	\setkeys*[NumericDataPlot]{putxLabel}{#1}%
 	%
	\setcounter{BufferCounter}{10000*\ratio{\xLabelSep}{\CPicHeight}}%
	\FPsub{\NumDataPlotBuffer}{\NumDataPlotGyPicMax}{\NumDataPlotGyPicMin}%
	\FPmul{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\theBufferCounter}%
	\FPdiv{\NumDataPlotBuffer}{\NumDataPlotBuffer}{10000}%
	\FPmul{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotDistance}%
 	\FPadd{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotBaseline}%
	%
	\rput[\NumDataPlotxLabelRefPt]%
		{\NumDataPlotxLabelRot}%
		(!\NumDataPlotxCoordRange\space \NumDataPlotxLabelPos\space mul %
		\NumDataPlotxCoordMin\space add \NumDataPlotBuffer\space){%
			\makeXLabel{#2}%
		}%
}

\newcommand{\makeXLabel}[1]{%
	\NumDataPlotxLabelOption{}%
	\testframe{%
	\setlength{\tabcolsep}{0pt}%
	\expandafter\tabular\NumDataPlotxLabelOrientation{}%
		#1%
	\endtabular%
	}%
}


\newcommand{\PutLabelYaxis}[2][]{%
	\setkeys*[NumericDataPlot]{putyLabel}{#1}%
 	%
	\setcounter{BufferCounter}{10000*\ratio{\yLabelSep}{\CPicWidth}}%
	\FPsub{\NumDataPlotBuffer}{\NumDataPlotGxPicMax}{\NumDataPlotGxPicMin}%
	\FPmul{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\theBufferCounter}%
	\FPdiv{\NumDataPlotBuffer}{\NumDataPlotBuffer}{10000}%
	\FPmul{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotDistance}%
 	\FPadd{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotBaseline}%
	%
	\rput[\NumDataPlotyLabelRefPt]%
		{\NumDataPlotyLabelRot}%
		(!\NumDataPlotBuffer\space %
		\NumDataPlotyCoordRange\space \NumDataPlotyLabelPos\space mul %
		\NumDataPlotyCoordMin\space add){%
			\makeYLabel{#2}%
		}%
}

\newcommand{\makeYLabel}[1]{%
	\NumDataPlotyLabelOption{}%
	\testframe{%
	\setlength{\tabcolsep}{0pt}%
	\expandafter\tabular\NumDataPlotyLabelOrientation{}%
		#1%
	\endtabular%
	}%
}


