MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sparklineRenderRange

Function sparklineRenderRange

app/redis-6.2.6/src/sparkline.c:97–162  ·  view source on GitHub ↗

Render part of a sequence, so that render_sequence() call call this function * with different parts in order to create the full output without overflowing * the current terminal columns. */

Source from the content-addressed store, hash-verified

95 * with different parts in order to create the full output without overflowing
96 * the current terminal columns. */
97sds sparklineRenderRange(sds output, struct sequence *seq, int rows, int offset, int len, int flags) {
98 int j;
99 double relmax = seq->max - seq->min;
100 int steps = charset_len*rows;
101 int row = 0;
102 char *chars = zmalloc(len);
103 int loop = 1;
104 int opt_fill = flags & SPARKLINE_FILL;
105 int opt_log = flags & SPARKLINE_LOG_SCALE;
106
107 if (opt_log) {
108 relmax = log(relmax+1);
109 } else if (relmax == 0) {
110 relmax = 1;
111 }
112
113 while(loop) {
114 loop = 0;
115 memset(chars,' ',len);
116 for (j = 0; j < len; j++) {
117 struct sample *s = &seq->samples[j+offset];
118 double relval = s->value - seq->min;
119 int step;
120
121 if (opt_log) relval = log(relval+1);
122 step = (int) (relval*steps)/relmax;
123 if (step < 0) step = 0;
124 if (step >= steps) step = steps-1;
125
126 if (row < rows) {
127 /* Print the character needed to create the sparkline */
128 int charidx = step-((rows-row-1)*charset_len);
129 loop = 1;
130 if (charidx >= 0 && charidx < charset_len) {
131 chars[j] = opt_fill ? charset_fill[charidx] :
132 charset[charidx];
133 } else if(opt_fill && charidx >= charset_len) {
134 chars[j] = '|';
135 }
136 } else {
137 /* Labels spacing */
138 if (seq->labels && row-rows < label_margin_top) {
139 loop = 1;
140 break;
141 }
142 /* Print the label if needed. */
143 if (s->label) {
144 int label_len = strlen(s->label);
145 int label_char = row - rows - label_margin_top;
146
147 if (label_len > label_char) {
148 loop = 1;
149 chars[j] = s->label[label_char];
150 }
151 }
152 }
153 }
154 if (loop) {

Callers 1

sparklineRenderFunction · 0.85

Calls 5

zmallocFunction · 0.85
memsetFunction · 0.85
sdscatlenFunction · 0.85
zfreeFunction · 0.70
logFunction · 0.50

Tested by

no test coverage detected