• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup UI_Components
18  * @{
19  *
20  * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  * @file ui_chart.h
28  *
29  * @brief Defines the attributes of the chart component and provides functions for adding and deleting
30  *        data sets to display a chart.
31  *
32  * @since 1.0
33  * @version 1.0
34  */
35 
36 #ifndef GRAPHIC_LITE_UI_CHART_H
37 #define GRAPHIC_LITE_UI_CHART_H
38 
39 #include "components/ui_axis.h"
40 #include "components/ui_view_group.h"
41 #include "gfx_utils/list.h"
42 
43 namespace OHOS {
44 class UIChart;
45 /**
46  * @brief Defines a data set and provides functions such as adding and deleting data points.
47  *
48  * @since 1.0
49  * @version 1.0
50  */
51 class UIChartDataSerial : public HeapBase {
52 public:
53     /**
54      * @brief A constructor used to create a <b>UIChartDataSerial</b> instance.
55      *
56      * @since 1.0
57      * @version 1.0
58      */
59     UIChartDataSerial();
60 
61     /**
62      * @brief A destructor used to delete the <b>UIChartDataSerial</b> instance.
63      *
64      * @since 1.0
65      * @version 1.0
66      */
~UIChartDataSerial()67     virtual ~UIChartDataSerial()
68     {
69         if (pointArray_ != nullptr) {
70             UIFree(pointArray_);
71             pointArray_ = nullptr;
72         }
73     }
74 
75     /**
76      * @brief Sets the maximum number of data points that can be stored in a data set.
77      *
78      * This function must be called before data is added, deleted, or modified. Otherwise, data operations will fail.
79      *
80      * @param maxCount Indicates the number of data points. The default value is <b>0</b>.
81      *
82      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
83      * @since 1.0
84      * @version 1.0
85      */
86     bool SetMaxDataCount(uint16_t maxCount);
87 
88     /**
89      * @brief Modifies the value of a data point in the data set.
90      *
91      * @param index Indicates the index of the data point to modify.
92      * @param point Indicates the new value of the data point.
93      *
94      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
95      * @since 1.0
96      * @version 1.0
97      */
98     bool ModifyPoint(uint16_t index, const Point& point);
99 
100     /**
101      * @brief Obtains the coordinates in the chart for a data point in the data set.
102      *
103      * @param index Indicates the index of the data point to obtain.
104      * @param point Indicates the obtained coordinates. If the data set is not added to the chart,
105      *              the original value of the data point is printed.
106      *
107      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
108      * @since 1.0
109      * @version 1.0
110      */
111     bool GetPoint(uint16_t index, Point& point);
112 
113     /**
114      * @brief Adds data points.
115      *
116      * The new data points are appended to the last added data. \n
117      * No more data points can be added if the maximum number is reached \n
118      *
119      * @param data  Indicates the pointer to the start address of the data point.
120      * @param count Indicates the number of data points to add.
121      * @return Returns <b>true</b> if the data points are added successfully; returns <b>false</b> otherwise.
122      * @since 1.0
123      * @version 1.0
124      */
125     bool AddPoints(const Point* data, uint16_t count);
126 
127     /**
128      * @brief Clears all data points.
129      *
130      * @since 1.0
131      * @version 1.0
132      */
133     void ClearData();
134 
135     /**
136      * @brief Obtains the number of data points available in the data set.
137      *
138      * @return Returns the number of data points.
139      * @since 1.0
140      * @version 1.0
141      */
GetDataCount()142     uint16_t GetDataCount() const
143     {
144         return dataCount_;
145     }
146 
147     /**
148      * @brief Sets whether to smooth a polyline.
149      *
150      * This function applies only to line charts. After the smoothing, some data is discarded.
151      * Therefore, the polyline does not pass through all data points. \n
152      * If <b>smooth</b> is set to <b>true</b>, the filling color, top point, and bottom point of a line chart have
153      * deviations. Therefore, you are advised not to use these functions at the same time. \n
154      *
155      * @param smooth Specifies whether to smooth a polyline. Value <b>true</b> means to smooth a polyline, and value
156      *               <b>false</b> means not to smooth a polyline. The default value is <b>false</b>.
157      * @since 1.0
158      * @version 1.0
159      */
EnableSmooth(bool smooth)160     void EnableSmooth(bool smooth)
161     {
162         smooth_ = smooth;
163     }
164 
165     /**
166      * @brief Checks whether smoothing is performed on a polyline.
167      *
168      * @return Returns <b>true</b> if smooth processing is performed on the polyline; returns <b>false</b> otherwise.
169      * @since 1.0
170      * @version 1.0
171      */
IsSmooth()172     bool IsSmooth() const
173     {
174         return smooth_;
175     }
176 
177     /**
178      * @brief Enables the fill color of a line chart.
179      *
180      * This function applies only to line charts. By default, the area between the polyline and the x-axis is filled.
181      * You can use {@link SetGradientBottom} to modify the filled region. \n
182      *
183      * @param enable Specifies whether to enable the fill color. Value <b>true</b> means to enable the fill color,
184      *               and value <b>false</b> means to disable the fill color. The default value is <b>false</b>.
185      * @since 1.0
186      * @version 1.0
187      */
EnableGradient(bool enable)188     void EnableGradient(bool enable)
189     {
190         enableGradient_ = enable;
191     }
192 
193     /**
194      * @brief Checks whether a polyline has a fill color.
195      *
196      * @return Returns <b>true</b> if there is a fill color; returns <b>false</b> otherwise.
197      * @since 1.0
198      * @version 1.0
199      */
IsGradient()200     bool IsGradient() const
201     {
202         return enableGradient_;
203     }
204 
205     /**
206      * @brief Obtains the index of the top point in the data set.
207      *
208      * @return Returns the index of the top point. If there are multiple top points, the first one is returned.
209      * @since 1.0
210      * @version 1.0
211      */
GetPeakIndex()212     uint16_t GetPeakIndex() const
213     {
214         return peakPointIndex_;
215     }
216 
217     /**
218      * @brief Obtains the index of the frontmost point (the latest added or modified data point in a data set).
219      *
220      * @return Returns the index of the frontmost point.
221      * @since 1.0
222      * @version 1.0
223      */
GetLatestIndex()224     uint16_t GetLatestIndex() const
225     {
226         return latestIndex_;
227     }
228 
229     /**
230      * @brief Obtains the index of the bottom point in a data set.
231      *
232      * @return Returns the index of the bottom point. If there are multiple bottom points, the first one is returned.
233      * @since 1.0
234      * @version 1.0
235      */
GetValleyIndex()236     uint16_t GetValleyIndex() const
237     {
238         return valleyPointIndex_;
239     }
240 
241     /**
242      * @brief Obtains the Y value of the top point in a data set.
243      *
244      * The Y value is the data added by users, not the pixel coordinate.
245      *
246      * @return Returns the Y value.
247      * @since 1.0
248      * @version 1.0
249      */
GetPeakData()250     int16_t GetPeakData() const
251     {
252         return peakData_;
253     }
254 
255     /**
256      * @brief Obtains the Y value of the bottom point in a data set.
257      *
258      * The Y value is the data added by users, not the pixel coordinate.
259      *
260      * @return Returns the Y value.
261      * @since 1.0
262      * @version 1.0
263      */
GetValleyData()264     int16_t GetValleyData() const
265     {
266         return valleyData_;
267     }
268 
SetLastPointIndex(uint16_t value)269     void SetLastPointIndex(uint16_t value)
270     {
271         lastPointIndex_ = value;
272     }
273 
GetLastPointIndex()274     uint16_t GetLastPointIndex() const
275     {
276         return lastPointIndex_;
277     }
278 
279     /**
280      * @brief Obtains the polyline color of the data set in a line chart.
281      *
282      * @return Returns the polyline color of the data set.
283      * @see SetLineColor
284      * @since 1.0
285      * @version 1.0
286      */
GetLineColor()287     ColorType GetLineColor() const
288     {
289         return serialColor_;
290     }
291 
292     /**
293      * @brief Obtains the fill color of the data set.
294      *
295      * @return Returns the fill color.
296      * @see SetFillColor
297      * @since 1.0
298      * @version 1.0
299      */
GetFillColor()300     ColorType GetFillColor() const
301     {
302         return fillColor_;
303     }
304 
305     /**
306      * @brief Sets the fill color of the data set.
307      *
308      * For a line chart, <b>color</b> refers to the fill color between the line and the x-axis.
309      * For a bar chart, <b>color</b> refers to the color of the bars.
310      *
311      * @param color Indicates the fill color to set.
312      * @see GetFillColor
313      * @since 1.0
314      * @version 1.0
315      */
SetFillColor(const ColorType & color)316     void SetFillColor(const ColorType& color)
317     {
318         fillColor_ = color;
319     }
320 
321     /**
322      * @brief Sets the polyline color of the data set in the line chart.
323      *
324      * This function applies only to line charts.
325      *
326      * @param color Indicates the polyline color to set.
327      * @see GetLineColor
328      * @since 1.0
329      * @version 1.0
330      */
SetLineColor(const ColorType & color)331     void SetLineColor(const ColorType& color)
332     {
333         serialColor_ = color;
334     }
335 
BindToChart(UIChart * chart)336     void BindToChart(UIChart* chart)
337     {
338         chart_ = chart;
339     }
340 
341     /**
342      * @brief Hides some points in the data set.
343      *
344      * This function applies only to line charts. After the points are hidden, the line connected by the points
345      * is not displayed. \n
346      * The top and bottom points may appear in the hidden region. If this method is enabled,
347      * you are not advised to enable the display of the top and bottom points.
348      *
349      * @param index Indicates the point from which the hide starts.
350      * @param count Indicates the number of points to hide.
351      * @since 1.0
352      * @version 1.0
353      */
354     void HidePoint(uint16_t index, uint16_t count);
355 
356     /**
357      * @brief Obtains the index from which the data set starts to hide.
358      *
359      * @return Returns the index.
360      * @see HidePoint
361      * @since 1.0
362      * @version 1.0
363      */
GetHideIndex()364     uint16_t GetHideIndex() const
365     {
366         return hideIndex_;
367     }
368 
369     /**
370      * @brief Obtains the number of hidden points in the data set.
371      *
372      * @return Returns the number of hidden points.
373      * @see HidePoint
374      * @since 1.0
375      * @version 1.0
376      */
GetHideCount()377     uint16_t GetHideCount() const
378     {
379         return hideCount_;
380     }
381 
382     /**
383      * @brief Defines the style for the top, bottom, and frontmost points in a line chart.
384      */
385     struct PointStyle : public HeapBase {
386         /** Fill color */
387         ColorType fillColor;
388         /** Border color */
389         ColorType strokeColor;
390         /** Inner radius */
391         uint16_t radius;
392         /** Border width, which extends outwards from the inner radius */
393         uint16_t strokeWidth;
394     };
395 
396     /**
397      * @brief Sets the style of the frontmost point on a polyline.
398      *
399      * @param style Indicates the style to set. For details, see {@link PointStyle}.
400      * @since 1.0
401      * @version 1.0
402      */
SetHeadPointStyle(const PointStyle & style)403     void SetHeadPointStyle(const PointStyle& style)
404     {
405         headPointStyle_ = style;
406     }
407 
408     /**
409      * @brief Sets the style of the top point of a polyline.
410      *
411      * @param style Indicates the style to set. For details, see {@link PointStyle}.
412      * @since 1.0
413      * @version 1.0
414      */
SetTopPointStyle(const PointStyle & style)415     void SetTopPointStyle(const PointStyle& style)
416     {
417         topPointStyle_ = style;
418     }
419 
420     /**
421      * @brief Sets the style of the bottom point of a polyline.
422      *
423      * @param style Indicates the style to set. For details, see {@link PointStyle}.
424      * @since 1.0
425      * @version 1.0
426      */
SetBottomPointStyle(const PointStyle & style)427     void SetBottomPointStyle(const PointStyle& style)
428     {
429         bottomPointStyle_ = style;
430     }
431 
432     /**
433      * @brief Obtains the style of the frontmost point on a polyline.
434      *
435      * @return Returns the style of the point. For details, see {@link PointStyle}.
436      * @since 1.0
437      * @version 1.0
438      */
GetHeadPointStyle()439     const PointStyle& GetHeadPointStyle() const
440     {
441         return headPointStyle_;
442     }
443 
444     /**
445      * @brief Obtains the style of the top point of a polyline.
446      *
447      * @return Returns the style of the point. For details, see {@link PointStyle}.
448      * @since 1.0
449      * @version 1.0
450      */
GetTopPointStyle()451     const PointStyle& GetTopPointStyle() const
452     {
453         return topPointStyle_;
454     }
455 
456     /**
457      * @brief Obtains the style of the bottom point of a polyline.
458      *
459      * @return Returns the style of the point. For details, see {@link PointStyle}.
460      * @since 1.0
461      * @version 1.0
462      */
GetBottomPointStyle()463     const PointStyle& GetBottomPointStyle() const
464     {
465         return bottomPointStyle_;
466     }
467 
468     /**
469      * @brief Enables the feature of drawing the frontmost point on a polyline.
470      *
471      * @param enable Specifies whether to draw the frontmost point. Value <b>true</b> means to draw the frontmost
472      *               point, and value <b>false</b> means not to draw the frontmost point.
473      * @since 1.0
474      * @version 1.0
475      */
EnableHeadPoint(bool enable)476     void EnableHeadPoint(bool enable)
477     {
478         enableHeadPoint_ = enable;
479     }
480 
481     /**
482      * @brief enableHeadPoint_.
483      *
484      * @return Returns enableHeadPoint_.
485      */
GetEnableHeadPoint()486     bool GetEnableHeadPoint() const
487     {
488         return enableHeadPoint_;
489     }
490 
491     /**
492      * @brief Enables the feature of drawing the top point of a polyline. If there are multiple top points,
493      *        only the first one is drawn.
494      *
495      * @param enable Specifies whether to draw the top point. Value <b>true</b> means to draw the top point,
496      *               and value <b>false</b> means not to draw the top point.
497      * @since 1.0
498      * @version 1.0
499      */
EnableTopPoint(bool enable)500     void EnableTopPoint(bool enable)
501     {
502         enableTopPoint_ = enable;
503     }
504 
505     /**
506      * @brief enableTopPoint_.
507      *
508      * @return Returns enableTopPoint_.
509      */
GetEnableTopPoint()510     bool GetEnableTopPoint() const
511     {
512         return enableTopPoint_;
513     }
514 
515     /**
516      * @brief Enables the feature of drawing the bottom point of a polyline. If there are multiple bottom points,
517      *        only the first one is drawn.
518      *
519      * @param enable Specifies whether to draw the bottom point. Value <b>true</b> means to draw the bottom point,
520      *               and value <b>false</b> means not to draw the bottom point.
521      * @since 1.0
522      * @version 1.0
523      */
EnableBottomPoint(bool enable)524     void EnableBottomPoint(bool enable)
525     {
526         enableBottomPoint_ = enable;
527     }
528 
529     /**
530      * @brief enableBottomPoint_.
531      *
532      * @return Returns enableBottomPoint_.
533      */
GetEnableBottomPoint()534     bool GetEnableBottomPoint() const
535     {
536         return enableBottomPoint_;
537     }
538 
539     void DrawPoint(BufferInfo& gfxDstBuffer, const Rect& mask);
540 
541     void Refresh();
542 
543 protected:
544     uint16_t maxCount_;
545     Point* pointArray_;
546 
547 private:
548     constexpr static uint16_t DEFAULT_POINT_RADIUS = 5;
549     constexpr static uint16_t MAX_POINTS_COUNT = 512;
550 
551     ColorType serialColor_;
552     ColorType fillColor_;
553     uint16_t dataCount_;
554     uint16_t peakPointIndex_;
555     int16_t peakData_;
556     int16_t valleyData_;
557     uint16_t valleyPointIndex_;
558     uint16_t lastPointIndex_;
559     uint16_t latestIndex_;
560     uint16_t hideIndex_;
561     uint16_t hideCount_;
562     bool smooth_ : 1;
563     bool enableGradient_ : 1;
564     bool enableHeadPoint_ : 1;
565     bool enableTopPoint_ : 1;
566     bool enableBottomPoint_ : 1;
567     PointStyle headPointStyle_;
568     PointStyle topPointStyle_;
569     PointStyle bottomPointStyle_;
570     UIChart* chart_;
571     Rect invalidateRect_;
572     void RefreshInvalidateRect(uint16_t startIndex, uint16_t endIndex);
573     void RefreshInvalidateRect(uint16_t pointIndex, const PointStyle& style);
574     bool UpdatePeakAndValley(uint16_t startPos, uint16_t endPos);
575     void DoDrawPoint(BufferInfo& gfxDstBuffer, const Point& point, const PointStyle& style, const Rect& mask);
576 };
577 
578 /**
579  * @brief Defines the chart class and provides functions such as adding and deleting data sets to display a chart.
580  *
581  * @since 1.0
582  * @version 1.0
583  */
584 class UIChart : public UIViewGroup {
585 public:
586     /**
587      * @brief A constructor used to create a <b>UIChart</b> instance.
588      *
589      * @since 1.0
590      * @version 1.0
591      */
UIChart()592     UIChart() : enableReverse_(false), needRefresh_(false), mixData_(nullptr)
593     {
594         Add(&xAxis_);
595         Add(&yAxis_);
596         SetStyle(STYLE_LINE_WIDTH, 1);
597         SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
598     }
599 
600     /**
601      * @brief A destructor used to delete the <b>UIChart</b> instance.
602      *
603      * @since 1.0
604      * @version 1.0
605      */
606     virtual ~UIChart();
607 
608     /**
609      * @brief Obtains the view type.
610      *
611      * @return Returns the view type. For details, see {@link UIViewType}.
612      * @since 1.0
613      * @version 1.0
614      */
GetViewType()615     UIViewType GetViewType() const override
616     {
617         return UI_CHART;
618     }
619 
620     /**
621      * @brief Sets the height for this component.
622      *
623      * @param height Indicates the height to set.
624      * @since 1.0
625      * @version 1.0
626      */
627     void SetHeight(int16_t height) override;
628 
629     /**
630      * @brief Sets the width for this component.
631      *
632      * @param width Indicates the width to set.
633      * @since 1.0
634      * @version 1.0
635      */
636     void SetWidth(int16_t width) override;
637 
OnPreDraw(Rect & invalidatedArea)638     bool OnPreDraw(Rect& invalidatedArea) const override
639     {
640         return false;
641     }
642 
643     void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
644 
645     /**
646      * @brief Adds a data set.
647      *
648      * @param dataSerial Indicates the pointer to the data set class. For details, see {@link UIChartDataSerial}.
649      * @return Returns <b>true</b> if the data set is added successfully; returns <b>false</b> otherwise.
650      * @see DeleteDataSerial
651      * @since 1.0
652      * @version 1.0
653      */
654     virtual bool AddDataSerial(UIChartDataSerial* dataSerial);
655 
656     /**
657      * @brief Deletes a data set.
658      *
659      * @param dataSerial Indicates the pointer to the data set class. For details, see {@link UIChartDataSerial}.
660      * @return Returns <b>true</b> if the data set is deleted successfully; returns <b>false</b> otherwise.
661      * @see AddDataSerial
662      * @since 1.0
663      * @version 1.0
664      */
665     virtual bool DeleteDataSerial(UIChartDataSerial* dataSerial);
666 
667     /**
668      * @brief Clears all data sets.
669      *
670      * @since 1.0
671      * @version 1.0
672      */
673     virtual void ClearDataSerial();
674 
675     /**
676      * @brief Refreshes a chart and redraws the dirty region.
677      *
678      * Only the parts that need to be redrawn are refreshed, for example, new data points.
679      * This function provides better performance than {@link Invalidate}.
680      *
681      * @since 1.0
682      * @version 1.0
683      */
684     virtual void RefreshChart() = 0;
685 
686     /**
687      * @brief Obtains the x-axis instance.
688      *
689      * @return Returns the x-axis instance.
690      * @since 1.0
691      * @version 1.0
692      */
GetXAxis()693     UIXAxis& GetXAxis()
694     {
695         return xAxis_;
696     }
697 
698     /**
699      * @brief Obtains the y-axis instance.
700      *
701      * @return Returns the y-axis instance.
702      * @since 1.0
703      * @version 1.0
704      */
GetYAxis()705     UIYAxis& GetYAxis()
706     {
707         return yAxis_;
708     }
709 
710     /**
711      * @brief Enables chart reverse.
712      *
713      * After the chart is reversed, the x-axis aligns with the top of the chart. The pixel position corresponding
714      * to the data point remains unchanged. Complementary filling is performed on the chart
715      * (only the part that is not filled previously will be filled).
716      *
717      * @param enable Specifies whether to enable chart reverse. Value <b>true</b> means to enable chart reverse,
718      *               and value <b>false</b> means not to enable chart reverse. The default value is <b>false</b>.
719      * @since 1.0
720      * @version 1.0
721      */
EnableReverse(bool enable)722     void EnableReverse(bool enable)
723     {
724         if (enableReverse_ != enable) {
725             enableReverse_ = enable;
726             xAxis_.EnableReverse(enable);
727             yAxis_.EnableReverse(enable);
728         }
729     }
730 
731 protected:
732     List<UIChartDataSerial*> list_;
733     UIXAxis xAxis_;
734     UIYAxis yAxis_;
735     bool enableReverse_;
736     bool needRefresh_;
737     uint8_t* mixData_;
738     virtual void DrawDataSerials(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) = 0;
739 };
740 
741 /**
742  * @brief Provides special functions for implementing a bar chart.
743  *
744  * @since 1.0
745  * @version 1.0
746  */
747 class UIChartPillar : public UIChart {
748 public:
749     /**
750      * @brief A constructor used to create a <b>UIChartPillar</b> instance.
751      *
752      * @since 1.0
753      * @version 1.0
754      */
UIChartPillar()755     UIChartPillar() {}
756 
757     /**
758      * @brief A destructor used to delete the <b>UIChartPillar</b> instance.
759      *
760      * @since 1.0
761      * @version 1.0
762      */
~UIChartPillar()763     virtual ~UIChartPillar() {}
764 
765     /**
766      * @brief Refreshes a bar chart and redraws the dirty region.
767      *
768      * Only the parts that need to be redrawn are refreshed, for example, new data points.
769      * This function provides better performance than {@link Invalidate}.
770      *
771      * @since 1.0
772      * @version 1.0
773      */
774     void RefreshChart() override;
775 
776 protected:
777     void DrawDataSerials(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
778 
779 private:
780     static constexpr float DEFAULT_MARK_PERCENTAGE = 0.1f;
781 };
782 
783 /**
784  * @brief Provides special functions for implementing a polyline.
785  *
786  * @since 1.0
787  * @version 1.0
788  */
789 class UIChartPolyline : public UIChart {
790 public:
791     /**
792      * @brief A constructor used to create a <b>UIChartPolyline</b> instance.
793      *
794      * @since 1.0
795      * @version 1.0
796      */
UIChartPolyline()797     UIChartPolyline() : minOpa_(OPA_TRANSPARENT), maxOpa_(OPA_OPAQUE), gradientBottom_(0) {}
798 
799     /**
800      * @brief A destructor used to delete the <b>UIChartPolyline</b> instance.
801      *
802      * @since 1.0
803      * @version 1.0
804      */
~UIChartPolyline()805     virtual ~UIChartPolyline() {}
806 
807     /**
808      * @brief Refreshes a line chart and redraws the dirty region.
809      *
810      * Only the parts that need to be redrawn are refreshed, for example, new data points.
811      * This function provides better performance than {@link Invalidate}.
812      *
813      * @since 1.0
814      * @version 1.0
815      */
816     void RefreshChart() override;
817 
818     /**
819      * @brief Sets the opacity range of the fill color gradient.
820      *
821      * This function sets the opacity range between the top point and bottom point of the line chart.
822      * The opacity of each horizontal line is calculated based on the ratio.
823      *
824      * @param minOpa Indicates the opacity closest to the x-axis.
825      * @param maxOpa Indicates the opacity farthest away from the x-axis.
826      * @since 1.0
827      * @version 1.0
828      */
SetGradientOpacity(uint8_t minOpa,uint8_t maxOpa)829     void SetGradientOpacity(uint8_t minOpa, uint8_t maxOpa)
830     {
831         minOpa_ = minOpa;
832         maxOpa_ = maxOpa;
833         needRefresh_ = true;
834     }
835 
836     /**
837      * @brief Sets the distance between the bottom edge of the fill color range and the x-axis.
838      *
839      * This function fills in the area between the polyline and bottom of the line chart. For a chart that is not
840      * reversed, if the bottom is above the polyline, there is no filling. For a reversed chart,
841      * if the bottom is below the polyline, there is no filling.
842      *
843      * @param bottom Indicates the bottom of the filling range. The value is the distance to the x-axis.
844      * @since 1.0
845      * @version 1.0
846      */
SetGradientBottom(uint16_t bottom)847     void SetGradientBottom(uint16_t bottom)
848     {
849         gradientBottom_ = bottom;
850     }
851 
852 protected:
853     void DrawDataSerials(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
854 
855 private:
856     struct ChartLine {
857         Point start;
858         Point end;
859     };
860 
861     struct CrossPointSet {
862         Point first;
863         Point second;
864         Point nextFirst;
865         bool firstFind;
866         bool secondFind;
867     };
868 
869     constexpr static uint8_t SMOOTH_SLOPE_ANGLE = 3;
870     constexpr static uint8_t LINE_JOIN_WIDTH = 3;
871     uint8_t minOpa_;
872     uint8_t maxOpa_;
873     uint16_t gradientBottom_;
874 
875     void GradientColor(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, UIChartDataSerial* data);
876     void DrawGradientColor(BufferInfo& gfxDstBuffer,
877                            const Rect& invalidatedArea,
878                            UIChartDataSerial* data,
879                            const ChartLine& linePoints,
880                            const ChartLine& limitPoints,
881                            int16_t startY);
882     void DrawSmoothPolyLine(BufferInfo& gfxDstBuffer,
883                             uint16_t startIndex,
884                             uint16_t endIndex,
885                             const Rect& invalidatedArea,
886                             UIChartDataSerial* data);
887     void DrawPolyLine(BufferInfo& gfxDstBuffer, uint16_t startIndex, uint16_t endIndex,
888                       const Rect& invalidatedArea, UIChartDataSerial* data);
889     bool GetLineCrossPoint(const Point& p1, const Point& p2, const Point& p3, const Point& p4, Point& cross);
890     void FindCrossPoints(const ChartLine& line, const ChartLine& polyLine, CrossPointSet& cross);
891     void ReMeasure() override;
892     void CalcVerticalInfo(int16_t top, int16_t bottom, int16_t start, int16_t end, int16_t& y, int16_t& yHeight);
893 };
894 } // namespace OHOS
895 #endif // GRAPHIC_LITE_UI_CHART_H
896