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

Function scatterplot

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

Source from the content-addressed store, hash-verified

44 * @doc {heading: 'Charts', namespace: 'render'}
45 */
46export async function scatterplot(
47 container: Drawable, data: XYPlotData,
48 opts: XYPlotOptions = {}): Promise<void> {
49 let _values = data.values;
50 const _series = data.series == null ? [] : data.series;
51
52 // Nest data if necessary before further processing
53 _values = Array.isArray(_values[0]) ? _values as Point2D[][] :
54 [_values] as Point2D[][];
55
56 const values: Point2D[] = [];
57 _values.forEach((seriesData, i) => {
58 const seriesName: string =
59 _series[i] != null ? _series[i] : `Series ${i + 1}`;
60 const seriesVals =
61 seriesData.map(v => Object.assign({}, v, {series: seriesName}));
62 values.push(...seriesVals);
63 });
64
65 if (opts.seriesColors != null) {
66 assert(
67 opts.seriesColors.length === _values.length,
68 'Must have an equal number of series colors as there are data series');
69 }
70
71 const drawArea = getDrawArea(container);
72 const options = Object.assign({}, defaultOpts, opts);
73
74 const embedOpts = {
75 actions: false,
76 mode: 'vega-lite' as Mode,
77 defaultStyle: false,
78 };
79
80 const xDomain = (): {}|undefined => {
81 if (options.zoomToFit) {
82 return {'zero': false};
83 } else if (options.xAxisDomain != null) {
84 return {'domain': options.xAxisDomain};
85 }
86 return undefined;
87 };
88
89 const yDomain = (): {}|undefined => {
90 if (options.zoomToFit) {
91 return {'zero': false};
92 } else if (options.yAxisDomain != null) {
93 return {'domain': options.yAxisDomain};
94 }
95 return undefined;
96 };
97
98 const spec: VisualizationSpec = {
99 'width': options.width || getDefaultWidth(drawArea),
100 'height': options.height || getDefaultHeight(drawArea),
101 'padding': 0,
102 'autosize': {
103 'type': 'fit',

Callers 1

Calls 8

assertFunction · 0.90
getDrawAreaFunction · 0.90
getDefaultWidthFunction · 0.90
getDefaultHeightFunction · 0.90
xDomainFunction · 0.85
yDomainFunction · 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…