Skip to content

Commit

Permalink
split radial scale lineArc setting into two settings: labelPoints and…
Browse files Browse the repository at this point in the history
… gridLines.circular
  • Loading branch information
etimberg committed Jan 11, 2017
1 parent 27b2e33 commit 75f406d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
7 changes: 4 additions & 3 deletions docs/02-Scales.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,15 @@ The following additional configuration options are provided by the radial linear

Name | Type | Default | Description
--- | --- | --- | ---
lineArc | Boolean | false | If true, circular arcs are used else straight lines are used. The former is used by the polar area chart and the latter by the radar chart
labelPoints | Boolean | true | If true, angle lines and point labels are drawn.
*gridLines*.circular | Boolean | false | if true, radial lines are circular. If false, they are straight lines connecting the the different angle line locations.
angleLines | Object | - | See the Angle Line Options section below for details.
pointLabels | Object | - | See the Point Label Options section below for details.
ticks | Object | - | See the Ticks table below for options.

#### Angle Line Options

The following options are used to configure angled lines that radiate from the center of the chart to the point labels. They can be found in the `angleLines` sub options. Note that these options only apply if `lineArc` is false.
The following options are used to configure angled lines that radiate from the center of the chart to the point labels. They can be found in the `angleLines` sub options. Note that these options only apply if `labelPoints` is true.

Name | Type | Default | Description
--- | --- | --- | ---
Expand All @@ -327,7 +328,7 @@ lineWidth | Number | 1 | Width of angled lines

#### Point Label Options

The following options are used to configure the point labels that are shown on the perimeter of the scale. They can be found in the `pointLabels` sub options. Note that these options only apply if `lineArc` is false.
The following options are used to configure the point labels that are shown on the perimeter of the scale. They can be found in the `pointLabels` sub options. Note that these options only apply if `labelPoints` is true.

Name | Type | Default | Description
--- | --- | --- | ---
Expand Down
1 change: 0 additions & 1 deletion docs/06-Polar-Area-Chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ Name | Type | Default | Description
startAngle | Number | -0.5 * Math.PI | Sets the starting angle for the first item in a dataset
scale | Object | [See Scales](#scales) and [Defaults for Radial Linear Scale](#scales-radial-linear-scale) | Options for the one scale used on the chart. Use this to style the ticks, labels, and grid.
*scale*.type | String |"radialLinear" | As defined in ["Radial Linear"](#scales-radial-linear-scale).
*scale*.lineArc | Boolean | true | When true, lines are circular.
*animation*.animateRotate | Boolean |true | If true, will animate the rotation of the chart.
*animation*.animateScale | Boolean | true | If true, will animate scaling the chart.
*legend*.*labels*.generateLabels | Function | `function(data) {} ` | Returns labels for each the legend
Expand Down
5 changes: 4 additions & 1 deletion src/controllers/controller.polarArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module.exports = function(Chart) {

scale: {
type: 'radialLinear',
lineArc: true, // so that lines are circular
labelPoints: false,
gridLines: {
circular: true
},
ticks: {
beginAtZero: true
}
Expand Down
20 changes: 13 additions & 7 deletions src/scales/scale.radialLinear.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ module.exports = function(Chart) {

// Boolean - Whether to animate scaling the chart from the centre
animate: true,
lineArc: false,
position: 'chartArea',

// Boolean - if true, include angle lines and point labels
labelPoints: true,

angleLines: {
display: true,
color: 'rgba(0, 0, 0, 0.1)',
lineWidth: 1
},

gridLines: {
circular: false
},

// label settings
ticks: {
// Boolean - Show a backdrop to the scale label
Expand Down Expand Up @@ -48,7 +54,7 @@ module.exports = function(Chart) {
};

function getValueCount(scale) {
return !scale.options.lineArc ? scale.chart.data.labels.length : 0;
return scale.options.labelPoints ? scale.chart.data.labels.length : 0;
}

function getPointLabelFontOptions(scale) {
Expand Down Expand Up @@ -274,7 +280,7 @@ module.exports = function(Chart) {
ctx.strokeStyle = helpers.getValueAtIndexOrDefault(gridLineOpts.color, index - 1);
ctx.lineWidth = helpers.getValueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);

if (scale.options.lineArc) {
if (scale.options.gridLines.circular) {
// Draw circular arcs between the points
ctx.beginPath();
ctx.arc(scale.xCenter, scale.yCenter, radius, 0, Math.PI * 2);
Expand Down Expand Up @@ -365,10 +371,10 @@ module.exports = function(Chart) {
return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
},
fit: function() {
if (this.options.lineArc) {
fit(this);
} else {
if (this.options.labelPoints) {
fitWithPointLabels(this);
} else {
fit(this);
}
},
/**
Expand Down Expand Up @@ -502,7 +508,7 @@ module.exports = function(Chart) {
}
});

if (!opts.lineArc) {
if (opts.labelPoints) {
drawPointLabels(me);
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/scale.radialLinear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Test the radial linear scale', function() {
animate: true,
display: true,
gridLines: {
circular: false,
color: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
Expand All @@ -30,7 +31,7 @@ describe('Test the radial linear scale', function() {
borderDash: [],
borderDashOffset: 0.0
},
lineArc: false,
labelPoints: true,
pointLabels: {
fontSize: 10,
callback: defaultConfig.pointLabels.callback, // make this nicer, then check explicitly below
Expand Down

0 comments on commit 75f406d

Please sign in to comment.