Skip to content

Commit

Permalink
feat(Minimap): Import the Minimap component directly from G6
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoli committed Jan 15, 2019
1 parent d6ef9b1 commit 4bba85e
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions src/components/Minimap/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import React from 'react';
import Editor from '@components/Base/Editor';
import G6 from '@antv/g6';
import { pick } from '@utils';
import { MINIMAP_CONTAINER } from '@common/constants';
import withGGEditorContext from '@common/context/GGEditorContext/withGGEditorContext';

require('@antv/g6/build/plugin.tool.minimap');

const { Minimap: G6Minimap } = G6.Components;

class Minimap extends React.Component {
minimap = null;

get containerId() {
const { editor } = this.props;

return `${MINIMAP_CONTAINER}_${editor.id}`;
}

componentDidMount() {
get currentPage() {
const { editor } = this.props;

return editor.getCurrentPage();
}

constructor(props) {
super(props);

this.bindEvent();
}

componentDidMount() {
this.init();
this.bindPage();
}

init() {
const {
container = this.containerId,
width,
Expand All @@ -23,13 +45,34 @@ class Minimap extends React.Component {

const { clientWidth, clientHeight } = document.getElementById(container);

editor.add(new Editor.Minimap({
this.minimap = new G6Minimap({
container,
width: width || clientWidth,
height: height || clientHeight,
viewportWindowStyle,
viewportBackStyle,
}));
});

this.minimap.getGraph = () => this.currentPage.getGraph();
}

bindPage() {
if (!this.minimap || !this.currentPage) {
return;
}

const graph = this.currentPage.getGraph();

this.minimap.bindGraph(graph);
this.minimap.debounceRender();
}

bindEvent() {
const { onAfterAddPage } = this.props;

onAfterAddPage(() => {
this.bindPage();
});
}

render() {
Expand Down

0 comments on commit 4bba85e

Please sign in to comment.