| 953 | } |
| 954 | |
| 955 | compute_view_padding() { |
| 956 | // This function returns a dictionary with keys as the scales and |
| 957 | // value as the pixel padding required for the rendering of the |
| 958 | // mark. |
| 959 | const domScale = this.domScale; |
| 960 | const orient = this.model.get('orientation'); |
| 961 | let xPadding = 0; |
| 962 | const avail_space = |
| 963 | orient === 'vertical' |
| 964 | ? this.parent.plotareaWidth |
| 965 | : this.parent.plotareaHeight; |
| 966 | if (domScale) { |
| 967 | if ( |
| 968 | this.stackedScale !== null && |
| 969 | this.stackedScale !== undefined && |
| 970 | this.stackedScale.domain().length !== 0 |
| 971 | ) { |
| 972 | if (!isOrdinalScale(domScale)) { |
| 973 | if (this.align === 'center') { |
| 974 | xPadding = |
| 975 | avail_space / (2.0 * this.stackedScale.domain().length) + 1; |
| 976 | } else if (this.align === 'left' || this.align === 'right') { |
| 977 | xPadding = avail_space / this.stackedScale.domain().length + 1; |
| 978 | } |
| 979 | } else { |
| 980 | if (this.align === 'left' || this.align === 'right') { |
| 981 | xPadding = parseFloat( |
| 982 | (this.stackedScale.bandwidth() / 2).toFixed(2) |
| 983 | ); |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | if (orient === 'vertical') { |
| 989 | if (xPadding !== this.xPadding) { |
| 990 | this.xPadding = xPadding; |
| 991 | this.trigger('mark_padding_updated'); |
| 992 | //dispatch the event |
| 993 | } |
| 994 | } else { |
| 995 | if (xPadding !== this.yPadding) { |
| 996 | this.yPadding = xPadding; |
| 997 | this.trigger('mark_padding_updated'); |
| 998 | //dispatch the event |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | private domOffset: number; |
| 1004 | private domScale: LinearScale | OrdinalScale; |