Add hidden map

This commit is contained in:
maciejhirsz committed 2018-07-15 22:50:41 +02:00
1 parent 071c26ef51
commit 43a87deb9c
8 files changed
+117 -96

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ export default class Feed {
public static feedVersion(): FeedMessage.Message {
return {
action: Actions.FeedVersion,
action: Actions.FeedVersionLegacy,
payload: VERSION
};
}
+20 -12
View File
@@ -16,18 +16,19 @@ import {
} from './types';
export const Actions = {
FeedVersion : 0xff as 0xff,
BestBlock : 0x00 as 0x00,
AddedNode : 0x01 as 0x01,
RemovedNode : 0x02 as 0x02,
LocatedNode : 0x03 as 0x03,
ImportedBlock : 0x04 as 0x04,
NodeStats : 0x05 as 0x05,
TimeSync : 0x06 as 0x06,
AddedChain : 0x07 as 0x07,
RemovedChain : 0x08 as 0x08,
SubscribedTo : 0x09 as 0x09,
UnsubscribedFrom : 0x0A as 0x0A,
FeedVersionLegacy : 0xff as 0xff,
FeedVersion : 0x00 as 0x00,
BestBlock : 0x01 as 0x01,
AddedNode : 0x02 as 0x02,
RemovedNode : 0x03 as 0x03,
LocatedNode : 0x04 as 0x04,
ImportedBlock : 0x05 as 0x05,
NodeStats : 0x06 as 0x06,
TimeSync : 0x07 as 0x07,
AddedChain : 0x08 as 0x08,
RemovedChain : 0x09 as 0x09,
SubscribedTo : 0x0A as 0x0A,
UnsubscribedFrom : 0x0B as 0x0B,
};
export type Action = typeof Actions[keyof typeof Actions];
@@ -38,6 +39,12 @@ export namespace Variants {
action: Action;
}
// TOOD: remove
export interface FeedVersionLegacyMessage extends MessageBase {
action: typeof Actions.FeedVersionLegacy;
payload: FeedVersion;
}
export interface FeedVersionMessage extends MessageBase {
action: typeof Actions.FeedVersion;
payload: FeedVersion;
@@ -100,6 +107,7 @@ export namespace Variants {
}
export type Message =
| Variants.FeedVersionLegacyMessage
| Variants.FeedVersionMessage
| Variants.BestBlockMessage
| Variants.AddedNodeMessage
+2
View File
@@ -97,6 +97,8 @@ export class Connection {
messages: for (const message of FeedMessage.deserialize(data)) {
switch (message.action) {
// TODO: Kick legacy out on next update
case Actions.FeedVersionLegacy:
case Actions.FeedVersion: {
if (message.payload !== VERSION) {
this.state = this.update({ status: 'upgrade-requested' });
-75
View File
@@ -1,75 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="1602.7142"
height="741.71301"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="Carte du monde simplifiée (à usage pédagogique).svg">
<defs
id="defs4">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
<inkscape:perspective
id="perspective2824"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.43852551"
inkscape:cx="625.17606"
inkscape:cy="385.25041"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1366"
inkscape:window-height="705"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(275.17606,-309.45844)">
<path
style="fill:none;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none"
d="m 103.03633,1028.2696 c -5.999639,-2.2452 -7.677682,-4.4437 -6.252601,-8.192 0.660208,-1.7365 1.92836,-3.1572 2.818108,-3.1572 0.889763,0 4.784553,2.0468 8.655113,4.5484 3.87055,2.5017 8.60343,5.1172 10.51748,5.8122 l 3.48011,1.2636 -4.28138,0.093 c -2.35476,0.051 -5.8094,0.3148 -7.67697,0.5856 -1.86757,0.2708 -5.13451,-0.1584 -7.25986,-0.9538 z m -13.617114,-11.5249 c -1.129671,-0.6322 -3.013043,-0.845 -4.185257,-0.473 -1.476198,0.4685 -2.616074,-0.2294 -3.708482,-2.2705 -0.86745,-1.6209 -2.422177,-3.2377 -3.454954,-3.5929 -2.369572,-0.815 -7.336604,-8.8624 -10.101315,-16.36571 -1.396299,-3.78947 -3.27412,-6.40899 -5.503286,-7.67697 -3.955704,-2.25003 -4.238878,-3.27049 -1.17721,-4.24223 3.502752,-1.11172 4.154443,-7.28662 1.206028,-11.42728 -1.4072,-1.97624 -2.147696,-4.29669 -1.723727,-5.40156 0.500314,-1.30378 -0.880536,-3.59153 -4.224091,-6.99837 -4.220359,-4.30022 -5.000799,-5.86343 -5.189558,-10.3945 -0.122193,-2.9332 -0.836376,-6.07316 -1.587065,-6.97768 -0.94566,-1.13945 -1.138541,-5.2292 -0.627987,-13.31493 0.553332,-8.76296 0.231029,-14.17132 -1.293746,-21.70944 -2.264363,-11.19452 -3.420974,-32.05213 -2.8326,-51.08135 0.125536,-4.05993 -0.400666,-9.63389 -1.169331,-12.38658 -1.87181,-6.70318 -10.484184,-15.16456 -21.128344,-20.75791 -7.613094,-4.00056 -8.683641,-5.02624 -11.659646,-11.17093 -1.8022915,-3.72126 -5.2467333,-9.28288 -7.6543242,-12.35916 -2.40760275,-3.07628 -5.0252118,-7.59388 -5.8169195,-10.03911 -2.512848,-7.76109 -6.9425399,-15.55931 -9.9621623,-17.53784 -1.60686,-1.05286 -3.439682,-3.79074 -4.072937,-6.08421 -1.02458,-3.71073 -0.754492,-4.74676 2.45272,-9.40827 3.477641,-5.05459 3.518636,-5.26071 1.168493,-5.87529 -5.774696,-1.51012 -3.346071,-9.22866 7.0194155,-22.30875 6.8892381,-8.69344 8.9074651,-15.31624 6.9990541,-22.96735 -0.72726845,-2.91572 -1.37849954,-5.96568 -1.44717885,-6.77766 -0.0687384,-0.81199 -0.58647293,-1.47634 -1.15064725,-1.47634 -0.5641743,0 -0.4556692,-1.06528 0.2411512,-2.36728 1.07365319,-2.00615 0.80246734,-2.5789 -1.7776427,-3.75448 -3.7604139,-1.71335 -9.438416,-0.0195 -9.460348,2.82228 -0.02634,3.40766 -1.524929,3.6587 -6.466202,1.08317 -2.646416,-1.37938 -5.39523,-2.50798 -6.108479,-2.50798 -0.713261,0 -3.487173,-1.88687 -6.164261,-4.19303 -2.677088,-2.30617 -5.531785,-4.71879 -6.343772,-5.36139 -0.811986,-0.6426 -1.476339,-2.39374 -1.476339,-3.89142 0,-1.49768 -1.042957,-3.66692 -2.317676,-4.82053 -1.274731,-1.15361 -2.926542,-3.94232 -3.6707,-6.19714 -0.978057,-2.96353 -1.710463,-3.74223 -2.642825,-2.80987 -1.945768,1.94577 -4.82665,1.57622 -11.818936,-1.51609 -3.655441,-1.61662 -7.463676,-4.37747 -8.984826,-6.51372 -1.452104,-2.0393 -4.226453,-4.5281 -6.165217,-5.53067 -3.199405,-1.65448 -3.999345,-1.64172 -8.659877,0.13816 l -5.134851,1.96101 -15.754258,-7.63407 c -9.69082,-4.6959 -17.21178,-9.17543 -19.54129,-11.63894 -3.6119,-3.81967 -3.72877,-4.23446 -2.52692,-8.96936 1.10099,-4.33758 0.91403,-5.67948 -1.48062,-10.62649 -1.50741,-3.1141 -4.80097,-7.89722 -7.31902,-10.62914 -2.51805,-2.73191 -4.29226,-5.42992 -3.94267,-5.99555 0.34957,-0.56562 -1.42418,-4.37776 -3.94167,-8.47141 -2.85994,-4.65052 -4.87833,-9.6321 -5.37973,-13.27775 -0.64275,-4.67339 -1.39167,-6.10321 -3.76259,-7.18347 -2.51322,-1.1451 -3.21598,-0.99916 -4.655,0.96669 -2.02672,2.76872 -1.45057,5.69173 3.03076,15.37588 1.82106,3.93532 3.70302,9.76916 4.18213,12.96407 0.47911,3.19492 1.89425,7.81448 3.14476,10.26569 2.96198,5.80595 1.04946,5.70351 -3.62143,-0.19397 -2.75488,-3.47831 -3.49889,-5.38594 -2.95142,-7.5673 0.58456,-2.32906 0.009,-3.4507 -2.85428,-5.56806 -4.34257,-3.21059 -5.26164,-5.2817 -3.66648,-8.26228 0.93021,-1.73812 0.50367,-3.64427 -1.85868,-8.30615 -2.39904,-4.73427 -2.90082,-7.02763 -2.30685,-10.54332 0.97096,-5.74708 -1.60746,-10.94864 -6.41421,-12.93966 -2.77525,-1.14955 -3.73197,-2.43553 -4.29743,-5.77645 -0.40007,-2.36374 -1.1663,-6.02083 -1.70272,-8.12689 -0.55799,-2.19071 -0.5174,-4.11222 0.0949,-4.49061 0.5886,-0.36377 0.20347,-1.98417 -0.85584,-3.60088 -1.56016,-2.38111 -1.66699,-3.50796 -0.5624,-5.93227 0.74999,-1.64604 1.03306,-3.52765 0.62905,-4.18135 -0.40401,-0.65369 0.60277,-2.60692 2.23728,-4.34051 1.63451,-1.73359 3.8106,-5.19102 4.83574,-7.68319 1.02515,-2.49217 4.18431,-7.11207 7.02037,-10.26644 2.83605,-3.15439 6.43146,-8.67989 7.9898,-12.27891 2.16305,-4.99564 3.43094,-6.54843 5.35951,-6.56382 1.3894,-0.0106 2.45237,0.6442 2.36215,1.45618 -0.37598,3.38371 2.29955,2.34125 5.30474,-2.06687 1.77141,-2.59836 2.72717,-4.90145 2.12392,-5.11798 -0.60324,-0.21653 -1.09681,-1.19402 -1.09681,-2.17222 0,-0.97819 -2.44505,-4.15485 -5.43343,-7.05922 -4.95654,-4.81722 -5.27485,-5.45592 -3.6267,-7.27709 1.33529,-1.47549 1.49233,-2.55818 0.60183,-4.14941 -1.56493,-2.79638 0.90447,-9.05861 3.58203,-9.08378 1.1059,-0.0106 1.42152,-0.38694 0.74251,-0.8858 -1.52334,-1.11919 -2.2135,-3.66087 -1.99948,-7.36362 0.34182,-5.91393 -0.95236,-8.38769 -5.3492,-10.2248 -2.37157,-0.99091 -5.99032,-3.08181 -8.04168,-4.64646 -2.05136,-1.56465 -4.65399,-2.8448Line truncated
id="path2830" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 84 KiB

+5 -4
View File
@@ -39,10 +39,11 @@
.Chain-map-node {
width: 10px;
height: 10px;
background: #f00; /* #d64ca8;*/
border-radius: 5px;
margin-left: -5px;
margin-top: -5px;
background: #d64ca8;
border: 1px solid #000;
border-radius: 6px;
margin-left: -6px;
margin-top: -6px;
position: absolute;
top: 50%;
left: 50%;
+76 -3
View File
@@ -1,7 +1,8 @@
import * as React from 'react';
import { State as AppState } from '../state';
import { formatNumber, secondsWithPrecision } from '../utils';
import { formatNumber, secondsWithPrecision, viewport } from '../utils';
import { Tile, Icon, Node, Ago } from './';
import { Types } from '@dotstats/common';
import nodeIcon from '../icons/server.svg';
import nodeTypeIcon from '../icons/terminal.svg';
@@ -13,6 +14,9 @@ import blockTimeIcon from '../icons/history.svg';
import propagationTimeIcon from '../icons/dashboard.svg';
import lastTimeIcon from '../icons/watch.svg';
const MAP_RATIO = 495 / 266; // width / height
const HEADER = 148;
import './Chain.css';
export namespace Chain {
@@ -22,6 +26,12 @@ export namespace Chain {
export interface State {
display: 'map' | 'table';
map: {
width: number;
height: number;
top: number;
left: number;
}
}
}
@@ -43,10 +53,45 @@ export class Chain extends React.Component<Chain.Props, Chain.State> {
super(props);
this.state = {
display: 'table'
display: window.location.hash === '#map' ? 'map' : 'table',
map: {
width: 0,
height: 0,
top: 0,
left: 0
}
};
}
public componentWillMount() {
const vp = viewport();
vp.height -= HEADER;
const ratio = vp.width / vp.height;
let top = 0;
let left = 0;
let width = 0;
let height = 0;
if (ratio >= MAP_RATIO) {
console.log('wider');
width = Math.round(vp.height * MAP_RATIO);
height = Math.round(vp.height);
left = (vp.width - width) / 2;
} else {
console.log('taller');
width = Math.round(vp.width);
height = Math.round(vp.width / MAP_RATIO);
top = (vp.height - height) / 2;
}
this.setState({ map: { top, left, width, height }});
}
public render() {
const { best, blockTimestamp, blockAverage } = this.props.appState;
@@ -75,12 +120,40 @@ export class Chain extends React.Component<Chain.Props, Chain.State> {
return (
<div className="Chain-map">
{
this.nodes().map((node) => <div key={node.id} className="Chain-map-node" data-foo={JSON.stringify(node)} />)
// Debug rect
// <div style={{ position: 'absolute', background: 'rgba(0,255,0,0.5)', ...this.state.map}} />
}
{
this.nodes().map((node) => {
const location = node.location || [0, 0] as Types.NodeLocation;
// const location = [51.4825891, -0.0164137] as Types.NodeLocation; // Greenwich
// const location = [52.2330653, 20.921111] as Types.NodeLocation; // Warsaw
// const location = [48.8589507, 2.2770201] as Types.NodeLocation; // Paris
// const location = [36.7183391, -4.5193071]as Types.NodeLocation; // Malaga
return (
<div
key={node.id}
className="Chain-map-node"
style={this.pixelPosition(location[0], location[1])}
data-location={JSON.stringify(node.location)}
/>
);
})
}
</div>
);
}
private pixelPosition(lat: Types.Latitude, lon: Types.Longitude): { left: number, top: number } {
const { map } = this.state;
const left = Math.round(((lon + 180) / 360) * map.width + map.left) - 35;
const top = Math.round(((-lat + 90) / 180) * map.height + map.top) + 4;
return { left, top }
}
private renderTable() {
return (
<table className="Chain-node-list">
+1 -1
View File
@@ -28,7 +28,7 @@ export class Chains extends React.Component<Chains.Props, {}> {
{
this.chains.map((chain) => this.renderChain(chain))
}
<a className="Chains-fork-me" href="https://github.com/polkadot-js/dotstats" target="blank">
<a className="Chains-fork-me" href="https://github.com/polkadot-js/dotstats" target="_blank">
<Icon src={githubIcon} alt="Fork Me!" />
</a>
</div>
+12
View File
@@ -1,3 +1,15 @@
export interface Viewport {
width: number;
height: number;
}
export function viewport(): Viewport {
const width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
const height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
return { width, height };
}
export function formatNumber(num: number): string {
const input = num.toString();