12
$\begingroup$

In the course of exploring @kglr's answer to Edmund's question gain some insight into how I might answer my own question here, I came across the undocumented System`ChartElementData function, which evidently allows you to map the strings passed as options to ChartElementFunction to the actual functions which draw the elements. Thus, using the calling convention described for BoxChart in the docs for ChartElementFunction, you can do the following:

In[1]:= cfd = ChartElementData["Rectangle"]
Out[1]= ChartElementDataFunction["Rectangle"]

In[2]:= cfd[{{0, 1}, {0, 1}}, 1, "foo"]
Out[2]= Rectangle[{0, 0}, {1, 1}, "RoundingRadius" -> 0]

That's pretty neat. However, you can also find out that there are many applicable, named, ChartElementDataFunctions for any given chart type:

In[3]:= ChartElementData["BarChart"]
Out[3]= {"ArrowRectangle", "EdgeFadingRectangle", "FadingRectangle", 
         "GlassRectangle", "GradientRectangle", "GradientScaleRectangle", 
         "ObliqueRectangle", "Rectangle", "SegmentScaleRectangle"}

Looking at some output, I'm pretty sure that "Rectangle" is the default for BarChart, but I'm not 100% certain, and it would be nice to avoid having to do trial and error for every bar type should I wish to discover the default. Is there a way to find, programmatically, what ChartElementDataFunction is used by any given chart type when it's passed ChartElementFunction -> Automatic?

$\endgroup$
  • 4
    $\begingroup$ TracePrint[(* charting function *), ChartElementDataFunction[_], TraceInternal -> True] quickly reveals not a few secrets. $\endgroup$ – J. M. will be back soon Nov 12 '15 at 5:16
  • 1
    $\begingroup$ @J.M., if you don't write that up as an answer, how am I supposed to give you your bounty? :) $\endgroup$ – Pillsy Nov 12 '15 at 5:20
  • $\begingroup$ It doesn't always work, you see: TracePrint[PieChart3D[{1, 2, 3, 4}, PlotTheme -> "Marketing"], ChartElementDataFunction[_], TraceInternal -> True] so I left it as a comment. $\endgroup$ – J. M. will be back soon Nov 12 '15 at 5:23
  • $\begingroup$ @J.M. Got it. Still a good start, though. $\endgroup$ – Pillsy Nov 12 '15 at 5:24
  • 1
    $\begingroup$ For "Marketing", this works: ChartElementFunction /. Charting`ResolvePlotTheme["Marketing", BarChart3D]. For some of the other plot themes this doesn't work, but the previously presented approach works. I don't know if there's a situation where neither will work, but this at least reveals some inconsistency in internal handling. $\endgroup$ – J. M. will be back soon Nov 12 '15 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.