7
$\begingroup$
SetOptions[BarChart, LabelStyle -> {}];
Options[BarChart, LabelStyle]

When I evaluate this code

BarChart[Labeled[#, Rotate["label", 90 Degree], Above, 
    LabelStyle -> Directive[Red, FontSize -> 32]] & /@ Range[8]]

with V11.0.1 on OS X I get

enter image description here

When I examine the InputForm the labels are coded like this:

Text[Style[
  Rotate["label", 
   90*Degree], {LabelStyle -> 
    Directive[RGBColor[1, 0, 0], FontSize -> 32], Directive[], 
   Directive[]}], Offset[{0, 4}, {1., 1.}], ImageScaled[{0.5, 0}]]

So we have the LabelStyle for Labeled plus duplicates of the global LabelStyle for BarChart.

SetOptions[BarChart, 
  LabelStyle -> Directive[RGBColor[1, 0, 0], FontSize -> 12]];

Now I get:

enter image description here

with the labels configured this way:

Text[Style[
  Rotate["label", 
   90*Degree], {BaseStyle -> 
    Directive[RGBColor[1, 0, 0], FontSize -> 24], 
          LabelStyle -> Directive[RGBColor[1, 0, 0], FontSize -> 32], 
   Directive[RGBColor[1, 0, 0], FontSize -> 12], 
          Directive[RGBColor[1, 0, 0], FontSize -> 12]}], 
 Offset[{0, 4}, {1., 1.}], ImageScaled[{0.5, 0}]]

which confirms the duplicate of the BarChart LabelStyle Directive. The configuration of the styling options for these labels looks to be a mess. I'm assuming that being unable to locally style the label use the Labeled LabelStyle option is a bug?

And when I try this:

SetOptions[BarChart, LabelStyle -> {}];
BarChart[Labeled[
    Style[#, Directive[FontColor -> Red, FontSize -> 32]], 
    Rotate["label", 90 Degree], Above] & /@ Range[8]]

I get this:

enter image description here

 Text[Style[Rotate["label", 90*Degree], {Directive[], Directive[]}], Offset[{0, 4}, {5., 5.}], ImageScaled[{0.5, 0}]]

Note also that modifying the LabeledLabel style in my stylesheet also had no effect.

This appears to be either a bug or a design oversight. Does anyone have any thoughts?

$\endgroup$
  • 3
    $\begingroup$ Maybe BarChart[Labeled[#, Rotate["label", 90 Degree], Above, Directive[Red, FontSize -> 32]] & /@ Range[8]]? $\endgroup$ – Carl Woll Apr 20 '17 at 5:01
  • $\begingroup$ @CarlWoll yes that works. If you post the answer I will accept. It appears like a bug through given that the solution is undocumented and is not in the form of an option. $\endgroup$ – Mike Honeychurch Apr 20 '17 at 6:46
  • 1
    $\begingroup$ or BarChart[Labeled[#, Style[Rotate["label", 90 Degree], Red, 32], Above] & /@ Range[8]]? $\endgroup$ – kglr Apr 20 '17 at 19:10
  • $\begingroup$ @kglr yes that works too. I realise I had a brain fade when using Style above but nonetheless the rest of the pot seems like correct usage and therefore a bug? $\endgroup$ – Mike Honeychurch Apr 20 '17 at 23:17
3
$\begingroup$

This looks like a bug. I'll seek confirmation from WRI and post accordingly. In the meantime Carl's suggestion is a work around:

BarChart[Labeled[#, Rotate["label", 90 Degree], Above, Directive[Red, FontSize 
-> 32]] & /@ Range[8]]

or alternatively from @kglr:

BarChart[Labeled[#, Style[Rotate["label", 90 Degree], Red, 32], Above] & /@ Range[8]]
$\endgroup$
2
$\begingroup$

It appears there is a missing step in the processing of LabelStyle within the Labeled wrapper, if it is to work as desired. I think Carl Woll's work-around does this manually but it should be done automatically.

Most of the options of Labeled apply not to the labels themselves but either to be object being labeled, e.g. Background and Frame, or affect the overall layout e.g. Spacings and ImageSize. I think it makes sense for these options to be ignored by BarChart as it has its own directives for these aspects.

Attempting to dig through the Charting` definitions it is hard to know where exactly handling of LabelStyle should have been applied.

We can get some possibly useful information by turning on Charting debug printing:

Charting`dbPrint = Print;

Now:

SetOptions[BarChart, LabelStyle -> {}];

BarChart[
  Labeled[#, "label", Above, 
     LabelStyle -> Directive[Red, FontSize -> 32]] & /@ Range[8]
]

iBarChart via: BarChart

ChartParser: hasWrappedInputQ: True

ChartParser: WrapperFunctions: {{1}->{{Labeled,label,Above,LabelStyle->Directive[,FontSize->32]}},{2}->{{Labeled,label,Above,LabelStyle->Directive[,FontSize->32]}},{3}->{{Labeled,label,Above,LabelStyle->Directive[,FontSize->32]}},{4}->{{Labeled,label,Above,LabelStyle->Directive[,FontSize->32]}},{5}->{{Labeled,label,Above,LabelStyle->Directive[,FontSize->32]}},{6}->{{Labeled,label,Above,LabelStyle->Directive[,FontSize->32]}},{7}->{{Labeled,label,Above,LabelStyle->Directive[,FontSize->32]}},{8}->{{Labeled,label,Above,LabelStyle->Directive[,FontSize->32]}}}

.

.

.

Wrappers defined in Charting`ParserDump`$ApplicationWrapperFunctions which include Labeled appear to be handled generically.

Charting`ChartParser is used to process the chart data. It calls Charting`ParserDump`processWrappers which contains the definition:

(* contexts stripped for brevity *)

processWrappers[obj_, d : h_[x_, y___], pos_, wrappers_List] /; 
  MemberQ[wrappers, h] :=
 Module[{data},
  appendProperty[obj, 
   "WrapperFunctions", {pos -> 
     Which[MemberQ[$SystemWrapperFunctions, h], data = x; {h, h[#1, y] &}, 
      MemberQ[$ApplicationWrapperFunctions, h], data = x; {h, y}, 
      MemberQ[$MetaWrapperFunctions, h], data = x; {h, y}, 
      MemberQ[$ModelWrapperFunctions, h], data = d["InputData"]; {h, d}, True, 
      dbPrint["processWrappers: ", h, " is not in any of the wrapper lists. "]]}]; 
   processWrappers[obj, data, pos, wrappers]
 ]

Note that for every Application Wrapper Function the same transformation is applied, i.e. wrapper[foo, bar, baz] -> {wrapper, bar, baz}.

I get lost in the definitions here but I cannot find anything that would handle LableStyle specifically.

$\endgroup$
  • $\begingroup$ I didn;t know about Charting`dbPrint = Print. It is too time consuming to run a Trace on this sort of thing due to the volume of output. Given that LabelStyle is a documented option (note that same thing happens for BaseStyle) it appears to be a bug. How do you feel about adding "bugs" for this post? $\endgroup$ – Mike Honeychurch Apr 23 '17 at 0:43
  • $\begingroup$ @MikeHoneychurch Well it looks buggy but since I didn't finish walking through the code before I got tired I cannot really say. Arguably it falls into the category of omission, which I suppose are bugs to some people and not to others. $\endgroup$ – Mr.Wizard Apr 23 '17 at 0:52
  • $\begingroup$ I think if a documented option does not work then it is a bug -- just MHO $\endgroup$ – Mike Honeychurch Apr 23 '17 at 0:56
  • $\begingroup$ @Mike What about the Labeled options that make no sense within BarChart? $\endgroup$ – Mr.Wizard Apr 23 '17 at 1:04
  • $\begingroup$ Thats pedantic! :) I am referring to options that clearly should work. I'd expect options that make no sense to be filtered out. $\endgroup$ – Mike Honeychurch Apr 23 '17 at 1:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.