Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Add on press radar chart #164

Merged
merged 6 commits into from
Jun 26, 2017
Merged
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
8 changes: 7 additions & 1 deletion example/src/radar/RadarChartBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class RadarChartBasic extends Component {
static navigationOptions = ({ navigation }) => ({
title: `Radar - Basic`,
});

onLabelPress = (label, value) => {
alert(label + ':' + value);
}

render() {
let data = [{
"speed": 74,
Expand Down Expand Up @@ -68,7 +73,8 @@ class RadarChartBasic extends Component {
fontFamily: 'Arial',
fontSize: 14,
fontWeight: true,
fill: '#34495E'
fill: '#34495E',
onLabelPress: this.onLabelPress
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default class RadarChart extends Component
const center = this.props.center || [x, y]

const keys = Object.keys(this.props.data[0])
const keys_value = this.props.data[0];
const chart = Radar({
center: this.props.center || [x, y],
r: this.props.options.r || radius,
Expand All @@ -98,6 +99,10 @@ export default class RadarChart extends Component
const textStyle = fontAdapt(options.label)

const labels = chart.rings[length - 1].path.points().map(function (p, i) {
function onLabelPress() {
textStyle.onLabelPress(keys[i], keys_value[`${keys[i]}`]);
}

return (
<G key={'label' + i}>
<Line x1={p[0]} y1={p[1]} x2={center[0]} y2={center[1]} stroke={colors.stroke} strokeOpacity={colors.strokeOpacity}/>
Expand All @@ -107,6 +112,7 @@ export default class RadarChart extends Component
fontWeight={textStyle.fontWeight}
fontStyle={textStyle.fontStyle}
fill={textStyle.fill}
onPress={onLabelPress}
textAnchor="middle" x={Math.floor(p[0])} y={Math.floor(p[1])}>{keys[i]}
</Text>
</G>
Expand Down
3 changes: 2 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const fontAdapt = (fontProps) => {
rotate: fontProps.rotate || 0,
fontWeight: fontProps.fontWeight ? 'bold' : 'normal',
fontStyle: fontProps.fontStyle ? 'italic' : 'normal' ,
fill: fill
fill: fill,
onLabelPress: fontProps.onLabelPress
}
}

Expand Down