How to flip x-y axis on click using d3 - charts

I am using d3 chart to plot some charts.
I am looking for something by which I can flip my axis on a click of a button. Having said that I mean, I am looking for the functionality which seamlessly works for all type of charts like bar, line, stack etc.
Has anyone done some awesome work like this? Please help
Here is the sample
http://jsfiddle.net/adityasethi2601/ae5BP/

If you arrange your chart carefully, you should be able to achieve the flip with SVG Transforms to rotate your image, translate it if necessary to new margins, and then reverse-rotate any text that you still want to be horizontal.
As a quick-and-dirty example, I've adapted your fiddle so that when the button is clicked, a class gets toggled on the SVG as a whole, which triggers a CSS rotate transform on the entire image.
Javascript:
d3.select("div#chart > svg") ///select the svg
.classed("rotate", function(){
return !d3.select(this).classed("rotate");
//check whether it is currently rotated
//and set it to the opposite
});
CSS:
svg.rotate{
/* rotate the entire image */
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
}
http://jsfiddle.net/ae5BP/6/
However, note that CSS transforms (which apply to html objects, such as the entire SVG when embedded in a webpage) are not directly equivalent to SVG transforms, so I wasn't able to get the "reverse-rotate" on text elements working. To use SVG transforms, you'll need to wrap your entire chart in a <g> element to which you can apply the rotation. You'll also need to figure out the appropriate "center of rotation" coordinate, otherwise things will be rotated around your (0,0) origin point.
But this should give you an idea of where to start.
P.S. I also adapted the fiddle to make proper use of JSFiddle formatting and the external resources option for loading D3 -- use this format in the future.

You could also draw two versions of your chart (vertical & horizontal bar versions), and achieve a similar affect by having the "Flip Axis" button toggle visibility between the two.

Related

How to create vertical container, with 3d filling effect

I am trying to create something like this in flutter:
Image 1 -
Image 2
The two main aspects are:
the filled part of the vertical container has this elipse with darker color on the top, which gives the 3d depth effect
on Image 2 there is that % indicator, moving accordingly
What I have tried is:
tried to modify different progress_indicator packages, so that to achieve the 2 things above. However, I was never able to do that 3d depth effect.
tried to implement it as 2 expanded containers, where the flex of the bottom one represents the persentage. However again I was not able to do the elipse on the top.
From my searches online, it looks like I need to use the CustomPaint class, but it look very complicated.
If you have any better suggestions, or ever code pieces that can help, I would be extremely thankful !

GTK (GTK#) TreeView, make gridlines more visible?

I enabled gridlines like below.
tree.EnableGridLines = TreeViewGridLines.Both;
But the problem is the lines are barely visible like below (if you think there are no gridlines, zoom the image, and look really hard). Gtk.TreeView had GridLineWidth, but it was read-only. How can I make them more visible?
I have tried to find C# equivalent of the answer's C code and the following worked. Making the gridlines thicker worked but the problem was that in Ubuntu, the colour of the gridline is too light that it was not really visible even it it were thicker. So, I changed the colour instead.
var p = new CssProvider();
p.LoadFromData("*{border-color:darkgray;}");
tree.StyleContext.AddProvider(p,Gtk.StyleProviderPriority.Application);
You could use a CSS provider and set the grid line width to a larger value than one pixel. Again, the following code snippets are written in "C"; however, it should be easy enough to interpret the code to use equivalent C# statements.
First, off one would create a GTK CSS provider.
GtkCssProvider *provider;
provider = gtk_css_provider_new();
Then, the customized CSS style information would be defined for the CSS provider widget and the CSS provider widget would be associated with your tree view.
gtk_css_provider_load_from_data(provider, "*{-GtkTreeView-grid-line-width: 4;}", -1, NULL);
gtk_style_context_add_provider(gtk_widget_get_style_context(view), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
Note that GTK defines a specific set of attributes for grid elements as opposed to using a standard element such as "border-width". The attribute needing customization in this scenario is "-GtkTreeView-grid-line-width".
Having set the grid width to an exaggerated width of four pixels, the following sample illustrates the effect of the custom CSS style enhancement.
I hope that points you in the correct direction.
Regards.

Is there a way to check for markers whos icons intersect / overlap visibly?

I am building a map and want to use the leaflet markercluster plugin to cluster any markers that intersect visibly (the icons overlap each other). I can't seem to figure out a way to check whether the markers icons intersect though.
I've examined the documentation and the Marker objects. The marker object has no "bounds" object and has no function to return the bounds of the icon.
Yes, it's possible.
This is implemented in some Leaflet plugins, like Leaflet.LayerGroup.Collision - the technique involves fetching the computed style of each icon's HTML element to get the actual size in CSS pixels, offset those numbers by the relative pixel position of the marker's LatLng, and using a rtree data structure to speed up the calculation of the overlaps. Do have a look at the complete source for LayerGroup.Collision plugin.
Note that this technique only takes into account the rectangular bounding boxes of the icons; while it would be possible to check for the individual transparent pixels, that would involve more complex data structures and a different technique to fetch the opacity of each pixel.

How to make chart with two data axis in different sytle

How to apply different styles on characters X1 (bold and center/left position) and show asdasd (rightposition) in Y-axis of a table??
reality
edit in paint :)
You can use a multi-level axis for the category axis.
If Excel does not recognize the multi-levels, then you can fix that in the data source dialog.
There is, however, no way to format the axis labels to have different fonts and font sizes for the different levels. Excel simply does not support that.
Edit: there is also no setting to turn the outer level label around. Excel will determine how to show it and there is nothing the user can do to change that.
Don't shoot the messenger.

Matlab datatips: no text visible with view([0 90])

When I create a surface plot and use view([0 90]), so that I get a nice top-down view of the plot, the datatips are empty, i.e. the text is not visible. See the attached picture. As soon as I move the view a little bit they become visible though. Why is this happening and is there any fix?(1)
I don't really like the workaround to use view([0 90.0001]) instead. I'd rather see a fix than a workaround.
Mind that this doesn't happen when you save the file as a picture.
(1) It has probably something to do with heights. I think that the text height is at the exact same height as the box, which makes it possible that the text is drawn before the box, overwriting the text. I noticed that the box in that view sometimes disappears behind a surface which has a positive z-axis value.