/
InteractionWithAnnotationsFragment.java
162 lines (149 loc) · 7.99 KB
/
InteractionWithAnnotationsFragment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// InteractionWithAnnotationsFragment.java is part of SCICHART®, High Performance Scientific Charts
// For full terms and conditions of the license, see http://www.scichart.com/scichart-eula/
//
// This source code is protected by international copyright law. Unauthorized
// reproduction, reverse-engineering, or distribution of all or any portion of
// this source code is strictly prohibited.
//
// This source code contains confidential and proprietary trade secrets of
// SciChart Ltd., and should at no time be copied, transferred, sold,
// distributed or made available without express written permission.
//******************************************************************************
package com.scichart.examples.fragments.examples2d.chartAnnotations;
import android.graphics.Typeface;
import android.view.Gravity;
import androidx.annotation.NonNull;
import com.scichart.charting.model.dataSeries.OhlcDataSeries;
import com.scichart.charting.modifiers.ZoomPanModifier;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.annotations.AnnotationCoordinateMode;
import com.scichart.charting.visuals.annotations.AnnotationSurfaceEnum;
import com.scichart.charting.visuals.annotations.HorizontalAnchorPoint;
import com.scichart.charting.visuals.annotations.LabelPlacement;
import com.scichart.drawing.utility.ColorUtil;
import com.scichart.examples.R;
import com.scichart.examples.data.MarketDataService;
import com.scichart.examples.data.PriceSeries;
import com.scichart.examples.fragments.base.ExampleSingleChartBaseFragment;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
public class InteractionWithAnnotationsFragment extends ExampleSingleChartBaseFragment {
@Override
public boolean showDefaultModifiersInToolbar() {
return false;
}
@Override
protected void initExample(@NonNull SciChartSurface surface) {
surface.setTheme(R.style.SciChart_NavyBlue);
final OhlcDataSeries<Date, Double> dataSeries = sciChartBuilder.newOhlcDataSeries(Date.class, Double.class).build();
final MarketDataService marketDataService = new MarketDataService(Calendar.getInstance().getTime(), 5, 5);
final PriceSeries data = marketDataService.getHistoricalData(200);
dataSeries.append(data.getDateData(), data.getOpenData(), data.getHighData(), data.getLowData(), data.getCloseData());
Collections.addAll(surface.getRenderableSeries(), sciChartBuilder.newCandlestickSeries().withDataSeries(dataSeries).withOpacity(0.4f).build());
Collections.addAll(surface.getXAxes(), sciChartBuilder.newCategoryDateAxis().build());
Collections.addAll(surface.getYAxes(), sciChartBuilder.newNumericAxis().withVisibleRange(30d, 37d).build());
Collections.addAll(surface.getChartModifiers(), new ZoomPanModifier());
Collections.addAll(surface.getAnnotations(),
sciChartBuilder.newTextAnnotation()
.withPosition(10, 30.5d)
.withIsEditable(true)
.withText("Buy!")
.withFontStyle(20, ColorUtil.White)
.withZIndex(1) // draw this annotation above other annotations
.build(),
sciChartBuilder.newTextAnnotation()
.withPosition(50, 34d)
.withBackgroundDrawableId(R.drawable.example_text_annotation_background)
.withIsEditable(true)
.withText("Sell!")
.withFontStyle(20, ColorUtil.White)
.withPadding(8)
.withZIndex(1) // draw this annotation above other annotations
.build(),
sciChartBuilder.newTextAnnotation()
.withX1(80d).withY1(37d)
.withIsEditable(true)
.withText("Rotated text")
.withFontStyle(20, ColorUtil.White)
.withRotationAngle(30)
.withZIndex(1) // draw this annotation above other annotations
.build(),
sciChartBuilder.newBoxAnnotation()
.withPosition(50, 35.5, 120, 32)
.withIsEditable(true)
.withBackgroundDrawableId(R.drawable.example_box_annotation_background_4)
.build(),
sciChartBuilder.newLineAnnotation()
.withPosition(40, 30.5d, 60, 33.5d)
.withIsEditable(true)
.withStroke(2f, 0xAAFF6600)
.build(),
sciChartBuilder.newLineAnnotation()
.withPosition(120, 30.5, 175, 36)
.withIsEditable(true)
.withStroke(2f, 0xAAFF6600)
.build(),
sciChartBuilder.newLineArrowAnnotation()
.withPosition(50, 35d, 80, 31.4d)
.withArrowHeadLength(8f)
.withArrowHeadWidth(16f)
.withIsEditable(true)
.build(),
sciChartBuilder.newAxisMarkerAnnotation()
.withIsEditable(true)
.withY1(32.7d)
.build(),
sciChartBuilder.newAxisMarkerAnnotation()
.withAnnotationSurface(AnnotationSurfaceEnum.XAxis)
.withFormattedValue("Horizontal")
.withIsEditable(true)
.withX1(100)
.build(),
sciChartBuilder.newHorizontalLineAnnotation()
.withPosition(150d, 32.2d)
.withStroke(2, ColorUtil.Red)
.withHorizontalGravity(Gravity.END)
.withIsEditable(true)
.withAnnotationLabel(LabelPlacement.Axis)
.build(),
sciChartBuilder.newHorizontalLineAnnotation()
.withX1(130).withY1(33.9d).withX2(160)
.withStroke(2, ColorUtil.Blue)
.withHorizontalGravity(Gravity.CENTER_HORIZONTAL)
.withIsEditable(true)
.withAnnotationLabel(LabelPlacement.Left, "Left")
.withAnnotationLabel(LabelPlacement.Top, "Top")
.withAnnotationLabel(LabelPlacement.Right, "Right")
.build(),
sciChartBuilder.newVerticalLineAnnotation()
.withX1(20).withY1(35d).withY2(33d)
.withStroke(2, ColorUtil.DarkGreen)
.withVerticalGravity(Gravity.CENTER_VERTICAL)
.withIsEditable(true)
.build(),
sciChartBuilder.newVerticalLineAnnotation()
.withPosition(40, 34)
.withStroke(2, ColorUtil.Green)
.withVerticalGravity(Gravity.TOP)
.withIsEditable(true)
.withAnnotationLabel(LabelPlacement.Top, null, 90)
.build(),
sciChartBuilder.newTextAnnotation()
.withPosition(0.5, 0.5)
.withCoordinateMode(AnnotationCoordinateMode.Relative)
.withHorizontalAnchorPoint(HorizontalAnchorPoint.Center)
.withText("EUR.USD")
.withFontStyle(Typeface.DEFAULT_BOLD, 72, 0x77FFFFFF)
.withZIndex(-1) // draw this annotation below other annotations
.build()
);
}
}