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

Add capacity for axis position #198

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
2 changes: 2 additions & 0 deletions docs/scatterplot/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ render() {
showTicks: true,
zeroAxis: false,
orient: 'bottom',
position: 'top', //optional
label: {
fontFamily: 'Arial',
fontSize: 8,
Expand All @@ -226,6 +227,7 @@ render() {
showTicks: true,
zeroAxis: false,
orient: 'left',
position: 'right', //optional
label: {
fontFamily: 'Arial',
fontSize: 8,
Expand Down
2 changes: 2 additions & 0 deletions docs/smoothline/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ render() {
showTicks: true,
zeroAxis: false,
orient: 'bottom',
position: 'top', //optional
label: {
fontFamily: 'Arial',
fontSize: 14,
Expand All @@ -169,6 +170,7 @@ render() {
showTicks: true,
zeroAxis: false,
orient: 'left',
position: 'right', //optional
label: {
fontFamily: 'Arial',
fontSize: 14,
Expand Down
2 changes: 2 additions & 0 deletions docs/stockline/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ render() {
showTicks: true,
zeroAxis: false,
orient: 'bottom',
position: 'top', //optional
tickValues: [],
label: {
fontFamily: 'Arial',
Expand All @@ -215,6 +216,7 @@ render() {
showTicks: true,
zeroAxis: false,
orient: 'left',
position: 'right', //optional
tickValues: [],
label: {
fontFamily: 'Arial',
Expand Down
13 changes: 10 additions & 3 deletions src/Axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export default class Axis extends Component {
if (options.orient === 'left') xy = [-5,-10]
if (options.orient === 'right') xy = [5,5]

const positionMargin = {x: 0, y: 0};

if (options.position) {
if (options.position === 'right') positionMargin.x += (chartArea.x.max);
if (options.position === 'top') positionMargin.y -= (chartArea.y.min + xy[1]);
}

if (typeof options.color !== 'string') {
options.color = '#3E90F0'
}
Expand Down Expand Up @@ -155,7 +162,7 @@ export default class Axis extends Component {
let returnValue
if (label !== undefined && label !== null) {
returnValue =
<G key={i} x={gxy[0]} y={gxy[1]}>
<G key={i} x={gxy[0] + positionMargin.x} y={gxy[1] + positionMargin.y}>
{options.showTicks &&
<Circle r={options.tickSize} cx="0" cy="0" stroke={options.tickColor} fill={options.tickColor} />
}
Expand All @@ -176,8 +183,8 @@ export default class Axis extends Component {
})

let offset = {
x: chartArea.margin.left * -1,
y: chartArea.margin.top * -1
x: chartArea.margin.left * -1 + positionMargin.x,
y: chartArea.margin.top * -1 + positionMargin.y
// x: 0,
// y: 0
}
Expand Down