Conversation
| isHorizontal() { | ||
| return (this.position === 'top' || this.position === 'bottom'); | ||
| const elSelector = this.config.get('elSelector'); | ||
| const rootEl = this.config.get('rootEl'); |
There was a problem hiding this comment.
Just a note, it seems weird that elements can live in config. not sure why
There was a problem hiding this comment.
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
src/ui/public/vislib/lib/axis.js
Outdated
| text.each(function textWidths() { | ||
| lengths.push((() => { | ||
| if (self.isHorizontal()) { | ||
| if (self.config.isHorizontal()) { |
There was a problem hiding this comment.
If you prefetch this above you could almost get rid of self 😜
There was a problem hiding this comment.
Which I hate for some reason
There was a problem hiding this comment.
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
src/ui/public/vislib/lib/axis.js
Outdated
| draw() { | ||
| const self = this; | ||
| const config = this.config; | ||
| const style = config.style; |
There was a problem hiding this comment.
Should this be config.get('style')?
| if (self.axisLabels) self.axisLabels.render(svg); | ||
| svg.call(self.adjustSize()); | ||
| } | ||
| if (self.axisLabels) self.axisLabels.render(svg); |
There was a problem hiding this comment.
this used to only happen if there was a container. Was that a bug?
| class AxisConfig { | ||
| constructor(config) { | ||
| if (config.type === 'category') { | ||
| _.defaultsDeep(config, categoryDefaults); |
There was a problem hiding this comment.
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);There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
I think this should expose the ability to pass in a default
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
spalger
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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; |
| // 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); |
There was a problem hiding this comment.
What is the purpose of scale.clamp? maybe there is a different indicator we could look for?
There was a problem hiding this comment.
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()) { |
| 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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
its accessing vis config .... in the future we'll probably extract vis config in similar manner we did with axis config ?
|
hmm, not sure why some of the changes are under the review and some aren't, lame |
|
most of the tests are now passing ... |
|
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.
|
|
Looking good |
spalger
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Is it a possible issue that we are setting the innerHTML to the text value of each tick? Should we be using textContent?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ah, cool, thought that maybe .text() was setting the text value
introducing AxisConfig class to handle all axis configuration, to help decouple Axis components from Axis. not complete yet but you can take a look.