Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 6x 6x 21x 21x 21x 21x 21x 27x 2x 2x 1x 1x 1x 1x 1x 1x 27x 19x 19x 21x 21x 21x 21x 27x 122x 122x 16x 16x 16x 106x 120x 92x 122x 14x 14x 106x 106x 122x 4x 122x 6x 6x 106x 106x 21x 21x 21x 21x 21x 21x 27x 122x 122x 3x 3x 3x 122x 13x 13x 13x 122x 17x 17x 17x 17x 17x 89x 89x 122x 3x 122x 1x 86x 2x 85x 83x 83x 89x 89x 21x 27x 25x 25x 25x 25x 25x | /**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
// MODULES //
var abs = require( '@stdlib/math/base/special/abs' );
var round = require( '@stdlib/math/base/special/round' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
// VARIABLES //
// See [Braille Patterns]{@link https://en.wikipedia.org/wiki/Braille_Patterns}.
var UNICODE_BRAILLE_ELEMENTS = [
[ '⣀', '⡠', '⡐', '⡈' ], // U+28C0, U+2860, U+2850, U+2848
[ '⢄', '⠤', '⠔', '⠌' ], // U+2884, U+2824, U+2814, U+2802
[ '⢂', '⠢', '⠒', '⠊' ], // U+2882, U+2822, U+2812, U+280A
[ '⢁', '⠡', '⠑', '⠉' ] // U+2881, U+2821, U+2811, U+2809
];
var UNICODE_INF = '∞'; // U+221E
var MISSING_VALUE = ' ';
// MAIN //
/**
* Renders a chart.
*
* @private
* @returns {string} rendered chart
*/
function render() {
/* eslint-disable no-invalid-this */
var glyphs;
var range;
var str;
var min;
var max;
var len;
var idx;
var FLG;
var d;
var v;
var n;
var i;
var j;
len = this._data.length;
if ( len === 0 ) {
return '';
}
min = this.yMin;
max = this.yMax;
range = abs( max-min );
// Check if data is constant...
if ( range === 0.0 ) {
// If `max` is `0`, encode each finite datum as the lowest Braille glyph...
if ( max === 0.0 ) {
glyphs = [ [ UNICODE_BRAILLE_ELEMENTS[0][0] ] ];
}
// Otherwise, encode each finite datum as a mid-sized Braille glyph...
else {
glyphs = [ [ UNICODE_BRAILLE_ELEMENTS[2][2] ] ];
}
} else {
glyphs = UNICODE_BRAILLE_ELEMENTS;
}
// Assign each datum to a bin...
idx = new Array( len );
FLG = new Array( len );
n = glyphs.length - 1;
for ( i = 0; i < len; i++ ) {
d = this._data[ i ];
if ( !this._isDefined( d, i ) || d === PINF || d === NINF ) {
FLG[ i ] = true;
continue;
}
// Normalize the datum (aka feature scaling):
if ( range ) {
v = ( d-min ) / range;
} else {
v = 0.0;
}
// Determine the bin index:
j = round( v*n );
if ( j < 0 ) {
j = 0;
} else if ( j > n ) {
j = n;
}
idx[ i ] = j;
}
// TODO: color encoding: one color for both pos and neg or two colors for separate colors
// TODO: negative values diff color (red)
// For each datum, we peek ahead to determine if the next value is greater than or less than the current value. The magnitude of the difference determines the glyph slope.
str = '';
for ( i = 0; i < len; i++ ) {
d = this._data[ i ];
if ( this._infinities && ( d === PINF || d === NINF ) ) {
str += UNICODE_INF;
continue;
}
if ( FLG[ i ] ) {
str += MISSING_VALUE;
continue;
}
if ( i === len-1 ) {
// The final glyph is flat, as the next value is unknown...
j = idx[ i ];
str += glyphs[ j ][ j ];
break;
}
j = i + 1;
n = this._data[ j ];
if ( n === PINF ) {
j = 3; // highest bin
} else if ( n === NINF ) {
j = 0; // lowest bin
} else if ( FLG[ j ] ) {
j = idx[ i ]; // same bin, as no slope can be inferred from a missing value
} else {
j = idx[ j ]; // slope toward the next value's bin
}
str += glyphs[ idx[i] ][ j ];
}
return str;
}
// EXPORTS //
module.exports = render;
|