• 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 Enables the feature of drawing the top point of a polyline. If there are multiple top points,
483      *        only the first one is drawn.
484      *
485      * @param enable Specifies whether to draw the top point. Value <b>true</b> means to draw the top point,
486      *               and value <b>false</b> means not to draw the top point.
487      * @since 1.0
488      * @version 1.0
489      */
EnableTopPoint(bool enable)490     void EnableTopPoint(bool enable)
491     {
492         enableTopPoint_ = enable;
493     }
494 
495     /**
496      * @brief Enables the feature of drawing the bottom point of a polyline. If there are multiple bottom points,
497      *        only the first one is drawn.
498      *
499      * @param enable Specifies whether to draw the bottom point. Value <b>true</b> means to draw the bottom point,
500      *               and value <b>false</b> means not to draw the bottom point.
501      * @since 1.0
502      * @version 1.0
503      */
EnableBottomPoint(bool enable)504     void EnableBottomPoint(bool enable)
505     {
506         enableBottomPoint_ = enable;
507     }
508 
509     void DrawPoint(BufferInfo& gfxDstBuffer, const Rect& mask);
510 
511     void Refresh();
512 
513 protected:
514     uint16_t maxCount_;
515     Point* pointArray_;
516 
517 private:
518     constexpr static uint16_t DEFAULT_POINT_RADIUS = 5;
519     constexpr static uint16_t MAX_POINTS_COUNT = 512;
520 
521     ColorType serialColor_;
522     ColorType fillColor_;
523     uint16_t dataCount_;
524     uint16_t peakPointIndex_;
525     int16_t peakData_;
526     int16_t valleyData_;
527     uint16_t valleyPointIndex_;
528     uint16_t lastPointIndex_;
529     uint16_t latestIndex_;
530     uint16_t hideIndex_;
531     uint16_t hideCount_;
532     bool smooth_ : 1;
533     bool enableGradient_ : 1;
534     bool enableHeadPoint_ : 1;
535     bool enableTopPoint_ : 1;
536     bool enableBottomPoint_ : 1;
537     PointStyle headPointStyle_;
538     PointStyle topPointStyle_;
539     PointStyle bottomPointStyle_;
540     UIChart* chart_;
541     Rect invalidateRect_;
542     void RefreshInvalidateRect(uint16_t startIndex, uint16_t endIndex);
543     void RefreshInvalidateRect(uint16_t pointIndex, const PointStyle& style);
544     bool UpdatePeakAndValley(uint16_t startPos, uint16_t endPos);
545     void DoDrawPoint(BufferInfo& gfxDstBuffer, const Point& point, const PointStyle& style, const Rect& mask);
546 };
547 
548 /**
549  * @brief Defines the chart class and provides functions such as adding and deleting data sets to display a chart.
550  *
551  * @since 1.0
552  * @version 1.0
553  */
554 class UIChart : public UIViewGroup {
555 public:
556     /**
557      * @brief A constructor used to create a <b>UIChart</b> instance.
558      *
559      * @since 1.0
560      * @version 1.0
561      */
UIChart()562     UIChart() : enableReverse_(false), needRefresh_(false), mixData_(nullptr)
563     {
564         Add(&xAxis_);
565         Add(&yAxis_);
566         SetStyle(STYLE_LINE_WIDTH, 1);
567         SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
568     }
569 
570     /**
571      * @brief A destructor used to delete the <b>UIChart</b> instance.
572      *
573      * @since 1.0
574      * @version 1.0
575      */
576     virtual ~UIChart();
577 
578     /**
579      * @brief Obtains the view type.
580      *
581      * @return Returns the view type. For details, see {@link UIViewType}.
582      * @since 1.0
583      * @version 1.0
584      */
GetViewType()585     UIViewType GetViewType() const override
586     {
587         return UI_CHART;
588     }
589 
590     /**
591      * @brief Sets the height for this component.
592      *
593      * @param height Indicates the height to set.
594      * @since 1.0
595      * @version 1.0
596      */
597     void SetHeight(int16_t height) override;
598 
599     /**
600      * @brief Sets the width for this component.
601      *
602      * @param width Indicates the width to set.
603      * @since 1.0
604      * @version 1.0
605      */
606     void SetWidth(int16_t width) override;
607 
OnPreDraw(Rect & invalidatedArea)608     bool OnPreDraw(Rect& invalidatedArea) const override
609     {
610         return false;
611     }
612 
613     void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
614 
615     /**
616      * @brief Adds a data set.
617      *
618      * @param dataSerial Indicates the pointer to the data set class. For details, see {@link UIChartDataSerial}.
619      * @return Returns <b>true</b> if the data set is added successfully; returns <b>false</b> otherwise.
620      * @see DeleteDataSerial
621      * @since 1.0
622      * @version 1.0
623      */
624     virtual bool AddDataSerial(UIChartDataSerial* dataSerial);
625 
626     /**
627      * @brief Deletes a data set.
628      *
629      * @param dataSerial Indicates the pointer to the data set class. For details, see {@link UIChartDataSerial}.
630      * @return Returns <b>true</b> if the data set is deleted successfully; returns <b>false</b> otherwise.
631      * @see AddDataSerial
632      * @since 1.0
633      * @version 1.0
634      */
635     virtual bool DeleteDataSerial(UIChartDataSerial* dataSerial);
636 
637     /**
638      * @brief Clears all data sets.
639      *
640      * @since 1.0
641      * @version 1.0
642      */
643     virtual void ClearDataSerial();
644 
645     /**
646      * @brief Refreshes a chart and redraws the dirty region.
647      *
648      * Only the parts that need to be redrawn are refreshed, for example, new data points.
649      * This function provides better performance than {@link Invalidate}.
650      *
651      * @since 1.0
652      * @version 1.0
653      */
654     virtual void RefreshChart() = 0;
655 
656     /**
657      * @brief Obtains the x-axis instance.
658      *
659      * @return Returns the x-axis instance.
660      * @since 1.0
661      * @version 1.0
662      */
GetXAxis()663     UIXAxis& GetXAxis()
664     {
665         return xAxis_;
666     }
667 
668     /**
669      * @brief Obtains the y-axis instance.
670      *
671      * @return Returns the y-axis instance.
672      * @since 1.0
673      * @version 1.0
674      */
GetYAxis()675     UIYAxis& GetYAxis()
676     {
677         return yAxis_;
678     }
679 
680     /**
681      * @brief Enables chart reverse.
682      *
683      * After the chart is reversed, the x-axis aligns with the top of the chart. The pixel position corresponding
684      * to the data point remains unchanged. Complementary filling is performed on the chart
685      * (only the part that is not filled previously will be filled).
686      *
687      * @param enable Specifies whether to enable chart reverse. Value <b>true</b> means to enable chart reverse,
688      *               and value <b>false</b> means not to enable chart reverse. The default value is <b>false</b>.
689      * @since 1.0
690      * @version 1.0
691      */
EnableReverse(bool enable)692     void EnableReverse(bool enable)
693     {
694         if (enableReverse_ != enable) {
695             enableReverse_ = enable;
696             xAxis_.EnableReverse(enable);
697             yAxis_.EnableReverse(enable);
698         }
699     }
700 
701 protected:
702     List<UIChartDataSerial*> list_;
703     UIXAxis xAxis_;
704     UIYAxis yAxis_;
705     bool enableReverse_;
706     bool needRefresh_;
707     uint8_t* mixData_;
708     virtual void DrawDataSerials(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) = 0;
709 };
710 
711 /**
712  * @brief Provides special functions for implementing a bar chart.
713  *
714  * @since 1.0
715  * @version 1.0
716  */
717 class UIChartPillar : public UIChart {
718 public:
719     /**
720      * @brief A constructor used to create a <b>UIChartPillar</b> instance.
721      *
722      * @since 1.0
723      * @version 1.0
724      */
UIChartPillar()725     UIChartPillar() {}
726 
727     /**
728      * @brief A destructor used to delete the <b>UIChartPillar</b> instance.
729      *
730      * @since 1.0
731      * @version 1.0
732      */
~UIChartPillar()733     virtual ~UIChartPillar() {}
734 
735     /**
736      * @brief Refreshes a bar chart and redraws the dirty region.
737      *
738      * Only the parts that need to be redrawn are refreshed, for example, new data points.
739      * This function provides better performance than {@link Invalidate}.
740      *
741      * @since 1.0
742      * @version 1.0
743      */
744     void RefreshChart() override;
745 
746 protected:
747     void DrawDataSerials(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
748 
749 private:
750     static constexpr float DEFAULT_MARK_PERCENTAGE = 0.1f;
751 };
752 
753 /**
754  * @brief Provides special functions for implementing a polyline.
755  *
756  * @since 1.0
757  * @version 1.0
758  */
759 class UIChartPolyline : public UIChart {
760 public:
761     /**
762      * @brief A constructor used to create a <b>UIChartPolyline</b> instance.
763      *
764      * @since 1.0
765      * @version 1.0
766      */
UIChartPolyline()767     UIChartPolyline() : minOpa_(OPA_TRANSPARENT), maxOpa_(OPA_OPAQUE), gradientBottom_(0) {}
768 
769     /**
770      * @brief A destructor used to delete the <b>UIChartPolyline</b> instance.
771      *
772      * @since 1.0
773      * @version 1.0
774      */
~UIChartPolyline()775     virtual ~UIChartPolyline() {}
776 
777     /**
778      * @brief Refreshes a line chart and redraws the dirty region.
779      *
780      * Only the parts that need to be redrawn are refreshed, for example, new data points.
781      * This function provides better performance than {@link Invalidate}.
782      *
783      * @since 1.0
784      * @version 1.0
785      */
786     void RefreshChart() override;
787 
788     /**
789      * @brief Sets the opacity range of the fill color gradient.
790      *
791      * This function sets the opacity range between the top point and bottom point of the line chart.
792      * The opacity of each horizontal line is calculated based on the ratio.
793      *
794      * @param minOpa Indicates the opacity closest to the x-axis.
795      * @param maxOpa Indicates the opacity farthest away from the x-axis.
796      * @since 1.0
797      * @version 1.0
798      */
SetGradientOpacity(uint8_t minOpa,uint8_t maxOpa)799     void SetGradientOpacity(uint8_t minOpa, uint8_t maxOpa)
800     {
801         minOpa_ = minOpa;
802         maxOpa_ = maxOpa;
803         needRefresh_ = true;
804     }
805 
806     /**
807      * @brief Sets the distance between the bottom edge of the fill color range and the x-axis.
808      *
809      * This function fills in the area between the polyline and bottom of the line chart. For a chart that is not
810      * reversed, if the bottom is above the polyline, there is no filling. For a reversed chart,
811      * if the bottom is below the polyline, there is no filling.
812      *
813      * @param bottom Indicates the bottom of the filling range. The value is the distance to the x-axis.
814      * @since 1.0
815      * @version 1.0
816      */
SetGradientBottom(uint16_t bottom)817     void SetGradientBottom(uint16_t bottom)
818     {
819         gradientBottom_ = bottom;
820     }
821 
822 protected:
823     void DrawDataSerials(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
824 
825 private:
826     struct ChartLine {
827         Point start;
828         Point end;
829     };
830 
831     struct CrossPointSet {
832         Point first;
833         Point second;
834         Point nextFirst;
835         bool firstFind;
836         bool secondFind;
837     };
838 
839     constexpr static uint8_t SMOOTH_SLOPE_ANGLE = 3;
840     constexpr static uint8_t LINE_JOIN_WIDTH = 3;
841     uint8_t minOpa_;
842     uint8_t maxOpa_;
843     uint16_t gradientBottom_;
844 
845     void GradientColor(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, UIChartDataSerial* data);
846     void DrawGradientColor(BufferInfo& gfxDstBuffer,
847                            const Rect& invalidatedArea,
848                            UIChartDataSerial* data,
849                            const ChartLine& linePoints,
850                            const ChartLine& limitPoints,
851                            int16_t startY);
852     void DrawSmoothPolyLine(BufferInfo& gfxDstBuffer,
853                             uint16_t startIndex,
854                             uint16_t endIndex,
855                             const Rect& invalidatedArea,
856                             UIChartDataSerial* data);
857     void DrawPolyLine(BufferInfo& gfxDstBuffer, uint16_t startIndex, uint16_t endIndex,
858                       const Rect& invalidatedArea, UIChartDataSerial* data);
859     bool GetLineCrossPoint(const Point& p1, const Point& p2, const Point& p3, const Point& p4, Point& cross);
860     void FindCrossPoints(const ChartLine& line, const ChartLine& polyLine, CrossPointSet& cross);
861     void ReMeasure() override;
862     void CalcVerticalInfo(int16_t top, int16_t bottom, int16_t start, int16_t end, int16_t& y, int16_t& yHeight);
863 };
864 } // namespace OHOS
865 #endif // GRAPHIC_LITE_UI_CHART_H
866