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

Fixed #26 - axes now respect offsets properly and cleanup of other offset #27

Merged
merged 2 commits into from
Dec 2, 2016
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
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "^15.3.0",
"react": "~15.3.0",
"react-native": "^0.35.0",
"react-native-pathjs-charts": "file:../"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"react-native-svg": "^4.3.0"
},
"devDependencies": {
"react": "^15.3.0",
"react": "~15.3.0",
"react-native": "^0.35.0"
}
}
19 changes: 13 additions & 6 deletions src/Axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,21 @@ class AxisStruct {
const fixed = this.options.zeroAxis?this.scale(0):horizontal?yAxis.min:xAxis.min
const start = {x: horizontal?xAxis.min:fixed, y: horizontal?fixed:yAxis.min}
const end = {x:horizontal?xAxis.max:fixed,y: horizontal?fixed:yAxis.max}
const tailLength = this.options.tailLength || 10

const margin = this.margin
if (margin !== undefined){
if (horizontal){
start.x -= margin.left || 0
end.x += margin.right || 0
start.x += (margin.left - tailLength) || 0
start.y += margin.top || 0
end.x += (margin.left) || 0
end.y += margin.top || 0
}
else {
start.y += margin.bottom || 0
end.y -= margin.top || 0
start.x += margin.left || 0
start.y += (margin.top + tailLength) || 0
end.x += margin.left || 0
end.y += (margin.top - tailLength) || 0
}
}

Expand All @@ -80,8 +85,8 @@ class AxisStruct {
path: Pathjs().moveto(start).lineto(end).closepath(),
ticks: ticks,
lines: ticks.map(c => {
const lineStart = {x: horizontal ? this.scale(c) : xAxis.min, y: horizontal ? yAxis.min : this.scale(c)}
return Pathjs().moveto(lineStart).lineto(horizontal ? lineStart.x : xAxis.max, horizontal ? yAxis.max : lineStart.y)
const lineStart = {x: horizontal ? this.scale(c) + margin.left : xAxis.min + margin.left, y: horizontal ? yAxis.min + margin.top : this.scale(c) + margin.top}
return Pathjs().moveto(lineStart).lineto(horizontal ? lineStart.x : xAxis.max + margin.left, horizontal ? yAxis.max + (margin.top - tailLength) : lineStart.y)
},this)
}
}
Expand Down Expand Up @@ -143,6 +148,8 @@ export default class Axis extends Component {
let offset = {
x: chartArea.margin.left * -1,
y: chartArea.margin.top * -1
// x: 0,
// y: 0
}

let returnV = <G>
Expand Down
4 changes: 1 addition & 3 deletions src/Bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class BarChart extends Component {
<G x={options.margin.left} y={options.margin.top}>
<Text fontFamily={textStyle.fontFamily}
fontSize={textStyle.fontSize} fontWeight={textStyle.fontWeight} fontStyle={textStyle.fontStyle}
fill={textStyle.fill} x={c.line.centroid[0]} y={chartArea.y.min + 25} rotate={45} textAnchor="middle">{c.item.name}</Text></G>
fill={textStyle.fill} x={c.line.centroid[0]} y={chartArea.y.min} rotate={45} textAnchor="middle">{c.item.name}</Text></G>
:null}
</G>
)
Expand All @@ -132,9 +132,7 @@ export default class BarChart extends Component {
return (<Svg width={options.width} height={options.height}>
<G x={options.margin.left} y={options.margin.top}>
<Axis scale={chart.scale} options={options.axisY} chartArea={chartArea} />
<G x={options.margin.left * -1 } y={options.margin.top * -1}>
{lines}
</G>
</G>
</Svg>)
}
Expand Down
9 changes: 1 addition & 8 deletions src/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,13 @@ export default class LineChart extends Component {
if(showAreas){
areas = _.map(chart.curves, function (c, i) {
return <Path key={'areas' + i} d={ c.area.path.print() } fillOpacity={0.5} stroke="none" fill={ this.color(i) }/>
}.bind(this))
}

let offset = {
x: chartArea.margin.left * -1,
y: chartArea.margin.top * -1
}.bind(this))
}

let returnValue = <Svg width={options.width} height={options.height}>
<G x={options.margin.left} y={options.margin.top}>
<G x={offset.x} y={offset.y}>
{ areas }
{ lines }
</G>
<Axis key="x" scale={chart.xscale} options={options.axisX} chartArea={chartArea} />
<Axis key="y" scale={chart.yscale} options={options.axisY} chartArea={chartArea} />
</G>
Expand Down
4 changes: 1 addition & 3 deletions src/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ export default class TreeChart extends Component {
return (
<Svg width={options.width} height={options.height}>
<G x={options.margin.left} y={options.margin.top}>
<G x={options.margin.left * -1} y={options.margin.top * -1}>
{ curves }
</G>
{ curves }
{ nodes }
</G>
</Svg>
Expand Down