npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-picture-mosaic

v1.2.14

Published

A simple animated picture mosaic.

Downloads

24

Readme

React Picture Mosaic

React Picture Mosaic is a simple animated picture mosaic.

react-picture-mosaic

A example can be found here.

Getting Started

Install

npm i --save react-picture-mosaic

Basic usage

import PictureMosaic from "react-picture-mosaic";

const loadTileImage = (column, row) => {
  return "https://path.to.image"
}


const containerStyle = {
  position: "absolute",
  top: "0",
  left: "0",
  margin: "50px",
  width: "500px",
  height: "350px"
}

// The container needs to have a height and width, otherwise nothing will be shown.
<div style={containerStyle}>
    <PictureMosaic
      columns={15}
      rows={10}
      mosaicImage={"https://path.to.image"}
      loadTileImage={loadTileImage}
      imageInterval={3000}
    />
</div>

Custom blend mode

const overlayStyle = {
  mixBlendMode: "color-burn",
}

<PictureMosaic
  // required params...
  overlayStyle={overlayStyle}
/>

Custom image positioning

It is possible to overwrite the algorithm which places the images.

This will place the images completely random.

const nextTileTarget =  (previousColumn, previousRow, config) => {
  const maxIndex = config.columns * config.rows
  const randomIndex = Math.floor(Math.random()*(maxIndex + 1))
  const column = randomIndex % config.columns
  const row = Math.floor(randomIndex / config.columns)

  return {
    column,
    row
  }
}

<PictureMosaic
  // required params...
  nextTileTarget={nextTileTarget}
/>

Custom animation

It is also possible to create some custom animations, just mind that every property you want to animate, has to be present in the createTileStyle as well.

Also keep in mind that delays and animation duration are not respected by the interval.

Besides the normal css attributes, there are some react-spring attributes like delay or {config: duration}.

const createTileStyle = (x, y, width, height) => {
  return {
    zIndex: 400,
    opacity: 0.3,
    width: `${width}px`,
    height: `${height}px`,
    transform: `translate(${x}px, ${y}px)`
  }
}

const createTileAnimations = (column, row, element, gridRect, config) => {
  const width = Math.round((gridRect?.width || 1) / config.columns)
  const height = Math.round((gridRect?.height || 1) / config.rows)
  const translateX = column * width
  const translateY = row * height

  const elementRect = element.getBoundingClientRect()
  const previewWidth = gridRect.width / 4
  const previewHeight = gridRect.height / 4
  const previewTranslateX = gridRect.width - (previewWidth)
  const previewTranslateY = gridRect.height - (previewHeight)

  return [
    {
      delay: 0,
      config: {
        duration: 0
      },
      zIndex: 500,
      opacity: 1,
      width: `${previewWidth}px`,
      height: `${previewHeight}px`,
      transform: `translate(${previewTranslateX}px, ${previewTranslateY}px)`
    },
    {
      delay: 2000,
      config: {
        duration: 1000
      },
      zIndex: 400,
      opacity: 0.3,
      width: `${width}px`,
      height: `${height}px`,
      transform: `translate(${translateX}px, ${translateY}px)`
    }
  ]
}

<PictureMosaic
  // required params...
  createTileStyle={createTileStyle}
  createTileAnimations={createTileAnimations}
/>

Parameters

For further customization reference the parameters below.

Required Parameters

columns: number

Number of columns for the grid

rows: number

Number of rows for the grid

mosaicImage: string

Image which the whole mosaic builds up to

loadTileImage: (column: number, row: number) => string

Called everytime a new image is added two the grid, where column and row is the targeted tile position. This should return the path to the image that should be shown on this tile.

imageInterval: number

Interval (in milliseconds) in which new images will appear. Note that this interval is not the time between new images. So if the interval is 3 seconds but the image animation takes 5 then you will have two overlapping animations

Optional Parameters

imageSeed?: string[]

It is possible to seed the mosaic with images, this then should just be an array of paths.

loop?: boolean

default: true If true then new images will be added even if every tile of the mosaic has a image.

overlayStyle?: CSSProperties

Styles for the overlay image.

blockingTileStyle?: CSSProperties

Before a tile is set to an image, it is blocked by another tile, which is just white. You can overwrite the style of those blocking tiles trough this.

createTileStyle?: (x: number, y: number, width: number, height: number) => CSSProperties

So that css properties can be animated, they have to appear here. (The default can be found here)

createTileAnimations?: (column: number, row: number, element: HTMLElement, gridRect: DOMRect, config: MosaicConfig) => any[]

Return an array of css properties and also there is the option for some additional react-spring properties (version 9). (The default can be found here)

canvasStyle: CSSProperties

After tiles are animated, they will be drawn to a canvas, that canvas can be styled trough this property.

drawTileToCanvas?: (canvas: any, image: MosaicImage, width, height, x, y) => void

After tiles are animated, they will be drawn to a canvas, you can handle how images will be drawn on the canvas trough this property. (The default can be found here)

nextTileTarget?: (previousColumn: number, previousRow: number, config: MosaicConfig) => { column: number, row: number }

Trough this it is possible to define the next target tile, where the next image will be placed in. (The default can be found here)