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

added options #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/react-native-pure-chart.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

190 changes: 95 additions & 95 deletions examples/pure-chart/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,78 +228,78 @@ export const getGuideArray = (max, height, numberOfPoints = 5) => {

export const drawYAxis = (color = '#e0e0e0') => {
return (
<View style={{
borderRightWidth: 1,
borderColor: color,
width: 1,
height: '100%',
marginRight: 0
<View style={{
borderRightWidth: 1,
borderColor: color,
width: 1,
height: '100%',
marginRight: 0

}} />
}} />

)
}

export const drawYAxisLabels = (arr, height, minValue, color = '#000000') => {
return (
<View style={{
width: 33,
height: height,
justifyContent: 'flex-end',
alignItems: 'flex-end',
marginBottom: minValue && arr && arr.length > 0 ? -1 * arr[0][2] * minValue : null,
overflow: 'hidden'
}}>

{arr.length === 0 ? (
<View
key={'guide0'}
style={{
bottom: 0,
position: 'absolute'
}}>
<Text style={{fontSize: 11}}>0</Text>
</View>
) : arr.map((v, i) => {
if (v[1] > height) return null
return (
<View
key={'guide' + i}
style={{
bottom: v[1] - 5,
position: 'absolute'
}}>
<Text style={{fontSize: 11, color: color}}>{v[0]}</Text>
</View>
)
})}

</View>
<View style={{
width: 33,
height: height,
justifyContent: 'flex-end',
alignItems: 'flex-end',
marginBottom: minValue && arr && arr.length > 0 ? -1 * arr[0][2] * minValue : null,
overflow: 'hidden'
}}>

{arr.length === 0 ? (
<View
key={'guide0'}
style={{
bottom: 0,
position: 'absolute'
}}>
<Text style={{fontSize: 11}}>0</Text>
</View>
) : arr.map((v, i) => {
if (v[1] > height) return null
return (
<View
key={'guide' + i}
style={{
bottom: v[1] - 5,
position: 'absolute'
}}>
<Text style={{fontSize: 11, color: color}}>{v[0]}</Text>
</View>
)
})}

</View>
)
}
export const drawGuideLine = (arr, color = '#e0e0e0') => {
return (
<View style={{
width: '100%',
height: '100%',
position: 'absolute'
}}>

{arr.map((v, i) => {
return (
<View
key={'guide' + i}
style={{
width: '100%',
borderTopWidth: 1,
borderTopColor: color,
bottom: v[1],
position: 'absolute'
}} />
)
})}

</View>
<View style={{
width: '100%',
height: '100%',
position: 'absolute'
}}>

{arr.map((v, i) => {
return (
<View
key={'guide' + i}
style={{
width: '100%',
borderTopWidth: 1,
borderTopColor: color,
bottom: v[1],
position: 'absolute'
}} />
)
})}

</View>
)
}

Expand All @@ -323,43 +323,43 @@ export const numberWithCommas = (x, summary = true) => {

export const drawXAxis = (color = '#e0e0e0') => {
return (
<View style={{
width: '100%',
borderTopWidth: 1,
borderTopColor: color
}} />
<View style={{
width: '100%',
borderTopWidth: 1,
borderTopColor: color
}} />
)
}
export const drawXAxisLabels = (sortedData, gap, color = '#000000', showEvenNumberXaxisLabel) => {
return (
<View style={{
width: '100%',
paddingVertical: 10,
height: 10
}}>
{sortedData.map((data, i) => {
// if (data[3] && i % 2 === 1) {
if (data['x'] && i % 2 === 1 || !showEvenNumberXaxisLabel) {
return (
<View key={'label' + i} style={{
position: 'absolute',
// left: data[0] - gap / 2,
left: data['gap'] - gap / 2,
width: gap,
alignItems: 'center'
}}>
<Text style={{fontSize: 9, color: color}}>
{
// data[3]
data['x']
}
</Text>
</View>
)
} else {
return null
}
})}
</View>
<View style={{
width: '100%',
paddingVertical: 10,
height: 10
}}>
{sortedData.map((data, i) => {
// if (data[3] && i % 2 === 1) {
if ((data['x'] && i % 2 === 1 || !showEvenNumberXaxisLabel) && data['x'] >0 ) {
return (
<View key={'label' + i} style={{
position: 'absolute',
// left: data[0] - gap / 2,
left: data['gap'] - gap / 2,
width: gap,
alignItems: 'center'
}}>
<Text style={{fontSize: 9, color: color}}>
{
// data[3]
data['x']
}
</Text>
</View>
)
} else {
return null
}
})}
</View>
)
}
87 changes: 43 additions & 44 deletions examples/pure-chart/components/column-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ export default class ColumnChart extends Component {
let dataCount = standardSeries.data.length
for (let i = 0; i < dataCount; i++) {
renderColumns.push(
<ColumnChartItem key={i} seriesArray={this.state.sortedData}
dataIndex={i}
defaultWidth={this.props.defaultColumnWidth}
defaultHeight={this.props.height + 20}
defaultMargin={this.props.defaultColumnMargin}
isSelected={this.state.selectedIndex === i}
highlightColor={this.props.highlightColor}
onClick={(evt) => this.handleClick(evt, i)} />
<ColumnChartItem key={i} seriesArray={this.state.sortedData}
dataIndex={i}
defaultWidth={this.props.defaultColumnWidth}
defaultHeight={this.props.height + 20}
defaultMargin={this.props.defaultColumnMargin}
isSelected={this.state.selectedIndex === i}
highlightColor={this.props.highlightColor}
onClick={(evt) => this.handleClick(evt, i)} />
)
}
}
return (
<Animated.View style={[styles.chartView, {
transform: [{scaleY: fadeAnim}],
marginBottom: this.props.minValue && this.state.guideArray && this.state.guideArray.length > 0 ? -1 * this.state.guideArray[0][2] * this.props.minValue : null
}]}>
{renderColumns}
</Animated.View>
<Animated.View style={[styles.chartView, {
transform: [{scaleY: fadeAnim}],
marginBottom: this.props.minValue && this.state.guideArray && this.state.guideArray.length > 0 ? -1 * this.state.guideArray[0][2] * this.props.minValue : null
}]}>
{renderColumns}
</Animated.View>
)
}

Expand Down Expand Up @@ -92,7 +92,6 @@ export default class ColumnChart extends Component {
} else if (selectedIndex === standardSeries.data.length - 1) {
plusGap = -50
}
// 차트 width를 마지막에 늘려야겠음.

let left = standardSeries.data[selectedIndex]['gap'] + plusGap
let tooltipRenders = []
Expand All @@ -102,18 +101,18 @@ export default class ColumnChart extends Component {
tooltipRenders.push(<Text key={'tooltipTitle-' + i} style={styles.tooltipTitle}>{series.data[selectedIndex]['x']}</Text>)
}
tooltipRenders.push(
<View key={'tooltipText-' + i} style={{flexDirection: 'row', paddingLeft: 5, alignItems: 'center'}}>
<View style={[styles.tooltipColor, {backgroundColor: !series.seriesColor ? this.props.primaryColor : series.seriesColor}]} />
<Text style={styles.tooltipValue}>{numberWithCommas(series.data[selectedIndex]['y'], false)}</Text>
</View>
<View key={'tooltipText-' + i} style={{flexDirection: 'row', paddingLeft: 5, alignItems: 'center'}}>
<View style={[styles.tooltipColor, {backgroundColor: !series.seriesColor ? this.props.primaryColor : series.seriesColor}]} />
<Text style={styles.tooltipValue}>{numberWithCommas(series.data[selectedIndex]['y'], false)}</Text>
</View>
)
}
return (
<View style={[styles.tooltipWrapper, { left: left }]}>
<View style={styles.tooltip}>
{tooltipRenders}
<View style={[styles.tooltipWrapper, { left: left }]}>
<View style={styles.tooltip}>
{tooltipRenders}
</View>
</View>
</View>
)
} else {
return null
Expand All @@ -125,29 +124,29 @@ export default class ColumnChart extends Component {
if (this.state.sortedData && this.state.sortedData.length === 0) return null

return (
<View style={StyleSheet.flatten([styles.wrapper, {
backgroundColor: this.props.backgroundColor
}])}>
<View style={{paddingRight: 5}}>
{drawYAxisLabels(this.state.guideArray, this.props.height + 20, this.props.minValue, this.props.labelColor)}
</View>
<View style={styles.mainContainer}>
<ScrollView horizontal>
<View>
<View ref='chartView' style={styles.chartContainer}>
{drawYAxis(this.props.yAxisColor)}
{drawGuideLine(this.state.guideArray, this.props.yAxisGridLineColor)}
{this.renderColumns(fadeAnim)}
</View>
{drawXAxis(this.props.xAxisColor)}
<View style={{ marginLeft: this.props.defaultColumnWidth / 2 }}>
{drawXAxisLabels(this.state.sortedData[0].data, this.state.gap, this.props.labelColor, this.props.showEvenNumberXaxisLabel)}
<View style={StyleSheet.flatten([styles.wrapper, {
backgroundColor: this.props.backgroundColor
}])}>
<View style={{paddingRight: 5}}>
{/*{ this.props.drawYAxisLabels && drawYAxisLabels(this.state.guideArray, this.props.height + 20, this.props.minValue, this.props.labelColor)}*/}
</View>
<View style={styles.mainContainer}>
<ScrollView horizontal>
<View>
<View ref='chartView' style={styles.chartContainer}>
{drawYAxis(this.props.yAxisColor)}
{drawGuideLine(this.state.guideArray, this.props.yAxisGridLineColor)}
{this.renderColumns(fadeAnim)}
</View>
{drawXAxis(this.props.xAxisColor)}
<View style={{ marginLeft: this.props.defaultColumnWidth / 2 }}>
{drawXAxisLabels(this.state.sortedData[0].data, this.state.gap, this.props.labelColor, false)}
</View>
</View>
</View>
{this.drawTooltip(this.state.selectedIndex)}
</ScrollView>
{/*{this.props.drawTooltip && this.drawTooltip(this.state.selectedIndex)}*/}
</ScrollView>
</View>
</View>
</View>
)
}
}
Expand Down
Loading