Skip to content

Commit

Permalink
Remove assumption, use what we know instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jan 13, 2019
1 parent 4c79da1 commit 8f3c764
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/scales/scale.category.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var helpers = require('../helpers/index');
var Scale = require('../core/core.scale');

var defaultConfig = {
Expand Down Expand Up @@ -51,17 +52,13 @@ module.exports = Scale.extend({
var me = this;
var chart = me.chart;
var data = chart.data;
var isHorizontal = me.isHorizontal();

var ds = chart.getDatasetMeta(datasetIndex).controller;
var controller = chart.getDatasetMeta(datasetIndex).controller;

// For controllers supporting getValueScaleId, we can be sure if this is a value scale.
// For others, vertical scale is assumed to be value.
// Note: This assumption works correctly for all charts with {x,y} data,
// because getRightValue returns correct thing regardless if it's a index or value.
var isValueScale = ds.getValueScaleId
? ds.getValueScaleId() === me.id
: !isHorizontal;
// For object data ({x,y} etc.) we can rely on getRightValue to return correct thing.
var isValueScale = controller.getValueScaleId
? controller.getValueScaleId() === me.id
: helpers.isObject(data[0]);

if (isValueScale) {
return me.getRightValue(data.datasets[datasetIndex].data[index]);
Expand Down

0 comments on commit 8f3c764

Please sign in to comment.