Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed tooltip labelling on Bar Chart when min is defined (#3618) #3620

Merged
merged 1 commit into from
Nov 28, 2016

Conversation

Jareechang
Copy link
Contributor

As title states, create a fix for #3618.

summary of changes:

  • Created a new helper method to map index into sliced array when min is defined
  • Added test for helper method
  • Added integration test to trigger element to ensure correct index

var min = chartConfig.options.scales.xAxes[0].ticks.min;
var labels = chartConfig.data.labels;

if (!element._adjustedIndex && min) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this condition min !== 0 or min !== undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition should check min !== undefined. I may need to rethink this adjustment because this "adjustment" in the index is very specific to the Barchart.

element._index -= labels.indexOf(min);
element._adjustedIndex = true;
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this method directly be on the element class instead?

    adjustIndex: function(config) {
        var min = config.options.scales.xAxes[0].ticks.min;
        if (this._adjustedIndex || min === undefined) {
            return;
        }

        this._index -= config.data.labels.indexOf(min);
        this._adjustedIndex = true;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonbrunel, yes, this is a better place for the helper. I'll go ahead and update that

@@ -21,6 +22,7 @@ module.exports = function(Chart) {
for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
var element = meta.data[j];
if (!element._view.skip) {
helpers.adjustIndex(element, chartConfig);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chartConfig is only called from here, chart.config should be used instead:

    element.adjustIndex(chart.config);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, I will make this edit

@@ -53,6 +53,16 @@ module.exports = function(Chart) {
}
return base;
};
// Adjust element index when min is defined
helpers.adjustIndex = function(element, chartConfig) {
var min = chartConfig.options.scales.xAxes[0].ticks.min;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the element doesn't belong to the first axis (xAxes[0])?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I was looking into scatter plot where you can define multiple xAxes with different ticks.min... which is the case I think you are referring to.

as per documentation:

Name Type Default Description
scales.xAxes Array The bar chart officially supports only 1 x-axis but uses an array to keep the API consistent. Use a scatter chart if you need multiple x axes.

how about if I make this patch specific to when only one xAxes is defined (Given scatter plot is only time where multi xAxes is possible) ?

added helper method to adjust the index

pass in chartConfig rather than access within method, make it easier to
test

added semi-colon at the end of helper method

added test for adjustIndex helper method

fixed lint issues

added integration test for the interaction of trigger an event over the
bar

.

.

moved adjustIndex into element helper

removed method from helper and adjusted method in core.interaction

added test for the element adjustIndex helper

added a skipIndexAdjustment method to handle when to skip the adjustment
along with test cases

fixed lint issues

removed the test for the helper method
@Jareechang
Copy link
Contributor Author

hi @simonbrunel, i've made the requested changes. Could you please let me know how it looks 😄 thanks!

Copy link
Member

@simonbrunel simonbrunel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed your last commit. Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants