Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript definitions #197

Closed
23 of 26 tasks
plouc opened this issue May 22, 2018 · 30 comments
Closed
23 of 26 tasks

TypeScript definitions #197

plouc opened this issue May 22, 2018 · 30 comments

Comments

@plouc
Copy link
Owner

plouc commented May 22, 2018

This issue is used to track down the ongoing work on TypeScript definitions for nivo packages.

As nivo isn't built using TypeScript, it does not include definitions, if you're working in a TS environment and already created one for your use case, please do not hesitate to submit a PR!

@plouc
Copy link
Owner Author

plouc commented May 22, 2018

@kodedevil, if you're willing to contribute with sankey definition, please link your PR to this issue :)

@wyze
Copy link
Contributor

wyze commented May 23, 2018

We use TypeScript in our project that contains nivo. A lot of the times we just use an empty declare module '@nivo/bar' in a global setting and move on. I'll definitely take some of these and contribute them so we can remove those from our project.

@plouc plouc added 🔴 circle-packing @nivo/circle-packing package 📆 calendar @nivo/calendar package radar @nivo/radar package stream @nivo/stream package 📈 line @nivo/line package chord @nivo/chord package scatterplot @nivo/scatterplot package 🌳 treemap @nivo/treemap package 🌞 sunburst and removed 📆 calendar @nivo/calendar package labels Jun 4, 2018
@kallebornemark
Copy link

kallebornemark commented Sep 18, 2018

@plouc It seems like the current Typescript definitions for ResponsiveBar requires one to provide a lot of props that are marked as optional in the docs, such as defs. Or am I missing something?

@plouc
Copy link
Owner Author

plouc commented Sep 18, 2018

@kallebornemark, the doc says they're not required, but in fact they are required but defaultProps are defined, recent TypeScript version supports this, so the definitions should be updated :/

@kallebornemark
Copy link

@plouc I see. Do you think still will happen anytime soon? We're looking for a sophisticated graph lib for our project, and yours looks really promising. We're very reliant on TS at the moment though.

@plouc
Copy link
Owner Author

plouc commented Sep 19, 2018

Not soon, I won't have much time to work on nivo in the upcoming weeks, but contributions are welcome :) All components have quite exhaustive prop types, it can help to write TS definitions.

@plouc
Copy link
Owner Author

plouc commented Oct 17, 2018

Support added for @nivo/line package

@plouc
Copy link
Owner Author

plouc commented Oct 18, 2018

Definitions added for @nivo/scatterplot package

@SaphuA
Copy link

SaphuA commented Nov 14, 2018

As I don't have time right now to submit a pr (I might later) I'll use this place to sum up typescript issues I find as I go:

Bar v0.51

  • Axis is missing renderTick property.
  • Axis legendPosition contains center but should be middle.
  • I think colorBy and tooltip should receive BarExtendedDatum as prop instead of BarDatum.

Pie v0.51
- [ ] Small issue, but doing something like this colorBy={(datum) => datum.color} won't work because datum is of a specific type even though it could contain anything. Never mind, PieDatum has an indexer.

@plouc
Copy link
Owner Author

plouc commented Nov 14, 2018

@SaphuA, thank you

@plouc
Copy link
Owner Author

plouc commented May 18, 2019

@nivo/stream & @nivo/radar now come with TypeScript definitions.

@sloanepetit
Copy link

sloanepetit commented Jun 3, 2019

Hi,

It seems that the cellComponent & legends props declarations are missing in the Waffle component.

@molzahn-sio
Copy link

Great work! I'm starting with typescript and nivo and these definitions are a blessing.

I noticed two missing typings in LineCustomLayerProps though when attempting to do dashed lines by copying the custom line style example:

  • lineGenerator
  • areaGenerator

@latema
Copy link

latema commented Sep 6, 2019

The pointSymbol prop is missing from the LineProps interface in line typings. I created a PR for it: #681.

@felipap
Copy link

felipap commented Sep 14, 2019

Hi there, has the Typescript issue with borderColor in @nivo/bar (#344) been fixed?

@londonbarrett
Copy link

renderTick is still missing ..

@joseantonomh
Copy link

First of anything, thanks for the awesome work. Keep it up! :)

I just realized, that the Types of the Axis' property legend are inconsistent between LineChart and BarChart.

Axis.legend is type string (Bar)
AxisProps.legend is type React.ReactNode (Line)

Since both seems to accept strings and components (at least <tspan>) I believe that legend should be of type React.ReactNode for both.

@maayanbar13
Copy link

Hi! just wanted to mention that there are some type definitions missing for the @nivo/core package, stumbled upon it while trying to use linearGradientDef. should probably add it to the list.

escobar5 added a commit to escobar5/nivo that referenced this issue May 5, 2020
…ptions

Some curve options where missing (basis, cardinal, catmullRom)
plouc pushed a commit that referenced this issue May 10, 2020
… options (#197, #944)

Some curve options where missing (basis, cardinal, catmullRom)
@plouc plouc removed 🌳 treemap @nivo/treemap package 🌞 sunburst 📆 calendar @nivo/calendar package labels Jun 26, 2020
@plouc plouc closed this as completed Jun 26, 2020
@seppu
Copy link

seppu commented Sep 7, 2020

Hi @plouc , I am trying to add a total to the ResponsiveBar stacked bars from @nivo/bars using the Layer option.
I am trying to follow a similar logic to this codepen

I have created my project with typescript so when I am adding the following line
layers={["grid", "axes", "bars", TotalLabels, "markers", "legends"]}
I am getting a type error

No overload matches this call.
  Overload 2 of 2, '(props: BarSvgProps, context?: any): ResponsiveBar', gave the following error.
    Type '"grid"' is not assignable to type 'Layer'.
  Overload 2 of 2, '(props: BarSvgProps, context?: any): ResponsiveBar', gave the following error.
    Type '"axes"' is not assignable to type 'Layer'.
  Overload 2 of 2, '(props: BarSvgProps, context?: any): ResponsiveBar', gave the following error.
    Type '"bars"' is not assignable to type 'Layer'.
  Overload 2 of 2, '(props: BarSvgProps, context?: any): ResponsiveBar', gave the following error.
...............................................................................

Checking the type definitions for bars I can see it has types for Layers. Any idea where I am going wrong
Following is my code


import React from "react";
import { ResponsiveBar, BarCustomLayer } from "@nivo/bar";
const TotalLabels:BarCustomLayer = ({ bars , yScale }: any) => {
    // space between top of stacked bars and total label
    const labelMargin = 20;
  
    return bars.map(({ data: { data, indexValue }, x, width }: any, i: number) => {
      // sum of all the bar values in a stacked bar
      const total = data['Net Spend'];
  
      return (
        <g
          transform={`translate(${x}, ${yScale(total) - labelMargin})`}
          key={`${indexValue}-${i}`}
        >
          <text
            // add any class to the label here
            className="bar-total-label"
            x={width / 2}
            y={labelMargin / 2}
            textAnchor="middle"
            alignmentBaseline="central"
            // add any style to the label here
            style={{
              fill: "rgb(51, 51, 51)"
            }}
          >
            {total}
          </text>
        </g>
      );
    });
  };
const ResponsiveStackedBar: React.FunctionComponent<any> = ({ data, keys }) => { 
    return (
        <ResponsiveBar
            data={data}
            keys={keys}
            indexBy="scenario"
            margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
            padding={0.5}
            // colors={{ scheme: 'nivo' }}
            colors={({ id, data }) => data[`${id}Color`]}
            
            borderColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }}
            axisTop={null}
            axisRight={null}
            axisBottom={{
                tickSize: 5,
                tickPadding: 5,
                tickRotation: 0,
                legend: 'Scenario',
                legendPosition: 'middle',
                legendOffset: 40
            }}
            axisLeft={{
                tickSize: 5,
                tickPadding: 5,
                tickRotation: 0,
                legend: 'Amount',
                legendPosition: 'middle',
                legendOffset: -55,
                format: '$.2s'
            }}
            labelSkipWidth={12}
            labelSkipHeight={12}
            labelTextColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }}
            labelFormat="$.2s"
            legends={[
                {
                    dataFrom: 'keys',
                    anchor: 'top-right',
                    direction: 'column',
                    justify: false,
                    translateX: 120,
                    translateY: 0,
                    itemWidth: 100,
                    itemHeight: 20,
                    itemsSpacing: 0,
                    symbolSize: 20,
                    itemDirection: 'left-to-right'
                }
            ]}
            animate={true}
            motionStiffness={90}
            motionDamping={15}
            layers={["grid", "axes", "bars", TotalLabels, "markers", "legends"]}
        />
    )
};

If I change the line to
layers={[TotalLabels]}
there is no type error but the graphs are not shown even though I can see the totals. And this I know will not work as grid needs to come first

@wyze
Copy link
Contributor

wyze commented Sep 10, 2020

It is because the layers you are passing in are coming as string instead of grid or axes, etc. You might be able to do layers={["grid", "axes", "bars", TotalLabels, "markers", "legends"] as const}, but if that doesn't work, you will need to import Layer from @nivo/bar and do layers={["grid", "axes", "bars", TotalLabels, "markers", "legends"] as Layer[]}.

@stephanoshadjipetrou
Copy link

@plouc when trying to install @nivo/treemap package seems that the index.d.ts file is missing. Based on the initial comment list of yours treemap has ts types defined, isn't that right?

@wyze
Copy link
Contributor

wyze commented Oct 6, 2020

@stephanoshadjipetrou It is on master but hasn't been made to a release. It will be in the next release, whenever that might be.

@stephanoshadjipetrou
Copy link

@wyze thanks for the quick response! just another quick question: is this the same case for sunburst package?

@wyze
Copy link
Contributor

wyze commented Oct 6, 2020

Yup!

@madhavan-sundararaj
Copy link

Thank you for the awesome effort. Any chance of adding Module LineComputedSerieData to @nivo/line in types? Because I am getting following error.

Module '"@nivo/line"' has no exported member 'LineComputedSerieData'.

@mikejackowski
Copy link

Seems like Treemap is missing tooltip. Any chance of adding it?

@wyze
Copy link
Contributor

wyze commented Apr 21, 2021

Hi @maddy2894 and @mikejackowski please open separate issues specific to your requests and we can handle it there. Thanks!

@lhguerra
Copy link

I see Pie is already checked as done, but I'm unable to import the type for data property (I expeted it to be PieDatum but it is not exported). Should I use some other type or is this a separate issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests