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

Function linechart

tfjs-vis/src/render/linechart.ts:60–207  ·  view source on GitHub ↗
(
    container: Drawable, data: XYPlotData,
    opts: XYPlotOptions = {})

Source from the content-addressed store, hash-verified

58 * @doc {heading: 'Charts', namespace: 'render'}
59 */
60export async function linechart(
61 container: Drawable, data: XYPlotData,
62 opts: XYPlotOptions = {}): Promise<void> {
63 // Nest data if necessary before further processing
64 const _data = Array.isArray(data.values[0]) ? data.values as Point2D[][] :
65 [data.values] as Point2D[][];
66 const numValues = _data[0].length;
67
68 // Create series names if none were passed in.
69 const _series: string[] =
70 data.series ? data.series : _data.map((_, i) => `Series ${i + 1}`);
71 assert(
72 _series.length === _data.length,
73 'Must have an equal number of series labels as there are data series');
74
75 if (opts.seriesColors != null) {
76 assert(
77 opts.seriesColors.length === _data.length,
78 'Must have an equal number of series colors as there are data series');
79 }
80
81 const vlChartValues: VLChartValue[] = [];
82 for (let valueIdx = 0; valueIdx < numValues; valueIdx++) {
83 const v: VLChartValue = {
84 x: valueIdx,
85 };
86
87 _series.forEach((seriesName, seriesIdx) => {
88 const seriesValue = _data[seriesIdx][valueIdx].y;
89 v[seriesName] = seriesValue;
90 v[`${seriesName}-name`] = seriesName;
91 });
92 vlChartValues.push(v);
93 }
94
95 const options = Object.assign({}, defaultOpts, opts);
96
97 const yScale = (): {}|undefined => {
98 if (options.zoomToFit) {
99 return {'zero': false};
100 } else if (options.yAxisDomain != null) {
101 return {'domain': options.yAxisDomain};
102 }
103 return undefined;
104 };
105
106 const sharedEncoding = {
107 x: {
108 field: 'x',
109 type: options.xType,
110 title: options.xLabel,
111 },
112 tooltip: [
113 {field: 'x', type: 'quantitative'},
114 ..._series.map(seriesName => {
115 return {
116 field: seriesName,
117 type: 'quantitative',

Callers 2

historyFunction · 0.90
linechart_test.tsFile · 0.90

Calls 7

assertFunction · 0.90
getDrawAreaFunction · 0.90
getDefaultWidthFunction · 0.90
getDefaultHeightFunction · 0.90
yScaleFunction · 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…