Code Monkey home page Code Monkey logo

react-hexgrid's People

Contributors

alcalyn avatar awatson1978 avatar cachilders avatar cburbank avatar davesag avatar dependabot[bot] avatar hellenic avatar jannikbuschke avatar jason-henriksen avatar luetkemj avatar luisfrocha avatar parkerbjur avatar tieje avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-hexgrid's Issues

Mobile friendly drag and drop

Currently, drag and drop do not work on mobile. Could you consider mapping existing event handlers to mobile equivalents (eg. onDragStart also handling onTouchStart) or adding separate props for mobile events handlers?

Refactor react class methods to use arrow functions

Methods such as onMouseOver() in Hexagon.js need to be refactored to be onMouseOver = (e) => () => . This way in render it could be onMouseOver={this.onMouseOver} without creating a new function every render

hexgrid usage

Hi Hellenic, I'm trying to achieve something with this library and I was wondering if you can help me out. we can communicate via email.

Below is what I'm trying to achieve. Please help.

Screenshot 2019-06-04 at 08 13 30

Passing 100% in HexGrid width and height

width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,

Hi,

I can pass 100% to width and height, but it throws: Warning: Failed prop type: Invalid prop width of type string supplied to HexGrid, expected number.

I think it should allows either a number or a string, like 100%

Actually, it breaks integration testing

Test Skipped in GridGenerator.test.tsx

Running the following command to test the GridGenerator static methods shows all tests pass.

  • npx jest test/src/GridGenerator.test.tsx
    However, running the following command to run all tests show that a test in GridGenerator.test.tsx is being skipped.
  • npm run test

Why is this single test skipped?

Missing demo source and documentation

The demo shown doesn't really have much source code such as the applied CSS, what createBoard() returns? actions? configs? the props passed to the Board component?

It would be great if I could just run the same demo you generated your screenshot with.

What does `s` do? Can we get short docs/comments on the attributes?

I was playing with the custom-grid sample and found that two of the grid tiles use and display hex values as follows:

  • 1, -1, 0 (ie. q=1, r=-1, s=0)
  • 1, 0, -1 (ie. q=1, r=0, s=-1)

It's not clear what s is doing here. The difference in position seems to be based entirely on the q and r values, and a look at the source code confirms that. Modifying the s value does not change position, size, opacity, or z-index, and I can't think of anything else it might affect.

Additionally, s seems to be used in certain methods such as HexUtils.lengths() or HexUtils.round(), but given that it's not used in the HexUtils.hexToPixel() method, I'm not sure why it would appear there (or in HexUtils.getID(), for example, where its usage suggests it's important to the identity of the hex).

The request:

  • Clarify the usage of the s value specifically.
  • Document the component APIs in the README, or perhaps in the component's proptypes.
  • Update the custom-grid sample to use more clear/meaningful values

This library is great, and I'll be ignoring the s value for now. Any guidance could help us get more use out of it.

Text should accept number

Text should be accepting numbers as well as strings. Numbers are easily rendered, why not accept them? By converting my numbers to strings I first have to check if number is defined, wasting CPU ticks

Deprecation warning on componentWillReceiveProps from React

I'm seeing this warning in the console:

react-dom.development.js:88 Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: Hexagon

I haven't upgraded my react to 17 yet, but it is out now so this library will probably break on the latest react

toString functions on models

it would be extremely useful if the Hex model had a toString function, so that it can be used as the key in a hash map

the default behavior is [object Object], which makes it pretty useless, and a hash map is the recommended storage method on the red blob post!

thoughts?

Path route conditions

Hi. I'm enjoying this project!

Is there any easy/obvious approach towards making a path avoid some hexes? The use case for me is the idea of 'impassable' tiles...

screen shot

(I want my Mongolian Horde to not be able to go over Mt Everest!)

Note: I recognise this is a side project, so I understand if you don't want to/have time to respond. 😀 It's not a big issue for me, just something I was wondering about.

Text Overflow out of Hexagon

Hi
I noticed when you insert a long string into the hexagon, the string overflows out of the hexagon boundary. Is there a way to allow the string to text wrap within a hexagon?

Thanks
text overflow

Accessing individual elements generated by GridGenerator

There currently seems to be no way to access elements by [p,q,r], only accepted method is to use a single array index. The hexToPixel/pixelTohex functions seem to be broken since f0/f1 are not defined. Is there a recommended way to use these functions? The examples do not show any usages.

Maintainers wanted!

Hey all!

I'm very pleased to see that this library is being used somewhat widely and in different use cases. This library I wrote mostly for my personal prototyping but still published for the community to try out. Once it was "ready" for my use case, I didn't really bother to look back and moved on to different things. Currently I still don't have plans to develop it further or maintain it.

That being said, since it's still being used and I can see people actively starring and forking it, I'm happy to invite new maintainers to the project!

Happy to hear recommendations as well how this can be safely done, and how we can make sure the future releases of the library remain safe for users to use.

How to center screen on a specific hex?

I assume the Layout.origin should be used, but I can't seem to figure out the correct units to set it to. I currently have

const [hexagons, setHexagons] = useState(GridGenerator.hexagon(3));
...
<HexGrid width={windowWidth} height={windowHeight}>
  <Layout
    size={{ x: hexSize, y: hexSize }}
    flat={true}
    origin={{ x: -10, y: 0 }}
  >
    {hexagons.map((hex, i) => (
      <Hexagon key={i} q={hex.q} r={hex.r} s={hex.s} fill={'black'} />
    ))}
  </Layout>
</HexGrid>

Any help would be appreciated!

patterns and images do not inherit proper sizing from hexagons

It appears that the sizing of patterns and images always defaults to this:

<pattern id="1,2,-3" patternUnits="objectBoundingBox" x="0" y="0" width="10" height="10">
  <image xlink:href="http://lorempixel.com/400/400/cats/1/" x="0" y="0" width="20" height="20"></image>
</pattern>

even when the hexagons in question have, say, size 8 8, as is the case in the drag and drop example (tiles) from which I took this code: http://karkk.ai//nen/react-hexgrid/examples/drag-and-drop/

If you look carefully at the above example, you can see that the cats are actually masked differently in the tiles than in the game hexgrid, which I think is counter to expectations.

I think there might be two issues / concerns here:

SVG Items not Draggable

I am having an issue extending the draggable example into my application. My understanding is that the draggable property is not supported by SVG and I am hoping you can help me understand how the example is able to bypass that issue

New grid generator options missing

Hello. I submitted the pull request with the spiral and circle options for the Grid generator. However, they don't seem to be included in any file in the lib or dist directories. Is there an additional step I need to take after "npm install react-hexgrid", or did I forget to perform a step before submitting the PR? I see the changes in the source files, but not in the installation in node_modules. (Full disclosure, this is my first PR submission ever)

Word Wrap

When entering text into the Hexagrid Hexagons, the text won't wrap. Please can this be fixed..

Thanks

TypeError: undefined is not an object (evaluating '_react.PropTypes.string')

Latest node and react, breaks with this error.

×
TypeError: undefined is not an object (evaluating '_react.PropTypes.string')
(anonymous function)
node_modules/react-hexgrid/lib/Hexagon/Text.js:102
   99 |   }(_react.Component);
  100 | 
  101 |   Text.propTypes = {
> 102 |     children: _react.PropTypes.string
  103 |   };
  104 |   exports.default = Text;
  105 | });
View compiled
(anonymous function)
node_modules/react-hexgrid/lib/Hexagon/Text.js:3
  1 | (function (global, factory) {
  2 |   if (typeof define === "function" && define.amd) {
> 3 |     define(["exports", "react"], factory);
  4 |   } else if (typeof exports !== "undefined") {
  5 |     factory(exports, require("react"));
  6 |   } else {
View compiled
./node_modules/react-hexgrid/lib/Hexagon/Text.js
node_modules/react-hexgrid/lib/Hexagon/Text.js:13
  10 |     factory(mod.exports, global.React);
  11 |     global.Text = mod.exports;
  12 |   }
> 13 | })(this, function (exports, _react) {
  14 |   "use strict";
  15 | 
  16 |   Object.defineProperty(exports, "__esModule", {
View compiled
__webpack_require__
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:669
  666 | };
  667 | 
  668 | // Execute the module function
> 669 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
  670 | 
  671 | // Flag the module as loaded
  672 | module.l = true;
View compiled
fn
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:87
  84 | 		console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
  85 | 		hotCurrentParents = [];
  86 | 	}
> 87 | 	return __webpack_require__(request);
  88 | };
  89 | var ObjectFactory = function ObjectFactory(name) {
  90 | 	return {
View compiled
(anonymous function)
node_modules/react-hexgrid/lib/index.js:3
  1 | (function (global, factory) {
  2 |   if (typeof define === "function" && define.amd) {
> 3 |     define(['exports', './GridGenerator', './HexGrid', './HexUtils', './Layout', './Path', './Pattern', './Hexagon/Hexagon', './Hexagon/Text', './models/Hex'], factory);
  4 |   } else if (typeof exports !== "undefined") {
  5 |     factory(exports, require('./GridGenerator'), require('./HexGrid'), require('./HexUtils'), require('./Layout'), require('./Path'), require('./Pattern'), require('./Hexagon/Hexagon'), require('./Hexagon/Text'), require('./models/Hex'));
  6 |   } else {
View compiled
./node_modules/react-hexgrid/lib/index.js
node_modules/react-hexgrid/lib/index.js:13
  10 |     factory(mod.exports, global.GridGenerator, global.HexGrid, global.HexUtils, global.Layout, global.Path, global.Pattern, global.Hexagon, global.Text, global.Hex);
  11 |     global.index = mod.exports;
  12 |   }
> 13 | })(this, function (exports, _GridGenerator, _HexGrid, _HexUtils, _Layout, _Path, _Pattern, _Hexagon, _Text, _Hex) {
  14 |   'use strict';
  15 | 
  16 |   Object.defineProperty(exports, "__esModule", {
View compiled
__webpack_require__
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:669
  666 | };
  667 | 
  668 | // Execute the module function
> 669 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
  670 | 
  671 | // Flag the module as loaded
  672 | module.l = true;
View compiled
fn
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:87
  84 | 		console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
  85 | 		hotCurrentParents = [];
  86 | 	}
> 87 | 	return __webpack_require__(request);
  88 | };
  89 | var ObjectFactory = function ObjectFactory(name) {
  90 | 	return {
View compiled
./src/App.js
http://localhost:3000/static/js/bundle.js:106290:91
__webpack_require__
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:669
  666 | };
  667 | 
  668 | // Execute the module function
> 669 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
  670 | 
  671 | // Flag the module as loaded
  672 | module.l = true;
View compiled
fn
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:87
  84 | 		console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
  85 | 		hotCurrentParents = [];
  86 | 	}
> 87 | 	return __webpack_require__(request);
  88 | };
  89 | var ObjectFactory = function ObjectFactory(name) {
  90 | 	return {
View compiled
./src/index.js
http://localhost:3000/static/js/bundle.js:106507:82
__webpack_require__
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:669
  666 | };
  667 | 
  668 | // Execute the module function
> 669 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
  670 | 
  671 | // Flag the module as loaded
  672 | module.l = true;
View compiled
fn
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:87
  84 | 		console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
  85 | 		hotCurrentParents = [];
  86 | 	}
> 87 | 	return __webpack_require__(request);
  88 | };
  89 | var ObjectFactory = function ObjectFactory(name) {
  90 | 	return {
View compiled
(anonymous function)
http://localhost:3000/static/js/bundle.js:106645:37
__webpack_require__
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:669
  666 | };
  667 | 
  668 | // Execute the module function
> 669 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
  670 | 
  671 | // Flag the module as loaded
  672 | module.l = true;
View compiled
(anonymous function)
/Users/dom/Desktop/bitopoly-client/webpack/bootstrap 9505ad37cf0f3551ccaa:715
  712 | __webpack_require__.h = function() { return hotCurrentHash; };
  713 | 
  714 | // Load entry module and return exports
> 715 | return hotCreateRequire(0)(__webpack_require__.s = 0);
  716 | 
  717 | 
  718 | 
View compiled
global code
http://localhost:3000/static/js/bundle.js:717:12
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.

Bug

In the newest release 1.0.0-rc3 I encounter this error: Cannot read property 'spacing' of undefined

TypeError: Cannot read property 'spacing' of undefined
    at Function.hexToPixel (webpack:///./~/react-hexgrid/lib/HexUtils.js?:117:23)
    at Hexagon.componentWillReceiveProps (webpack:///./~/react-hexgrid/lib/Hexagon/Hexagon.js?:127:40)
    at eval (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:611:23)
    at measureLifeCyclePerf (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:75:12)
    at ReactCompositeComponentWrapper.updateComponent (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:610:9)
    at ReactCompositeComponentWrapper.receiveComponent (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:547:10)
    at Object.receiveComponent (webpack:///./~/react-dom/lib/ReactReconciler.js?:125:22)
    at Object.updateChildren (webpack:///./~/react-dom/lib/ReactChildReconciler.js?:109:25)
    at ReactDOMComponent._reconcilerUpdateChildren (webpack:///./~/react-dom/lib/ReactMultiChild.js?:208:32)
    at ReactDOMComponent._updateChildren (webpack:///./~/react-dom/lib/ReactMultiChild.js?:312:31)

hexmap.component.js

import React from 'react';
import { HexGrid, Layout, Hexagon, GridGenerator, HexUtils, Pattern } from 'react-hexgrid';
import './hexmap.component.scss';

const config = {
  width: 2300,
  height: 2000,
  layout: { width: 0.7, height: 0.7, flat: false, spacing: 1.03 },
  origin: { x: -45, y: -40 },
  map: 'rectangle',
  mapProps: [32, 32],
};

export default function HexMap() {
  const generator = GridGenerator.getGenerator(config.map);
  const hexagons = generator.apply(this, config.mapProps);
  const layout = config.layout;
  const size = { x: layout.width, y: layout.height };

  return (
    <HexGrid width={config.width} height={config.height} className="hexGrid">
      <Layout size={size} flat={layout.flat} spacing={layout.spacing} origin={config.origin}>
        {
          hexagons.map(hex => (
            <Hexagon
              key={HexUtils.getID(hex)}
              q={hex.q}
              r={hex.r}
              s={hex.s}
            />
          ))
        }
      </Layout>
    </HexGrid>
  );
}

Couple questions re HexUtils.js

https://github.com/Hellenic/react-hexgrid/blob/master/src/HexUtils.js#L72
This function can result in a hex with floating points. Should we round in this function or leave it up to the user? It makes sense to me to take the extra step unless there is value in the precision that I have overlooked.

https://github.com/Hellenic/react-hexgrid/blob/master/src/HexUtils.js#L84
Is there a reason you chose to include commas here? Seems like you could get away with just the values and make the ids a lot cleaner. "1,-2,3" => "1-23"

How to use local img in Pattern

Everything is in the title, I tried to change link="" by src={} with an import, didn't work, i'm kinda new a React so might be a dumb question but you'd be so kind to help me here.

Path not working in rectangle layout

image_178

Will do a PR if i ever find how this works 😂

The three problems I could identify:

  • if flat = false, it still does the path as if flat === true
  • does not adapt to the size
  • does not adapt to the position of the origin if this is moved

A dirty example of workaround (just working for my particular case)

svg path {
...
 transform: rotate(-30deg) scale(0.4);
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.