hellenic / react-hexgrid Goto Github PK
View Code? Open in Web Editor NEWBuild interactive hexagon grids with React
Home Page: https://hellenic.github.io/react-hexgrid/examples/
License: MIT License
Build interactive hexagon grids with React
Home Page: https://hellenic.github.io/react-hexgrid/examples/
License: MIT License
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?
Make a comment on what the PixelToHex
function does in HexUtils.ts
I don't know what it does.
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
Drag and Drop not work in Firefox 65.0
Test coverage is needed for the Ring and Spiral static methods in GridGenerator.tsx for the GridGenerator.test.tsx test file.
Creating the test shouldn't be difficult.
want to custom it but don't work. is it okay using sass?
Lines 6 to 7 in 6f745a2
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
Running the following command to test the GridGenerator static methods shows all tests pass.
npx jest test/src/GridGenerator.test.tsx
npm run test
Why is this single test skipped?
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.
Make a comment on what the HexToPixel
function does in HexUtils.ts
I don't know what it does.
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:
s
value specifically.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 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
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
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?
Make a comment on what the round
function does in HexUtils.ts
I don't know what it does.
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...
(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.
✘ [ERROR] Could not resolve "@emotion/react/jsx-runtime"
../../node_modules/react-hexgrid/lib/Layout.js:12:28:
12 │ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "@emotion/react/jsx-runtime" as external to exclude it from the bundle,
which will remove this error.
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.
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.
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!
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:
viewBox
, which should obviate the need for passing around sizes, as in: https://stackoverflow.com/posts/22886596propTypes for x and y in Text should be String instead of number, since it can take values such as '0.3em'.
Thanks for the component!
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
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)
When entering text into the Hexagrid Hexagons, the text won't wrap. Please can this be fixed..
Thanks
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.
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>
);
}
With create-react-app 5 we get errors due to missing source maps. See: facebook/create-react-app#11767
I suppose that including the src
folder in the installed package would solve it from this end, right?
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"
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.
Will do a PR if i ever find how this works 😂
The three problems I could identify:
A dirty example of workaround (just working for my particular case)
svg path {
...
transform: rotate(-30deg) scale(0.4);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.