• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.github.mikephil.charting.interfaces.datasets;
2 
3 import android.graphics.DashPathEffect;
4 import android.graphics.PointF;
5 import android.graphics.Typeface;
6 
7 import com.github.mikephil.charting.components.Legend;
8 import com.github.mikephil.charting.components.YAxis;
9 import com.github.mikephil.charting.data.DataSet;
10 import com.github.mikephil.charting.data.Entry;
11 import com.github.mikephil.charting.formatter.IValueFormatter;
12 import com.github.mikephil.charting.utils.MPPointF;
13 
14 import java.util.List;
15 
16 /**
17  * Created by Philipp Jahoda on 21/10/15.
18  */
19 public interface IDataSet<T extends Entry> {
20 
21     /** ###### ###### DATA RELATED METHODS ###### ###### */
22 
23     /**
24      * returns the minimum y-value this DataSet holds
25      *
26      * @return
27      */
getYMin()28     float getYMin();
29 
30     /**
31      * returns the maximum y-value this DataSet holds
32      *
33      * @return
34      */
getYMax()35     float getYMax();
36 
37     /**
38      * returns the minimum x-value this DataSet holds
39      *
40      * @return
41      */
getXMin()42     float getXMin();
43 
44     /**
45      * returns the maximum x-value this DataSet holds
46      *
47      * @return
48      */
getXMax()49     float getXMax();
50 
51     /**
52      * Returns the number of y-values this DataSet represents -> the size of the y-values array
53      * -> yvals.size()
54      *
55      * @return
56      */
getEntryCount()57     int getEntryCount();
58 
59     /**
60      * Calculates the minimum and maximum x and y values (mXMin, mXMax, mYMin, mYMax).
61      */
calcMinMax()62     void calcMinMax();
63 
64     /**
65      * Calculates the min and max y-values from the Entry closest to the given fromX to the Entry closest to the given toX value.
66      * This is only needed for the autoScaleMinMax feature.
67      *
68      * @param fromX
69      * @param toX
70      */
calcMinMaxY(float fromX, float toX)71     void calcMinMaxY(float fromX, float toX);
72 
73     /**
74      * Returns the first Entry object found at the given x-value with binary
75      * search.
76      * If the no Entry at the specified x-value is found, this method
77      * returns the Entry at the closest x-value according to the rounding.
78      * INFORMATION: This method does calculations at runtime. Do
79      * not over-use in performance critical situations.
80      *
81      * @param xValue the x-value
82      * @param closestToY If there are multiple y-values for the specified x-value,
83      * @param rounding determine whether to round up/down/closest
84      *                 if there is no Entry matching the provided x-value
85      * @return
86      *
87      *
88      */
getEntryForXValue(float xValue, float closestToY, DataSet.Rounding rounding)89     T getEntryForXValue(float xValue, float closestToY, DataSet.Rounding rounding);
90 
91     /**
92      * Returns the first Entry object found at the given x-value with binary
93      * search.
94      * If the no Entry at the specified x-value is found, this method
95      * returns the Entry at the closest x-value.
96      * INFORMATION: This method does calculations at runtime. Do
97      * not over-use in performance critical situations.
98      *
99      *
100      * @param xValue the x-value
101      * @param closestToY If there are multiple y-values for the specified x-value,
102      * @return
103      */
getEntryForXValue(float xValue, float closestToY)104     T getEntryForXValue(float xValue, float closestToY);
105 
106     /**
107      * Returns all Entry objects found at the given x-value with binary
108      * search. An empty array if no Entry object at that x-value.
109      * INFORMATION: This method does calculations at runtime. Do
110      * not over-use in performance critical situations.
111      *
112      * @param xValue
113      * @return
114      */
getEntriesForXValue(float xValue)115     List<T> getEntriesForXValue(float xValue);
116 
117     /**
118      * Returns the Entry object found at the given index (NOT xIndex) in the values array.
119      *
120      * @param index
121      * @return
122      */
getEntryForIndex(int index)123     T getEntryForIndex(int index);
124 
125     /**
126      * Returns the first Entry index found at the given x-value with binary
127      * search.
128      * If the no Entry at the specified x-value is found, this method
129      * returns the Entry at the closest x-value according to the rounding.
130      * INFORMATION: This method does calculations at runtime. Do
131      * not over-use in performance critical situations.
132      *
133      * @param xValue the x-value
134      * @param closestToY If there are multiple y-values for the specified x-value,
135      * @param rounding determine whether to round up/down/closest
136      *                 if there is no Entry matching the provided x-value
137      * @return
138      */
getEntryIndex(float xValue, float closestToY, DataSet.Rounding rounding)139     int getEntryIndex(float xValue, float closestToY, DataSet.Rounding rounding);
140 
141     /**
142      * Returns the position of the provided entry in the DataSets Entry array.
143      * Returns -1 if doesn't exist.
144      *
145      * @param e
146      * @return
147      */
getEntryIndex(T e)148     int getEntryIndex(T e);
149 
150 
151     /**
152      * This method returns the actual
153      * index in the Entry array of the DataSet for a given xIndex. IMPORTANT: This method does
154      * calculations at runtime, do not over-use in performance critical
155      * situations.
156      *
157      * @param xIndex
158      * @return
159      */
getIndexInEntries(int xIndex)160     int getIndexInEntries(int xIndex);
161 
162     /**
163      * Adds an Entry to the DataSet dynamically.
164      * Entries are added to the end of the list.
165      * This will also recalculate the current minimum and maximum
166      * values of the DataSet and the value-sum.
167      *
168      * @param e
169      */
addEntry(T e)170     boolean addEntry(T e);
171 
172 
173     /**
174      * Adds an Entry to the DataSet dynamically.
175      * Entries are added to their appropriate index in the values array respective to their x-position.
176      * This will also recalculate the current minimum and maximum
177      * values of the DataSet and the value-sum.
178      *
179      * @param e
180      */
addEntryOrdered(T e)181     void addEntryOrdered(T e);
182 
183     /**
184      * Removes the first Entry (at index 0) of this DataSet from the entries array.
185      * Returns true if successful, false if not.
186      *
187      * @return
188      */
removeFirst()189     boolean removeFirst();
190 
191     /**
192      * Removes the last Entry (at index size-1) of this DataSet from the entries array.
193      * Returns true if successful, false if not.
194      *
195      * @return
196      */
removeLast()197     boolean removeLast();
198 
199     /**
200      * Removes an Entry from the DataSets entries array. This will also
201      * recalculate the current minimum and maximum values of the DataSet and the
202      * value-sum. Returns true if an Entry was removed, false if no Entry could
203      * be removed.
204      *
205      * @param e
206      */
removeEntry(T e)207     boolean removeEntry(T e);
208 
209     /**
210      * Removes the Entry object closest to the given x-value from the DataSet.
211      * Returns true if an Entry was removed, false if no Entry could be removed.
212      *
213      * @param xValue
214      */
removeEntryByXValue(float xValue)215     boolean removeEntryByXValue(float xValue);
216 
217     /**
218      * Removes the Entry object at the given index in the values array from the DataSet.
219      * Returns true if an Entry was removed, false if no Entry could be removed.
220      *
221      * @param index
222      * @return
223      */
removeEntry(int index)224     boolean removeEntry(int index);
225 
226     /**
227      * Checks if this DataSet contains the specified Entry. Returns true if so,
228      * false if not. NOTE: Performance is pretty bad on this one, do not
229      * over-use in performance critical situations.
230      *
231      * @param entry
232      * @return
233      */
contains(T entry)234     boolean contains(T entry);
235 
236     /**
237      * Removes all values from this DataSet and does all necessary recalculations.
238      */
clear()239     void clear();
240 
241 
242     /** ###### ###### STYLING RELATED (& OTHER) METHODS ###### ###### */
243 
244     /**
245      * Returns the label string that describes the DataSet.
246      *
247      * @return
248      */
getLabel()249     String getLabel();
250 
251     /**
252      * Sets the label string that describes the DataSet.
253      *
254      * @param label
255      */
setLabel(String label)256     void setLabel(String label);
257 
258     /**
259      * Returns the axis this DataSet should be plotted against.
260      *
261      * @return
262      */
getAxisDependency()263     YAxis.AxisDependency getAxisDependency();
264 
265     /**
266      * Set the y-axis this DataSet should be plotted against (either LEFT or
267      * RIGHT). Default: LEFT
268      *
269      * @param dependency
270      */
setAxisDependency(YAxis.AxisDependency dependency)271     void setAxisDependency(YAxis.AxisDependency dependency);
272 
273     /**
274      * returns all the colors that are set for this DataSet
275      *
276      * @return
277      */
getColors()278     List<Integer> getColors();
279 
280     /**
281      * Returns the first color (index 0) of the colors-array this DataSet
282      * contains. This is only used for performance reasons when only one color is in the colors array (size == 1)
283      *
284      * @return
285      */
getColor()286     int getColor();
287 
288     /**
289      * Returns the color at the given index of the DataSet's color array.
290      * Performs a IndexOutOfBounds check by modulus.
291      *
292      * @param index
293      * @return
294      */
getColor(int index)295     int getColor(int index);
296 
297     /**
298      * returns true if highlighting of values is enabled, false if not
299      *
300      * @return
301      */
isHighlightEnabled()302     boolean isHighlightEnabled();
303 
304     /**
305      * If set to true, value highlighting is enabled which means that values can
306      * be highlighted programmatically or by touch gesture.
307      *
308      * @param enabled
309      */
setHighlightEnabled(boolean enabled)310     void setHighlightEnabled(boolean enabled);
311 
312     /**
313      * Sets the formatter to be used for drawing the values inside the chart. If
314      * no formatter is set, the chart will automatically determine a reasonable
315      * formatting (concerning decimals) for all the values that are drawn inside
316      * the chart. Use chart.getDefaultValueFormatter() to use the formatter
317      * calculated by the chart.
318      *
319      * @param f
320      */
setValueFormatter(IValueFormatter f)321     void setValueFormatter(IValueFormatter f);
322 
323     /**
324      * Returns the formatter used for drawing the values inside the chart.
325      *
326      * @return
327      */
getValueFormatter()328     IValueFormatter getValueFormatter();
329 
330     /**
331      * Returns true if the valueFormatter object of this DataSet is null.
332      *
333      * @return
334      */
needsFormatter()335     boolean needsFormatter();
336 
337     /**
338      * Sets the color the value-labels of this DataSet should have.
339      *
340      * @param color
341      */
setValueTextColor(int color)342     void setValueTextColor(int color);
343 
344     /**
345      * Sets a list of colors to be used as the colors for the drawn values.
346      *
347      * @param colors
348      */
setValueTextColors(List<Integer> colors)349     void setValueTextColors(List<Integer> colors);
350 
351     /**
352      * Sets a Typeface for the value-labels of this DataSet.
353      *
354      * @param tf
355      */
setValueTypeface(Typeface tf)356     void setValueTypeface(Typeface tf);
357 
358     /**
359      * Sets the text-size of the value-labels of this DataSet in dp.
360      *
361      * @param size
362      */
setValueTextSize(float size)363     void setValueTextSize(float size);
364 
365     /**
366      * Returns only the first color of all colors that are set to be used for the values.
367      *
368      * @return
369      */
getValueTextColor()370     int getValueTextColor();
371 
372     /**
373      * Returns the color at the specified index that is used for drawing the values inside the chart.
374      * Uses modulus internally.
375      *
376      * @param index
377      * @return
378      */
getValueTextColor(int index)379     int getValueTextColor(int index);
380 
381     /**
382      * Returns the typeface that is used for drawing the values inside the chart
383      *
384      * @return
385      */
getValueTypeface()386     Typeface getValueTypeface();
387 
388     /**
389      * Returns the text size that is used for drawing the values inside the chart
390      *
391      * @return
392      */
getValueTextSize()393     float getValueTextSize();
394 
395     /**
396      * The form to draw for this dataset in the legend.
397      * <p/>
398      * Return `DEFAULT` to use the default legend form.
399      */
getForm()400     Legend.LegendForm getForm();
401 
402     /**
403      * The form size to draw for this dataset in the legend.
404      * <p/>
405      * Return `Float.NaN` to use the default legend form size.
406      */
getFormSize()407     float getFormSize();
408 
409     /**
410      * The line width for drawing the form of this dataset in the legend
411      * <p/>
412      * Return `Float.NaN` to use the default legend form line width.
413      */
getFormLineWidth()414     float getFormLineWidth();
415 
416     /**
417      * The line dash path effect used for shapes that consist of lines.
418      * <p/>
419      * Return `null` to use the default legend form line dash effect.
420      */
getFormLineDashEffect()421     DashPathEffect getFormLineDashEffect();
422 
423     /**
424      * set this to true to draw y-values on the chart.
425      *
426      * NOTE (for bar and line charts): if `maxVisibleCount` is reached, no values will be drawn even
427      * if this is enabled
428      * @param enabled
429      */
setDrawValues(boolean enabled)430     void setDrawValues(boolean enabled);
431 
432     /**
433      * Returns true if y-value drawing is enabled, false if not
434      *
435      * @return
436      */
isDrawValuesEnabled()437     boolean isDrawValuesEnabled();
438 
439     /**
440      * Set this to true to draw y-icons on the chart.
441      *
442      * NOTE (for bar and line charts): if `maxVisibleCount` is reached, no icons will be drawn even
443      * if this is enabled
444      *
445      * @param enabled
446      */
setDrawIcons(boolean enabled)447     void setDrawIcons(boolean enabled);
448 
449     /**
450      * Returns true if y-icon drawing is enabled, false if not
451      *
452      * @return
453      */
isDrawIconsEnabled()454     boolean isDrawIconsEnabled();
455 
456     /**
457      * Offset of icons drawn on the chart.
458      *
459      * For all charts except Pie and Radar it will be ordinary (x offset,y offset).
460      *
461      * For Pie and Radar chart it will be (y offset, distance from center offset); so if you want icon to be rendered under value, you should increase X component of CGPoint, and if you want icon to be rendered closet to center, you should decrease height component of CGPoint.
462      * @param offset
463      */
setIconsOffset(MPPointF offset)464     void setIconsOffset(MPPointF offset);
465 
466     /**
467      * Get the offset for drawing icons.
468      */
getIconsOffset()469     MPPointF getIconsOffset();
470 
471     /**
472      * Set the visibility of this DataSet. If not visible, the DataSet will not
473      * be drawn to the chart upon refreshing it.
474      *
475      * @param visible
476      */
setVisible(boolean visible)477     void setVisible(boolean visible);
478 
479     /**
480      * Returns true if this DataSet is visible inside the chart, or false if it
481      * is currently hidden.
482      *
483      * @return
484      */
isVisible()485     boolean isVisible();
486 }
487