Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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';
import { ViewConfig } from '../view-layer';
/**
* 负责图表theme的管理
*/
const G2DefaultTheme = G2.Global.theme;
export default class ThemeController {
/**
* 通过 theme 和图表类型,获取当前 plot 对应的主题
* @param props
* @param type
*/
public getPlotTheme(props: T, type: string) {
const { theme } = props;
if (_.isString(theme)) {
return _.deepMix({}, getGlobalTheme(theme), getTheme(type));
}
return _.deepMix({}, getGlobalTheme(), getTheme(type), theme);
}
/**
/** 简化折线点 */
import * as G2 from '@antv/g2';
import * as _ from '@antv/util';
import { lineSimplification } from '../../util/math';
import { getSplinePath } from '../../util/path';
import LineParser from './main';
const G2DefaultTheme = G2.Global.theme;
G2.registerShape('line', 'miniLine', {
draw(cfg, container) {
const points = lineSimplification(cfg.points);
const path = [];
for (let i = 0; i < points.length; i++) {
const p = points[i];
const flag = i === 0 ? 'M' : 'L';
path.push([flag, p.x, p.y]);
}
const shape = container.addShape('path', {
attrs: _.mix(
{
path,
stroke: cfg.color || G2DefaultTheme.defaultColor,
lineWidth: cfg.size || 2,
ILegend,
ILegendConfig,
ISeries,
ISeriesConfig,
ITooltip,
ITooltipConfig,
IView,
IViewConfig,
IScale,
IMain,
ISlider,
};
export const registerAnimation = CustomizeUtils.registerAnimation;
export const registerShape = CustomizeUtils.registerShape;
export const Global = G2.Global;
function hasDataCondition(config: any) {
let hasData = false;
if (!_.isEmpty(config.data)) {
hasData = true;
}
if (!_.isNil(config.views)) {
if (_.isPlainObject(config.views) && !_.isEmpty(config.views.data)) {
hasData = true;
}
if (_.isArray(config.views)) {
for (const item of config.views) {
if (!_.isEmpty(item.data)) {
function getFillAttrs(cfg: any) {
const defaultAttrs = G2.Global.shape.interval;
const attrs = G2.Util.mix({}, defaultAttrs, {
fill: cfg.color,
stroke: cfg.color,
fillOpacity: cfg.opacity,
}, cfg.style);
return attrs;
}
default: () => {
return G2.Global.colors_pie_16
}
},
/** 简化折线点 */
import * as G2 from '@antv/g2';
import * as _ from '@antv/util';
import { lineSimplification } from '../../util/math';
import { getSplinePath } from '../../util/path';
import AreaParser from './main';
const G2DefaultTheme = G2.Global.theme;
G2.registerShape('area', 'miniArea', {
draw(cfg, container) {
const path = getPath(cfg, this, false);
const shape = container.addShape('path', {
attrs: {
path,
fill: parseGradient(cfg.color || G2DefaultTheme.defaultColor),
opacity: cfg.opacity || 0.4,
},
});
return shape;
},
});
G2.registerShape('area', 'miniAreaSmooth', {