5
$\begingroup$

Can users modify the default format of colors in the front end?

Red

enter image description here

For example, dimensions, aspect ratio, EdgeForm? The motivation is the functional convenience in data visualization application especially when combined w/ Row, Column etc as in this graphic fragment:

enter image description here

Here would like to compress the horizontal bar, eg

Table[Red, {5}] // Row

by changing AspectRatio from squares to thin rectangles, and decrease the thickness of EdgeForm.

EDIT

Given

ds = {Red, Blue} 

Would like to achieve something like this but on the box form rather than Graphics, to avoid scaling and padding problems when interacting with Row and Column

rectangleForm[w_, h_][c_] := 
  Graphics[{c, Rectangle[RoundingRadius -> 1/5]},
   AspectRatio -> (h/w), ImageSize -> {w, h}]; 

Then

ds // Query[{Map[rectangleForm[10, 20]] /* Row, Map[rectangleForm[20, 10]] /* Row, Map[rectangleForm[20, 10]] /* Column}]

enter image description here

Note the unwanted spacing in the last pais using Column. Maybe this can be remedied by use of ImagePadding or related, but this takes effort to coordinate.

$\endgroup$
2
  • $\begingroup$ Try the Graphics commands, like Graphics[{Red, Rectangle[{0, 1}, {2, 1.1}]}] and you can make any shape of any color. $\endgroup$
    – bill s
    Commented Aug 13, 2015 at 21:11
  • $\begingroup$ @bills, That works, eg Table[Graphics[{Red, Rectangle[]}, AspectRatio -> 2, ImageSize -> 10], {5}] // Row $\endgroup$ Commented Aug 13, 2015 at 21:33

2 Answers 2

4
$\begingroup$

You will really need to roll your own color bar, which isn't too difficult. Here is an example of making a highly customized color bar.

With[{n = 24}, 
  Graphics[
    Table[{Hue[i/n], Translate[Rectangle[{0, 0}, {1, 1}], {i, 0}]}, {i, 0, n - 1}], 
    ImageSize -> 550, PlotRangePadding -> None, AspectRatio -> 3/n, 
    Frame -> True, FrameTicks -> None, 
    FrameStyle -> AbsoluteThickness[6], ImageMargins -> 0]]

colors

$\endgroup$
4
$\begingroup$

Although I strongly suggest you just create and use your own formatting function if possible, e.g. form[Red], the question of modifying the internal behavior is interesting.

You can either turn off the automatic color directive formatting and define your own MakeBoxes rules on e.g. RGBColor to take its place, or you can modify the internal function used to produce the color icons. To turn off the automatic formatting evaluate:

SetSystemOptions["TypesetOptions" -> "ColorDirectiveSwatches" -> False]

If instead you wish to modify the swatch routine it is contained in:

ElisionsDump`makeColorSwatches

You can view its definition with:

ToBoxes[Red]; (* preload; do not remove *)    
Needs["GeneralUtilities`"]
PrintDefinitions @ ElisionsDump`makeColorSwatches

Modifying that definition will change the form of all future color icons. For example making a replacement on its DownValues to change the AspectRatio of the GraphicsBox:

With[{dv := DownValues @ ElisionsDump`makeColorSwatches},
  dv = dv /. (AspectRatio -> _) :> (AspectRatio -> 2);
]

Now:

Table[Red, {5}] // Row

enter image description here

$\endgroup$
3
  • $\begingroup$ In fact I would prefer to apply operators eg form[verticalRectangle] to Red rather than modify the built in. I should rephrase or ask a separate Q? By built in I meant operate directly on the box rather than creating Graphics. Doable? $\endgroup$ Commented Aug 14, 2015 at 21:12
  • $\begingroup$ @alancalvitti Could you clarify your goals? (You can edit this question, IMO.) You say rather than creating Graphics; I take this to mean that you want to use a formatting wrapper, such that form[Red] // InputForm is form[RGBColor[1, 0, 0]], but Graphics (or at least GraphicsBox) will be used internally. Is that correct? $\endgroup$
    – Mr.Wizard
    Commented Aug 15, 2015 at 1:37
  • $\begingroup$ I edited to emphasize that I'm looking to apply Graphics like options but to the box format if possible. $\endgroup$ Commented Aug 17, 2015 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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