Skip to content

Commit 5cd86fc

Browse files
committed
ternary scaffolding
1 parent 6b4af04 commit 5cd86fc

File tree

6 files changed

+149
-2
lines changed

6 files changed

+149
-2
lines changed

src/plot_api/plot_api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ Plotly.plot = function(gd, data, layout, config) {
280280
if(fullLayout._hasCartesian || fullLayout._hasPie) {
281281
plotRegistry.cartesian.plot(gd);
282282
}
283+
if(fullLayout._hasTernary) plotRegistry.ternary.plot(gd);
283284

284285
// clean up old scenes that no longer have associated data
285286
// will this be a performance hit?
@@ -2595,7 +2596,8 @@ function makePlotFramework(gd) {
25952596

25962597
if(fullLayout._hasCartesian) makeCartesianPlotFramwork(gd, subplots);
25972598

2598-
// single shape and pie layers for the whole plot
2599+
// single ternary, shape and pie layers for the whole plot
2600+
fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true);
25992601
fullLayout._shapelayer = fullLayout._paper.append('g').classed('shapelayer', true);
26002602
fullLayout._pielayer = fullLayout._paper.append('g').classed('pielayer', true);
26012603

src/plots/layout_attributes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ module.exports = {
188188
valType: 'boolean',
189189
dflt: false
190190
},
191+
_hasTernary: {
192+
valType: 'boolean',
193+
dflt: false
194+
},
191195
_composedModules: {
192196
'*': 'Fx'
193197
},
@@ -200,6 +204,7 @@ module.exports = {
200204
'geo': 'geo',
201205
'legend': 'Legend',
202206
'annotations': 'Annotations',
203-
'shapes': 'Shapes'
207+
'shapes': 'Shapes',
208+
'ternary': 'ternary'
204209
}
205210
};

src/plots/plots.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ plots.supplyDefaults = function(gd) {
470470
else if(plots.traceIs(fullTrace, 'geo')) newFullLayout._hasGeo = true;
471471
else if(plots.traceIs(fullTrace, 'pie')) newFullLayout._hasPie = true;
472472
else if(plots.traceIs(fullTrace, 'gl2d')) newFullLayout._hasGL2D = true;
473+
else if(plots.traceIs(fullTrace, 'ternary')) newFullLayout._hasTernary = true;
473474
else if('r' in fullTrace) newFullLayout._hasPolar = true;
474475

475476
_module = fullTrace._module;
@@ -714,6 +715,7 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) {
714715
coerce('_hasGeo');
715716
coerce('_hasPie');
716717
coerce('_hasGL2D');
718+
coerce('_hasTernary');
717719
};
718720

719721
plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) {

src/plots/ternary/index.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright 2012-2016, 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 Ternary = require('./ternary');
13+
14+
var Plots = require('../../plots/plots');
15+
16+
17+
exports.name = 'ternary';
18+
19+
exports.attr = 'ternary';
20+
21+
exports.idRoot = 'ternary';
22+
23+
exports.idRegex = /^ternary([2-9]|[1-9][0-9]+)?$/;
24+
25+
exports.attrRegex = /^ternary([2-9]|[1-9][0-9]+)?$/;
26+
27+
exports.attributes = require('./layout/attributes');
28+
29+
exports.layoutAttributes = require('./layout/layout_attributes');
30+
31+
exports.supplyLayoutDefaults = require('./layout/defaults');
32+
33+
exports.plot = function plotTernary(gd) {
34+
var fullLayout = gd._fullLayout,
35+
fullData = gd._fullData,
36+
ternaryIds = Plots.getSubplotIds(fullLayout, 'ternary');
37+
38+
for(var i = 0; i < ternaryIds.length; i++) {
39+
var ternaryId = ternaryIds[i],
40+
fullTernaryData = Plots.getSubplotData(fullData, 'ternary', ternaryId),
41+
ternary = fullLayout[ternaryId]._ternary;
42+
43+
// If ternary is not instantiated, create one!
44+
if(ternary === undefined) {
45+
ternary = new Ternary({
46+
id: ternaryId,
47+
graphDiv: gd,
48+
container: fullLayout._ternarycontainer.node()
49+
},
50+
fullLayout
51+
);
52+
53+
fullLayout[ternaryId]._ternary = ternary;
54+
}
55+
56+
ternary.plot(fullTernaryData, fullLayout, gd._promises);
57+
}
58+
};
59+
60+
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
61+
var oldTernaryKeys = Plots.getSubplotIds(oldFullLayout, 'ternary');
62+
63+
for(var i = 0; i < oldTernaryKeys.length; i++) {
64+
var oldTernaryKey = oldTernaryKeys[i];
65+
var oldTernary = oldFullLayout[oldTernaryKey]._ternary;
66+
67+
if(!newFullLayout[oldTernaryKey] && !!oldTernary) {
68+
oldTernary.ternaryDiv.remove();
69+
}
70+
}
71+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2012-2016, 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 Lib = require('../../../lib');
13+
var layoutAttributes = require('./axis_attributes');
14+
15+
var axesNames = ['aaxis', 'baxis', 'caxis'];
16+
17+
18+
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {
19+
var containerIn, containerOut;
20+
21+
function coerce(attr, dflt) {
22+
return Lib.coerce(containerIn, containerOut, layoutAttributes, attr, dflt);
23+
}
24+
25+
for(var j = 0; j < axesNames.length; j++) {
26+
var axName = axesNames[j];
27+
containerIn = layoutIn[axName] || {};
28+
29+
containerOut = {
30+
_name: axName
31+
};
32+
33+
// TODO - what can we reuse from cartesian?
34+
}
35+
};

src/plots/ternary/layout/defaults.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright 2012-2016, 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 handleSubplotDefaults = require('../../subplot_defaults');
13+
var layoutAttributes = require('./layout_attributes');
14+
var supplyTernaryAxisLayoutDefaults = require('./axis_defaults');
15+
16+
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
17+
if(!layoutOut._hasTernary) return;
18+
19+
handleSubplotDefaults(layoutIn, layoutOut, fullData, {
20+
type: 'ternary',
21+
attributes: layoutAttributes,
22+
handleDefaults: handleTernaryDefaults,
23+
font: layoutOut.font
24+
});
25+
};
26+
27+
function handleTernaryDefaults(ternaryLayoutIn, ternaryLayoutOut, coerce, options) {
28+
coerce('bgcolor');
29+
coerce('sum');
30+
31+
supplyTernaryAxisLayoutDefaults(ternaryLayoutIn, ternaryLayoutOut, options);
32+
}

0 commit comments

Comments
 (0)