How to use the @gitgraph/core.GitgraphCore function in @gitgraph/core

To help you get started, we’ve selected a few @gitgraph/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nicoespeon / gitgraph.js / packages / gitgraph-js / src / gitgraph.ts View on Github external
// E.g. {20: 30} means for commit: y=20 -> y=30
  // Offset should be computed when graph is rendered (componentDidUpdate).
  let commitYWithOffsets: CommitYWithOffsets = {};
  let shouldRecomputeOffsets = false;
  let lastData: RenderedData;
  let $commits: SVGElement;
  let commitMessagesX = 0;
  let $tooltip: SVGElement | null = null;

  // Create an `svg` context in which we'll render the graph.
  const svg = createSvg();
  adaptSvgOnUpdate();
  graphContainer.appendChild(svg);

  // React on gitgraph updates to re-render the graph.
  const gitgraph = new GitgraphCore(options);
  gitgraph.subscribe((data) => {
    shouldRecomputeOffsets = true;
    render(data);
  });

  // Return usable API for end-user.
  return gitgraph.getUserApi();

  function render(data: RenderedData): void {
    // Reset before new rendering to flush previous state.
    commitsElements = {};

    const { commits, branchesPaths } = data;
    commitMessagesX = data.commitMessagesX;

    // Store data so we can re-render after offsets are computed.
github nicoespeon / gitgraph.js / packages / stories / src / gitgraph-react / 1-basic-usage.stories.tsx View on Github external
.add("pass graph instance as a prop", () => {
    const graph = new GitgraphCore>({
      generateCommitHash: createFixedHashGenerator(),
    });

    const gitgraph = graph.getUserApi();
    const master = gitgraph
      .branch("master")
      .commit("Initial commit (from graph props)");
    const develop = gitgraph.branch("develop");
    develop.commit("one");
    master.commit("two");
    develop.commit("three");
    master.merge(develop);

    return ;
  })
  .add("stop on last commit", () => (
github nicoespeon / gitgraph.js / packages / gitgraph-react / src / Gitgraph.tsx View on Github external
constructor(props: GitgraphProps) {
    super(props);
    this.state = {
      commits: [],
      branchesPaths: new Map(),
      commitMessagesX: 0,
      commitYWithOffsets: {},
      shouldRecomputeOffsets: true,
      currentCommitOver: null,
    };
    this.gitgraph = isPropsWithGraph(props)
      ? props.graph
      : new GitgraphCore(props.options);
    this.gitgraph.subscribe((data) => {
      const { commits, branchesPaths, commitMessagesX } = data;
      this.setState({
        commits,
        branchesPaths,
        commitMessagesX,
        shouldRecomputeOffsets: true,
      });
    });
  }

@gitgraph/core

Core of gitgraph, a JavaScript library to draw pretty git graphs

MIT
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis