• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "frameworks/bridge/common/dom/dom_chart.h"
17 
18 #include "frameworks/bridge/common/utils/utils.h"
19 
20 #include "base/utils/linear_map.h"
21 #include "base/utils/string_utils.h"
22 #include "base/utils/utils.h"
23 #include "core/components/common/properties/color_factory.h"
24 
25 namespace OHOS::Ace::Framework {
26 namespace {
27 
28 const char LIGHT_RED_COLOR[] = "#EB4034";
29 const char LIGHT_GREEN_COLOR[] = "#AEEB34";
30 const char LIGHT_BLUE_COLOR[] = "#34EBD9";
31 constexpr double PROGRESS_DEFAULT_MAX_VALUE = 100.0;
32 constexpr uint32_t METHOD_APPEND_ARGS_SIZE = 1;
33 
34 } // namespace
35 
GetSpecializedComponent()36 RefPtr<Component> DOMChart::GetSpecializedComponent()
37 {
38     if (chartType_ == ChartType::BAR || chartType_ == ChartType::LINE) {
39         return chartChild_;
40     }
41     if (chartType_ == ChartType::GAUGE) {
42         return progressChild_;
43     }
44     return dataPanelChild_;
45 }
46 
DOMChart(NodeId nodeId,const std::string & nodeName)47 DOMChart::DOMChart(NodeId nodeId, const std::string& nodeName) : DOMNode(nodeId, nodeName) {}
48 
SetChartAttrOptions(const ChartOptions & chartOptions)49 void DOMChart::SetChartAttrOptions(const ChartOptions& chartOptions)
50 {
51     chartOptions_ = chartOptions;
52 }
53 
SetChartAttrDatasets(const std::vector<MainChart> & datasets)54 void DOMChart::SetChartAttrDatasets(const std::vector<MainChart>& datasets)
55 {
56     chartDatasets_ = datasets;
57     isResetPosition_ = false;
58     position_ = 0;
59     seriesNum_ = 0;
60     lineData_.clear();
61     isSetFirst_ = false;
62 }
63 
SetChartAttrSegments(const std::vector<Segment> & segments)64 void DOMChart::SetChartAttrSegments(const std::vector<Segment>& segments)
65 {
66     segments_ = segments;
67 }
68 
SetSpecializedAttr(const std::pair<std::string,std::string> & attr)69 bool DOMChart::SetSpecializedAttr(const std::pair<std::string, std::string>& attr)
70 {
71     // this map should be sorted by key.
72     static const LinearMapNode<void (*)(const std::string&, DOMChart&)> chartAttrsOperators[] = {
73         { DOM_CHART_ANIMATION_DURATION,
74             [](const std::string& val, DOMChart& chart) {
75               chart.animationDuration_ = StringToDouble(val);
76             } },
77         { DOM_AUTO_SCALE,
78             [](const std::string& val, DOMChart& chart) {
79               chart.autoScale_ = StringToBool(val);
80             } },
81         { DOM_EFFECTS_ON,
82             [](const std::string& val, DOMChart& chart) {
83               chart.showEffect_ = StringToBool(val);
84             } },
85         { DOM_PROGRESS_PERCENT,
86             [](const std::string& val, DOMChart& chart) {
87                 chart.percent_ = StringToDouble(val);
88                 if (chart.percent_ > chart.max_) {
89                     chart.percent_ = chart.max_;
90                 }
91                 if (chart.percent_ < chart.min_) {
92                     chart.percent_ = chart.min_;
93                 }
94             } },
95         { DOM_CHART_TYPE,
96             [](const std::string& val, DOMChart& chart) {
97                 if (val == DOM_CHART_TYPE_GAUGE) {
98                     chart.chartType_ = ChartType::GAUGE;
99                 } else if (val == DOM_CHART_TYPE_BAR) {
100                     chart.chartType_ = ChartType::BAR;
101                 } else if (val == DOM_CHART_TYPE_LINE) {
102                     chart.chartType_ = ChartType::LINE;
103                 } else if (val == DOM_CHART_TYPE_PROGRESS) {
104                     chart.chartType_ = ChartType::PROGRESS;
105                 } else if (val == DOM_CHART_TYPE_RAINBOW) {
106                     chart.chartType_ = ChartType::RAINBOW;
107                 } else if (val == DOM_CHART_TYPE_LOADING) {
108                     chart.chartType_ = ChartType::LOADING;
109                 } else {
110                     chart.chartType_ = ChartType::LINE;
111                 }
112             } },
113     };
114     auto operatorIter = BinarySearchFindIndex(chartAttrsOperators, ArraySize(chartAttrsOperators), attr.first.c_str());
115     if (operatorIter != -1) {
116         chartAttrsOperators[operatorIter].value(attr.second, *this);
117         return true;
118     }
119     return false;
120 }
121 
SetSpecializedStyle(const std::pair<std::string,std::string> & style)122 bool DOMChart::SetSpecializedStyle(const std::pair<std::string, std::string>& style)
123 {
124     // this map should be sorted by key.
125     static const LinearMapNode<void (*)(const std::string&, DOMChart&)> chartStylesOperators[] = {
126         { DOM_BACKGROUND_COLOR,
127             [](const std::string& val, DOMChart& chart) {
128                 if (chart.chartType_ == ChartType::LINE || (chart.chartType_ == ChartType::BAR) ||
129                     (chart.chartType_ == ChartType::GAUGE)) {
130                     auto declaration = chart.GetDeclaration();
131                     if (declaration) {
132                         auto backgroundColor = chart.ParseColor(val);
133                         declaration->GetBackDecoration()->SetBackgroundColor(backgroundColor);
134                         declaration->SetHasBackGroundColor(true);
135                         declaration->SetHasDecorationStyle(true);
136                         return;
137                     }
138                 }
139                 chart.backgroundColor_ = chart.ParseColor(val);
140                 chart.trackColorSet_ = true;
141             } },
142         { DOM_CENTER_X,
143             [](const std::string& val, DOMChart& chart) {
144                 chart.centerX_.first = StringToDouble(val);
145                 chart.centerX_.second = true;
146             } },
147         { DOM_CENTER_Y,
148             [](const std::string& val, DOMChart& chart) {
149                 chart.centerY_.first = StringToDouble(val);
150                 chart.centerY_.second = true;
151             } },
152         { DOM_COLORS_ARRAY,
153             [](const std::string& val, DOMChart& chart) {
154                 chart.colors_.clear();
155                 StringUtils::StringSplitter(val, ',', chart.colors_);
156             } },
157         { DOM_TEXT_FONT_FAMILY,
158             [](const std::string& val, DOMChart& chart) {
159               chart.fontFamily_ = ConvertStrToFontFamilies(val);
160             } },
161         { DOM_TEXT_FONT_SIZE,
162             [](const std::string& val, DOMChart& chart) {
163                 chart.textSize_ = StringToDouble(val);
164             } },
165         { DOM_PROGRESS_RADIUS,
166             [](const std::string& val, DOMChart& chart) {
167                 chart.radius_.first = StringToDouble(val);
168                 chart.radius_.second = true;
169             } },
170         { DOM_START_DEGREE,
171             [](const std::string& val, DOMChart& chart) {
172                 chart.startAngle_.first = StringToDouble(val);
173                 chart.startAngle_.second = true;
174             } },
175         { DOM_PROGRESS_STROKE_WIDTH,
176             [](const std::string& val, DOMChart& chart) {
177                 chart.strokeWidth_.first = chart.ParseDimension(val);
178                 chart.strokeWidth_.second = true;
179             } },
180         { DOM_SWEEP_DEGREE,
181             [](const std::string& val, DOMChart& chart) {
182                 chart.totalAngle_.first = StringToDouble(val);
183                 chart.totalAngle_.second = true;
184             } },
185         { DOM_WEIGHTS_ARRAY,
186             [](const std::string& val, DOMChart& chart) {
187                 chart.weights_.clear();
188                 StringUtils::StringSplitter(val, ',', chart.weights_);
189             } },
190     };
191     auto operatorIter =
192         BinarySearchFindIndex(chartStylesOperators, ArraySize(chartStylesOperators), style.first.c_str());
193     if (operatorIter != -1) {
194         chartStylesOperators[operatorIter].value(style.second, *this);
195         return true;
196     }
197     return false;
198 }
199 
OnSetStyleFinished()200 void DOMChart::OnSetStyleFinished()
201 {
202     // colors or weight are illegal, and set default color and weight
203     if (colors_.empty() || weights_.empty() || colors_.size() != weights_.size()) {
204         colors_.push_back(ParseColor(LIGHT_RED_COLOR));
205         colors_.push_back(ParseColor(LIGHT_GREEN_COLOR));
206         colors_.push_back(ParseColor(LIGHT_BLUE_COLOR));
207         // equally separate the range
208         weights_.push_back(1);
209         weights_.push_back(1);
210         weights_.push_back(1);
211     }
212     if (!centerY_.second || !centerX_.second || !radius_.second) {
213         centerY_.first = -1.0;
214         centerX_.first = -1.0;
215         radius_.first = -1.0;
216         centerY_.second = false;
217         centerX_.second = false;
218         radius_.second = false;
219     }
220 }
221 
222 // Sets other properties of a point, except coordinates.
SetPoint(PointInfo & pointInfo,PointInfo getPointInfo)223 void DOMChart::SetPoint(PointInfo& pointInfo, PointInfo getPointInfo)
224 {
225     if (!getPointInfo.GetFillColorString().empty()) {
226         getPointInfo.SetFillColor(ParseColor(getPointInfo.GetFillColorString()));
227     }
228     pointInfo.SetFillColor(getPointInfo.GetFillColor());
229     if (!getPointInfo.GetStrokeColorString().empty()) {
230         getPointInfo.SetStrokeColor(ParseColor(getPointInfo.GetStrokeColorString()));
231     }
232     pointInfo.SetStrokeColor(getPointInfo.GetStrokeColor());
233     pointInfo.SetPointStrokeWidth(getPointInfo.GetPointStrokeWidth());
234     pointInfo.SetPointSize(getPointInfo.GetPointSize());
235     pointInfo.SetPointShape(getPointInfo.GetPointShape());
236     pointInfo.SetDisplay(getPointInfo.GetDisplay());
237 }
238 
SetChart(MainChart & chartDataset)239 void DOMChart::SetChart(MainChart& chartDataset)
240 {
241     chartDataset.SetLineWidth(chartOptions_.GetLineWidth());
242     chartDataset.SetSmoothFlag(chartOptions_.GetSmoothFlag());
243     chartDataset.SetLineGradient(chartOptions_.GetLineGradient());
244     chartDataset.SetWholeLineGradient(chartOptions_.GetWholeLineGradient());
245     chartDataset.SetTargetColor(chartOptions_.GetTargetColor());
246     chartDataset.SetErasePointNumber(chartOptions_.GetErasePointNumber());
247     chartDataset.SetTextSize(textSize_);
248     chartDataset.SetFontFamily(fontFamily_);
249 
250     auto points = chartDataset.GetData();
251     if (points.empty()) {
252         return;
253     }
254 
255     // parse color from color string
256     for (auto& point : points) {
257         auto pointInfo = point.GetPointInfo();
258         if (!pointInfo.GetStrokeColorString().empty()) {
259             pointInfo.SetStrokeColor(ParseColor(pointInfo.GetStrokeColorString()));
260         }
261         if (!pointInfo.GetFillColorString().empty()) {
262             pointInfo.SetFillColor(ParseColor(pointInfo.GetFillColorString()));
263         }
264         auto segment = point.GetSegmentInfo();
265         if (!segment.GetColorString().empty()) {
266             segment.SetSegmentColor(ParseColor(segment.GetColorString()));
267         }
268         auto text = point.GetTextInfo();
269         if (!text.GetColorString().empty()) {
270             text.SetColor(ParseColor(text.GetColorString()));
271         }
272         point.SetPointInfo(pointInfo);
273         point.SetSegmentInfo(segment);
274         point.SetTextInfo(text);
275     }
276 
277     // remove points out of range. get topPoint and bottomPoint.
278     sort(points.begin(), points.end(),
279         [](LineInfo a, LineInfo b) { return a.GetPointInfo().GetX() < b.GetPointInfo().GetX(); });
280 
281     PointInfo headPoint;
282     PointInfo topPoint = points.begin()->GetPointInfo();
283     PointInfo bottomPoint = points.begin()->GetPointInfo();
284 
285     for (auto pointInfo = points.begin(); pointInfo != points.end();) {
286         auto point = pointInfo->GetPointInfo();
287         auto segment = pointInfo->GetSegmentInfo();
288         if (segment.GetSegmentColor() == Color::TRANSPARENT) {
289             segment.SetSegmentColor(chartDataset.GetStrokeColor());
290             pointInfo->SetSegmentInfo(segment);
291         }
292         if ((chartType_ == ChartType::LINE && point.GetX() < chartOptions_.GetXAxis().min) ||
293             (chartType_ == ChartType::LINE && point.GetX() > chartOptions_.GetXAxis().max) ||
294             ((chartType_ != ChartType::LINE && chartType_ != ChartType::BAR)
295             && (point.GetY() < chartOptions_.GetYAxis().min || point.GetY() > chartOptions_.GetYAxis().max))) {
296             points.erase(pointInfo);
297         } else {
298             if (point.GetY() > topPoint.GetY()) {
299                 topPoint = point;
300             }
301             if (point.GetY() < bottomPoint.GetY()) {
302                 bottomPoint = point;
303             }
304             ++pointInfo;
305         }
306     }
307     chartDataset.SetData(points);
308 
309     if (!points.empty()) {
310         headPoint = points[points.size() - 1].GetPointInfo();
311         SetPoint(headPoint, chartOptions_.GetHeadPoint());
312         chartDataset.SetHeadPoint(headPoint);
313     }
314 
315     SetPoint(topPoint, chartOptions_.GetTopPoint());
316     chartDataset.SetTopPoint(topPoint);
317 
318     SetPoint(bottomPoint, chartOptions_.GetBottomPoint());
319     chartDataset.SetBottomPoint(bottomPoint);
320 }
321 
PrepareSpecializedComponent()322 void DOMChart::PrepareSpecializedComponent()
323 {
324     if (chartType_ == ChartType::GAUGE) {
325         if (!progressChild_) {
326             progressChild_ =
327                 AceType::MakeRefPtr<ProgressComponent>(0.0, 0.0, 0.0, PROGRESS_DEFAULT_MAX_VALUE, ProgressType::GAUGE);
328         }
329         progressChild_->SetValue(percent_);
330         progressChild_->SetMaxValue(max_);
331         progressChild_->SetMinValue(min_);
332         progressChild_->GetTrack()->SetIndicatorFlag(true);
333         progressChild_->GetTrack()->SetSectionsStyle(colors_, weights_);
334         progressChild_->GetTrack()->SetTrackThickness(strokeWidth_.first);
335         progressChild_->GetTrack()->GetTrackInfo()->SetStartDegree(startAngle_.first);
336         progressChild_->GetTrack()->GetTrackInfo()->SetSweepDegree(totalAngle_.first);
337         progressChild_->GetTrack()->SetCenterX(centerX_.first);
338         progressChild_->GetTrack()->SetCenterY(centerY_.first);
339         progressChild_->GetTrack()->SetRadius(radius_.first);
340     } else if (chartType_ == ChartType::BAR || chartType_ == ChartType::LINE) {
341         if (!chartChild_) {
342             chartChild_ = AceType::MakeRefPtr<ChartComponent>(chartType_);
343         }
344         chartChild_->SetHorizontalOption(chartOptions_.GetXAxis());
345         chartChild_->SetVerticalOption(chartOptions_.GetYAxis());
346         // Convert the data in options to mainchart
347         for (auto& charDataset : chartDatasets_) {
348             SetChart(charDataset);
349         }
350         chartChild_->SetMainCharts(chartDatasets_);
351     } else if (chartType_ == ChartType::PROGRESS || chartType_ == ChartType::LOADING) {
352         dataPanelChild_ = AceType::MakeRefPtr<ProgressDataPanelComponent>(chartType_);
353         dataPanelChild_->InitalStyle(GetThemeManager());
354         dataPanelChild_->SetEffects(showEffect_);
355         if (trackColorSet_) {
356             dataPanelChild_->SetTrackColor(backgroundColor_);
357         }
358         dataPanelChild_->SetAutoScale(autoScale_);
359         if (segments_.empty()) {
360             return;
361         }
362         auto progressDataPanel = AceType::DynamicCast<ProgressDataPanelComponent>(dataPanelChild_);
363         if (segments_[0].GetColorType() == SegmentStyleType::USE_COLOR) {
364             progressDataPanel->SetStartColor(segments_[0].GetStartColor());
365             progressDataPanel->SetEndColor(segments_[0].GetEndColor());
366         } else if (segments_[0].GetColorType() == SegmentStyleType::USE_GRADIENT) {
367             auto& colorManager = ColorFactory::GetInstance();
368             auto colorPair = colorManager.GetColorTuple(segments_[0].GetColorDescriptor());
369             progressDataPanel->SetStartColor(colorPair.first);
370             progressDataPanel->SetEndColor(colorPair.second);
371         }
372         // for else case, keep default color
373         progressDataPanel->SetProgressValue(segments_[0].GetValue());
374         if (strokeWidth_.second) {
375             dataPanelChild_->SetThickness(strokeWidth_.first);
376         }
377     } else if (chartType_ == ChartType::RAINBOW) {
378         dataPanelChild_ = AceType::MakeRefPtr<PercentageDataPanelComponent>(chartType_);
379         dataPanelChild_->SetAnimationDuration(animationDuration_);
380         dataPanelChild_->SetEffects(showEffect_);
381         dataPanelChild_->SetAutoScale(autoScale_);
382         auto percentageDataPanel = AceType::DynamicCast<PercentageDataPanelComponent>(dataPanelChild_);
383         // the angle range is from 0 to 360.
384         percentageDataPanel->SetStartDegree(startAngle_.second ? startAngle_.first : 0.0);
385         percentageDataPanel->SetSweepDegree(totalAngle_.second ? totalAngle_.first : 360.0);
386         percentageDataPanel->ClearSegment();
387         if (segments_.empty()) {
388             return;
389         }
390         for (const auto& segment : segments_) {
391             percentageDataPanel->AppendSegment(segment);
392         }
393         dataPanelChild_->InitalStyle(GetThemeManager());
394         if (trackColorSet_) {
395             dataPanelChild_->SetTrackColor(backgroundColor_);
396         }
397         if (strokeWidth_.second) {
398             dataPanelChild_->SetThickness(strokeWidth_.first);
399         }
400     }
401 }
402 
CallSpecializedMethod(const std::string & method,const std::string & args)403 void DOMChart::CallSpecializedMethod(const std::string& method, const std::string& args)
404 {
405     if (method != DOM_METHOD_APPEND) {
406         return;
407     }
408     std::unique_ptr<JsonValue> argsValue = JsonUtil::ParseJsonString(args);
409     if (!argsValue || !argsValue->IsArray() || argsValue->GetArraySize() != METHOD_APPEND_ARGS_SIZE) {
410         return;
411     }
412 
413     std::unique_ptr<JsonValue> serialValue = argsValue->GetArrayItem(0)->GetValue("serial");
414     if (!serialValue || !serialValue->IsNumber()) {
415         return;
416     }
417     seriesNum_ = serialValue->GetInt();
418 
419     std::unique_ptr<JsonValue> dataValue = argsValue->GetArrayItem(0)->GetValue("data");
420     if (!dataValue || !dataValue->IsArray()) {
421         return;
422     }
423     int32_t arraySize = dataValue->GetArraySize();
424     auto chartDatas = chartChild_->GetMainCharts();
425 
426     if (seriesNum_ < 0 || (static_cast<size_t>(seriesNum_) >= chartDatas.size())) {
427         LOGW("series number is greater or equal to the size of chart");
428         return;
429     }
430 
431     if (!isSetFirst_) {
432         isSetFirst_ = true;
433         for (int32_t i = 0; i < static_cast<int32_t>(chartDatas.size()); i++) {
434             lineData_.emplace_back(chartOptions_.GetXAxis().min, false);
435         }
436     }
437 
438     // get the head point position of the series data to be updated.
439     position_ = lineData_[seriesNum_].first;
440     isResetPosition_ = lineData_[seriesNum_].second;
441 
442     for (int32_t i = 0; i < arraySize; i++) {
443         std::unique_ptr<JsonValue> coorVal = dataValue->GetArrayItem(i);
444         if (!coorVal || !coorVal->IsNumber()) {
445             return;
446         }
447         int32_t coorY = coorVal->GetInt();
448         if (coorY <= chartOptions_.GetYAxis().max && coorY >= chartOptions_.GetYAxis().min) {
449             UpdateChartData(coorY, chartDatas);
450         }
451     }
452 
453     // save the head point position of the updated series data.
454     lineData_[seriesNum_].first = position_;
455     lineData_[seriesNum_].second = isResetPosition_;
456 
457     UpdateTopBottomPoint(chartDatas);
458 
459     chartChild_->SetMainCharts(chartDatas);
460     auto node = DOMNode::GetRootComponent();
461     node->MarkNeedUpdate();
462     auto pipelineContext = pipelineContext_.Upgrade();
463     if (!pipelineContext) {
464         return;
465     }
466     pipelineContext->ScheduleUpdate(node);
467 }
468 
UpdateTopBottomPoint(std::vector<MainChart> & data)469 void DOMChart::UpdateTopBottomPoint(std::vector<MainChart>& data)
470 {
471     Point bottomPt = Point(0, 0);
472     Point topPt = Point(0, 0);
473     auto pointVec = data[seriesNum_].GetData();
474     double minY = pointVec[0].GetPointInfo().GetY();
475     double maxY = pointVec[0].GetPointInfo().GetY();
476 
477     for (auto iter : pointVec) {
478         if (iter.GetPointInfo().GetY() <= minY) {
479             bottomPt.SetX(iter.GetPointInfo().GetX());
480             bottomPt.SetY(iter.GetPointInfo().GetY());
481             minY = iter.GetPointInfo().GetY();
482         }
483         if (iter.GetPointInfo().GetY() >= maxY) {
484             topPt.SetX(iter.GetPointInfo().GetX());
485             topPt.SetY(iter.GetPointInfo().GetY());
486             maxY = iter.GetPointInfo().GetY();
487         }
488     }
489     auto bottomPoint = data[seriesNum_].GetBottomPoint();
490     bottomPoint.SetX(bottomPt.GetX());
491     bottomPoint.SetY(bottomPt.GetY());
492     data[seriesNum_].SetBottomPoint(bottomPoint);
493 
494     auto topPoint = data[seriesNum_].GetTopPoint();
495     topPoint.SetX(topPt.GetX());
496     topPoint.SetY(topPt.GetY());
497     data[seriesNum_].SetTopPoint(topPoint);
498 }
499 
UpdateChartData(int32_t coorY,std::vector<MainChart> & data)500 void DOMChart::UpdateChartData(int32_t coorY, std::vector<MainChart>& data)
501 {
502     if (isResetPosition_) {
503         position_ = position_ + 1;
504     } else {
505         position_ = static_cast<int32_t>(data[seriesNum_].GetData().size());
506     }
507     if (position_ > chartOptions_.GetXAxis().max || position_ < chartOptions_.GetXAxis().min) {
508         return;
509     }
510     if (chartOptions_.GetLoop() && position_ > chartOptions_.GetXAxis().max - 1) {
511         isResetPosition_ = true;
512         position_ = chartOptions_.GetXAxis().min;
513         Point coor = Point(position_, coorY);
514         PointInfo point = PointInfo(coor);
515         SegmentInfo segment;
516         segment.SetSegmentColor(data[seriesNum_].GetStrokeColor());
517         LineInfo line = LineInfo(point);
518         line.SetSegmentInfo(segment);
519         data[seriesNum_].ReplaceData(position_, line);
520         data[seriesNum_].SetErasePointNumber(chartOptions_.GetErasePointNumber());
521         data[seriesNum_].SetHeadPointIndex(position_);
522     } else {
523         Point coor = Point(position_, coorY);
524         PointInfo point = PointInfo(coor);
525         SegmentInfo segment;
526         segment.SetSegmentColor(data[seriesNum_].GetStrokeColor());
527         LineInfo line = LineInfo(point);
528         line.SetSegmentInfo(segment);
529         if (!isResetPosition_) {
530             data[seriesNum_].AppendData(line);
531         } else {
532             data[seriesNum_].ReplaceData(position_, line);
533             data[seriesNum_].SetHeadPointIndex(position_);
534         }
535     }
536     auto headPoint = data[seriesNum_].GetHeadPoint();
537     headPoint.SetX(position_);
538     headPoint.SetY(coorY);
539     data[seriesNum_].SetHeadPoint(headPoint);
540 }
541 
542 } // namespace OHOS::Ace::Framework
543