Skip to content

AxisConfig#8275

Merged
ppisljar merged 26 commits intoelastic:vislib-axis-refactorfrom
ppisljar:vislib/axis-2
Sep 20, 2016
Merged

AxisConfig#8275
ppisljar merged 26 commits intoelastic:vislib-axis-refactorfrom
ppisljar:vislib/axis-2

Conversation

@ppisljar
Copy link
Contributor

@ppisljar ppisljar commented Sep 14, 2016

introducing AxisConfig class to handle all axis configuration, to help decouple Axis components from Axis. not complete yet but you can take a look.

@ppisljar ppisljar added review Feature:Vislib Vislib chart implementation labels Sep 14, 2016
isHorizontal() {
return (this.position === 'top' || this.position === 'bottom');
const elSelector = this.config.get('elSelector');
const rootEl = this.config.get('rootEl');
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note, it seems weird that elements can live in config. not sure why

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i completely agree. however i think this should be changed at a later stage, when we start doing changes to the vis itself, for now i just made rootEl availible on config instead of going to vis.el

text.each(function textWidths() {
lengths.push((() => {
if (self.isHorizontal()) {
if (self.config.isHorizontal()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you prefetch this above you could almost get rid of self 😜

Copy link
Contributor

Choose a reason for hiding this comment

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

Which I hate for some reason

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i hate self as well ... mostly with arrow functions we should be able to get rid of it ,.... however d3 (as far as i know) is kind of dependand on the old functions ... maybe thats not the case anymore, i'll check it out

draw() {
const self = this;
const config = this.config;
const style = config.style;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be config.get('style')?

if (self.axisLabels) self.axisLabels.render(svg);
svg.call(self.adjustSize());
}
if (self.axisLabels) self.axisLabels.render(svg);
Copy link
Contributor

Choose a reason for hiding this comment

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

this used to only happen if there was a container. Was that a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup

class AxisConfig {
constructor(config) {
if (config.type === 'category') {
_.defaultsDeep(config, categoryDefaults);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is modifying the config variable, which probably isn't a good idea because the AxisConfig doesn't know where it came from or what it's purpose it.

We should probably start off the constructor with this._values = {} and then apply the defaults:

const typeDefaults = config.type === 'category' ? categoryDefaults : {}
this._values = _.defaultsDeep({}, config, typeDefaults, defaults);

Copy link
Contributor

Choose a reason for hiding this comment

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

This also has the benefit of storing the config values under a private property, meaning that there is a single API to reading config, config.get('proerty')

};

get(property) {
return _.get(this, property, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should expose the ability to pass in a default

Copy link
Contributor

@spalger spalger Sep 14, 2016

Choose a reason for hiding this comment

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

I also think it should verify that the property exists using _.has() and throw an error if it's not defined. That has proved pretty valuable on the server, and helps to ensure that changes to the defaults are updated everywhere they need to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how exactly would that work ? (has + defaults) ...
if we have a defaults when there isnt a value set we return default ...

or should we return error if value is not set at all, and only return default if value is set to undefined ?

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

This looks great, a couple changes requested, but should be pretty minor changes

this.filter = attr && attr.filter ? attr.filter : false;
this.rotate = attr && attr.rotate ? attr.rotate : 70;
if (this.config.isHorizontal() && this.config.isOrdinal()) {
this.filter = config.labels && config.labels.filter ? config.labels.filter : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

these could be updated to use the config.get() function with the default argument:

this.filter = config.get('labels.filter', false)

isPercentage() {
return (this.axis._attr.mode === 'percentage');
const mode = this.config.get('mode');
return (mode === 'percentage');
Copy link
Contributor

Choose a reason for hiding this comment

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

Go ahead and drop the parens around these


if (isNaN(val)) throw new Error(val + ' is not a valid number');
if (this.axis.isPercentage() && this.axis._attr.setYExtents) return val / 100;
if (this.isPercentage() && this.isUserDefined()) return val / 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

// Prevents bars from going off the chart when the y extents are within the domain range
if (this.axis._attr.type === 'histogram' && this.scale.clamp) this.scale.clamp(true);
// todo: make this work (its accessing chart config ... we only have axis config availible)
//if (this.axis._attr.type === 'histogram' && this.scale.clamp) this.scale.clamp(true);
Copy link
Contributor

@spalger spalger Sep 14, 2016

Choose a reason for hiding this comment

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

What is the purpose of scale.clamp? maybe there is a different indicator we could look for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in case of histogram chart we want to make sure that the last column is the same size as the previous ones ...

const bbox = svg.append('text')
.attr('transform', function () {
if (self.axis.isHorizontal()) {
if (self.config.isHorizontal()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

-self

getLength(el, n) {
if (this.isHorizontal()) {
return $(el).parent().width() / n - this._attr.margin.left - this._attr.margin.right - 50;
const margin = this.config.get('vis._attr.margin');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this accessing the entire vis? Or just the vis configuration? It feels like, if the vis has some property that should influence the axis it should pass it to the axis, rather than the axis reach out and read it from the vis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its accessing vis config .... in the future we'll probably extract vis config in similar manner we did with axis config ?

@spalger
Copy link
Contributor

spalger commented Sep 14, 2016

hmm, not sure why some of the changes are under the review and some aren't, lame

@ppisljar
Copy link
Contributor Author

ppisljar commented Sep 15, 2016

most of the tests are now passing ...

@ppisljar
Copy link
Contributor Author

tomorrow im gonna test this really well (comparing with old behaviour). i already found 2 things that are not working correctly, probably there are more.

  • wiggle option has no effect
  • percentage mode does not work correctly (the remaining tests are failing because of this)

@spalger
Copy link
Contributor

spalger commented Sep 16, 2016

Looking good

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

One last question, but I'm ready to merge

return config.get('labels.axisFormatter')(d);
if ((startPos + halfSize) < myPos && maxSize > (myPos + halfSize)) {
startPos = myPos + halfSize;
return this.innerHTML;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a possible issue that we are setting the innerHTML to the text value of each tick? Should we be using textContent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are not setting it, just reading it. this part filters labels if there are to many, in case label should not be filtered it returns it AS IS ... so if your label would happen to include some html it would also work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, cool, thought that maybe .text() was setting the text value

@ppisljar ppisljar merged commit 9148892 into elastic:vislib-axis-refactor Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Vislib Vislib chart implementation review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments