3.3.0 • Published 3 years ago

@coddicat/vue-map-hexagon v3.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

vue-map-hexagon

Vue component for displaying a map/grid of hexagons. The component supports scrolling and scaling.

example:

https://vue-map-hexagon.coddicat.com/

Installation

npm i @coddicat/vue-map-hexagon

Dependencies

The component uses following external components:

  • @coddicat/vue-pinch-scroll-zoom
  • @coddicat/vue-hexagon

Usage without slot with cells prop

template:

  <MapHexagon
    :item-size="100"
    :items-gap="5"
    :center="[0, 0]"
    :cells="cells"
    style="border: 1px solid black"
    @click="onClick"
  >
  </MapHexagon>

type script:

  import { Component, Vue } from "vue-property-decorator";
  import MapHexagon, { HexagonCell } from "@coddicat/vue-map-hexagon";
  
  //get array of cells
  function generateCells(): HexagonCell[] {
    const cells = Array<HexagonCell>();
    let index = 0;
    for (let col = -5; col <= 5; col++)
      for (let row = -5; row <= 5; row++) {
        cells.push({
          row: row,
          col: col,
          index: index,
          borderSize: 1,
          text: `#${index} <br/> (${col}, ${row})`,
          textStyle: { "text-align": "center" },
          hexagonClass: undefined,
          borderColor: undefined,
          backgroundColor: undefined,
          backgroundImage: undefined,
        });
        index++;
      }
    return cells;
  }

  @Component({
    name: "MapHexagonExample",
    components: {
      MapHexagon
    },
  })
  export default class MapHexagonExample extends Vue {
    private cells: HexagonCell[] = generateCells();
    public onClick(cell: HexagonCell): void {
      alert(`Clicked #${cell.index}`);
    }
  }

Usage with a slot and with component @coddicat/vue-hexagon

(can be replaced with whatever you want) template:

  <HexagonMap
      :scale="scale"
      :center="center"
      :x-range="[-5, 10]"
      :y-range="[-10, 15]"
      :item-size="120"
      :items-gap="10"
      style="border: 1px solid black"
  >
      <template slot-scope="{ index, itemSize, col, row }">
        <Hexagon :size="itemSize" :border-size="1">
          <span>
            {{ index }} <br/> 
            ({{ col }}, {{ row }})
          </span>
        </Hexagon>
      </template>
  </HexagonMap>

type script:

  import { Component, Vue } from "vue-property-decorator";
  import MapHexagon from "@coddicat/vue-map-hexagon";
  import Hexagon from "@coddicat/vue-hexagon";
  
  @Component({
    name: "MapHexagonExample",
    components: {
      MapHexagon,
      Hexagon
    },
  })
  export default class MapHexagonExample extends Vue {
    private scale: number = 1;
    private center: number[] = [3, 3];
    
    public reset(): void {
      this.scale = 1;
      this.center = [3, 3];
      const map = this.$refs.map as MapHexagon;
      map.submitScale();
      map.submitCenter();
    }
  }

Props

the following properties don't support the ".async" modifier

namerequireddescriptiondefault
cellsnoarray of cells to render without slot
widthnovisible area width400
heightnovisible area height400
xRangenostart, end array of two items to set range of the x axis-5,5 or min, max col property, if the cells prop exists
yRangenostart, end array of two items to set range of the y axis-5,5 or min, max row property, if the cells prop exists
itemSizenohexagon size100
itemsGapnosize of gaps between cells of hexagons100
withinnolimit scrolling of content to its bordersfalse
zoomnoscaling of/offtrue
minScalenominimum allowable scaling0.6
maxScalenomaximum allowable scaling3
centernocol, row array of two items to set the centered cell to be displayed in the center of the visible areaautomatically calculated on xRange and yRange props
scalenoscale of the content1
autoCenternodisplay centered cell to be displayed in the center of the visible areayes
draggablenodraggable of/offtrue
scrollZoomThrottleDelaynozooming/dragging rendering delay (milliseconds)40
renderThrottleDelaynohexagon hide/show rendering delay (milliseconds)200

Events

  • dragging
  • scaling
  • click //click on hexagon when used cells prop
  • ranging - on change visible range

Methods

.submitCenter(); //when changed center prop or goto centered cell
.submitSize(); //when changed width and height props
.submitScale(); //when changed scale prop or restore scale with the value
3.3.0

3 years ago

3.2.4

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.3

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.0.0

3 years ago

1.0.0

3 years ago