├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── assets └── logo.svg ├── lerna.json ├── package.json ├── packages ├── datalith-barcode │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.tsx │ ├── tsconfig.json │ └── yarn.lock ├── datalith-dotmap │ ├── README.md │ ├── package.json │ ├── src │ │ ├── components │ │ │ ├── DotMap │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ │ ├── DotMapUs │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ │ └── DotMapWorld │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ └── index.ts │ ├── tsconfig.json │ └── yarn.lock ├── datalith-flower │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.tsx │ ├── tsconfig.json │ └── yarn.lock ├── datalith-gridmap │ ├── README.md │ ├── package.json │ ├── src │ │ ├── components │ │ │ ├── GridMap │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ │ ├── GridMapUs │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ │ └── GridMapWorld │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ ├── index.ts │ │ ├── json │ │ │ ├── italy.json │ │ │ ├── us.json │ │ │ └── world.json │ │ └── utils │ │ │ ├── geometry.ts │ │ │ └── gridMap.ts │ ├── tsconfig.json │ └── yarn.lock ├── datalith-hexmap │ ├── README.md │ ├── package.json │ ├── src │ │ ├── components │ │ │ ├── HexMap │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ │ ├── HexMapUs │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ │ └── HexMapWorld │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ └── index.ts │ ├── tsconfig.json │ └── yarn.lock ├── datalith-pack │ ├── README.md │ ├── package.json │ ├── src │ │ ├── generatePack.ts │ │ └── index.tsx │ ├── tsconfig.json │ └── yarn.lock ├── datalith-pixelmap │ ├── README.md │ ├── package.json │ ├── src │ │ ├── components │ │ │ ├── PixelMap │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ │ ├── PixelMapUs │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ │ └── PixelMapWorld │ │ │ │ ├── README.md │ │ │ │ └── index.tsx │ │ └── index.ts │ ├── tsconfig.json │ └── yarn.lock ├── datalith-ripple │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.tsx │ ├── tsconfig.json │ └── yarn.lock ├── datalith-shutter │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.tsx │ ├── tsconfig.json │ └── yarn.lock ├── datalith-spiral │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.tsx │ ├── tsconfig.json │ └── yarn.lock ├── datalith-storybook │ ├── .storybook │ │ ├── main.js │ │ ├── manager.js │ │ ├── preview-head.html │ │ └── preview.js │ ├── README.md │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── logo-ext.svg │ │ └── logo.svg │ ├── src │ │ ├── components │ │ │ ├── barcode.stories.tsx │ │ │ ├── dotmap.stories.tsx │ │ │ ├── flower.stories.tsx │ │ │ ├── gridmap.stories.tsx │ │ │ ├── hexmap.stories.tsx │ │ │ ├── intro.stories.jsx │ │ │ ├── pack.stories.tsx │ │ │ ├── pixelmap.stories.tsx │ │ │ ├── ripple.stories.tsx │ │ │ ├── shutter.stories.tsx │ │ │ └── spiral.stories.tsx │ │ ├── index.d.ts │ │ ├── lib.ts │ │ └── scripts │ │ │ └── index.ts │ ├── tsconfig.json │ └── yarn.lock ├── datalith-util │ ├── README.md │ ├── package.json │ ├── src │ │ ├── ResponsiveWrapper.tsx │ │ └── index.ts │ ├── tsconfig.json │ └── yarn.lock └── datalith │ ├── README.md │ ├── package.json │ ├── src │ └── index.ts │ ├── tsconfig.json │ └── yarn.lock ├── tsconfig.json ├── tsconfig.test.json ├── tslint.json ├── website ├── assets │ └── images │ │ ├── dotpattern.svg │ │ ├── logo.svg │ │ └── share.jpg ├── favicon.ico ├── index.html └── style.css └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | 6 | # testing 7 | coverage 8 | 9 | # production 10 | dist 11 | storybook 12 | 13 | # IDEs and editors 14 | /.idea 15 | /.vscode 16 | 17 | # misc 18 | .DS_Store 19 | .env.local 20 | .env.development.local 21 | .env.test.local 22 | .env.production.local 23 | Thumbs.db 24 | 25 | *.log 26 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "semi": false, 4 | "singleQuote": true, 5 | "trailingComma": "all" 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Luca Falasco 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
datalithDate: ${date.toLocaleDateString()}
97 |Value: ${Number(value).toFixed(2)}
` 98 | } 99 | /> 100 | ) 101 | } 102 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/components/dotmap.stories.tsx: -------------------------------------------------------------------------------- 1 | import { DotMap, DotMapUs, DotMapWorld } from '@datalith/dotmap/src' 2 | import italyTopology from '@datalith/gridmap/src/json/italy.json' 3 | import { geoNaturalEarth1, geoOrthographic } from 'd3-geo' 4 | import { scaleLinear } from 'd3-scale' 5 | import * as React from 'react' 6 | import { feature } from 'topojson' 7 | import { genCoordsValue, genCoordsValueIt, genCoordsValueUs } from '../scripts' 8 | 9 | interface ItalyAtlas extends TopoJSON.Topology { 10 | objects: { 11 | sub: TopoJSON.GeometryCollection 12 | } 13 | } 14 | 15 | const y = d => d.value 16 | const defaultData = genCoordsValue(200) 17 | const side = 10 18 | 19 | const defaultDataUs = genCoordsValueUs(1000) 20 | const defaultDataIt = genCoordsValueIt(200) 21 | const italyAtlas = italyTopology as any 22 | const italy = feature(italyAtlas, (italyAtlas as ItalyAtlas).objects.sub) 23 | const projection = geoNaturalEarth1() 24 | 25 | const yScale = scaleLinear() 26 | .domain([Math.min(...defaultData.map(y)), Math.max(...defaultData.map(y))]) 27 | .range([1, side * 0.5]) 28 | 29 | const zScale = scaleLinear() 30 | .domain([0, Math.max(...defaultData.map(y))]) 31 | .range([0.1, 0.9]) 32 | .nice() 33 | 34 | export default { 35 | title: 'DATALITHS/DotMap', 36 | component: DotMap, 37 | } 38 | 39 | export const naturalEarth = () => { 40 | return ( 41 |Value: ${value.toFixed(2)}
`} 98 | /> 99 | ) 100 | } 101 | export const us = () => { 102 | return ( 103 |Value: ${value.toFixed(2)}
`} 115 | /> 116 | ) 117 | } 118 | export const customGeojson = () => { 119 | return ( 120 |Value: ${value.toFixed(2)}
`} 134 | /> 135 | ) 136 | } 137 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/components/flower.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Flower, FlowerComponent } from '@datalith/flower/src' 2 | import { normalize } from '@datalith/util' 3 | import { scaleLinear } from 'd3-scale' 4 | import * as React from 'react' 5 | import { Spring } from 'react-spring/renderprops' 6 | import { easeInOutCubic } from '../lib' 7 | import { genDateValue } from '../scripts' 8 | 9 | const width = window.innerWidth 10 | const height = window.innerHeight 11 | const defaultData = genDateValue(20) 12 | 13 | const y = d => d.value 14 | 15 | const defs = ( 16 |Date: ${date.toLocaleDateString()}
96 |Value: ${yScale.invert(Number(value)).toFixed(2)}
` 97 | } 98 | /> 99 | ) 100 | } 101 | export const gradient = () => { 102 | return ( 103 |Value: ${value.toFixed(2)}
`} 98 | /> 99 | ) 100 | } 101 | export const us = () => { 102 | return ( 103 |Value: ${value.toFixed(2)}
`} 115 | /> 116 | ) 117 | } 118 | export const customGeojson = () => { 119 | return ( 120 |Value: ${value.toFixed(2)}
`} 134 | /> 135 | ) 136 | } 137 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/components/intro.stories.jsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import Logo from '../../public/logo.svg' 3 | 4 | export default { 5 | title: 'INTRO/Getting Started', 6 | parameters: { 7 | previewTabs: { 8 | 'storybook/docs/panel': { 9 | hidden: true, 10 | }, 11 | }, 12 | }, 13 | } 14 | 15 | export const readme = () => { 16 | return ( 17 |37 | Datalith is a collection of clean, lightweight and easily customizable{' '} 38 | React components for data visualization. 39 |
40 |
55 | $ yarn add datalith
56 |
57 |
66 | $ yarn add @datalith/flower @datalith/hexmap
67 |
68 |
71 | Select a datalith from the sidebar to see example usage.
72 | You can read the documentation for each component by clicking on the Docs tab on
73 | the top toolbar.
74 |
75 |
76 |
77 | View on{' '}
78 |
83 | Github
84 |
85 |
86 |
Date: ${date.toLocaleDateString()}
87 |Value: ${Number(value).toFixed(2)}
` 88 | } 89 | /> 90 | ) 91 | } 92 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/components/pixelmap.stories.tsx: -------------------------------------------------------------------------------- 1 | import italyTopology from '@datalith/gridmap/src/json/italy.json' 2 | import { PixelMap, PixelMapUs, PixelMapWorld } from '@datalith/pixelmap/src' 3 | import { geoNaturalEarth1, geoOrthographic } from 'd3-geo' 4 | import { scaleLinear } from 'd3-scale' 5 | import * as React from 'react' 6 | import { feature } from 'topojson' 7 | import { genCoordsValue, genCoordsValueIt, genCoordsValueUs } from '../scripts' 8 | 9 | interface ItalyAtlas extends TopoJSON.Topology { 10 | objects: { 11 | sub: TopoJSON.GeometryCollection 12 | } 13 | } 14 | 15 | const y = d => d.value 16 | const defaultData = genCoordsValue(200) 17 | const side = 10 18 | 19 | const defaultDataUs = genCoordsValueUs(1000) 20 | const defaultDataIt = genCoordsValueIt(200) 21 | const italyAtlas = italyTopology as any 22 | const italy = feature(italyAtlas, (italyAtlas as ItalyAtlas).objects.sub) 23 | const projection = geoNaturalEarth1() 24 | 25 | const yScale = scaleLinear() 26 | .domain([Math.min(...defaultData.map(y)), Math.max(...defaultData.map(y))]) 27 | .range([1, side * 0.9]) 28 | 29 | const zScale = scaleLinear() 30 | .domain([0, Math.max(...defaultData.map(y))]) 31 | .range([0.1, 0.9]) 32 | .nice() 33 | 34 | export default { 35 | title: 'DATALITHS/PixelMap', 36 | component: PixelMap, 37 | } 38 | 39 | export const naturalEarth = () => { 40 | return ( 41 |Value: ${value.toFixed(2)}
`} 98 | /> 99 | ) 100 | } 101 | export const us = () => { 102 | return ( 103 |Value: ${value.toFixed(2)}
`} 115 | /> 116 | ) 117 | } 118 | export const customGeojson = () => { 119 | return ( 120 |Value: ${value.toFixed(2)}
`} 134 | /> 135 | ) 136 | } 137 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/components/ripple.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Ripple, RippleComponent } from '@datalith/ripple/src' 2 | import { scaleLinear } from 'd3-scale' 3 | import * as React from 'react' 4 | import { Spring } from 'react-spring/renderprops' 5 | import { easeInOutCubic } from '../lib' 6 | import { genDateValue } from '../scripts' 7 | 8 | const width = window.innerWidth 9 | const height = window.innerHeight 10 | const defaultData = genDateValue(20) 11 | 12 | const y = d => d.value 13 | 14 | // scales 15 | const yScale = scaleLinear() 16 | .domain([Math.min(...defaultData.map(y)), Math.max(...defaultData.map(y))]) 17 | .range([0, Math.min(width, height) * 0.3]) 18 | .clamp(true) 19 | 20 | const zScale = scaleLinear() 21 | .domain([0, Math.max(...defaultData.map(y))]) 22 | .range([0.9, 0.1]) 23 | .nice() 24 | 25 | export default { 26 | title: 'DATALITHS/Ripple', 27 | component: RippleComponent, 28 | args: { 29 | primary: true, 30 | }, 31 | } 32 | 33 | export const basic = () => { 34 | const data = defaultData.map(d => yScale(d.value)) 35 | returnDate: ${date.toLocaleDateString()}
96 |Value: ${value.toFixed(2)}
` 97 | } 98 | /> 99 | ) 100 | } 101 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/components/shutter.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Shutter, ShutterComponent } from '@datalith/shutter/src' 2 | import { scaleLinear } from 'd3-scale' 3 | import * as React from 'react' 4 | import { Spring } from 'react-spring/renderprops' 5 | import { easeInOutCubic } from '../lib' 6 | import { genDateValue } from '../scripts' 7 | 8 | const width = window.innerWidth 9 | const height = window.innerHeight 10 | const defaultData = genDateValue(20) 11 | 12 | const y = d => d.value 13 | 14 | // scales 15 | const zScale = scaleLinear() 16 | .domain([0, Math.max(...defaultData.map(y))]) 17 | .range([0.1, 1]) 18 | 19 | export default { 20 | title: 'DATALITHS/Shutter', 21 | component: ShutterComponent, 22 | } 23 | 24 | export const basic = () => { 25 | returnDate: ${date.toLocaleDateString()}
72 |Value: ${parseFloat(zScale(value).toFixed(2))}
73 |Color: rgba(0, 0, 255, ${zScale(value).toFixed(2)})
` 74 | } 75 | /> 76 | ) 77 | } 78 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/components/spiral.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Spiral, SpiralComponent } from '@datalith/spiral/src' 2 | import { scaleLinear } from 'd3-scale' 3 | import * as React from 'react' 4 | import { Spring } from 'react-spring/renderprops' 5 | import { genDateValue } from '../scripts' 6 | 7 | const defaultData = genDateValue(110) 8 | 9 | const y = d => d.value 10 | 11 | // scales 12 | const yScale = scaleLinear() 13 | .domain([0, Math.max(...defaultData.map(y))]) 14 | .range([1, 20]) 15 | 16 | const opacityScale = scaleLinear() 17 | .domain([Math.min(...defaultData.map(y)), Math.max(...defaultData.map(y))]) 18 | .range([0.3, 0.8]) 19 | 20 | export default { 21 | title: 'DATALITHS/Spiral', 22 | component: SpiralComponent, 23 | } 24 | 25 | export const basic = () => { 26 | const data = defaultData.map(d => yScale(d.value)) 27 | returnDate: ${date.toLocaleDateString()}
131 |Value: ${yScale.invert(Number(value)).toFixed(2)}
` 132 | } 133 | /> 134 | ) 135 | } 136 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.md' { 2 | const content: string 3 | export default content 4 | } 5 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/lib.ts: -------------------------------------------------------------------------------- 1 | export const easeInOutCubic = (t: number) => 2 | t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1 3 | -------------------------------------------------------------------------------- /packages/datalith-storybook/src/scripts/index.ts: -------------------------------------------------------------------------------- 1 | function getRandomInt(min: number, max: number) { 2 | min = Math.ceil(min) 3 | max = Math.floor(max) 4 | return Math.floor(Math.random() * (max - min + 1)) + min 5 | } 6 | 7 | export function genDateValue(n: number) { 8 | return Array(n) 9 | .fill(1) 10 | .map((d, i) => { 11 | return { 12 | date: new Date(Date.now() - i * 3600000), 13 | value: Math.max(250, Math.random() * 3000), 14 | value2: Math.max(250, Math.random() * 3000), 15 | } 16 | }) 17 | } 18 | 19 | export function genCoordsValue(n: number) { 20 | return Array(n) 21 | .fill(1) 22 | .map((d, i) => { 23 | return { 24 | lat: getRandomInt(-90, 90), 25 | lng: getRandomInt(-180, 180), 26 | value: Math.max(250, Math.random() * 3000), 27 | } 28 | }) 29 | } 30 | 31 | export function genCoordsValueUs(n: number) { 32 | return Array(n) 33 | .fill(1) 34 | .map((d, i) => { 35 | return { 36 | lat: getRandomInt(20, 50), 37 | lng: getRandomInt(-70, -125), 38 | value: Math.max(250, Math.random() * 3000), 39 | } 40 | }) 41 | } 42 | 43 | export function genCoordsValueIt(n: number) { 44 | return Array(n) 45 | .fill(1) 46 | .map((d, i) => { 47 | return { 48 | lat: getRandomInt(35, 47), 49 | lng: getRandomInt(8, 17), 50 | value: Math.max(250, Math.random() * 3000), 51 | } 52 | }) 53 | } 54 | -------------------------------------------------------------------------------- /packages/datalith-storybook/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "allowJs": false, 6 | "jsx": "react", 7 | "declaration": true, 8 | "declarationDir": "dist/types" 9 | }, 10 | "include": ["src"] 11 | } 12 | -------------------------------------------------------------------------------- /packages/datalith-util/README.md: -------------------------------------------------------------------------------- 1 | # @datalith/util 2 | 3 | #### Collection of React components to build cool data visualizations 4 | 5 | ```sh 6 | yarn add @datalith/util 7 | ``` 8 | -------------------------------------------------------------------------------- /packages/datalith-util/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@datalith/util", 3 | "version": "0.12.1", 4 | "description": "datalith util", 5 | "main": "dist/index.js", 6 | "module": "dist/index.js", 7 | "types": "dist/types/index.d.ts", 8 | "scripts": { 9 | "prebuild": "rm -rf dist", 10 | "build": "tsc", 11 | "prepublish": "tsc" 12 | }, 13 | "files": [ 14 | "dist" 15 | ], 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/lucafalasco/datalith.git" 19 | }, 20 | "keywords": [ 21 | "datalith", 22 | "visualizations", 23 | "charts" 24 | ], 25 | "author": "@lucafalasco", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/lucafalasco/datalith/issues" 29 | }, 30 | "homepage": "https://github.com/lucafalasco/datalith#readme", 31 | "dependencies": { 32 | "lodash": "^4.17.11", 33 | "react-sizeme": "^2.6.7" 34 | }, 35 | "devDependencies": { 36 | "@types/lodash": "^4.14.135", 37 | "@types/react": "^16.8.5", 38 | "react": "^16.8.5", 39 | "react-dom": "^16.8.5", 40 | "react-test-renderer": "^16.8.5", 41 | "typescript": "^4.2.4" 42 | }, 43 | "peerDependencies": { 44 | "react": "^15.0.0-0 || ^16.0.0-0" 45 | }, 46 | "publishConfig": { 47 | "access": "public" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/datalith-util/src/ResponsiveWrapper.tsx: -------------------------------------------------------------------------------- 1 | import React, { ComponentType } from 'react' 2 | import { SizeMe } from 'react-sizeme' 3 | import { CommonProps } from '.' 4 | 5 | export default function ResponsiveWrapper(Component: ComponentType
) { 6 | return class Wrapper extends React.Component
{ 7 | static defaultProps = Component.defaultProps as Partial
8 |
9 | render() {
10 | return this.props.size ? (
11 |