├── .gitignore
├── src
├── index.js
├── assets
│ ├── thumbnail.png
│ └── transforms.js
├── components
│ ├── shapes
│ │ ├── index.js
│ │ └── Circle.js
│ ├── DataView
│ │ ├── cellStyles.js
│ │ ├── Cell.js
│ │ ├── Array.js
│ │ ├── Matrix.js
│ │ ├── NArray.js
│ │ └── index.js
│ ├── TransformButtons.js
│ ├── DemoView.js
│ ├── Button.js
│ ├── Demo.js
│ ├── App.js
│ └── Title.js
├── style
│ └── index.css
├── manifest.json
└── lib
│ └── css.js
├── preact.config.js
├── README.md
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules
2 | /build
3 | /npm-debug.log
4 |
5 | .env
6 | .DS_Store
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import "./style";
2 | import App from "./components/App";
3 |
4 | export default App;
5 |
--------------------------------------------------------------------------------
/src/assets/thumbnail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkh44/matrix-magic-demo/master/src/assets/thumbnail.png
--------------------------------------------------------------------------------
/preact.config.js:
--------------------------------------------------------------------------------
1 | export default (config, env, helpers) => {
2 | let { rule } = helpers.getLoadersByName(config, "babel-loader")[0];
3 | let babelConfig = rule.options;
4 |
5 | babelConfig.plugins.push("emotion");
6 | // babelConfig.env = { ...some settings... }
7 | };
8 |
--------------------------------------------------------------------------------
/src/components/shapes/index.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import Circle from './Circle';
3 |
4 | const circlePos =
5 |
6 | const ShapePicker = ({shape, x, y, width}) => {
7 | switch (shape) {
8 | case "circle":
9 |
10 | break;
11 |
12 | default:
13 | break;
14 | }
15 | }
16 |
17 | export default ShapePicker;
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Matrix Magic Demo
2 |
3 | [Link to site](https://matrix-magic.now.sh/)
4 |
5 | The demo for [matrix-magic](https://github.com/trainorpj/matrix-magic), a javascript library for manipulating, slicing, and doing other fun things with matrices.
6 |
7 | This page was made with [preact](https://preactjs.com/) and [emotion](https://emotion.sh/), among other wonderful technologies.
8 |
9 | Feel free to contribute!
--------------------------------------------------------------------------------
/src/components/shapes/Circle.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 |
3 | const Circle = ({ x, y, width }) => {
4 | const centerShift = x + width / 2;
5 |
6 | const styles = {
7 | cx: centerShift,
8 | cy: centerShift,
9 | r: width / 2,
10 | fill: "none",
11 | stroke: "black",
12 | strokeWidth: 1
13 | };
14 |
15 | return ;
16 | };
17 |
18 | export default Circle;
19 |
--------------------------------------------------------------------------------
/src/style/index.css:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | height: 100%;
4 | width: 100%;
5 | padding: 0;
6 | margin: 0;
7 | background: #c7e0fb;
8 | font-family: "Helvetica Neue", arial, sans-serif;
9 | font-weight: 400;
10 | color: #444;
11 | -webkit-font-smoothing: antialiased;
12 | -moz-osx-font-smoothing: grayscale;
13 | }
14 |
15 | * {
16 | box-sizing: border-box;
17 | }
18 |
19 | #app {
20 | height: 100%;
21 | }
22 |
--------------------------------------------------------------------------------
/src/components/DataView/cellStyles.js:
--------------------------------------------------------------------------------
1 | export const mainStyles = {
2 | matrix: {
3 | rx: 10,
4 | ry: 10,
5 | marginLeft: 5,
6 | marginBottom: 5,
7 | dx: 0,
8 | dy: 0
9 | },
10 | array: {
11 | rx: 3,
12 | ry: 3,
13 | marginLeft: 0,
14 | marginBottom: 0,
15 | dx: 0,
16 | dy: 7
17 | },
18 | nArray: {
19 | rx: 5,
20 | ry: 5,
21 | marginLeft: 2,
22 | marginBottom: 2,
23 | dx: 0,
24 | dy: 5
25 | }
26 | };
27 |
--------------------------------------------------------------------------------
/src/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Matrix Magic",
3 | "short_name": "Matrix Magic",
4 | "start_url": "/",
5 | "display": "standalone",
6 | "orientation": "portrait"
7 | // "background_color": "#fff",
8 | // "theme_color": "#673ab8"
9 | // "icons": [{
10 | // "src": "/assets/icons/android-chrome-192x192.png",
11 | // "type": "image/png",
12 | // "sizes": "192x192"
13 | // },
14 | // {
15 | // "src": "/assets/icons/android-chrome-512x512.png",
16 | // "type": "image/png",
17 | // "sizes": "512x512"
18 | // }]
19 | }
20 |
--------------------------------------------------------------------------------
/src/lib/css.js:
--------------------------------------------------------------------------------
1 | import { css } from "emotion";
2 |
3 | export const minDevice = styles => css`
4 | @media only screen and (min-device-width: 320px) and (max-device-width: 568px) and (-webkit-min-device-pixel-ratio: 2) {
5 | ${styles};
6 | }
7 | `;
8 |
9 | export const medBrowser = styles => css`
10 | @media only screen and (min-width: 946px) and (max-width: 1151px) and (-webkit-min-device-pixel-ratio: 1) {
11 | ${styles};
12 | }
13 | `;
14 |
15 | export const smallBrowser = styles => css`
16 | @media only screen and (min-width: 569px) and (max-width: 945px) and (-webkit-min-device-pixel-ratio: 1) {
17 | ${styles};
18 | }
19 | `;
20 |
--------------------------------------------------------------------------------
/src/components/TransformButtons.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import { css } from "emotion";
3 | import styled from "preact-emotion";
4 | import Button from "./Button";
5 | import { minDevice } from "../lib/css";
6 |
7 | const handheld = minDevice(`
8 | margin: 1em 5px;
9 | justify-content: flex-start;
10 | order: 2;
11 | `);
12 |
13 | const ButtonBin = styled.div`
14 | display: flex;
15 | flex-wrap: wrap;
16 | flex-direction: row;
17 | justify-content: center;
18 | margin: 1em;
19 | ${handheld};
20 | `;
21 |
22 | const TransformButtons = ({ transforms, action }) => {
23 | return (
24 |
25 | {transforms.map((d, i) => {
26 | return ;
27 | })}
28 |
29 | );
30 | };
31 |
32 | export default TransformButtons;
33 |
--------------------------------------------------------------------------------
/src/components/DataView/Cell.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import { mainStyles } from "./cellStyles";
3 |
4 | const Cell = ({ type, value, x, y, width, height }) => {
5 | const { entry, color, emoji } = value;
6 | const { marginBottom, marginLeft, rx, ry, dx, dy } = mainStyles[type];
7 |
8 | const textStyles = {
9 | x: (width - marginLeft) / 2,
10 | y: (height + marginBottom) / 2,
11 | dx,
12 | dy
13 | };
14 |
15 | return (
16 |
17 |
24 |
25 | {emoji}
26 |
27 |
28 | );
29 | };
30 |
31 | export default Cell;
32 |
--------------------------------------------------------------------------------
/src/components/DemoView.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import { css } from "emotion";
3 | import styled from "preact-emotion";
4 | import DataView from "./DataView";
5 | import { minDevice } from "../lib/css";
6 |
7 | const handheld = minDevice(`
8 | flex-direction: column;
9 | order: 1;
10 | margin-top: 1em;
11 | `);
12 |
13 | const View = styled.div`
14 | display: flex;
15 | justify-content: space-around;
16 |
17 | ${handheld};
18 | `;
19 |
20 | const DemoView = ({ matrix, fcn, label, type, styles }) => {
21 | return (
22 |
23 |
29 |
36 |
37 | );
38 | };
39 |
40 | export default DemoView;
41 |
--------------------------------------------------------------------------------
/src/components/Button.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import { css } from "emotion";
3 | import styled from "preact-emotion";
4 | import { minDevice } from "../lib/css";
5 |
6 | const borderRadius = `5px;`;
7 | const onColor = `background-color: black`;
8 | const offColor = `background-color: #3a466d`;
9 |
10 | const handheld = minDevice(`
11 | margin: 2px;
12 | border-radius: 0;
13 | border: none;
14 | `);
15 |
16 | const btn = css`
17 | flex-grow: 1;
18 | text-align: center;
19 | padding: 0.5em;
20 | color: #ffffff;
21 | margin: 0.25em 0.5em;
22 | border-radius: ${borderRadius};
23 | ${handheld};
24 | `;
25 |
26 | const OnButton = styled.div`${btn} ${onColor};`;
27 |
28 | const OffButton = styled.div`${btn} ${offColor};`;
29 |
30 | const Button = ({ transformObj, action }) => {
31 | const { on, label } = transformObj;
32 |
33 | if (on) {
34 | return action(transformObj)}>{label};
35 | }
36 | return action(transformObj)}>{label};
37 | };
38 |
39 | export default Button;
40 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "matrix-magic-demo",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "eslint src && preact test",
8 | "start": "if-env NODE_ENV=production && npm run -s serve || npm run -s dev",
9 | "build": "preact build",
10 | "serve": "preact build && preact serve",
11 | "dev": "preact watch"
12 | },
13 | "keywords": [],
14 | "author": "",
15 | "license": "ISC",
16 | "eslintConfig": {
17 | "extends": "eslint-config-synacor"
18 | },
19 | "devDependencies": {
20 | "eslint": "^4.8.0",
21 | "eslint-config-synacor": "^2.0.0",
22 | "if-env": "^1.0.0",
23 | "preact-cli": "^1.4.1"
24 | },
25 | "dependencies": {
26 | "@vx/scale": "0.0.140",
27 | "babel-plugin-emotion": "^8.0.2",
28 | "d3-array": "^1.2.1",
29 | "emotion": "^8.0.2",
30 | "matrix-magic": "^1.0.0",
31 | "preact": "^8.2.5",
32 | "preact-compat": "^3.17.0",
33 | "preact-emotion": "^8.0.2",
34 | "preact-helmet": "^4.0.0-alpha-3",
35 | "preact-router": "^2.5.7",
36 | "react-icons": "^2.2.7"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/components/DataView/Array.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import Cell from "./Cell";
3 | import { scaleLinear } from "@vx/scale";
4 |
5 | const STYLES = {
6 | rx: 3,
7 | ry: 3,
8 | marginLeft: 3,
9 | marginBottom: 0
10 | };
11 |
12 | const makeCoordinateArray = (arr, hrzScale, height, cellSize) => {
13 | const coordinateMatrix = arr.map((r, i) => {
14 | return {
15 | type: "array",
16 | value: r,
17 | x: hrzScale(i),
18 | y: height / 2 - cellSize,
19 | width: cellSize,
20 | height: cellSize
21 | };
22 | });
23 |
24 | return coordinateMatrix;
25 | };
26 |
27 | const Array = ({ arr, styles }) => {
28 | const svgWidth = styles.width;
29 | const svgHeight = styles.height;
30 |
31 | const width = arr.length;
32 |
33 | const cellSize = svgWidth / width;
34 |
35 | const hrz = scaleLinear({
36 | domain: [0, width],
37 | range: [0, svgWidth]
38 | });
39 |
40 | const coordinateArray = makeCoordinateArray(arr, hrz, svgHeight, cellSize);
41 |
42 | return (
43 | {coordinateArray.map((d, i) => | )}
44 | );
45 | };
46 |
47 | export default Array;
48 |
--------------------------------------------------------------------------------
/src/assets/transforms.js:
--------------------------------------------------------------------------------
1 | import * as mm from "matrix-magic";
2 |
3 | const addOutputType = (objArr, type) =>
4 | objArr.map(d => ({
5 | ...d,
6 | output: type
7 | }));
8 |
9 | const matrixOutputs = [
10 | { label: "Transpose", fcn: mm.transpose },
11 | { label: "Get Middle Columns", fcn: mm.getMiddleCols },
12 | { label: "Get Middle Rows", fcn: mm.getMiddleRows },
13 | { label: "Flip Columns", fcn: mm.flipCols },
14 | { label: "Flip Rows", fcn: mm.flipRows },
15 | { label: "Get All But Bottom Row", fcn: mm.getAllButBottomRow },
16 | { label: "Get All But Top Row", fcn: mm.getAllButTopRow },
17 | { label: "Get All But Left Column", fcn: mm.getAllButLeftCol },
18 | { label: "Get All But Right Column", fcn: mm.getAllButRightCol }
19 | ];
20 |
21 | const arrayOutputs = [
22 | { label: "Clockwise Spiral", fcn: mm.getClockwiseSpiral },
23 | { label: "Counterclockwise Spiral", fcn: mm.getCounterClockwiseSpiral }
24 | ];
25 |
26 | const nArrayOutputs = [
27 | { label: "Minor Diagonals", fcn: mm.getMinorDiagonals },
28 | { label: "Major Diagonals", fcn: mm.getMajorDiagonals }
29 | ];
30 |
31 | export default [
32 | ...addOutputType(matrixOutputs, "matrix"),
33 | ...addOutputType(arrayOutputs, "array"),
34 | ...addOutputType(nArrayOutputs, "nArray")
35 | ].map(d => ({ ...d, on: false }));
36 |
--------------------------------------------------------------------------------
/src/components/Demo.js:
--------------------------------------------------------------------------------
1 | import { h, render, Component } from "preact";
2 | import styled from "preact-emotion";
3 | import TransformButtons from "./TransformButtons";
4 | import DemoView from "./DemoView";
5 | import Title from "./Title";
6 | import transforms from "../assets/transforms";
7 |
8 | const styles = {
9 | width: 200,
10 | height: 200
11 | };
12 |
13 | const Bin = styled.div`
14 | margin: 1em;
15 | display: flex;
16 | flex-direction: column;
17 | `;
18 |
19 | const Footer = styled.div`
20 | text-align: center;
21 | margin: 2em 0;
22 | order: 4;
23 | `;
24 |
25 | class Demo extends Component {
26 | state = { transform: { ...transforms[0], on: true } };
27 |
28 | updateTransform = transformObj => this.setState({ transform: transformObj });
29 |
30 | render({ matrix, transformList }, { transform }) {
31 | const { label, fcn, output } = transform;
32 |
33 | return (
34 |
35 |
36 |
40 |
47 |
53 |
54 | );
55 | }
56 | }
57 |
58 | export default Demo;
59 |
--------------------------------------------------------------------------------
/src/components/DataView/Matrix.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import Cell from "./Cell";
3 | import { scaleLinear } from "@vx/scale";
4 | import { min } from "d3-array";
5 | import { getMatrixDimensions, flattenArray } from "matrix-magic";
6 |
7 | const getBarDim = (scale, margin = 0) => {
8 | const dim = Math.abs(scale.range()[1] - scale.range()[0]) / scale.domain()[1];
9 | return dim - margin;
10 | };
11 |
12 | const makeCoordinateArray = (matrix, hrzScale, vrtScale) => {
13 | const width = getBarDim(hrzScale);
14 | const height = getBarDim(vrtScale);
15 |
16 | const coordinateMatrix = matrix.map((r, rowIndex) => {
17 | return r.map((val, colIndex) => {
18 | return {
19 | type: "matrix",
20 | value: val,
21 | x: hrzScale(colIndex),
22 | y: vrtScale(rowIndex),
23 | width,
24 | height
25 | };
26 | });
27 | });
28 |
29 | return flattenArray(coordinateMatrix);
30 | };
31 |
32 | const Matrix = ({ matrix, styles }) => {
33 | const svgWidth = styles.width;
34 | const svgHeight = styles.height;
35 |
36 | const { width, height } = getMatrixDimensions(matrix);
37 |
38 | const cellSize = min([svgWidth / width, svgHeight / height]);
39 |
40 | const hrz = scaleLinear({
41 | domain: [0, width],
42 | range: [0, cellSize * width]
43 | });
44 |
45 | const vrt = scaleLinear({
46 | domain: [0, height],
47 | range: [0, cellSize * height]
48 | });
49 |
50 | const coordinateArray = makeCoordinateArray(matrix, hrz, vrt);
51 |
52 | return {coordinateArray.map((d, i) => | )};
53 | };
54 |
55 | export default Matrix;
56 |
--------------------------------------------------------------------------------
/src/components/DataView/NArray.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import Cell from "./Cell";
3 | import { scaleLinear } from "@vx/scale";
4 | import { max, min } from "d3-array";
5 | import { getMatrixDimensions, flattenArray } from "matrix-magic";
6 |
7 | const STYLES = {
8 | rx: 5,
9 | ry: 5,
10 | marginLeft: 2,
11 | marginBottom: 2
12 | };
13 |
14 | const getBarDim = (scale, margin = 0) => {
15 | const dim = Math.abs(scale.range()[1] - scale.range()[0]) / scale.domain()[1];
16 | return dim - margin;
17 | };
18 |
19 | const makeCoordinateArray = (matrix, hrzScale, vrtScale) => {
20 | const width = getBarDim(hrzScale);
21 | const height = getBarDim(vrtScale);
22 |
23 | const coordinateMatrix = matrix.map((r, rowIndex) => {
24 | return r.map((val, colIndex) => {
25 | return {
26 | type: "nArray",
27 | value: val,
28 | x: hrzScale(colIndex),
29 | y: vrtScale(rowIndex),
30 | width,
31 | height
32 | };
33 | });
34 | });
35 |
36 | return flattenArray(coordinateMatrix);
37 | };
38 |
39 | const NArray = ({ nArray, styles }) => {
40 | const svgWidth = styles.width;
41 | const svgHeight = styles.height;
42 |
43 | const height = nArray.length;
44 | const width = max([...nArray.map(d => d.length)]);
45 |
46 | const cellSize = min([svgWidth / width, svgHeight / height]);
47 |
48 | const hrz = scaleLinear({
49 | domain: [0, width],
50 | range: [0, cellSize * width]
51 | });
52 |
53 | const vrt = scaleLinear({
54 | domain: [0, height],
55 | range: [0, cellSize * height]
56 | });
57 |
58 | const coordinateArray = makeCoordinateArray(nArray, hrz, vrt);
59 |
60 | return (
61 | {coordinateArray.map((d, i) => | )}
62 | );
63 | };
64 |
65 | export default NArray;
66 |
--------------------------------------------------------------------------------
/src/components/App.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import styled from "preact-emotion";
3 | import Helmet from "preact-helmet";
4 | import Title from "./Title";
5 | import DemoView from "./DemoView";
6 | import TransformButtons from "./TransformButtons";
7 | import Demo from "./Demo";
8 | import transforms from "../assets/transforms";
9 | import { minDevice, smallBrowser, medBrowser } from "../lib/css";
10 |
11 | const matrix = [
12 | [
13 | { entry: "", color: "#ef8fc7", emoji: "😀" },
14 | { entry: "", color: "#ef8fc7", emoji: "💩" },
15 | { entry: "", color: "#ef8fc7", emoji: "🤖" },
16 | { entry: "", color: "#ef8fc7", emoji: "👏" }
17 | ],
18 | [
19 | { entry: "", color: "#8fd0ef", emoji: "😀" },
20 | { entry: "", color: "#8fd0ef", emoji: "💩" },
21 | { entry: "", color: "#8fd0ef", emoji: "🤖" },
22 | { entry: "", color: "#8fd0ef", emoji: "👏" }
23 | ],
24 | [
25 | { entry: "", color: "#efc38f", emoji: "😀" },
26 | { entry: "", color: "#efc38f", emoji: "💩" },
27 | { entry: "", color: "#efc38f", emoji: "🤖" },
28 | { entry: "", color: "#efc38f", emoji: "👏" }
29 | ]
30 | ];
31 |
32 | const handheld = minDevice(`
33 | width: 100%;
34 | `);
35 |
36 | const deskSmall = smallBrowser(`
37 | width: 80%;
38 | `);
39 |
40 | const deskMed = medBrowser(`
41 | width: 65%;
42 | `);
43 |
44 | const AppBin = styled.div`
45 | width: 50%;
46 | margin: 1em auto;
47 | ${deskSmall};
48 | ${deskMed};
49 | ${handheld};
50 | `;
51 |
52 | const App = () => {
53 | return (
54 |
55 |
63 |
64 |
65 | );
66 | };
67 |
68 | export default App;
69 |
--------------------------------------------------------------------------------
/src/components/Title.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import GitHub from "react-icons/lib/go/mark-github";
3 | import Twitter from "react-icons/lib/ti/social-twitter";
4 | import { css } from "emotion";
5 | import styled from "preact-emotion";
6 | import { minDevice } from "../lib/css";
7 |
8 | const TitleBin = styled.div`
9 | grid-area: title;
10 | color: #08232c;
11 | text-align: center;
12 | `;
13 |
14 | const Top = styled.div`font-size: 3em;`;
15 |
16 | const Name = styled.div`
17 | font-size: 1.5em;
18 | margin-top: 0.5em;
19 | `;
20 |
21 | const Social = styled.div`
22 | display: flex;
23 | justify-content: center;
24 | text-align: center;
25 |
26 | margin: 0.5em 0;
27 |
28 | a {
29 | align-self: center;
30 | }
31 |
32 | a:visited {
33 | color: black;
34 | }
35 | `;
36 |
37 | const Code = styled.div`
38 | background-color: #e2e2e2;
39 | text-align: center;
40 | padding: 0.5em 0;
41 | margin: 0 1.5em;
42 | border-radius: 5px;
43 | border: 1px solid #797979;
44 |
45 | ${minDevice(`
46 | margin: 0;
47 | `)};
48 | `;
49 |
50 | const Desc = styled.div`margin: 1em 0;`;
51 |
52 | const Title = () => {
53 | const len = "1.5em";
54 | return (
55 |
56 | Matrix Magic
57 | PJ Trainor
58 |
59 |
60 |
65 |
66 |
67 |
72 |
73 |
74 |
75 | A library to manipulate, slice, and do other fun things with matrices
76 |
77 |
78 | npm install --save matrix-magic
79 |
80 |
81 | );
82 | };
83 |
84 | export default Title;
85 |
--------------------------------------------------------------------------------
/src/components/DataView/index.js:
--------------------------------------------------------------------------------
1 | import { h, Component } from "preact";
2 | import { doMatrixCheck } from "matrix-magic";
3 | import styled from "preact-emotion";
4 | import Matrix from "./Matrix";
5 | import Array from "./Array";
6 | import NArray from "./NArray";
7 | import { minDevice } from "../../lib/css";
8 |
9 | const borderRadius = "10px";
10 |
11 | const Bin = styled.div`
12 | ${minDevice(`
13 | margin-bottom: 1em;
14 | `)};
15 | `;
16 |
17 | const Display = styled.div`
18 | background-color: #fff;
19 | padding: 2em;
20 | display: flex;
21 | flex-direction: column;
22 | justify-content: space-around;
23 | align-items: center;
24 | align-content: center;
25 | border-bottom-left-radius: ${borderRadius};
26 | border-bottom-right-radius: ${borderRadius};
27 | ${minDevice(`
28 | padding: 1em;
29 | `)};
30 | `;
31 |
32 | const Label = styled.div`
33 | background-color: #3a466d;
34 | color: #ffffff;
35 | text-align: center;
36 | padding: 1em 0;
37 | border-top-left-radius: ${borderRadius};
38 | border-top-right-radius: ${borderRadius};
39 | `;
40 |
41 | const TypeDisplay = styled.div`
42 | color: #afafaf;
43 | width: 100%;
44 | text-align: right;
45 | padding-right: 1em;
46 | padding-top: 0.5em;
47 | ${minDevice(`
48 | padding-top: 0;
49 | `)};
50 | `;
51 |
52 | const getComponent = (data, styles) => outputType => {
53 | switch (outputType) {
54 | case "matrix":
55 | return ;
56 | case "nArray":
57 | return ;
58 | case "array":
59 | return ;
60 | }
61 | };
62 |
63 | // TODO better array checking
64 | const emojiMatrix = matrix => {
65 | try {
66 | return matrix.map(d => d.map(x => x.emoji));
67 | } catch (err) {
68 | return matrix.map(d => d.emoji);
69 | }
70 | };
71 |
72 | const DataView = ({ matrix, type, label, styles, logTable = false }) => {
73 | const { width, height } = styles;
74 |
75 | const componentGetter = getComponent(matrix, styles);
76 |
77 | if (logTable) {
78 | console.log(`output of ${label}`);
79 | console.table(emojiMatrix(matrix));
80 | }
81 |
82 | return (
83 |
84 |
85 |
86 |
89 | Data type: {type}
90 |
91 |
92 | );
93 | };
94 |
95 | export default DataView;
96 |
--------------------------------------------------------------------------------