using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using ms.aq.cview.util;

namespace ms.aq.cview.draw {
    public class PlotPoint {
        public string SeriesLabel;
        public string ColumnLabel;
        public int HitMin = Settings.AXI_UNDEF, HitMax = Settings.AXI_UNDEF, HitDif = Settings.AXI_UNDEF,
            Hits = Settings.AXI_UNDEF;
        public int X = Settings.AXI_UNDEF, Y = Settings.AXI_UNDEF;
    }
    public interface ClotRowInterpreter {
        void SetReader(IDataReader reader_);
        PlotPoint[] InitRowPoints();
        void LoadRowPoints(PlotPoint[] points,int rangeCnt,out string rangeLabel);
    }
    public class RowInterpreter:ClotRowInterpreter {
        private IDataReader reader;
        private int read;
        public void SetReader(IDataReader reader_) {
            reader = reader_;
            read = 0;
        }
        public PlotPoint[] InitRowPoints() {
            return new PlotPoint[reader.FieldCount - 1];
        }
        public void LoadRowPoints(PlotPoint[] rst,int rangeCnt,out string rangeLabel) {
            string s = "";
            rangeLabel = null;
            for (int c = 0; c < reader.FieldCount; c++) {//first find the ind var
                s += "'"+reader.GetName(  c  )+"',";
                if (reader.GetName(c).StartsWith(Settings.XDIM_PREF)) {//then initialize rst, with this as the x coor
                    for (int i = 0; i < rst.Length; i++) {
                        if(rst[i] == null)rst[i] = new PlotPoint();
                        rst[i].X = (int)reader.GetValue(c);
                    }
                }
            }
            int offset = 0;
            for (int c = 0; c < reader.FieldCount; c++) {//now go through everything else, setting Y coors and labels
                if (reader.GetName(c).StartsWith(Settings.XDIM_PREF)) {
                    offset = offset-1;
                    continue;//already did this
                }
                if(rst[c+offset].SeriesLabel == null)
                    rst[c + offset].SeriesLabel = reader.GetName(c);
                rst[c + offset].Y = (int)reader.GetValue(c);
            }
            ++read;
        }
    }
}