()
| 121 | } |
| 122 | |
| 123 | fit() { |
| 124 | const {options, ctx} = this; |
| 125 | |
| 126 | // The legend may not be displayed for a variety of reasons including |
| 127 | // the fact that the defaults got set to `false`. |
| 128 | // When the legend is not displayed, there are no guarantees that the options |
| 129 | // are correctly formatted so we need to bail out as early as possible. |
| 130 | if (!options.display) { |
| 131 | this.width = this.height = 0; |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | const labelOpts = options.labels; |
| 136 | const labelFont = toFont(labelOpts.font); |
| 137 | const fontSize = labelFont.size; |
| 138 | const titleHeight = this._computeTitleHeight(); |
| 139 | const {boxWidth, itemHeight} = getBoxSize(labelOpts, fontSize); |
| 140 | |
| 141 | let width, height; |
| 142 | |
| 143 | ctx.font = labelFont.string; |
| 144 | |
| 145 | if (this.isHorizontal()) { |
| 146 | width = this.maxWidth; // fill all the width |
| 147 | height = this._fitRows(titleHeight, fontSize, boxWidth, itemHeight) + 10; |
| 148 | } else { |
| 149 | height = this.maxHeight; // fill all the height |
| 150 | width = this._fitCols(titleHeight, labelFont, boxWidth, itemHeight) + 10; |
| 151 | } |
| 152 | |
| 153 | this.width = Math.min(width, options.maxWidth || this.maxWidth); |
| 154 | this.height = Math.min(height, options.maxHeight || this.maxHeight); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * @private |
no test coverage detected