8000 Aashutosh habile by morwalz · Pull Request #188 · kevinsqi/react-calendar-heatmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Aashutosh habile #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47,733 changes: 47,733 additions & 0 deletions demo/package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions demo/src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { Component } from 'react';
import React from 'react';
import 'react-calendar-heatmap/dist/styles.css';
import './App.css';
import Demo from './Demo';

class App extends Component {
render() {
const App = () => {
return (
<div className="container py-5">
<div className="text-sm-center">
Expand Down Expand Up @@ -37,7 +36,6 @@ class App extends Component {
</div>
</div>
);
}
}

export default App;
102 changes: 48 additions & 54 deletions demo/src/Demo.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import React from 'react';
import React, { useState } from 'react';
import CalendarHeatmap from 'react-calendar-heatmap';
import ReactTooltip from 'react-tooltip';

function shiftDate(date, numDays) {
const shiftDate = (date, numDays) => {
const newDate = new Date(date);
newDate.setDate(newDate.getDate() + numDays);
return newDate;
}

function getRange(count) {
const getRange = (count) => {
const arr = [];
for (let idx = 0; idx < count; idx += 1) {
arr.push(idx);
}
return arr;
}

function getRandomInt(min, max) {
const getRandomInt = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function generateRandomValues(count, date = new Date()) {
const generateRandomValues = (count, date = new Date()) => {
return getRange(count).map((index) => {
return {
date: shiftDate(date, -index),
Expand All @@ -29,18 +29,14 @@ function generateRandomValues(count, date = new Date()) {
});
}

class Demo extends React.Component {
state = {
values: generateRandomValues(200),
};
const Demo = () => {
const [stateValues, setStateValues] = useState({ values: generateRandomValues(200) });

generateValues = () => {
this.setState({
values: generateRandomValues(200),
});
const generateValues = () => {
setStateValues({ values: generateRandomValues(200) });
};

getTooltipDataAttrs = (value) => {
const getTooltipDataAttrs = (value) => {
// Temporary hack around null value.date issue
if (!value || !value.date) {
return null;
Expand All @@ -51,50 +47,48 @@ class Demo extends React.Component {
};
};

handleClick = (value) => {
const handleClick = (value) => {
alert(`You clicked on ${value.date.toISOString().slice(0, 10)} with count: ${value.count}`);
};

render() {
return (
<div>
<div className="row">
<div className="col-12 col-sm-6">
<CalendarHeatmap
values={this.state.values}
classForValue={(value) => {
if (!value) {
return 'color-empty';
}
return `color-github-${value.count}`;
}}
tooltipDataAttrs={this.getTooltipDataAttrs}
>
/>
</div>
<div className="col-12 col-sm-6">
<CalendarHeatmap
values={this.state.values}
classForValue={(value) => {
if (!value) {
return 'color-empty';
}
return `color-gitlab-${value.count}`;
}}
tooltipDataAttrs={this.getTooltipDataAttrs}
>
/>
</div>
</div>{' '}
<div className="text-sm-center mt-4">
<button className="btn btn-link btn-sm text-secondary" >
Regenerate values
</button>
return (
<div>
<div className="row">
<div className="col-12 col-sm-6">
<CalendarHeatmap
values={stateValues.values}
classForValue={(value) => {
if (!value) {
return 'color-empty';
}
return `color-github-${value.count}`;
}}
tooltipDataAttrs={getTooltipDataAttrs}
>
/>
</div>
<div className="col-12 col-sm-6">
<CalendarHeatmap
values={stateValues.values}
classForValue={(value) => {
if (!value) {
return 'color-empty';
}
return `color-gitlab-${value.count}`;
}}
tooltipDataAttrs={getTooltipDataAttrs}
>
/>
</div>
<ReactTooltip />
</div>{' '}
<div className="text-sm-center mt-4">
<button className="btn btn-link btn-sm text-secondary" >
Regenerate values
</button>
</div>
);
}
}
<ReactTooltip />
</div>
);
};

export default Demo;
6 changes: 3 additions & 3 deletions demo/src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function register() {
}
}

function registerValidSW(swUrl) {
const registerValidSW = (swUrl) => {
navigator.serviceWorker
.register(swUrl)
.then((registration) => {
Expand Down Expand Up @@ -79,7 +79,7 @@ function registerValidSW(swUrl) {
});
}

function checkValidServiceWorker(swUrl) {
const checkValidServiceWorker = (swUrl) => {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then((response) => {
Expand All @@ -104,7 +104,7 @@ function checkValidServiceWorker(swUrl) {
});
}

export function unregister() {
export const unregister = () => {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then((registration) => {
registration.unregister();
Expand Down
Loading
0