Victory Charts cuts off tick labels when angled - react-native

(Edit: I also tried putting overflow: 'visible' in various locations to no avail.)
I'm using a date for the x-axis tick labels so I would like them to be at an angle to prevent overlap. The issue is that they are not being cut off at the bottom, as seen here (the colors are there to show different component edges):
Here is my code:
<View style={{ backgroundColor: 'red', paddingBottom: 50 }}>
<VictoryChart
theme={chartTheme}
width={screenWidth - 10}
animate={{
onLoad: { duration: 100 },
duration: 500,
}}
containerComponent={<VictoryContainer style={{ backgroundColor: 'blue', paddingBottom: 50 }} />} >
<VictoryAxis
label={plotText.xLabel}
style={{ // adding padding here does nothing
tickLabels: { angle: -45, textAnchor: 'end' } // adding padding here does nothing
}}
tickValues={dispRSHistData.ticks}
tickFormat={(t) => getFormattedDate(t)}
/>
<VictoryAxis
dependentAxis
label={plotText.yLabel} />
<VictoryLine
data={dispRSHistData.data}
x="timestamp"
y="percentSuccess"
style={{ data: { stroke: "tomato" } }}
size={10} />
</VictoryChart>
</View>
I've tried setting various heights manually but nothing seems to give space to show the full tick labels.

I didnt find an automatic solution to your problem
but mannualy adding "padding" prop to the chart worked for me
btw this solution is for VictoryNative on react native but I guess something similar works on react.js version too
check the 'padding' prop here
<VictoryChart width={400} theme={VictoryTheme.material}
padding={{bottom:100,right:50,left:50}}
>
<VictoryAxis //the x axis
// axisLabelComponent={<VictoryLabel angle={-90}/>}
tickLabelComponent={<VictoryLabel angle={-90} dy={-7}
textAnchor='end'
// labelPlacement="perpendicular"
/>}
/>
<VictoryAxis dependentAxis //the y axis
/>

Related

How to apply gradient shadow color in StackedAreaChart of "#rainbow-me/animated-charts" library?

I'm using this library to make a StackedAreaChart. It's currently working but I need to change the colors to gradients.Only I am able to plot points using the data,I want the gradient colors to be applied in the plotted chart area.
I have attached the code and screenshot for this.
<ChartPathProvider
data={{
points: chartData.map((data) => ({
x: toTimestamp(data.fiscal_year),
y:
data.close_price != null
? parseFloat(data.close_price).toFixed(
instrumentData.digit
)
: 0,
})),
smoothingStrategy: "bezier",
}}
>
<View>
<ChartPath
height={moderateScale(280)}
stroke="green"
strokeWidth={3}
width={screenWidth}
/>
<ChartDot>
<View
style={{
position: "absolute",
left: moderateScale(-35),
width: moderateScale(80),
alignItems: "center",
backgroundColor: "rgba(0, 0, 0, 0.4)",
}}
>
</View>
{/* Chart x & y axis */}
<ChartXLabel
format={toStringDate}
style={[
styles.M12_FW600_LH19_LS02,
styles.whiteColor,
]}
/>
<ChartYLabel
format={formatPrice}
style={[
styles.M12_FW600_LH19_LS02,
styles.whiteColor,
]}
/>
</View>
</ChartDot>
</View>
</ChartPathProvider>
Currently this charts
[1]: https://i.stack.imgur.com/jYptt.png
This is required
[2]: https://i.stack.imgur.com/pr270.png

chart in range of time react native svg charts

I'm working on chart with react-native-svg-charts library, and seems like it is very flexible and cool, but I faced the issue. I need to build 24 hours timeline for xAxis and can not understand how to do it.
So I have a chart it looks like this
and the code of the chart is next:
<>
<View style={{flex: 1}} {...panResponder.current.panHandlers}>
<AreaChart
animate
style={{flex: 1}}
data={glucoseValues}
yMin={0}
yMax={180}
curve={shape.curveNatural}
contentInset={{...verticalContentInset}}
svg={{fill: 'url(#gradient)'}}>
<CustomLine/>
<Tooltip/>
</AreaChart>
<SafeArea/>
</View>
<YAxis
style={{width: apx(44)}}
data={[...Array(19).fill(1).map((el, i) => el + i * 10)]}
contentInset={verticalContentInset}
svg={{fontSize: apx(20), fill: '#617485'}}
/>
<XAxis
style={{
alignSelf: 'stretch',
width: apx(INIT_WIDTH),
height: apx(40),
}}
data={[...Array(24).fill(1)]}
formatLabel={(value, i) => {
return i === 0 ? '00:00' :
i % 4 === 0 ? moment().startOf('day').add(i, 'hours').format('HH:mm') :
i === 23 ? '23:59' : '';
}}
contentInset={{
left: 20,
right: 20,
}}
svg={{
fontSize: apx(20),
fill: '#617485',
alignmentBaseline: 'center',
textAnchor: 'middle',
y: apx(10),
}}
/>
</>
So as you see XAxis is kinda shows timeline but it is not applied. If it would, before and after the chart, we should see empty space like on this picture.
My question is next. How can I set up domain for xAxis that will work as on picture above?
For chart I user array of values for Y and array of timestamps for X. Maybe I should point somehow xMax, xMin properties for AreaChart. Any ideas?

React native soft keyboard hides one of the inputs

(I'm testing on Android if it matters)
I'm using the component KeyboardAwareScrollView to make the inputs visible while the soft keyboard is open. I have two inputs, one below the other, and when I press the top one, the soft keyboard does make sure it's visible but also hides the one below.
Is there a way to make sure that when the keyboard is open, the two inputs will remain visible, even if the user pressed the one at the top?
My code:
<KeyboardAwareScrollView scrollEnabled={false} resetScrollToCoords={{ x: 0, y: 0 }}>
<Image {...this.image.header} style={{ height: 400, width: '100%' }} />
<View>
<TextInput style={{ backgroundColor: 'red' }} />
<TextInput style={{ backgroundColor: 'blue' }} />
</View>
</KeyboardAwareScrollView>
I am copying this answer of boredgames.
<TextInput
placeholder = "FirstTextInput"
returnKeyType = { "next" }
onSubmitEditing={() => { this.secondTextInput.focus(); }}
blurOnSubmit={false}
/>
<TextInput
ref={(input) => { this.secondTextInput = input; }}
placeholder = "secondTextInput"
/>

React Native Autocomplete Input results list ignores touch

I've been tackling this issue for a few weeks, and it's driving me insane.
Basically, I have a Modal component that nests a form. The form is a bunch of TextInput components, at the heart of everything. One of the components in the form is an Autocomplete, from React Native Autocomplete Input. The problem is that I'm able to put the results list from Autocomplete in front of everything else, but my touches pass right through the container and focuses on the TextInput behind the results list. I'm not able to change the order of components, so I can't just put this one input after everything else.
The general setup of the form is below:
<Modal>
<TouchableWithoutFeedback>
<View style={containerStyle}>
<TouchableWithoutFeedback>
<View>
<CardSection style={sectionStyle}>
<Input
...props...
/>
</CardSection>
<CardSection style={acSectionStyle}>
<Text style={labelStyle}>Brand *</Text>
<View style={acContainerStyle}>
<Autocomplete
autoCapitalize='none'
autoCorrect={false}
listStyle={acListStyle}
data={brands.length === 1 && comp(query, brands[0]) ? [] : brands}
defaultValue={query}
onChangeText={text => this.setState({ query: text })}
renderItem={this.renderItem.bind(this)}
hideResults={this.state.hideResults ? this.state.hideResults : undefined}
onBlur={() => this.setState({ hideResults: true })}
onFocus={() => this.setState({ hideResults: false })}
/>
</View>
</CardSection>
<CardSection style={sectionStyle}>
<Input
...props...
/>
</CardSection>
</View>
</TouchableWithoutFeedback>
</View>
</TouchableWithoutFeedback>
</Modal>
I had to stack the TouchableWithoutFeedback components in order to make the modal behave. There's more props in the components, but I only kept what was relevant.
My renderItem method is:
renderItem(brand) {
return (
<TouchableOpacity
style={{ width: '100%', height: 25 }}
onPress={() => {
this.setState({ pBrand: brand.trim(), query: brand.trim() });
}}
>
<Text style={styles.listItemStyle}>{brand}</Text>
</TouchableOpacity>
);
}
I don't believe it's a styling issue, but I've added the styles that deal with zIndex just in case:
containerStyle: {
backgroundColor: 'rgba(0, 0, 0, 0.75)',
position: 'relative',
flex: 1,
justifyContent: 'center',
zIndex: 1
},
acSectionStyle: {
justifyContent: 'center',
zIndex: 2,
height: 40
},
acContainerStyle: {
right: 0,
width: '75%',
flex: 1,
position: 'absolute',
zIndex: 2
}
The default keyboardShouldPersistTaps for Autocomplete is always. All of the questions I've seen suggest to set a higher zIndex (which isn't a problem - I can see the list, but if I tap on it, the tap goes through to the TextInput behind it), change the order of components (which I can't do), set onStartShouldSetResponderCapture to true (which didn't work), or mess with Pointer Events, none of which worked.
I'm using React Native V0.57.1, an actual Android device, and the project is built with Expo.
Finally, I've recorded a small demo for what my problem is. When the cursor re-appears, that's when I clicked on a result.
Is there just something I'm missing? I've only been writing in React Native for a few months so that's a definite possibility. I come from a web development background, so I thought that if a component was on top (thanks to zIndex), I'd be able to tap on it and not through it by default.
Edit: While messing around, if I change acSectionStyle to a height big enough for the dropdown, then the dropdown works how it should. The issue comes in when a sibling CardSection is being covered. The other CardSection takes precedence.
So, I finally found a workaround. Whether it's correct or not, which I feel like it isn't, at least it works!
I ended up taking the Autocomplete component (along with its' view) outside of the CardSection, but leaving the label in it, like so:
<CardSection style={acSectionStyle}>
<Text style={labelStyle}>Brand *</Text>
</CardSection>
<View style={acContainerStyle}>
<Autocomplete
autoCorrect={false}
listStyle={acListStyle}
// Text input container
inputContainerStyle={acTextContainerStyle}
style={acTextStyle}
placeholder='China Glaze'
data={brands.length === 1 && comp(query, brands[0]) ? [] : brands}
defaultValue={query}
onChangeText={text => this.setState({ query: text })}
renderItem={this.renderItem.bind(this)}
hideResults={this.state.hideResults ? this.state.hideResults : undefined}
onBlur={() => this.setState({ hideResults: true })}
onFocus={() => this.setState({ hideResults: false })}
/>
</View>
Then, and this is the part I think is wrong, I just played with the absolute-positioned view until I moved it far enough down to line up next to the label:
labelStyle: {
fontSize: 18,
paddingLeft: 20,
flex: 1
},
acContainerStyle: {
right: 0,
top: 102,
width: '72%',
flex: 1,
position: 'absolute',
zIndex: 10
}
I would love if someone has a better solution, but this is the best I could come up with. I try to avoid moving views with hard coded values just for scaling purposes, but it seems like this is the only option.

react native wheel picker (IOS) is not stay on selected value?

this works absolutely fine on android but not on IOS (not displaying value which user select from wheel picker). Check this Link.
https://drive.google.com/file/d/1y_ULGQuvPlzZj2V2zr1RAynrZKpme4Uc/view?usp=sharing
<Picker
style={{ width: 100, height: 80 }}
selectedValue={this.state.selectedHour}
itemStyle={{ color: "black", fontSize: 20 }}
onValueChange={index => this.onPickerHourSelect(index)}
>
{this.state.hourList.map((value, i) => (
<PickerItem label={value} value={i} key={"money" + value} />
))}
onPickerHourSelect(index) {
var hour = this.state.hourList[index];
this.setState({
selectedHour: hour,
}) }
Please suggest me another component or package of picker(Like Spinner Or Wheel Picker)
I've had the same problem! I solved it using selectedValue instead of selectedItem and passing the pickerItem's value.
This is my code:
<Picker style={{flex: 1, width: 150, height: 180}}
itemStyle={{color: 'black', fontSize: 26}}
selectedValue={this.state.minutes[this.state.indexSelected]}
onValueChange={(index) => {this.setState({indexSelected: index})}}>
{this.state.minutes.map((value, i) => (<PickerItem label={value} value={i} key={i}/>))}
</Picker>