Beispiel #1
0
	/**
	 * Returns the position of 0 value on chart.
	 *
	 * @return Position of 0 value on chart
	 */
	public float getZeroPosition(){

		if(mOrientation == Orientation.VERTICAL)
			return verController.parsePos(0, 0);
		else
			return horController.parsePos(0, 0);
	}
Beispiel #2
0
	/**
	 * Mandatory horizontal border when necessary (ex: BarCharts)
	 * Sets the attribute depending on the chart's orientation.
	 * e.g. If orientation is VERTICAL it means that this attribute must be handled
	 * by horizontal axis and not the vertical axis.
	 */
	void setMandatoryBorderSpacing(){

		if(mOrientation == Orientation.VERTICAL)
			horController.mandatoryBorderSpacing = 1;
		else
			verController.mandatoryBorderSpacing = 1;
	}
Beispiel #3
0
	/**
	 *
	 * @param minValue   The minimum value that Y axis will have as a label
	 * @param maxValue   The maximum value that Y axis will have as a label
	 * @return {@link com.db.chart.view.ChartView} self-reference.
	 */
	public ChartView setAxisBorderValues(int minValue, int maxValue){

		if(mOrientation == Orientation.VERTICAL)
			verController.setBorderValues(minValue, maxValue);
		else
			horController.setBorderValues(minValue, maxValue);

		return this;
	}
Beispiel #4
0
	/**
	 *
	 * @param spacing   Spacing between top of the chart and the first label
	 * @return {@link com.db.chart.view.ChartView} self-reference.
	 */
	public ChartView setTopSpacing(float spacing){

		if(mOrientation == Orientation.VERTICAL)
			verController.topSpacing = spacing;
		else
			horController.borderSpacing = spacing;

		return this;
	}
Beispiel #5
0
	/**
	 * Set the format to be added to Y labels.
	 *
	 * @param format   Format to be applied
	 * @return {@link com.db.chart.view.ChartView} self-reference.
	 */
	public ChartView setLabelsFormat(DecimalFormat format){

		if(mOrientation == Orientation.VERTICAL)
			verController.labelFormat = format;
		else
			horController.labelFormat = format;

		return this;
	}
Beispiel #6
0
	/**
	 * Sets the chart's orientation.
	 *
	 * @param orien   Orientation.HORIZONTAL | Orientation.VERTICAL
	 */
	void setOrientation(Orientation orien){

		mOrientation = orien;
		if(mOrientation == Orientation.VERTICAL) {
			verController.handleValues = true;
		}else{
			horController.handleValues = true;
		}
	}
Beispiel #7
0
		@SuppressLint("NewApi")
		@Override
		public boolean onPreDraw() {
			ChartView.this.getViewTreeObserver().removeOnPreDrawListener(this);

			style.init();

			// Define chart frame
			mChartTop = getPaddingTop() + verController.getLabelHeight()/2;
			mChartBottom = getMeasuredHeight() - getPaddingBottom()-LABELTEXTMAXLINE*(int)(style.labelsPaint.descent()-style.labelsPaint.ascent());
			mChartLeft = getPaddingLeft();
			mChartRight = getMeasuredWidth() - getPaddingRight();


			// Initialize controllers now that we have the measures
			verController.init();

			if(mHasThresholdValue) {
				mThresholdStartValue = verController.parsePos(0, mThresholdStartValue);
				mThresholdEndValue = verController.parsePos(0, mThresholdEndValue);
			}

			// Mandatory: X axis after Y axis!
			horController.init();

			// Process data to define screen positions
			digestData();

			// Tells view to execute code before starting drawing
			onPreDrawChart(data);

			// Define regions
			mRegions = defineRegions(data);

			// Prepares the animation if needed and gets the first dump 
			// of data to be drawn
			if(mAnim != null)
				data = mAnim.prepareEnterAnimation(ChartView.this);

			if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
				ChartView.this.setLayerType(LAYER_TYPE_SOFTWARE, null);

			return mReadyToDraw = true;
		}
Beispiel #8
0
	/**
	 * Convert {@link ChartEntry} values into screen points.
	 */
	private void digestData() {

		int nEntries = data.get(0).size();
		for(ChartSet set: data){
			for(int i = 0; i < nEntries; i++){
				set.getEntry(i)
						.setCoordinates(horController.parsePos(i, set.getValue(i)),
								verController.parsePos(i, set.getValue(i)));
			}
		}
	}
Beispiel #9
0
	/**
	 * A step is seen as the step to be defined between 2 labels. 
	 * As an example a step of 2 with a max label value of 6 will end 
	 * up with {0, 2, 4, 6} as labels.
	 *
	 * @param step   (real) value distance from every label
	 * @return {@link com.db.chart.view.ChartView} self-reference.
	 */
	public ChartView setStep(int step){

		if(step <= 0)
			throw new IllegalArgumentException("Step can't be lower or equal to 0");

		if(mOrientation == Orientation.VERTICAL)
			verController.step = step;
		else
			horController.step = step;

		return this;
	}
Beispiel #10
0
	@Override
	protected void onDraw(Canvas canvas) {

		mIsDrawing = true;
		super.onDraw(canvas);

		if(mReadyToDraw){

			//long time = System.currentTimeMillis();

			// Draw grid
			if(mGridType == GridType.FULL || mGridType == GridType.VERTICAL)
				drawVerticalGrid(canvas);
			if(mGridType == GridType.FULL || mGridType == GridType.HORIZONTAL)
				drawHorizontalGrid(canvas);

			// Draw Axis Y
			verController.draw(canvas);

			// Draw threshold
			if (mHasThresholdValue)
				drawThreshold(canvas,
						getInnerChartLeft(),
						mThresholdStartValue,
						getInnerChartRight(),
						mThresholdEndValue);
			if (mHasThresholdLabel)
				drawThreshold(canvas,
						data.get(0).getEntry(mThresholdStartLabel).getX(),
						getInnerChartTop(),
						data.get(0).getEntry(mThresholdEndLabel).getX(),
						getInnerChartBottom());

			// Draw data
			if(!data.isEmpty())
				onDrawChart(canvas, data);

			// Draw axis X
			horController.draw(canvas);

			//System.out.println("Time drawing "+(System.currentTimeMillis() - time));
		}

		mIsDrawing = false;
	}
Beispiel #11
0
	/**
	 * Method not expected to be used often. More for testing.
	 * Resets chart state to insert new configuration.
	 */
	public void reset(){

		if(mAnim != null && mAnim.isPlaying())
			mAnim.cancel();

		init();
		if(horController.mandatoryBorderSpacing != 0) {
			horController.reset();
		}

		if(verController.mandatoryBorderSpacing != 0) {
			verController.reset();
		}

		mHasThresholdLabel = false;
		mHasThresholdValue = false;
		style.thresholdPaint = null;

		style.gridPaint = null;
	}
Beispiel #12
0
	/**
	 * Inner Chart refers only to the area where chart data will be draw, 
	 * excluding labels, axis, etc.
	 *
	 * @return Position of the inner left side of the chart
	 */
	public float getInnerChartLeft(){
		return verController.getInnerChartLeft();
	}
Beispiel #13
0
	/**
	 * Inner Chart refers only to the area where chart data will be draw, 
	 * excluding labels, axis, etc.
	 *
	 * @return Position of the inner bottom side of the chart
	 */
	public float getInnerChartBottom(){
		return verController.getInnerChartBottom();
	}
Beispiel #14
0
	/**
	 * Set spacing between Labels and Axis. Will be applied to both X and Y.
	 *
	 * @param spacing   Spacing between labels and axis
	 * @return {@link com.db.chart.view.ChartView} self-reference.
	 */
	public ChartView setAxisLabelsSpacing(float spacing){

		horController.setAxisLabelsSpacing(spacing);
		verController.setAxisLabelsSpacing(spacing);
		return this;
	}
Beispiel #15
0
	/**
	 * Show/Hide Y axis.
	 *
	 * @param bool   If true axis won't be visible
	 * @return {@link com.db.chart.view.ChartView} self-reference.
	 */
	public ChartView setYAxis(boolean bool){
		verController.hasAxis = bool;
		return this;
	}
Beispiel #16
0
	/**
	 * Show/Hide Y labels and respective axis.
	 *
	 * @param position   NONE - No labels
	 *                   OUTSIDE - Labels will be positioned outside the chart
	 *                   INSIDE - Labels will be positioned inside the chart
	 * @return {@link com.db.chart.view.ChartView} self-reference.
	 */
	public ChartView setYLabels(YController.LabelPosition position){
		verController.labelsPositioning = position;
		return this;
	}