Skip to content

Commit 8f0f78b

Browse files
committed
table - initial
1 parent d47ace6 commit 8f0f78b

File tree

12 files changed

+1109
-0
lines changed

12 files changed

+1109
-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/traces/table/attributes.js

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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 colorAttributes = require('../../components/colorscale/color_attributes');
12+
var colorbarAttrs = require('../../components/colorbar/attributes');
13+
var colorscales = require('../../components/colorscale/scales');
14+
var axesAttrs = require('../../plots/cartesian/layout_attributes');
15+
var fontAttrs = require('../../plots/font_attributes');
16+
17+
var extendDeep = require('../../lib/extend').extendDeep;
18+
var extendFlat = require('../../lib/extend').extendFlat;
19+
20+
module.exports = {
21+
22+
domain: {
23+
x: {
24+
valType: 'info_array',
25+
role: 'info',
26+
items: [
27+
{valType: 'number', min: 0, max: 1},
28+
{valType: 'number', min: 0, max: 1}
29+
],
30+
dflt: [0, 1],
31+
description: [
32+
'Sets the horizontal domain of this `table` trace',
33+
'(in plot fraction).'
34+
].join(' ')
35+
},
36+
y: {
37+
valType: 'info_array',
38+
role: 'info',
39+
items: [
40+
{valType: 'number', min: 0, max: 1},
41+
{valType: 'number', min: 0, max: 1}
42+
],
43+
dflt: [0, 1],
44+
description: [
45+
'Sets the vertical domain of this `table` trace',
46+
'(in plot fraction).'
47+
].join(' ')
48+
}
49+
},
50+
51+
labelfont: extendFlat({}, fontAttrs, {
52+
description: 'Sets the font for the `dimension` labels.'
53+
}),
54+
55+
dimensions: {
56+
_isLinkedToArray: 'dimension',
57+
label: {
58+
valType: 'string',
59+
role: 'info',
60+
description: 'The shown name of the dimension.'
61+
},
62+
tickvals: axesAttrs.tickvals,
63+
ticktext: axesAttrs.ticktext,
64+
font: extendFlat({}, fontAttrs, {
65+
description: 'Sets the font for the `dimension` values.'
66+
}),
67+
valueformat: {
68+
valType: 'string',
69+
dflt: '3s',
70+
role: 'style',
71+
description: [
72+
'Sets the tick label formatting rule using d3 formatting mini-language',
73+
'which is similar to those of Python. See',
74+
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'
75+
].join(' ')
76+
},
77+
visible: {
78+
valType: 'boolean',
79+
dflt: true,
80+
role: 'info',
81+
description: 'Shows the dimension when set to `true` (the default). Hides the dimension for `false`.'
82+
},
83+
range: {
84+
valType: 'info_array',
85+
role: 'info',
86+
items: [
87+
{valType: 'number'},
88+
{valType: 'number'}
89+
],
90+
description: [
91+
'The domain range for the purpose of coloring. Defaults to the `values` extent.',
92+
'Must be an array of `[fromValue, toValue]` with finite numbers as elements.'
93+
].join(' ')
94+
},
95+
values: {
96+
valType: 'data_array',
97+
role: 'info',
98+
dflt: [],
99+
description: [
100+
'Dimension values. `values[n]` represents the value of the `n`th point in the dataset,',
101+
'therefore the `values` vector for all dimensions must be the same (longer vectors',
102+
'will be truncated). Each value must be a finite number.'
103+
].join(' ')
104+
},
105+
description: 'The dimensions (variables) of the table view.'
106+
},
107+
108+
line: extendFlat({},
109+
110+
// the default autocolorscale is set to Viridis - autocolorscale therefore defaults to false too,
111+
// to avoid being overridden by the blue-white-red autocolor palette
112+
extendDeep(
113+
{},
114+
colorAttributes('line'),
115+
{
116+
colorscale: extendDeep(
117+
{},
118+
colorAttributes('line').colorscale,
119+
{dflt: colorscales.Viridis}
120+
),
121+
autocolorscale: extendDeep(
122+
{},
123+
colorAttributes('line').autocolorscale,
124+
{
125+
dflt: false,
126+
description: [
127+
'Has an effect only if line.color` is set to a numerical array.',
128+
'Determines whether the colorscale is a default palette (`autocolorscale: true`)',
129+
'or the palette determined by `line.colorscale`.',
130+
'In case `colorscale` is unspecified or `autocolorscale` is true, the default ',
131+
'palette will be chosen according to whether numbers in the `color` array are',
132+
'all positive, all negative or mixed.',
133+
'The default value is false, so that `table` colorscale can default to `Viridis`.'
134+
].join(' ')
135+
}
136+
)
137+
138+
}
139+
),
140+
141+
{
142+
showscale: {
143+
valType: 'boolean',
144+
role: 'info',
145+
dflt: false,
146+
description: [
147+
'Has an effect only if `line.color` is set to a numerical array.',
148+
'Determines whether or not a colorbar is displayed.'
149+
].join(' ')
150+
},
151+
colorbar: colorbarAttrs
152+
}
153+
)
154+
};

src/traces/table/base_plot.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 d3 = require('d3');
12+
var Plots = require('../../plots/plots');
13+
var tablePlot = require('./plot');
14+
15+
exports.name = 'table';
16+
17+
exports.attr = 'type';
18+
19+
exports.plot = function(gd) {
20+
var calcData = Plots.getSubplotCalcData(gd.calcdata, 'table', 'table');
21+
if(calcData.length) tablePlot(gd, calcData);
22+
};
23+
24+
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
25+
var hadTable = (oldFullLayout._has && oldFullLayout._has('table'));
26+
var hasTable = (newFullLayout._has && newFullLayout._has('table'));
27+
28+
if(hadTable && !hasTable) {
29+
oldFullLayout._paperdiv.selectAll('.table').remove();
30+
oldFullLayout._paperdiv.selectAll('.table').remove();
31+
oldFullLayout._glimages.selectAll('*').remove();
32+
}
33+
};

src/traces/table/calc.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 hasColorscale = require('../../components/colorscale/has_colorscale');
12+
var calcColorscale = require('../../components/colorscale/calc');
13+
var Lib = require('../../lib');
14+
15+
module.exports = function calc(gd, trace) {
16+
var cs = !!trace.line.colorscale && Lib.isArray(trace.line.color);
17+
var color = cs ? trace.line.color : Array.apply(0, Array(trace.dimensions.reduce(function(p, n) {return Math.max(p, n.values.length);}, 0))).map(function() {return 0.5;});
18+
var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];
19+
20+
if(hasColorscale(trace, 'line')) {
21+
calcColorscale(trace, trace.line.color, 'line', 'c');
22+
}
23+
24+
return [{
25+
lineColor: color,
26+
cscale: cscale
27+
}];
28+
};

src/traces/table/colorbar.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
10+
'use strict';
11+
12+
var isNumeric = require('fast-isnumeric');
13+
14+
var Lib = require('../../lib');
15+
var Plots = require('../../plots/plots');
16+
var Colorscale = require('../../components/colorscale');
17+
var drawColorbar = require('../../components/colorbar/draw');
18+
19+
module.exports = function colorbar(gd, cd) {
20+
var trace = cd[0].trace,
21+
line = trace.line,
22+
cbId = 'cb' + trace.uid;
23+
24+
gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
25+
26+
if((line === undefined) || !line.showscale) {
27+
Plots.autoMargin(gd, cbId);
28+
return;
29+
}
30+
31+
var vals = line.color,
32+
cmin = line.cmin,
33+
cmax = line.cmax;
34+
35+
if(!isNumeric(cmin)) cmin = Lib.aggNums(Math.min, null, vals);
36+
if(!isNumeric(cmax)) cmax = Lib.aggNums(Math.max, null, vals);
37+
38+
var cb = cd[0].t.cb = drawColorbar(gd, cbId);
39+
var sclFunc = Colorscale.makeColorScaleFunc(
40+
Colorscale.extractScale(
41+
line.colorscale,
42+
cmin,
43+
cmax
44+
),
45+
{ noNumericCheck: true }
46+
);
47+
48+
cb.fillcolor(sclFunc)
49+
.filllevels({start: cmin, end: cmax, size: (cmax - cmin) / 254})
50+
.options(line.colorbar)();
51+
};

src/traces/table/constants.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 = {
12+
maxDimensionCount: 60,
13+
overdrag: 45,
14+
columnTitleOffset: 28,
15+
columnExtentOffset: 10,
16+
bar: {
17+
width: 4, // Visible width of the filter bar
18+
capturewidth: 10, // Mouse-sensitive width for interaction (Fitts law)
19+
fillcolor: 'magenta', // Color of the filter bar fill
20+
fillopacity: 1, // Filter bar fill opacity
21+
strokecolor: 'white', // Color of the filter bar side lines
22+
strokeopacity: 1, // Filter bar side stroke opacity
23+
strokewidth: 1, // Filter bar side stroke width in pixels
24+
handleheight: 16, // Height of the filter bar vertical resize areas on top and bottom
25+
handleopacity: 1, // Opacity of the filter bar vertical resize areas on top and bottom
26+
handleoverlap: 0 // A larger than 0 value causes overlaps with the filter bar, represented as pixels.'
27+
}
28+
};

0 commit comments

Comments
 (0)