gt: 		{ // basic options are handled via AttachedLabel rec
context: /*
   * --------- BEGIN COPYRIGHT NOTICE ---------
   * Copyright 2002-2012 Extentech Inc.
   * Copyright 2013 Infoteria America Corp.
   * 
   * This file is part of OpenXLS.
   * 
   * OpenXLS is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation, either version 3 of
   * the License, or (at your option) any later version.
   * 
   * OpenXLS is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Lesser General Public License for more details.
   * 
   * You should have received a copy of the GNU Lesser General Public
   * License along with OpenXLS.  If not, see
   * <http://www.gnu.org/licenses/>.
   * ---------- END COPYRIGHT NOTICE ----------
   */
  package org.openxls.formats.XLS.charts;
  
  import org.openxls.formats.XLS.XLSRecord;
  import org.openxls.toolkit.ByteTools;
  import org.openxls.formats.XLS.XLSConstants;
  
  /**
   * <b>DataFormat: Series and Data Point Numbers(0x1006)</b>
   * <p/>
   * 4	xi		2	the zero-based index of the data point within the series specified by yi. (FFFFh means entire series)
   * 6	yi		2	the zero-based index of a Series record
   * 8	iss		2	An unsigned integer that specifies properties of the data series, trendline or error bar, depending on the type of records in sequence of records:
   * <p/>
   * If does not contain a SerAuxTrend or SerAuxErrBar record, then this field specifies the plot order of the data series.
   * If the series order was changed, this field can be different from yi. MUST be less than or equal to the number of series in the chart.
   * MUST be unique among iss values for all instances of this record contained in the SERIESFORMAT rule that does not contain a SerAuxTrend or SerAuxErrBar record.
   * <p/>
   * If the SERIESFORMAT rule contains a SerAuxTrend record on the chart group, then this field specifies the trendline number for the series.
   * <p/>
   * If the SERIESFORMAT rule contains a SerAuxErrBar record on the chart group, then this field specifies a zero-based index into a Series record in the
   * collection of Series records in the current chart sheet substream for which the error bar applies to.
   * <p/>
   * 10	grbit	2	flags (0?)		ignored
   * <p/>
   * <p/>
   * ORDER OF SUB-RECS:
   * [Chart3DBarShape]
   * [LineFormat, AreaFormat, PieFormat]		== lines, fill
   * [SerFormat]			== smoothed lines ...
   * [GelFrame]
   * [MarkerFormat]
   * [AttachedLabel]		== data labels
   * [ShapeProps]
   * [CtrlMltFrt]
   */
  public class DataFormat extends GenericChartObject implements ChartObject
  {
  	/**
  	 * serialVersionUID
  	 */
  	private static final long serialVersionUID = -3526272512004348462L;
  	private short yi;
  	private short xi;
  	private short iss;
  
  	@Override
  	public void init()
  	{
  		super.init();
  		byte[] rkdata = getData();
  		xi = ByteTools.readShort( rkdata[0], rkdata[1] );
  		yi = ByteTools.readShort( rkdata[2], rkdata[3] );
  		iss = (short) ByteTools.readUnsignedShort( rkdata[4], rkdata[5] );
  	}
  
  	private byte[] PROTOTYPE_BYTES = new byte[]{ -1, -1, 0, 0, 0, 0, 0, 0 };
  
  	public void initNew()
  	{
  		setOpcode( XLSConstants.DATAFORMAT );
  		setData( PROTOTYPE_BYTES );
  		init();
  		Chart3DBarShape cs = new Chart3DBarShape();
  		cs.setOpcode( XLSConstants.CHART3DBARSHAPE );    // creates default bar shape==0, 0
  		addChartRecord( cs );
  	}
  
  	/**
  	 * Create a new dataformat
  	 *
  	 * @param parentChart
  	 * @return
  	 */
  	public static XLSRecord getPrototype()
  	{
  		DataFormat df = new DataFormat();
  		df.setOpcode( XLSConstants.DATAFORMAT );
  		df.setData( df.PROTOTYPE_BYTES );
  		df.init();
  		Chart3DBarShape cs = new Chart3DBarShape();
  		cs.setOpcode( XLSConstants.CHART3DBARSHAPE );    // creates default bar shape==0, 0
  		df.addChartRecord( cs );
  		return df;
  	}
  
  	public static XLSRecord getPrototypeWithFormatRecs( Chart parentChart )
  	{
  		return getPrototypeWithFormatRecs( 0, parentChart );
  	}
  
  	/**
  	 * Create DataFormat Record that HOPEFULLY reflects the necessary associated recs
  	 *
  	 * @param type
  	 * @return DataFormat Record
  	 */
  	public static XLSRecord getPrototypeWithFormatRecs( int seriesNumber, Chart parentChart )
  	{
  		DataFormat df = new DataFormat();
  		df.setOpcode( XLSConstants.DATAFORMAT );
  		df.setData( df.PROTOTYPE_BYTES );
  		df.init();
  		Chart3DBarShape cs = new Chart3DBarShape();
  		cs.setOpcode( XLSConstants.CHART3DBARSHAPE );    // creates default bar shape==0, 0
  		df.addChartRecord( cs );
  		df.setSeriesNumber( seriesNumber );
  		LineFormat lf = (LineFormat) LineFormat.getPrototype();
  		df.addChartRecord( lf );
  		AreaFormat af = (AreaFormat) AreaFormat.getPrototype();
  		af.setParentChart( parentChart );
  		df.addChartRecord( af );
  		PieFormat pf = (PieFormat) PieFormat.getPrototype();
  		pf.setParentChart( parentChart );
  		df.addChartRecord( pf );
  		MarkerFormat mf = (MarkerFormat) MarkerFormat.getPrototype();
  		mf.setParentChart( parentChart );
  		df.addChartRecord( mf );
  		 /* pieformat:
  	MUST not exist on chart group types other than  ---> doesn't appear true (???) 
  	pie, 
  	doughnut, 
  	bar of pie, or 
  	pie of pie. 
  	MUST not exist if the chart group type is doughnut and the series is not the outermost series. 
  	MUST not exist on the data points on the secondary bar/pie of a bar of pie chart group.	
            */
  		return df;
  	}
  
  	public void setPointNumber( int idx )
  	{
  		xi = (short) idx;
  		byte[] rkdata = getData();
  		byte[] num = ByteTools.shortToLEBytes( (short) idx );
  		rkdata[0] = num[0];
  		rkdata[1] = num[1];
  		setData( rkdata );
  	}
  
  	/**
  	 * Set the series index
  	 */
  	public void setSeriesIndex( int idx )
  	{
  		yi = (short) idx;
  		byte[] rkdata = getData();
  		byte[] num = ByteTools.shortToLEBytes( (short) idx );
  		rkdata[2] = num[0];
  		rkdata[3] = num[1];
  		setData( rkdata );
  	}
  
  	public void setSeriesNumber( int idx )
  	{
  		iss = (short) idx;
  		byte[] rkdata = getData();
  		byte[] num = ByteTools.shortToLEBytes( (short) idx );
  		rkdata[4] = num[0];
  		rkdata[5] = num[1];
  		setData( rkdata );
  	}
  
  	public short getSeriesIndex()
  	{
  		return yi;
  	}
  
  	public short getSeriesNumber()
  	{
  		return iss;
  	}
  
  	public short getPointNumber()
  	{
  		return xi;
  	}
  
  	private AttachedLabel getAttachedLabelRec( boolean bCreate )
  	{
  		AttachedLabel al = null;
  		al = (AttachedLabel) Chart.findRec( chartArr, AttachedLabel.class );
  		if( (al == null) && bCreate )
  