Giter Site home page Giter Site logo

pivot-js's People

Contributors

r3c avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

wuchao288

pivot-js's Issues

React implementation

For the record here is a POC-ed implementation using our stack:

import "./styles.css";
import { useState } from "react";
import { VariableSizeGrid } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";

let cellDefinitions = [
  () => ({
    value: Math.floor(Math.random() * 100)
  }),
  () => ({
    value: cellTexts[Math.floor(Math.random() * cellTexts.length)]
  }),
  () => ({
    value: cellModalities[Math.floor(Math.random() * cellModalities.length)]
  }),
  () => ({
    value: Math.random() < 0.5
  })
];

let cellModalities = [
  "Apple",
  "Banana",
  "Cherry",
  "Durian",
  "Elderberry",
  "Fig",
  "Grape",
  "Honeyberry",
  "Jujube",
  "Kumquat"
];
let cellTexts = [
  "Alice",
  "Bob",
  "Charlie",
  "Dan",
  "Eve",
  "Frank",
  "Grace",
  "Heidi",
  "Ivan",
  "Judy",
  "Ken"
];
function createArray(length, generator) {
  return new Array(length).fill(undefined).map((_, index) => generator(index));
}
function createTable() {
  let nbColumns = 100;
  let nbRows = 50000;

  return {
    pivot1: createArray(nbColumns, (index) => ({
      label: "Country #" + index,
      width: 60 + ~~(Math.random() * 120)
    })),
    pivot2: createArray(nbRows, (index) => ({
      label: "Product #" + index,
      height: 34
    })),
    data: createArray(nbColumns * nbRows, (index) =>
      cellDefinitions[(index % nbRows) % cellDefinitions.length]()
    )
  };
}

function Cell(props) {
  return (
    <div style={props.style}>
      {
        props.data.data[
          props.columnIndex + props.rowIndex * props.data.pivot1.length
        ].value
      }
    </div>
  );
}

export default function App() {
  const [table] = useState(() => createTable());
  return (
    <AutoSizer>
      {({ height, width }) => (
        <VariableSizeGrid
          columnCount={table.pivot1.length}
          columnWidth={(index) => table.pivot1[index].width}
          rowCount={table.pivot2.length}
          rowHeight={(index) => table.pivot2[index].height}
          width={width}
          height={height}
          itemData={table}
        >
          {Cell}
        </VariableSizeGrid>
      )}
    </AutoSizer>
  );
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.