Giter VIP home page Giter VIP logo

Comments (20)

mark-langer avatar mark-langer commented on May 3, 2024 41

For everyone else looking into this issue, by now ApexCharts has bundled their typescript files in the official repo.

The folder is types/apexcharts.d.ts

from apexcharts.js.

jimfilippou avatar jimfilippou commented on May 3, 2024 24

I'm waiting for @types/apexcharts to come out, but here is a temporary solution

export interface ApexOptions {
  chart: {
    width?: string | number;
    height?: string | number;
    type: string;
    foreColor?: string;
  };
  plotOptions?: {
    radialBar?: {
      offsetY?: number;
      startAngle?: number;
      endAngle?: number;
      hollow?: {
        margin: number;
        size: string;
        background: string;
        image: string | undefined,
      },
      track?: {
        show: boolean
      },
      dataLabels?: {
        showOn?: string;
        name?: {
          show: boolean,

        },
        value?: {
          show: boolean,
        }
      }
    };
    circle?: {
      track?: {
        show: boolean
      },
      dataLabels: {
        showOn?: string;
        name?: {
          show: boolean,
        },
        value?: {
          show: boolean,
        }
      }
    };
    pie?: {
      size?: undefined,
      donut?: {
        size?: string;
        background?: string;
      },
      customScale?: number;
      offsetX?: number;
      offsetY?: number;
      dataLabels?: {
        offset?: number;
      }
    }
  };
  colors?: string[];
  series: number[];
  labels?: string[];
  legend?: {
    show?: boolean;
    floating?: boolean;
    fontSize?: string;
    position?: string;
    verticalAlign?: string;
    textAnchor?: string;
    labels?: {
      useSeriesColors: boolean
    };
    markers?: {
      size: number
    };
    formatter?: Function;
    itemMargin?: {
      vertical: number;
    };
    containerMargin?: {
      left: number;
      top: number;
    }
  };
}

from apexcharts.js.

e4r avatar e4r commented on May 3, 2024 23

Hey guys, I've extended a bit the interface kindly posted by @jimfilippou , however I am still unsure about which are the required fields. Hope it helps!

export enum ChartHorizontalAlign {
  left = 'left',
  center = 'center',
  right = 'right'
}

export enum ChartVerticalAlign {
  top = 'top',
  middle = 'middle',
  bottom = 'bottom'
}

export enum ChartTypes {
  line = 'line',
  area = 'area',
  bar = 'bar',
  histogram = 'histogram',
  pie = 'pie',
  donut = 'donut',
  radialBar = 'radialBar',
  scatter = 'scatter',
  bubble = 'bubble',
  heatmap = 'heatmap'
}

export enum ChartShape {
  circle = 'circle',
  square = 'square'
}

export enum ChartPosition {
  top = 'top',
  right = 'right',
  bottom = 'bottom',
  left = 'left'
}

export enum ChartCurve {
  smooth = 'smooth',
  straight = 'straight'
}

export interface ChartLegend {
  show?: true;
  position?: ChartPosition;
  horizontalAlign?: ChartHorizontalAlign;
  verticalAlign?: ChartVerticalAlign;
  floating?: boolean;
  fontSize?: string;
  offsetX?: number;
  offsetY?: number;
  formatter?: any;
  textAnchor?: string;
  labels?: {
      foreColor?: string;
      useSeriesColors?: boolean;
  };
  markers?: {
      size?: number;
      strokeColor?: string;
      strokeWidth?: number;
      offsetX?: number;
      offsetY?: number;
      radius?: number;
      shape?: ChartShape;
  };
  itemMargin?: {
      horizontal?: number;
      vertical?: number
  };
  containerMargin?: {
      left?: number;
      top?: number;
  };
  onItemClick?: {
      toggleDataSeries?: boolean;
  };
  onItemHover?: {
      highlightDataSeries?: boolean;
  };
}

export interface ChartConfig {
  height?: number;
  type?: ChartTypes;
  shadow?: {
      enabled?: boolean;
      color?: string;
      top?: number;
      left?: number;
      blur?: number;
      opacity?: number
  };
  zoom?: {
      enabled?: boolean
  };
}

export interface ChartSerie {
  name?: string;
  data?: number[];
}

export interface ChartRow {
  colors?: string[];
  opacity?: number;
}

export interface Chart {
  chart?: ChartConfig;
  colors?: string[];
  stroke?: {
      curve?: ChartCurve;
  };
  series?: ChartSerie[];
  title?: {
      text?: string;
      align?: ChartHorizontalAlign;
  };
  grid?: {
      borderColor?: string;
      row?: ChartRow;
  };
  markers?: {
    size?: number;
    colors?: string[];
    strokeColor?: string;
    strokeWidth?: number;
    strokeOpacity?: number;
    fillOpacity?: number;
    shape?: ChartShape;
    radius?: number;
    offsetX?: number;
    offsetY?: number;
    hover?: {
      size?: number
    }
  };
  xaxis?: {
      categories?: string[];
      title?: {
          text?: string;
      }
  };
  yaxis?: {
      title?: {
          text?: string;
      };
      min?: number;
      max?: number;
  };
  legend?: ChartLegend;
}

from apexcharts.js.

junedchhipa avatar junedchhipa commented on May 3, 2024 5

react-apexcharts, as well as vue-apexcharts, also has their own types.
Thanks to all the people who contributed to the typescript support for ApexCharts.

from apexcharts.js.

sandangel avatar sandangel commented on May 3, 2024 4

@junedchhipa I could help with this. We definitely need typescript support to be able to create angular bindings.

from apexcharts.js.

sandangel avatar sandangel commented on May 3, 2024 3

thanks everyone, I'm gathering all of these and hopefully could send a draft PR to @types repo today or tomorrow.

from apexcharts.js.

cstlaurent avatar cstlaurent commented on May 3, 2024 3

I think it is simpler to embed types directly in the repository instead of publishing them to the @types organisation. See: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html . As an example, Vue.js does it like this, with an entry in the package.json file and a types directory. Doing it this way allow types to always track the source code.

from apexcharts.js.

floer32 avatar floer32 commented on May 3, 2024 2

Following on @mark-langer's comment, here's a direct link:

from apexcharts.js.

sandangel avatar sandangel commented on May 3, 2024 1

Hi everyone finally I have a few hours working on this. Options are copied from the options refs on docs page, then converted to json when pasting the js object to a json file and run prettier. then I used json to ts vscode extension to convert json to ts typings.

quick note: I used type instead of interface so when you hover the type in vscode, it will show the literal typings instead of the type name.

Still a WIP, hope I could find sometimes work on it tomorrow or next week.

DefinitelyTyped/DefinitelyTyped#28733

from apexcharts.js.

IssueHuntBot avatar IssueHuntBot commented on May 3, 2024 1

@sandangel has started working. Visit this issue on Issuehunt

from apexcharts.js.

junedchhipa avatar junedchhipa commented on May 3, 2024 1

@Micene09 I agree that Typescript comes with a lot of advantages, but porting the whole project from JS to TS will be extremely tedious if not challenging looking at the size of the current codebase.

I have got some more contributions in the typings and I will publish soon directly in the repository.
Thanks for the suggestion.

from apexcharts.js.

IssueHuntBot avatar IssueHuntBot commented on May 3, 2024

@BoostIO funded this issue with $30. Visit this issue on Issuehunt

from apexcharts.js.

jimfilippou avatar jimfilippou commented on May 3, 2024

@cstlaurent brilliant, thanks!

from apexcharts.js.

junedchhipa avatar junedchhipa commented on May 3, 2024

@cstlaurent Good to know. I was worried about how the types will be synced with the core options.

If anyone finishes the first version of the types, I'm happy to accept a PR

from apexcharts.js.

Micene09 avatar Micene09 commented on May 3, 2024

@junedchhipa the only way i see is to (slowly and carefully) port the whole project to Typescript.

The first and simplest thing you can do is to rename *.js to *.ts, then configure the build settings in webpack.config.js .
After that every compilation error was fixed (...i'm sure you will have to), you can try to implement that interface from @e4r and only when everything is working, again, we will get the typings implicitly (using just compilation options).

In my opinion, you should not accept any PR with just the typings...because the risk to unsync the options is too high.

You should consider the Typescript porting a big improvement, not only for typings, but for every future implementation.

from apexcharts.js.

katiesandford avatar katiesandford commented on May 3, 2024

amazing thanks @junedchhipa! anything else we can do to help this?

from apexcharts.js.

junedchhipa avatar junedchhipa commented on May 3, 2024

@katiesandford Sure, maybe you can validate the typescript declarations to make sure they work correctly?

from apexcharts.js.

junedchhipa avatar junedchhipa commented on May 3, 2024

I have added the initial typescript declarations which cover most of the options.
If anyone finds anything missing or not in sync with the options listed here - https://apexcharts.com/docs/options/ feel free to add them

from apexcharts.js.

baoduy avatar baoduy commented on May 3, 2024

Hi All,
Thanks for great work here. react-apexcharts is an amazing library and hope it will support typescript soon.

from apexcharts.js.

IssueHuntBot avatar IssueHuntBot commented on May 3, 2024

@rororofff has funded $2.00 to this issue.


from apexcharts.js.

Related Issues (20)

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.