Flutter Engine
The Flutter Engine
Classes | Functions
ChartSlide.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathBuilder.h"
#include "include/private/base/SkTDArray.h"
#include "src/base/SkRandom.h"
#include "tools/viewer/Slide.h"

Go to the source code of this file.

Classes

class  ChartSlide
 

Functions

static void gen_data (SkScalar yAvg, SkScalar ySpread, int count, SkTDArray< SkScalar > *dataPts)
 
static void gen_paths (const SkTDArray< SkScalar > &topData, const SkTDArray< SkScalar > *bottomData, SkScalar yBase, SkScalar xLeft, SkScalar xDelta, int leftShift, SkPathBuilder *plot, SkPathBuilder *fill)
 

Function Documentation

◆ gen_data()

static void gen_data ( SkScalar  yAvg,
SkScalar  ySpread,
int  count,
SkTDArray< SkScalar > *  dataPts 
)
static

Definition at line 16 of file ChartSlide.cpp.

16 {
17 dataPts->resize(count);
18 static SkRandom gRandom;
19 for (int i = 0; i < count; ++i) {
20 (*dataPts)[i] = gRandom.nextRangeScalar(yAvg - SkScalarHalf(ySpread),
21 yAvg + SkScalarHalf(ySpread));
22 }
23}
int count
Definition: FontMgrTest.cpp:50
#define SkScalarHalf(a)
Definition: SkScalar.h:75
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition: SkRandom.h:106
void resize(int count)
Definition: SkTDArray.h:183

◆ gen_paths()

static void gen_paths ( const SkTDArray< SkScalar > &  topData,
const SkTDArray< SkScalar > *  bottomData,
SkScalar  yBase,
SkScalar  xLeft,
SkScalar  xDelta,
int  leftShift,
SkPathBuilder plot,
SkPathBuilder fill 
)
static

Definition at line 29 of file ChartSlide.cpp.

34 {
35 plot->incReserve(topData.size());
36 if (nullptr == bottomData) {
37 fill->incReserve(topData.size() + 2);
38 } else {
39 fill->incReserve(2 * topData.size());
40 }
41
42 leftShift %= topData.size();
43 SkScalar x = xLeft;
44
45 // Account for the leftShift using two loops
46 int shiftToEndCount = topData.size() - leftShift;
47 plot->moveTo(x, topData[leftShift]);
48 fill->moveTo(x, topData[leftShift]);
49
50 for (int i = 1; i < shiftToEndCount; ++i) {
51 plot->lineTo(x, topData[i + leftShift]);
52 fill->lineTo(x, topData[i + leftShift]);
53 x += xDelta;
54 }
55
56 for (int i = 0; i < leftShift; ++i) {
57 plot->lineTo(x, topData[i]);
58 fill->lineTo(x, topData[i]);
59 x += xDelta;
60 }
61
62 if (bottomData) {
63 SkASSERT(bottomData->size() == topData.size());
64 // iterate backwards over the previous graph's data to generate the bottom of the filled
65 // area (and account for leftShift).
66 for (int i = 0; i < leftShift; ++i) {
67 x -= xDelta;
68 fill->lineTo(x, (*bottomData)[leftShift - 1 - i]);
69 }
70 for (int i = 0; i < shiftToEndCount; ++i) {
71 x -= xDelta;
72 fill->lineTo(x, (*bottomData)[bottomData->size() - 1 - i]);
73 }
74 } else {
75 fill->lineTo(x - xDelta, yBase);
76 fill->lineTo(xLeft, yBase);
77 }
78}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkPathBuilder & lineTo(SkPoint pt)
void incReserve(int extraPtCount, int extraVerbCount)
SkPathBuilder & moveTo(SkPoint pt)
int size() const
Definition: SkTDArray.h:138
float SkScalar
Definition: extension.cpp:12
double x
static void plot(SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr, bool requireES3=false)