Skip to content

Commit 50e933c

Browse files
authored
Merge pull request #2052 from plotly/table-squashed
Table view - squashed
2 parents c09d2e4 + d4f0ed7 commit 50e933c

21 files changed

+2052
-0
lines changed

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Plotly.register([
3434
require('./pointcloud'),
3535
require('./heatmapgl'),
3636
require('./parcoords'),
37+
require('./table'),
3738

3839
require('./scattermapbox'),
3940

lib/table.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = require('../src/traces/table');

src/lib/gup.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var identity = require('./identity');
12+
13+
function wrap(d) {return [d];}
14+
15+
module.exports = {
16+
17+
// The D3 data binding concept and the General Update Pattern promotes the idea of
18+
// traversing into the scenegraph by using the `.data(fun, keyFun)` call.
19+
// The `fun` is most often a `repeat`, ie. the elements beneath a `<g>` element need
20+
// access to the same data, or a `descend`, which fans a scenegraph node into a bunch of
21+
// of elements, e.g. points, lines, rows, requiring an array as input.
22+
// The role of the `keyFun` is to identify what elements are being entered/exited/updated,
23+
// otherwise D3 reverts to using a plain index which would screw up `transition`s.
24+
keyFun: function(d) {return d.key;},
25+
repeat: wrap,
26+
descend: identity,
27+
28+
// Plotly.js uses a convention of storing the actual contents of the `calcData` as the
29+
// element zero of a container array. These helpers are just used for clarity as a
30+
// newcomer to the codebase may not know what the `[0]` is, and whether there can be further
31+
// elements (not atm).
32+
wrap: wrap,
33+
unwrap: function(d) {return d[0];}
34+
};

src/lib/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ lib.raiseToTop = function raiseToTop(elem) {
161161
elem.parentNode.appendChild(elem);
162162
};
163163

164+
/**
165+
* cancel a possibly pending transition; returned selection may be used by caller
166+
*/
167+
lib.cancelTransition = function(selection) {
168+
return selection.transition().duration(0);
169+
};
170+
164171
// constrain - restrict a number v to be between v0 and v1
165172
lib.constrain = function(v, v0, v1) {
166173
if(v0 > v1) return Math.max(v1, Math.min(v0, v));

src/traces/table/attributes.js

+278
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var annAttrs = require('../../components/annotations/attributes');
12+
var extendFlat = require('../../lib/extend').extendFlat;
13+
var overrideAll = require('../../plot_api/edit_types').overrideAll;
14+
15+
module.exports = overrideAll({
16+
domain: {
17+
x: {
18+
valType: 'info_array',
19+
role: 'info',
20+
items: [
21+
{valType: 'number', min: 0, max: 1},
22+
{valType: 'number', min: 0, max: 1}
23+
],
24+
dflt: [0, 1],
25+
description: [
26+
'Sets the horizontal domain of this `table` trace',
27+
'(in plot fraction).'
28+
].join(' ')
29+
},
30+
y: {
31+
valType: 'info_array',
32+
role: 'info',
33+
items: [
34+
{valType: 'number', min: 0, max: 1},
35+
{valType: 'number', min: 0, max: 1}
36+
],
37+
dflt: [0, 1],
38+
description: [
39+
'Sets the vertical domain of this `table` trace',
40+
'(in plot fraction).'
41+
].join(' ')
42+
}
43+
},
44+
45+
columnwidth: {
46+
valType: 'number',
47+
arrayOk: true,
48+
dflt: null,
49+
role: 'style',
50+
description: 'The width of cells.'
51+
},
52+
53+
columnorder: {
54+
valType: 'data_array',
55+
role: 'info',
56+
description: [
57+
'Specifies the rendered order of the data columns; for example, a value `2` at position `0`',
58+
'means that column index `0` in the data will be rendered as the',
59+
'third column, as columns have an index base of zero.'
60+
].join(' ')
61+
},
62+
63+
header: {
64+
65+
values: {
66+
valType: 'data_array',
67+
role: 'info',
68+
dflt: [],
69+
description: [
70+
'Header cell values. `values[m][n]` represents the value of the `n`th point in column `m`,',
71+
'therefore the `values[m]` vector length for all columns must be the same (longer vectors',
72+
'will be truncated). Each value must be a finite number or a string.'
73+
].join(' ')
74+
},
75+
76+
format: {
77+
valType: 'data_array',
78+
role: 'info',
79+
dflt: [],
80+
description: [
81+
'Sets the cell value formatting rule using d3 formatting mini-language',
82+
'which is similar to those of Python. See',
83+
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'
84+
].join(' ')
85+
},
86+
87+
prefix: {
88+
valType: 'string',
89+
arrayOk: true,
90+
dflt: null,
91+
role: 'style',
92+
description: 'Prefix for cell values.'
93+
},
94+
95+
suffix: {
96+
valType: 'string',
97+
arrayOk: true,
98+
dflt: null,
99+
role: 'style',
100+
description: 'Suffix for cell values.'
101+
},
102+
103+
height: {
104+
valType: 'number',
105+
dflt: 28,
106+
role: 'style',
107+
description: 'The height of cells.'
108+
},
109+
110+
align: extendFlat({}, annAttrs.align, {arrayOk: true}),
111+
112+
line: {
113+
width: {
114+
valType: 'number',
115+
arrayOk: true,
116+
role: 'style'
117+
},
118+
color: {
119+
valType: 'color',
120+
arrayOk: true,
121+
role: 'style'
122+
}
123+
},
124+
125+
fill: {
126+
color: {
127+
valType: 'color',
128+
arrayOk: true,
129+
dflt: 'white',
130+
role: 'style',
131+
description: [
132+
'Sets the cell fill color. It accepts either a specific color',
133+
' or an array of colors.'
134+
].join('')
135+
}
136+
},
137+
138+
font: {
139+
family: {
140+
valType: 'string',
141+
arrayOk: true,
142+
role: 'style',
143+
noBlank: true,
144+
strict: true,
145+
description: [
146+
'HTML font family - the typeface that will be applied by the web browser.',
147+
'The web browser will only be able to apply a font if it is available on the system',
148+
'which it operates. Provide multiple font families, separated by commas, to indicate',
149+
'the preference in which to apply fonts if they aren\'t available on the system.',
150+
'The plotly service (at https://plot.ly or on-premise) generates images on a server,',
151+
'where only a select number of',
152+
'fonts are installed and supported.',
153+
'These include *Arial*, *Balto*, *Courier New*, *Droid Sans*,, *Droid Serif*,',
154+
'*Droid Sans Mono*, *Gravitas One*, *Old Standard TT*, *Open Sans*, *Overpass*,',
155+
'*PT Sans Narrow*, *Raleway*, *Times New Roman*.'
156+
].join(' ')
157+
},
158+
size: {
159+
valType: 'number',
160+
arrayOk: true,
161+
role: 'style'
162+
},
163+
color: {
164+
valType: 'color',
165+
arrayOk: true,
166+
role: 'style'
167+
}
168+
}
169+
},
170+
171+
cells: {
172+
173+
values: {
174+
valType: 'data_array',
175+
role: 'info',
176+
dflt: [],
177+
description: [
178+
'Cell values. `values[m][n]` represents the value of the `n`th point in column `m`,',
179+
'therefore the `values[m]` vector length for all columns must be the same (longer vectors',
180+
'will be truncated). Each value must be a finite number or a string.'
181+
].join(' ')
182+
},
183+
184+
format: {
185+
valType: 'data_array',
186+
role: 'info',
187+
dflt: [],
188+
description: [
189+
'Sets the cell value formatting rule using d3 formatting mini-language',
190+
'which is similar to those of Python. See',
191+
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'
192+
].join(' ')
193+
},
194+
195+
prefix: {
196+
valType: 'string',
197+
arrayOk: true,
198+
dflt: null,
199+
role: 'style',
200+
description: 'Prefix for cell values.'
201+
},
202+
203+
suffix: {
204+
valType: 'string',
205+
arrayOk: true,
206+
dflt: null,
207+
role: 'style',
208+
description: 'Suffix for cell values.'
209+
},
210+
211+
height: {
212+
valType: 'number',
213+
dflt: 20,
214+
role: 'style',
215+
description: 'The height of cells.'
216+
},
217+
218+
align: extendFlat({}, annAttrs.align, {arrayOk: true}),
219+
220+
line: {
221+
width: {
222+
valType: 'number',
223+
arrayOk: true,
224+
role: 'style'
225+
},
226+
color: {
227+
valType: 'color',
228+
arrayOk: true,
229+
role: 'style'
230+
}
231+
},
232+
233+
fill: {
234+
color: {
235+
valType: 'color',
236+
arrayOk: true,
237+
role: 'style',
238+
dflt: 'white',
239+
description: [
240+
'Sets the cell fill color. It accepts either a specific color',
241+
' or an array of colors.'
242+
].join('')
243+
}
244+
},
245+
246+
font: {
247+
family: {
248+
valType: 'string',
249+
arrayOk: true,
250+
role: 'style',
251+
noBlank: true,
252+
strict: true,
253+
description: [
254+
'HTML font family - the typeface that will be applied by the web browser.',
255+
'The web browser will only be able to apply a font if it is available on the system',
256+
'which it operates. Provide multiple font families, separated by commas, to indicate',
257+
'the preference in which to apply fonts if they aren\'t available on the system.',
258+
'The plotly service (at https://plot.ly or on-premise) generates images on a server,',
259+
'where only a select number of',
260+
'fonts are installed and supported.',
261+
'These include *Arial*, *Balto*, *Courier New*, *Droid Sans*,, *Droid Serif*,',
262+
'*Droid Sans Mono*, *Gravitas One*, *Old Standard TT*, *Open Sans*, *Overpass*,',
263+
'*PT Sans Narrow*, *Raleway*, *Times New Roman*.'
264+
].join(' ')
265+
},
266+
size: {
267+
valType: 'number',
268+
arrayOk: true,
269+
role: 'style'
270+
},
271+
color: {
272+
valType: 'color',
273+
arrayOk: true,
274+
role: 'style'
275+
}
276+
}
277+
}
278+
}, 'calc', 'from-root');

src/traces/table/base_plot.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plots = require('../../plots/plots');
12+
var tablePlot = require('./plot');
13+
14+
exports.name = 'table';
15+
16+
exports.attr = 'type';
17+
18+
exports.plot = function(gd) {
19+
var calcData = Plots.getSubplotCalcData(gd.calcdata, 'table', 'table');
20+
if(calcData.length) tablePlot(gd, calcData);
21+
};
22+
23+
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
24+
var hadTable = (oldFullLayout._has && oldFullLayout._has('table'));
25+
var hasTable = (newFullLayout._has && newFullLayout._has('table'));
26+
27+
if(hadTable && !hasTable) {
28+
oldFullLayout._paperdiv.selectAll('.table').remove();
29+
}
30+
};

src/traces/table/calc.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var wrap = require('../../lib/gup').wrap;
12+
13+
module.exports = function calc(gd, trace) {
14+
return wrap(trace);
15+
};

0 commit comments

Comments
 (0)