MCPcopy
hub / github.com/tensorflow/tfjs / histogram

Function histogram

tfjs-vis/src/render/histogram.ts:50–136  ·  view source on GitHub ↗
(
    container: Drawable, data: Array<{value: number}>|number[]|TypedArray,
    opts: HistogramOpts = {})

Source from the content-addressed store, hash-verified

48 * @doc {heading: 'Charts', namespace: 'render'}
49 */
50export async function histogram(
51 container: Drawable, data: Array<{value: number}>|number[]|TypedArray,
52 opts: HistogramOpts = {}) {
53 const values = prepareData(data);
54
55 const options = Object.assign({}, defaultOpts, opts);
56
57 const embedOpts = {
58 actions: false,
59 mode: 'vega-lite' as Mode,
60 defaultStyle: false,
61 };
62
63 const histogramContainer = subSurface(container, 'histogram');
64 if (opts.stats !== false) {
65 const statsContainer = subSurface(container, 'stats', {
66 prepend: true,
67 });
68 let stats: HistogramStats;
69
70 if (opts.stats) {
71 stats = opts.stats;
72 } else {
73 stats = arrayStats(values.map(x => x.value));
74 }
75 renderStats(stats, statsContainer, {fontSize: options.fontSize});
76 }
77
78 // If there are no data values return early
79 if (values.length === 0) {
80 return undefined;
81 }
82
83 // Now that we have rendered stats we need to remove any NaNs and Infinities
84 // before rendering the histogram
85 const filtered = [];
86 for (let i = 0; i < values.length; i++) {
87 const val = values[i].value;
88 if (val != null && isFinite(val)) {
89 filtered.push(values[i]);
90 }
91 }
92
93 const histogramSpec: VisualizationSpec = {
94
95 'width': options.width || getDefaultWidth(histogramContainer),
96 'height': options.height || getDefaultHeight(histogramContainer),
97 'padding': 0,
98 'autosize': {
99 'type': 'fit',
100 'contains': 'padding',
101 'resize': true,
102 },
103 'data': {'values': filtered},
104 'mark': {
105 'type': 'bar',
106 'tooltip': true,
107 },

Callers 3

handleSelectionFunction · 0.90
valuesDistributionFunction · 0.90
histogram_test.tsFile · 0.90

Calls 8

subSurfaceFunction · 0.90
arrayStatsFunction · 0.90
getDefaultWidthFunction · 0.90
getDefaultHeightFunction · 0.90
prepareDataFunction · 0.85
renderStatsFunction · 0.85
assignMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…