diff --git a/draftlogs/7684_change.md b/draftlogs/7684_change.md new file mode 100644 index 00000000000..93797426c49 --- /dev/null +++ b/draftlogs/7684_change.md @@ -0,0 +1 @@ + - Set default layout.axis.tickmode to 'sync' when axis is overlaying [[#7684](https://github.com/plotly/plotly.js/pull/7684)] \ No newline at end of file diff --git a/src/plots/cartesian/dragbox.js b/src/plots/cartesian/dragbox.js index 0aa0caceee2..e66ec74628d 100644 --- a/src/plots/cartesian/dragbox.js +++ b/src/plots/cartesian/dragbox.js @@ -732,7 +732,10 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { for(i = 0; i < axList.length; i++) { var axListI = axList[i]; var axListIType = axListI[axisType]; - if(!axListI.fixedrange && axListIType.tickmode === 'sync') activeAxIds.push(axListIType._id); + var axId = axListIType._id; + if(!axListI.fixedrange && axListIType.tickmode === 'sync' && !activeAxIds.includes(axId)) { + activeAxIds.push(axId); + } } } diff --git a/src/plots/cartesian/layout_attributes.js b/src/plots/cartesian/layout_attributes.js index d1ce0158ace..d7c207fd21f 100644 --- a/src/plots/cartesian/layout_attributes.js +++ b/src/plots/cartesian/layout_attributes.js @@ -35,7 +35,8 @@ var tickmode = extendFlat({}, minorTickmode, { description: [ minorTickmode.description, 'If *sync*, the number of ticks will sync with the overlayed axis', - 'set by `overlaying` property.' + 'set by `overlaying` property. When no other tick info is provided,', + 'overlaying (non-categorical) axes default to *sync*, while other axes default to *auto*.', ].join(' ') }); diff --git a/src/plots/cartesian/tick_value_defaults.js b/src/plots/cartesian/tick_value_defaults.js index 68b9207ee62..faa2d36f03b 100644 --- a/src/plots/cartesian/tick_value_defaults.js +++ b/src/plots/cartesian/tick_value_defaults.js @@ -5,8 +5,7 @@ var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray; var isTypedArraySpec = require('../../lib/array').isTypedArraySpec; var decodeTypedArraySpec = require('../../lib/array').decodeTypedArraySpec; -module.exports = function handleTickValueDefaults(containerIn, containerOut, coerce, axType, opts) { - if(!opts) opts = {}; +module.exports = function handleTickValueDefaults(containerIn, containerOut, coerce, axType, opts = {}) { var isMinor = opts.isMinor; var cIn = isMinor ? containerIn.minor || {} : containerIn; var cOut = isMinor ? containerOut.minor : containerOut; @@ -14,35 +13,40 @@ module.exports = function handleTickValueDefaults(containerIn, containerOut, coe function readInput(attr) { var v = cIn[attr]; - if(isTypedArraySpec(v)) v = decodeTypedArraySpec(v); + if (isTypedArraySpec(v)) v = decodeTypedArraySpec(v); - return ( - v !== undefined - ) ? v : (cOut._template || {})[attr]; + return v !== undefined ? v : (cOut._template || {})[attr]; } var _tick0 = readInput('tick0'); var _dtick = readInput('dtick'); var _tickvals = readInput('tickvals'); + var _overlaying = readInput('overlaying'); + var _categorical = axType === 'category' || axType === 'multicategory'; - var tickmodeDefault = isArrayOrTypedArray(_tickvals) ? 'array' : - _dtick ? 'linear' : - 'auto'; + var tickmodeDefault; + if (isArrayOrTypedArray(_tickvals)) { + tickmodeDefault = 'array'; + } else if (_dtick) { + tickmodeDefault = 'linear'; + } else if (_overlaying && !_categorical) { + tickmodeDefault = 'sync'; + } else { + tickmodeDefault = 'auto'; + } var tickmode = coerce(prefix + 'tickmode', tickmodeDefault); - if(tickmode === 'auto' || tickmode === 'sync') { + if (tickmode === 'auto' || tickmode === 'sync') { coerce(prefix + 'nticks'); - } else if(tickmode === 'linear') { + } else if (tickmode === 'linear') { // dtick is usually a positive number, but there are some // special strings available for log or date axes // tick0 also has special logic - var dtick = cOut.dtick = cleanTicks.dtick( - _dtick, axType); - cOut.tick0 = cleanTicks.tick0( - _tick0, axType, containerOut.calendar, dtick); - } else if(axType !== 'multicategory') { + var dtick = (cOut.dtick = cleanTicks.dtick(_dtick, axType)); + cOut.tick0 = cleanTicks.tick0(_tick0, axType, containerOut.calendar, dtick); + } else if (axType !== 'multicategory') { var tickvals = coerce(prefix + 'tickvals'); - if(tickvals === undefined) cOut.tickmode = 'auto'; - else if(!isMinor) coerce('ticktext'); + if (tickvals === undefined) cOut.tickmode = 'auto'; + else if (!isMinor) coerce('ticktext'); } }; diff --git a/test/image/baselines/20.png b/test/image/baselines/20.png index 230a6baf8b7..49c76b32f79 100644 Binary files a/test/image/baselines/20.png and b/test/image/baselines/20.png differ diff --git a/test/image/baselines/autorange-tozero-rangemode.png b/test/image/baselines/autorange-tozero-rangemode.png index ebc57f4d8d2..138d26a311b 100644 Binary files a/test/image/baselines/autorange-tozero-rangemode.png and b/test/image/baselines/autorange-tozero-rangemode.png differ diff --git a/test/image/baselines/candlestick_double-y-axis.png b/test/image/baselines/candlestick_double-y-axis.png index 077f3b8fab0..34d4f43bab1 100644 Binary files a/test/image/baselines/candlestick_double-y-axis.png and b/test/image/baselines/candlestick_double-y-axis.png differ diff --git a/test/image/baselines/candlestick_rangeslider_thai.png b/test/image/baselines/candlestick_rangeslider_thai.png index f40e1cdd0ef..345a3e4dab5 100644 Binary files a/test/image/baselines/candlestick_rangeslider_thai.png and b/test/image/baselines/candlestick_rangeslider_thai.png differ diff --git a/test/image/baselines/legend_scroll_beyond_plotarea.png b/test/image/baselines/legend_scroll_beyond_plotarea.png index 677421dd0ff..51ecafd947b 100644 Binary files a/test/image/baselines/legend_scroll_beyond_plotarea.png and b/test/image/baselines/legend_scroll_beyond_plotarea.png differ diff --git a/test/image/baselines/legend_visibility.png b/test/image/baselines/legend_visibility.png index e80069a9c02..bbdb2156d96 100644 Binary files a/test/image/baselines/legend_visibility.png and b/test/image/baselines/legend_visibility.png differ diff --git a/test/image/baselines/mult-yaxes-subplots-stacked.png b/test/image/baselines/mult-yaxes-subplots-stacked.png index 5aac4b389cd..855dcde1bf3 100644 Binary files a/test/image/baselines/mult-yaxes-subplots-stacked.png and b/test/image/baselines/mult-yaxes-subplots-stacked.png differ diff --git a/test/image/baselines/multicategory_series.png b/test/image/baselines/multicategory_series.png index dfbe24abe2e..7e4b0c8edf0 100644 Binary files a/test/image/baselines/multicategory_series.png and b/test/image/baselines/multicategory_series.png differ diff --git a/test/image/baselines/range_slider_legend_left.png b/test/image/baselines/range_slider_legend_left.png index 9eb5c4457ff..d35f8c99b28 100644 Binary files a/test/image/baselines/range_slider_legend_left.png and b/test/image/baselines/range_slider_legend_left.png differ diff --git a/test/image/baselines/yaxis-over-yaxis2.png b/test/image/baselines/yaxis-over-yaxis2.png index 175f1c39adb..6d3398ef7aa 100644 Binary files a/test/image/baselines/yaxis-over-yaxis2.png and b/test/image/baselines/yaxis-over-yaxis2.png differ diff --git a/test/image/baselines/zerolinelayer_above.png b/test/image/baselines/zerolinelayer_above.png index 10fca3a7e8c..6e4490680da 100644 Binary files a/test/image/baselines/zerolinelayer_above.png and b/test/image/baselines/zerolinelayer_above.png differ diff --git a/test/image/baselines/zerolinelayer_below.png b/test/image/baselines/zerolinelayer_below.png index d011848fa65..9e43516c183 100644 Binary files a/test/image/baselines/zerolinelayer_below.png and b/test/image/baselines/zerolinelayer_below.png differ diff --git a/test/image/mocks/shapes_layer_below_traces.json b/test/image/mocks/shapes_layer_below_traces.json index 9b221568538..049b66b9c4c 100644 --- a/test/image/mocks/shapes_layer_below_traces.json +++ b/test/image/mocks/shapes_layer_below_traces.json @@ -103,7 +103,8 @@ "yaxis2": { "gridwidth": 2, "side": "right", - "overlaying": "y" + "overlaying": "y", + "tickmode": "auto" } } } diff --git a/test/plot-schema.json b/test/plot-schema.json index 86964d4f5e9..5ae14291f41 100644 --- a/test/plot-schema.json +++ b/test/plot-schema.json @@ -14867,7 +14867,7 @@ "valType": "number" }, "tickmode": { - "description": "Sets the tick mode for this axis. If *auto*, the number of ticks is set via `nticks`. If *linear*, the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick` (*linear* is the default value if `tick0` and `dtick` are provided). If *array*, the placement of the ticks is set via `tickvals` and the tick text is `ticktext`. (*array* is the default value if `tickvals` is provided). If *sync*, the number of ticks will sync with the overlayed axis set by `overlaying` property.", + "description": "Sets the tick mode for this axis. If *auto*, the number of ticks is set via `nticks`. If *linear*, the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick` (*linear* is the default value if `tick0` and `dtick` are provided). If *array*, the placement of the ticks is set via `tickvals` and the tick text is `ticktext`. (*array* is the default value if `tickvals` is provided). If *sync*, the number of ticks will sync with the overlayed axis set by `overlaying` property. When no other tick info is provided, overlaying (non-categorical) axes default to *sync*, while other axes default to *auto*.", "editType": "ticks", "impliedEdits": {}, "valType": "enumerated", @@ -16146,7 +16146,7 @@ "valType": "number" }, "tickmode": { - "description": "Sets the tick mode for this axis. If *auto*, the number of ticks is set via `nticks`. If *linear*, the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick` (*linear* is the default value if `tick0` and `dtick` are provided). If *array*, the placement of the ticks is set via `tickvals` and the tick text is `ticktext`. (*array* is the default value if `tickvals` is provided). If *sync*, the number of ticks will sync with the overlayed axis set by `overlaying` property.", + "description": "Sets the tick mode for this axis. If *auto*, the number of ticks is set via `nticks`. If *linear*, the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick` (*linear* is the default value if `tick0` and `dtick` are provided). If *array*, the placement of the ticks is set via `tickvals` and the tick text is `ticktext`. (*array* is the default value if `tickvals` is provided). If *sync*, the number of ticks will sync with the overlayed axis set by `overlaying` property. When no other tick info is provided, overlaying (non-categorical) axes default to *sync*, while other axes default to *auto*.", "editType": "ticks", "impliedEdits": {}, "valType": "enumerated",