* Zooms the chart by a specified amount around a specific point * * @param {number} [zoomAmount] The percentage by which to zoom the x and y scale. * A value of 0.9 zooms in by 10%. A value of 1.1 zooms out by 10%. A value of 1 has * no effect. * @param {Plottable.Point} [centerValue]
(zoomAmount: number, centerValue?: Point, constrained = true)
| 135 | * values. Default true. |
| 136 | */ |
| 137 | public zoom(zoomAmount: number, centerValue?: Point, constrained = true) { |
| 138 | let centerX: number; |
| 139 | let centerY: number; |
| 140 | if (centerValue != null) { |
| 141 | centerX = centerValue.x; |
| 142 | centerY = centerValue.y; |
| 143 | if (constrained) { |
| 144 | this.xScales().forEach((xScale) => { |
| 145 | const constrained = this._constrainedZoom(xScale, zoomAmount, centerX); |
| 146 | centerX = constrained.centerPoint; |
| 147 | zoomAmount = constrained.zoomAmount; |
| 148 | }); |
| 149 | |
| 150 | this.yScales().forEach((yScale) => { |
| 151 | const constrained = this._constrainedZoom(yScale, zoomAmount, centerY); |
| 152 | centerY = constrained.centerPoint; |
| 153 | zoomAmount = constrained.zoomAmount; |
| 154 | }); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | this.xScales().forEach((xScale) => { |
| 159 | const range = xScale.range(); |
| 160 | const xCenter = centerX == null |
| 161 | ? (range[1] + range[0]) / 2 |
| 162 | : centerX; |
| 163 | |
| 164 | xScale.zoom(zoomAmount, xCenter); |
| 165 | }); |
| 166 | |
| 167 | this.yScales().forEach((yScale) => { |
| 168 | const range = yScale.range(); |
| 169 | const yCenter = centerY == null |
| 170 | ? (range[1] + range[0]) / 2 |
| 171 | : centerY; |
| 172 | |
| 173 | yScale.zoom(zoomAmount, yCenter); |
| 174 | }); |
| 175 | |
| 176 | this._panZoomUpdateCallbacks.callCallbacks(); |
| 177 | return { zoomAmount, centerValue: { centerX, centerY } }; |
| 178 | } |
| 179 | |
| 180 | protected _anchor(component: Component) { |
| 181 | super._anchor(component); |
no test coverage detected