react-vis icon indicating copy to clipboard operation
react-vis copied to clipboard

stroke and opacity properties issue on data object

Open romainneutron opened this issue 10 years ago • 6 comments

Hello,

First of all, thanks for this library. I'm trying to use the VerticalBarSeries like below and cannot manage to get it working like I would. Following the guide ate https://github.com/uber/react-vis/blob/master/docs/xy-plot.md#common-concepts, I expected to be allowed to defined either stroke, opacity, fill or color on any data object, however it does not seem to work. For instance using this code, I end up with {opacity: 0.1, stroke: "#12939A", fill: "#12939A"} set as style properties.

                    <XYPlot
                        width={800}
                        height={300}>
                        <VerticalBarSeries
                            data={source.map(data => ({
                                x: data.key,
                                y: data.doc_count,
                                fill: 'green',
                                stroke: 'red',
                                opacity: 0.4,
                            }))}
                        />
                    </XYPlot>

Is it a bug? Am I misusing the library?

Thanks

romainneutron avatar Oct 14 '16 06:10 romainneutron

Would you mind creating an example repo?

jameskraus avatar Nov 07 '16 19:11 jameskraus

+1 this has happened to mine as well. When opacity is manipulated, it defaults to 0.1.

georgesakourishan avatar Nov 22 '16 19:11 georgesakourishan

Hey @romainneutron

Opacity has some particular defaults. Generally I've found it more preferable to use the literal scale type

<XYPlot width={800} height={300}> <VerticalBarSeries opacityType="literal" data={source.map(data => ({ x: data.key, y: data.doc_count, fill: 'green', stroke: 'red', opacity: 0.4, }))} /> </XYPlot>

Which causes the value at hand not to be scaled or manipulated relative to the default. The literal scale type is great for time when you want to exactly specify a color, or a property you know well, such as opacity.

mcnuttandrew avatar Dec 14 '16 23:12 mcnuttandrew

Hey all,

In the recent major version bump (1.0.0) i modified the way that opacity works by default ot be a little more natural, so that it does not default to 0.1. This should clear up your opacity problems. I haven't been able to reproduce the stroke issues. I am closing this issue, but feel free to re-open if they are still going.

mcnuttandrew avatar Feb 27 '17 18:02 mcnuttandrew

Just an FYI I had a similar issue with the fill and stroke not being honored. By providing fillType: 'literal', etc... the series then honored the colors I set. This isn't really explicit in the XYPlot / Series type documentation, although it is mentioned in the Scales and Data docs.

My .02 would be to make the color types (fill, stroke, opacity) default to literal instead of linear. Thoughts?

akindr avatar Mar 01 '17 21:03 akindr

@akindr I couldn't agree more. If you specify fill and stroke attributes directly on your data items as suggested in the docs, the colors will not be honored if you don't provide fillType and strokeType attributes set to literal on your Series component.

The Scales and Data docs do not help in this case. I don't know about the implications of your suggestion, but it seems to be the right thing here. Whether or not this solution is adopted, users will always expect the rendered colors to match what they wrote in their code.

Thanks for your help!

@mcnuttandrew I think this issue should be re-opened.

WaldoJeffers avatar Mar 09 '17 16:03 WaldoJeffers