@carbon/charts
Version:
Carbon charting components
79 lines • 3.1 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// Internal Imports
import * as Configuration from './configuration';
import { ChartModel } from './model';
import { Tools } from './tools';
/** The meter chart model layer which extends some of the data setting options.
* Meter only uses 1 dataset
* */
var MeterChartModel = /** @class */ (function (_super) {
__extends(MeterChartModel, _super);
function MeterChartModel(services) {
return _super.call(this, services) || this;
}
MeterChartModel.prototype.generateDataLabels = function (newData) {
var dataLabels = {};
dataLabels[newData.label] = Configuration.legend.items.status.ACTIVE;
return dataLabels;
};
MeterChartModel.prototype.getDisplayData = function () {
if (!this.get('data')) {
return null;
}
// meter only uses displays one data group and value
return this.get('data')[0];
};
/**
* Use a provided color for the bar or default to carbon color if no status provided.
* Defaults to carbon color otherwise.
* @param group dataset group label
*/
MeterChartModel.prototype.getFillColor = function (group) {
var options = this.getOptions();
var userProvidedScale = Tools.getProperty(options, 'color', 'scale');
var status = this.getStatus();
// user provided a fill color or there isn't a status we can use the colorScale
if (userProvidedScale || !status) {
return _super.prototype.getFillColor.call(this, group);
}
else {
return null;
}
};
/**
* Get the associated status for the data by checking the ranges
*/
MeterChartModel.prototype.getStatus = function () {
var options = this.getOptions();
var dataValue = this.getDisplayData().value;
// use max value if the percentage is bigger than 100%
var boundedValue = dataValue > 100 ? 100 : dataValue;
// user needs to supply ranges
var allRanges = Tools.getProperty(options, 'meter', 'status', 'ranges');
if (allRanges) {
var result = allRanges.filter(function (step) {
return step.range[0] <= boundedValue &&
boundedValue <= step.range[1];
});
if (result.length > 0) {
return result[0].status;
}
}
return null;
};
return MeterChartModel;
}(ChartModel));
export { MeterChartModel };
//# sourceMappingURL=../src/model-meter.js.map