'use strict'; var Lib = require('../../lib'); var constants = require('../scatter/constants'); var subTypes = require('../scatter/subtypes'); var handleMarkerDefaults = require('../scatter/marker_defaults'); var handleLineDefaults = require('../scatter/line_defaults'); var handleLineShapeDefaults = require('../scatter/line_shape_defaults'); var handleTextDefaults = require('../scatter/text_defaults'); var handleFillColorDefaults = require('../scatter/fillcolor_defaults'); var attributes = require('./attributes'); module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) { function coerce(attr, dflt) { return Lib.coerce(traceIn, traceOut, attributes, attr, dflt); } coerce('carpet'); // XXX: Don't hard code this traceOut.xaxis = 'x'; traceOut.yaxis = 'y'; var a = coerce('a'); var b = coerce('b'); var len = Math.min(a.length, b.length); if(!len) { traceOut.visible = false; return; } traceOut._length = len; coerce('text'); coerce('texttemplate'); coerce('hovertext'); var defaultMode = len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines'; coerce('mode', defaultMode); if(subTypes.hasMarkers(traceOut)) { handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {gradient: true}); } if(subTypes.hasLines(traceOut)) { handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce, {backoff: true}); handleLineShapeDefaults(traceIn, traceOut, coerce); coerce('connectgaps'); } if(subTypes.hasText(traceOut)) { handleTextDefaults(traceIn, traceOut, layout, coerce); } var dfltHoverOn = []; if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) { coerce('marker.maxdisplayed'); dfltHoverOn.push('points'); } coerce('fill'); if(traceOut.fill !== 'none') { handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce); if(!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce); } if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') { dfltHoverOn.push('fills'); } var hoverOn = coerce('hoveron', dfltHoverOn.join('+') || 'points'); if(hoverOn !== 'fills') coerce('hovertemplate'); coerce('zorder'); Lib.coerceSelectionMarkerOpacity(traceOut, coerce); };