|
| 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 Lib = require('../../lib'); |
| 12 | +var Axes = require('../../plots/cartesian/axes'); |
| 13 | +var attributes = require('./attributes'); |
| 14 | + |
| 15 | +module.exports = function convert(scene) { |
| 16 | + var fullSceneLayout = scene.fullSceneLayout; |
| 17 | + var anns = fullSceneLayout.annotations; |
| 18 | + |
| 19 | + for(var i = 0; i < anns.length; i++) { |
| 20 | + mockAnnAxes(anns[i], scene); |
| 21 | + } |
| 22 | + |
| 23 | + scene.fullLayout._infolayer |
| 24 | + .selectAll('.annotation-' + scene.id) |
| 25 | + .remove(); |
| 26 | +}; |
| 27 | + |
| 28 | +function mockAnnAxes(ann, scene) { |
| 29 | + var fullSceneLayout = scene.fullSceneLayout; |
| 30 | + var domain = fullSceneLayout.domain; |
| 31 | + var size = scene.fullLayout._size; |
| 32 | + |
| 33 | + var base = { |
| 34 | + // this gets fill in on render |
| 35 | + pdata: null, |
| 36 | + |
| 37 | + // to get setConvert to not execute cleanly |
| 38 | + type: 'linear', |
| 39 | + |
| 40 | + // don't try to update them on `editable: true` |
| 41 | + autorange: false, |
| 42 | + |
| 43 | + // set infinite range so that annotation draw routine |
| 44 | + // does not try to remove 'outside-range' annotations, |
| 45 | + // this case is handled in the render loop |
| 46 | + range: [-Infinity, Infinity] |
| 47 | + }; |
| 48 | + |
| 49 | + ann._xa = {}; |
| 50 | + Lib.extendFlat(ann._xa, base); |
| 51 | + Axes.setConvert(ann._xa); |
| 52 | + ann._xa._offset = size.l + domain.x[0] * size.w; |
| 53 | + ann._xa.l2p = function() { |
| 54 | + return 0.5 * (1 + ann.pdata[0] / ann.pdata[3]) * size.w * (domain.x[1] - domain.x[0]); |
| 55 | + }; |
| 56 | + |
| 57 | + ann._ya = {}; |
| 58 | + Lib.extendFlat(ann._ya, base); |
| 59 | + Axes.setConvert(ann._ya); |
| 60 | + ann._ya._offset = size.t + (1 - domain.y[1]) * size.h; |
| 61 | + ann._ya.l2p = function() { |
| 62 | + return 0.5 * (1 - ann.pdata[1] / ann.pdata[3]) * size.h * (domain.y[1] - domain.y[0]); |
| 63 | + }; |
| 64 | + |
| 65 | + // or do something more similar to 2d |
| 66 | + // where Annotations.supplyLayoutDefaults is called after in Plots.doCalcdata |
| 67 | + // if category axes are found. |
| 68 | + function coerce(attr, dflt) { |
| 69 | + return Lib.coerce(ann, ann, attributes, attr, dflt); |
| 70 | + } |
| 71 | + |
| 72 | + function coercePosition(axLetter) { |
| 73 | + var axName = axLetter + 'axis'; |
| 74 | + |
| 75 | + // mock in such way that getFromId grabs correct 3D axis |
| 76 | + var gdMock = { _fullLayout: {} }; |
| 77 | + gdMock._fullLayout[axName] = fullSceneLayout[axName]; |
| 78 | + |
| 79 | + return Axes.coercePosition(ann, gdMock, coerce, axLetter, axLetter, 0.5); |
| 80 | + } |
| 81 | + |
| 82 | + coercePosition('x'); |
| 83 | + coercePosition('y'); |
| 84 | + coercePosition('z'); |
| 85 | +} |
0 commit comments