-
Notifications
You must be signed in to change notification settings - Fork 46
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
Dual-axis capability on a basic chart #28
Comments
Hey @yanofsky this sounds like a great addition to d4, let me see if I can figure it out. Do you have a fiddle or codepen you can share for what you've done so far? It is always helpful for me if I can fiddle with actual code. I understand the issue with the declarative nature of the API, maybe we can do something like this chart.y(function(){},1) where 1 is the index (defaulting to 0 if omitted)? I think I might need to wrap my head around it a bit before I am totally sure, however this is something which is very common in data visualization and therefore a worthwhile addition. Thanks! |
Sure thing, here's a fiddle http://jsfiddle.net/26n3znsh/ If we were to do it how you have above i can imagine the commented out methods on lines 70, 88, and 125 being the way forward (though maybe 125 isn't necessary?) |
@yanofsky thinking this through a bit last night I have a couple questions / comments i'd like to get your thoughts on.
With that in mind I am wondering what you think of this approach.
var chart = d4.charts.column();
chart
.x(function(axis){
axis
.scale('linear')
})
.using('bars', function(bars) {
bars
.xScale(function(axis){ axis.scale('ordinal')})
}) |
Sorry for the slow reply! That looks workable. The things that have been tying me up thinking about it is how to make it easiest to maintain the background auto scaling Would there be a way to select an scale/axis by index? Or get a list of the current list of scales/axes? I think that would be useful. |
Hey @yanofsky i am working on this feature as we speak so this is perfect timing. Can you explain what you mean by auto-scaling? My thinking was that d4 would assume a single scale at the chart level, and then features could be locally overridden with a new scale. In this way you'd declare a single scale object outside the main chart object and then assign it to all the features you'd need like the axis, and line series. This would keep the inner workings of d4 basically the same, while still allowing for feature specific overrides. Thoughts? |
Awesome, thanks, for doing this so quickly. It really helps us out a lot What I was getting at before is that by default the domain of the nth scale could be calculated automatically...but the person who gets this deep into charting with d4 would probably be okay setting the scale too |
Thank you for the feedback, if after playing with my implementation you have suggestions for improvements I am very happy to hear about it. Thanks again for your continued support of d4. |
@yanofsky sounds like you are using d4 on a regular basis, do you have any other pain points that you've noticed in using the lib? |
I do! I'll put them in as separate issues to keep them organized on here...as such some of them are unique to our use case so I won't be offended by any |
I've been working on trying to figure out the best way to allow for a left axis and a right axis on different scales. (and thus series on different scales) Like this:
At the moment d4 provides no way to override the chart-wide scale on a feature by feature basis.
So far I've tried the following,
alt_scale
to the yAxis feature's accessors with a default ofnull
yAxis.render
fromscope.scale(this.y)
toscope.scale(scope.alt_scale() ? scope.alt_scale() : this.y);
but there is no way to access a custom scale (that I can see) from inside of a feature (such as
lineSeries
) since the accessor is called in the context of the chart not the context of the feature. (e.g.d4.functor(scope.accessors.y).bind(this)
)If you want to keep this functionality, perhaps it's better adding
alt_y
on thechart
object instead—a clone ofchart.y
. Then there can bealt_y
accessors on each feature and logic on when to use it in the render based on ause_alt_y
accessor boolean on the feature. A similar thing could also be added to thex
methods.Of course once there are two axes...why not three, four, etc? That type of functionality would require the
chart.x
andchart.y
methods to return arrays of scales and features to have something likey_scale_index
(defaulting to 0). It could also really mess up the API.What are your thoughts on how to achieve this @heavysixer?
The text was updated successfully, but these errors were encountered: