Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why Box Annotation move #10

Open
justinwk11 opened this issue Sep 15, 2020 · 0 comments
Open

why Box Annotation move #10

justinwk11 opened this issue Sep 15, 2020 · 0 comments

Comments

@justinwk11
Copy link

I used box annotation like pic
in a boxAnnotation I used

.withIsEditable(true)
.withPosition(1,-2, 0, 2)
.withBackgroundDrawableId(R.drawable.example_box_annotation_background_4)
.withResizingGrip(customIResizingGrip)
.withAnnotationDragListener(customIAnnotationSelectionDrawable)
.withResizeDirections(Direction2D.XDirection)
.withDragDirections(Direction2D.XDirection)
.build();

and i made a 2 box like pic

i use box for drag one side to make a box big or small

the first box which is left doesn’t move anywhere.
it just can only drag that i want
but the second box, the box moves when i drag after first touch
the left box never moves on but right box moves first drags
just move sometimes

//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2017. All rights reserved.
//
// Web: http://www.scichart.com
// Support: [email protected]
// Sales: [email protected]
//
// AnnotationsAreEasyFragment.java is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use.
//
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied.
//******************************************************************************

package com.scichart.examples.fragments;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.scichart.charting.Direction2D;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.annotations.BoxAnnotation;
import com.scichart.charting.visuals.annotations.HorizontalAnchorPoint;
import com.scichart.charting.visuals.annotations.IAnnotation;
import com.scichart.charting.visuals.annotations.IResizingGrip;
import com.scichart.charting.visuals.annotations.OnAnnotationDragListener;
import com.scichart.charting.visuals.annotations.VerticalAnchorPoint;
import com.scichart.charting.visuals.axes.IAxis;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.examples.R;
import com.scichart.examples.fragments.base.ExampleBaseFragment;

import java.util.Collections;

import butterknife.BindView;

public class AnnotationsAreEasyFragment extends ExampleBaseFragment {
@BindView(R.id.chart)
SciChartSurface surface;

@Override
public boolean showDefaultModifiersInToolbar() {
    return false;
}

@Override
protected int getLayoutId() {
    return R.layout.example_single_chart_fragment;
}

@Override
protected void initExample() {
    Paint paint = new Paint();
    paint.setColor(Color.RED);

    Canvas canvas = new Canvas();
    canvas.drawRect(100, 100, 100, 100, paint);

    CustomIResizingGrip customIResizingGrip = new CustomIResizingGrip();
    CustomLeftBoxAnnotationDragListener customLeftBoxAnnotationDragListener = new CustomLeftBoxAnnotationDragListener();
    CustomRightBoxAnnotationDragListener customRightBoxAnnotationDragListener = new CustomRightBoxAnnotationDragListener();

    customIResizingGrip.onDraw(canvas, 10, 20);

    final BoxAnnotation boxAnnotation = sciChartBuilder.newBoxAnnotation()
            .withIsEditable(true)
            .withPosition(7d, 2d, 9d, 4d)
            .withBackgroundDrawableId(R.drawable.example_box_annotation_background_4)
            .withResizingGrip(customIResizingGrip)
            .withAnnotationDragListener(customLeftBoxAnnotationDragListener)
            .withDragDirections(Direction2D.XDirection)
            .withResizeDirections(Direction2D.XDirection)
            .build();

    final BoxAnnotation boxAnnotation2 = sciChartBuilder.newBoxAnnotation()
            .withIsEditable(true)
            .withPosition(4d,4d, 2d,2d)
            .withBackgroundDrawableId(R.drawable.example_box_annotation_background_4)
            .withResizingGrip(customIResizingGrip)
            .withAnnotationDragListener(customRightBoxAnnotationDragListener)
            .withDragDirections(Direction2D.XDirection)
            .withResizeDirections(Direction2D.XDirection)
            .build();

    UpdateSuspender.using(surface, new Runnable() {
        @Override
        public void run() {
            final IAxis xAxis = sciChartBuilder.newNumericAxis()
                    .withVisibleRange(0d, 10d)
                    .withGrowBy(0.1d, 0.1d)
                    .withTextFormatting("0.0#")
                    .build();

            final IAxis yAxis = sciChartBuilder.newNumericAxis()
                    .withVisibleRange(0d, 10d)
                    .withGrowBy(0.1d, 0.1d)
                    .withTextFormatting("0.0#")
                    .build();

            Collections.addAll(surface.getXAxes(), xAxis);
            Collections.addAll(surface.getYAxes(), yAxis);
            Collections.addAll(surface.getAnnotations(), boxAnnotation, boxAnnotation2);
            Collections.addAll(surface.getAnnotations(),
                    sciChartBuilder.newTextAnnotation()
                            .withX1(5d)
                            .withY1(8d)
                            .withHorizontalAnchorPoint(HorizontalAnchorPoint.Center)
                            .withVerticalAnchorPoint(VerticalAnchorPoint.Bottom)
                            .withText("Anchor Center (X1, Y1)")
                            .build(),
                    sciChartBuilder.newTextAnnotation()
                            .withX1(5d)
                            .withY1(8d)
                            .withHorizontalAnchorPoint(HorizontalAnchorPoint.Right)
                            .withVerticalAnchorPoint(VerticalAnchorPoint.Top)
                            .withText("Anchor Right")
                            .build(),
                    sciChartBuilder.newTextAnnotation()
                            .withX1(5d)
                            .withY1(8d)
                            .withHorizontalAnchorPoint(HorizontalAnchorPoint.Left)
                            .withVerticalAnchorPoint(VerticalAnchorPoint.Top)
                            .withText("or Anchor Left")
                            .build());

            surface.getChartModifiers().add(sciChartBuilder.newModifierGroupWithDefaultModifiers().build());
        }
    });
}

public static class CustomView1 extends View {

    private final int FILL_COLOR = Color.parseColor("#571CB61C");
    private final int STROKE_COLOR = Color.parseColor("#FF00B400");

    private final Path path = new Path();
    private final Paint paintFill = new Paint();
    private final Paint paintStroke = new Paint();

    public CustomView1(Context context) {
        super(context);
        init();
    }

    public CustomView1(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        paintFill.setStyle(Paint.Style.FILL);
        paintFill.setColor(FILL_COLOR);
        paintStroke.setStyle(Paint.Style.STROKE);
        paintStroke.setColor(STROKE_COLOR);

        path.moveTo(0, 15);
        path.lineTo(15, 0);
        path.lineTo(30, 15);
        path.lineTo(20, 15);
        path.lineTo(20, 30);
        path.lineTo(10, 30);
        path.lineTo(10, 15);
        path.lineTo(0, 15);

        setMinimumHeight(50);
        setMinimumWidth(50);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(path, paintFill);
        canvas.drawPath(path, paintStroke);
    }

}

public static class CustomView2 extends View {

    private final int FILL_COLOR = Color.parseColor("#57B22020");
    private final int STROKE_COLOR = Color.parseColor("#FF990000");

    private final Path path = new Path();
    private final Paint paintFill = new Paint();
    private final Paint paintStroke = new Paint();

    public CustomView2(Context context) {
        super(context);
        paintFill.setStyle(Paint.Style.FILL);
        paintFill.setColor(FILL_COLOR);
        paintStroke.setStyle(Paint.Style.STROKE);
        paintStroke.setColor(STROKE_COLOR);

        path.moveTo(0, 15);
        path.lineTo(10, 15);
        path.lineTo(10, 0);
        path.lineTo(20, 0);
        path.lineTo(20, 15);
        path.lineTo(30, 15);
        path.lineTo(15, 30);
        path.lineTo(0, 15);

        setMinimumHeight(50);
        setMinimumWidth(50);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(path, paintFill);
        canvas.drawPath(path, paintStroke);
    }

}

public static class CustomLeftBoxAnnotationDragListener implements OnAnnotationDragListener {
    @Override
    public void onDragStarted(IAnnotation iAnnotation) {
    }

    @Override
    public void onDragEnded(IAnnotation iAnnotation) {
        iAnnotation.setSelected(false);
        Log.i("Left", String.valueOf(iAnnotation.getX1()));
    }

    @Override
    public void onDragDelta(IAnnotation iAnnotation, float v, float v1) {
    }
}

public static class CustomRightBoxAnnotationDragListener implements OnAnnotationDragListener {

    @Override
    public void onDragStarted(IAnnotation iAnnotation) {

    }

    @Override
    public void onDragEnded(IAnnotation iAnnotation) {
        iAnnotation.setSelected(false);
        Log.i("Right", String.valueOf(iAnnotation.getX1()));
    }

    @Override
    public void onDragDelta(IAnnotation iAnnotation, float v, float v1) {

    }
}

public static class CustomIResizingGrip implements IResizingGrip {
    @Override
    public void onDraw(Canvas canvas, float v, float v1) {
    }

    @Override
    public boolean isHit(float v, float v1, float v2, float v3) {
        return true;
    }
}

}
제목 없음

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant