Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*
* @param {Element} element - param for Dygraph constructor
* @param {Array} data - param for Dygraph constructor
* @param {Object} options - param for Dygraph constructor
* @param {Function} yAxisRangeCalculate - takes a dygraph
* returns a [min, max] y axis range
*/
function CustomDygraph(element, data, options, yAxisRangeCalculate) {
// This code uses prototype syntax rather than class syntax because it needs
// to set `this.yAxisRangeCalculate_` before calling the Dygraph constructor,
// which isn't possible with class syntax.
this.yAxisRangeCalculate_ = yAxisRangeCalculate;
Dygraph.call(this, element, data, options);
}
CustomDygraph.prototype = Object.create(Dygraph.prototype);
CustomDygraph.prototype.drawGraph_ = function () {
let yExtentAdjusted = this.yAxisRangeCalculate_(this);
// Change it directly. Using `updateOptions` won't work. If it causes a
// redraw, there's a stack overflow. With blockRedraw=true, it doesn't update
// the axes. Avoid using a valueRange in the options if you're using a
// CustomDygraph.
this.axes_[0].valueRange = yExtentAdjusted;
this.axes_[0].computedValueRange = yExtentAdjusted;
this.axes_[0].extremeRange = yExtentAdjusted.map(
(v) => v - yExtentAdjusted[0]
);
Dygraph.prototype.drawGraph_.call(this);
};
CustomDygraph.prototype.drawGraph_ = function () {
let yExtentAdjusted = this.yAxisRangeCalculate_(this);
// Change it directly. Using `updateOptions` won't work. If it causes a
// redraw, there's a stack overflow. With blockRedraw=true, it doesn't update
// the axes. Avoid using a valueRange in the options if you're using a
// CustomDygraph.
this.axes_[0].valueRange = yExtentAdjusted;
this.axes_[0].computedValueRange = yExtentAdjusted;
this.axes_[0].extremeRange = yExtentAdjusted.map(
(v) => v - yExtentAdjusted[0]
);
Dygraph.prototype.drawGraph_.call(this);
};