An open API service indexing awesome lists of open source software.

https://github.com/ifvictr/g6-plugin-lazyload-images

🦥 Image lazy-loading plugin for AntV’s G6 engine
https://github.com/ifvictr/g6-plugin-lazyload-images

antv g6 g6-plugin lazy-loading

Last synced: about 1 month ago
JSON representation

🦥 Image lazy-loading plugin for AntV’s G6 engine

Awesome Lists containing this project

README

          

# g6-plugin-lazyload-images

Image lazy-loading plugin for AntV’s [G6](https://github.com/antvis/G6) engine.

Here’s a side-by-side comparison of what a graph might look like, before and after the plugin is added. The network connection is throttled down to fast 3G to highlight the difference:


Before
After








## Installation

```bash
npm install g6-plugin-lazyload-images
```

## Usage

Start off by instantiating the plugin and adding it to the graph:

```js
import G6 from '@antv/g6'
import LazyLoadImages from 'g6-plugin-lazyload-images'

const lazyLoadImages = new LazyLoadImages({
// You can use an external image here, but a data URI is preferable.
placeholder: 'data:image/svg+xml;base64,…'
})

const graph = new G6.Graph({
// Other configurations here…
plugins: [lazyLoadImages]
})
```

To start lazy loading images, you’ll need to make some slight modifications to the image node model when you add it to the graph:

```js
// Before
graph.addItem('node', {
type: 'image',
img: 'https://example.com/myimage.png'
})

// After
graph.addItem('node', {
type: 'image',
img: null,
imgLazy: 'https://example.com/myimage.png'
})
```

It’s imperative that you set the `img` key to `null`. Otherwise, G6 will use its own fallback image before the placeholder is injected and you’ll see a flash of that image.

## License

[MIT License](LICENSE.txt)