forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart-type-scatterplot.js
More file actions
101 lines (96 loc) · 3.3 KB
/
Copy pathchart-type-scatterplot.js
File metadata and controls
101 lines (96 loc) · 3.3 KB
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
var tauCharts = require('tauCharts');
module.exports = {
chartLabel: "Scatterplot",
fields: {
x: {
label: "x Axis",
inputType: "field-dropdown",
required: true,
$input: null,
val: null,
datatype: null,
min: null,
max: null
},
y: {
label: "y Axis",
inputType: "field-dropdown",
required: true
},
size: {
label: "Size",
inputType: "field-dropdown",
required: false
},
color: {
label: "Color",
inputType: "field-dropdown",
required: false
},
xFacet: {
requied: false,
label: "x Facet",
inputType: "field-dropdown"
},
yFacet: {
required: false,
label: "y Facet",
inputType: "field-dropdown"
},
trendline: {
required: false,
label: "Show Trendline",
inputType: "checkbox"
}
},
renderChart: function (meta, data, fields) {
// fields.x.datatype will be "date", "number", or "text"
for (var row in data) {
// make barvalue field a Number
if (fields.x.datatype == "text" || fields.x.datatype == "number") {
data[row][fields.x.val] = Number(data[row][fields.x.val]);
}
if (fields.y.datatype == "text" || fields.y.datatype == "number") {
data[row][fields.y.val] = Number(data[row][fields.y.val]);
}
if (fields.size.val) {
data[row][fields.size.val] = Number(data[row][fields.size.val]);
}
// Facets need to be a dimension, not a measure.
// tauCharts auto detects numbers to be measures
// Here we'll convert a number to a string,
// to trick tauCharts into thinking its a dimension
if (fields.xFacet.val && fields.xFacet.datatype == "number" && data[row][fields.xFacet.val]) {
data[row][fields.xFacet.val] = data[row][fields.xFacet.val].toString();
}
if (fields.yFacet.val && fields.yFacet.datatype == "number" && data[row][fields.yFacet.val]) {
data[row][fields.yFacet.val] = data[row][fields.yFacet.val].toString();
}
}
var x = fields.x.val;
if (fields.xFacet.val) {
x = [fields.xFacet.val, fields.x.val];
}
var y = fields.y.val;
if (fields.yFacet.val) {
y = [fields.yFacet.val, fields.y.val];
}
var plugins = [];
if (fields.trendline.val) {
plugins.push(tauCharts.api.plugins.get('trendline')());
}
plugins.push(tauCharts.api.plugins.get('tooltip')({fields: [fields.x.val, fields.y.val, fields.size.val, fields.color.val]}));
plugins.push(tauCharts.api.plugins.get('legend')());
var chart = new tauCharts.Chart({
data: data,
type: "scatterplot",
y: y,
x: x,
color: fields.color.val,
size: fields.size.val,
plugins: plugins
});
chart.renderTo('#chart');
return chart;
}
};