@antv/g2plot
Version:
G2 Plot, a market of plots built with the Grammar of Graphics'
60 lines • 2.06 kB
JavaScript
import * as G2 from '@antv/g2';
import * as _ from '@antv/util';
// import Theme from '../../theme';
import { convertToG2Theme, getGlobalTheme, getTheme } from '../../theme';
import { processAxisVisible } from '../../util/axis';
import { getResponsiveTheme } from '../../util/responsive/theme';
/**
* 负责图表theme的管理
*/
var G2DefaultTheme = G2.Global.theme;
var ThemeController = /** @class */ (function () {
function ThemeController() {
}
/**
* 获取指定的全局theme
* @param theme
*/
ThemeController.getGlobalTheme = function (theme) {
if (_.isString(theme)) {
return getGlobalTheme(theme);
}
return _.deepMix({}, getGlobalTheme(), theme);
};
/**
* 通过 theme 和图表类型,获取当前 plot 对应的主题
* @param props
* @param type
*/
ThemeController.prototype.getPlotTheme = function (props, type) {
var theme = props.theme;
if (_.isString(theme)) {
return _.deepMix({}, getGlobalTheme(theme), getTheme(type));
}
return _.deepMix({}, getGlobalTheme(), getTheme(type), theme);
};
/**
* 获取转化成 G2 的结构主题
* @param props
* @param type
*/
ThemeController.prototype.getTheme = function (props, type) {
var plotG2Theme = convertToG2Theme(this.getPlotTheme(props, type));
var g2Theme = _.deepMix({}, G2DefaultTheme, plotG2Theme);
// this._processVisible(g2Theme);
return g2Theme;
};
ThemeController.prototype.getResponsiveTheme = function (type) {
return getResponsiveTheme(type) || getResponsiveTheme('default');
};
ThemeController.prototype._processVisible = function (theme) {
processAxisVisible(theme.axis.left);
processAxisVisible(theme.axis.right);
processAxisVisible(theme.axis.top);
processAxisVisible(theme.axis.bottom);
return theme;
};
return ThemeController;
}());
export default ThemeController;
//# sourceMappingURL=theme.js.map