0.6.0 • Published 1 year ago

candl v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

What is Candl ?

Candl is a chart library that makes it easy to set up fully customizable candlestick charts.

  • 💪 Plug N Play.
  • 🛠️ Fully customizable.
  • ⚡ Multi-Layers 2D Canvas for better performance.
  • 🖱️ Mouse & Touch* interaction built-in.
  • 🎲 Mock data generators built-in.
  • 🕒 Underlying Day.js for date handling.

(*) not available yet

Get Started

Installation

npm i candl --save

Documentation

Full Example with Mock Data

Very basic example of a seeded chart in React with TypeScript.

import { useEffect, useRef } from "react";
import {
  Candl,
  CandlMock,
  CandlSerie,
  CandlTimeFrame,
  get1MBaseViews,
} from "candl";

const CandlWrapper: React.FC = () => {
  // Reference to the container of the chart
  const containerRef = useRef<HTMLDivElement | null>(null);

  // Reference to the chart
  const candlRef = useRef<Candl | null>(null);

  useEffect(() => {
    if (containerRef.current) {
      // Create the chart
      candlRef.current = new Candl(containerRef.current);

      // Create a serie for 1M TimeFrame
      const mySerie: CandlSerie = new CandlSerie(CandlTimeFrame.Time1Minute);

      // Add mocked data with 10 000 candles
      mySerie.setData(
        CandlMock.generateMockData(CandlTimeFrame.Time1Minute, 10000)
      );

      // Add default 1M base views to the serie
      mySerie.setViews(get1MBaseViews());

      // Add serie to Candl
      candlRef.current.addSerie(CandlTimeFrame.Time1Minute, mySerie);

      // Jump to the end of the chart
      candlRef.current.setOffset({
        x: candlRef.current.getLastCandleOffset(),
        y: candlRef.current.getOffset().y,
      });

      // Force update of the chart
      candlRef.current.forceUpdate();
    }

    return () => {
      // Don't forget to clean the chart
      if (candlRef.current != null) {
        candlRef.current.clean();
      }
    };
  }, []);

  return (
    <div
      style={{
        position: "relative",
        width: "100%",
        height: "100%",
      }}
      ref={containerRef}
    />
  );
};
export default CandlWrapper;

Code Quality

No coverage yet.

Before 1.0.0, unit tests will be a posteriori.

After it, unit tests will be a priori (TDD).

Author

THP-Software

0.5.0

1 year ago

0.3.2

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.3.4

1 year ago

0.6.0

1 year ago

0.3.3

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago