5
$\begingroup$

Reported to Wolfram Technical Support [CASE:4212712]


Using Options on IconData reveals:

Options @ IconData

(* {Background → None, ImageSize → Automatic} *)

Great! Let's simply use them:

IconData[ "WindDirection", 315, Background -> None ]

error

Why are we getting an unknown option error (OptionValue)? Is something similar also observable for other built-in functions?

Note: This will also happen for ImageSize. I am using Version 11.3 on Windows 10 (64 Bit).

Update:

While we may argue about the above -- after all the documentation for IconData will not show valid options --, note the following behavior:

SetOptions[ IconData, Background → Green];
IconData["WindDirection", 315]

You will note, that the options indeed have changed, but now there is no green background, while

IconData["WindDirection", 315, Background -> Green]

will show a green background albeit throwing an error message as given above.

$\endgroup$
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$ – Kuba Jan 15 at 14:10
4
$\begingroup$

Per my comment, if you look at InputForm@IconData["WindDirection", 315], you'll see that it returns a Graphics object.

Thus a sensible workaround would be:

Show[IconData["WindDirection", 315], Background -> Green]

since it will act like any other Graphics object.

For instance, you would also be able to use DiscretizeGraphics and its ilk:

discretize example

The natural Wolfram order of things is that if a symbol or something about a symbol is not documented, it's not officially supported and is likely to change, stop working, or exhibit weird behaviour (as in your case).

$\endgroup$
  • 1
    $\begingroup$ And yet, we are not spelunking, but simply checking for options, which are given but do not work as options should... $\endgroup$ – gwr Jan 14 at 21:35
  • 2
    $\begingroup$ I'm not disagreeing with you that they exist and should work; I'm just stating that it's not terribly surprising that they don't, given that they're undocumented. $\endgroup$ – Carl Lange Jan 14 at 21:52
4
$\begingroup$

From the above comments and some inspection we find that according to the decisive authority of the documentation using Options for IconData is not supported. Using Trace we see that IconData uses DataPaclets`IconDataDump` which will not make use of the options given in a way we want.

One work around is to use ReplaceAll for the Graphics object returned by IconData (a careful inspection using FullForm will tell you what to replace):

IconData["WindDirection", 315] // ReplaceAll@
    {
        Rule[Background, None] -> Rule[Background, Green],
        Rule[ImageSize, __ ] -> Rule[ImageSize, Large]
    }

LargeIcon

$\endgroup$
4
$\begingroup$

An alternative work-around is to take the graphics primitives returned by IconData and use them in Graphics with desired options added:

Graphics[First @ IconData["WindDirection", 315], 
 Background -> Green, ImageSize -> Large]

enter image description here

$\endgroup$
  • $\begingroup$ (+1) But I have to admit that Carl Lange's solution as given in the comments looks simpler, e.g. Show[ IconData["WindDirection", 315], Background -> Green, ImageSize -> Large ]. $\endgroup$ – gwr Jan 14 at 18:04
  • $\begingroup$ Thank you @gwr. I agree Show is more straightforward; I thought you commented that it produced the same error message in your system. $\endgroup$ – kglr Jan 14 at 18:23
  • 1
    $\begingroup$ Actually my bad: I missed his bracket making IconData an expression within Show (which is why I deleted my comment ... and probably should have told @CarlLange more explicitly). $\endgroup$ – gwr Jan 14 at 18:26

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.