You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.4 KiB
64 lines
2.4 KiB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
import { omit } from '@antv/util';
|
|
import { BasePlugin } from '../base-plugin';
|
|
import { createPluginContainer } from '../utils/dom';
|
|
/**
|
|
* <zh/> 背景图
|
|
*
|
|
* <en/> Background image
|
|
* @remarks
|
|
* <zh/> 支持为图画布设置一个背景图片,让画布更有层次感、叙事性。
|
|
*
|
|
* <en/> Support setting a background image for the canvas to make the canvas more hierarchical and narrative.
|
|
*/
|
|
export class Background extends BasePlugin {
|
|
constructor(context, options) {
|
|
super(context, Object.assign({}, Background.defaultOptions, options));
|
|
this.$element = createPluginContainer('background');
|
|
const $container = this.context.canvas.getContainer();
|
|
$container.prepend(this.$element);
|
|
this.update(options);
|
|
}
|
|
/**
|
|
* <zh/> 更新背景图配置
|
|
*
|
|
* <en/> Update the background image configuration
|
|
* @param options - <zh/> 配置项 | <en/> Options
|
|
* @internal
|
|
*/
|
|
update(options) {
|
|
const _super = Object.create(null, {
|
|
update: { get: () => super.update }
|
|
});
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
_super.update.call(this, options);
|
|
// Set the background style.
|
|
Object.assign(this.$element.style, omit(this.options, ['key', 'type']));
|
|
});
|
|
}
|
|
/**
|
|
* <zh/> 销毁背景图
|
|
*
|
|
* <en/> Destroy the background image
|
|
* @internal
|
|
*/
|
|
destroy() {
|
|
super.destroy();
|
|
// Remove the background dom.
|
|
this.$element.remove();
|
|
}
|
|
}
|
|
Background.defaultOptions = {
|
|
transition: 'background 0.5s',
|
|
backgroundSize: 'cover',
|
|
zIndex: '-1', // aviod to cover the other plugin's dom, eg: grid-line.
|
|
};
|
|
//# sourceMappingURL=index.js.map
|