Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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.
.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", () => (
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,
});
});
}