Group Abstract Group Abstract

Message Boards Message Boards

0
|
81 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

How to resize a DateObject?

Posted 19 hours ago

Suppose I have a DateObject:

myDateObject = DateObject[];

myDateObject

Is it possible to resize this DateObject — either by resizing the object directly, or by reducing the font size in the styling?

Resizing the DateObject directly

When I click on the DateObject, no image handles appear. That's likely because FullForm shows that the head of a date object is, well, DateObject:

FullForm[myDateObject]
Head[myDateObject]

(* DateObject[List[2025, 5, 7, 16, 7, 46.1461525`9.416710360655179],
  "Instant", "Gregorian", -4.`] *)
(* DateObject *)

My thought is to rasterize myDateObject using Rasterize:

myDateObject
originalImageSize = ImageDimensions[Rasterize[myDateObject]]
originalImageSize = First[originalImageSize]

newImageSize = Round[0.75 * originalImageSize];
Rasterize[myDateObject, ImageSize -> newImageSize]
(* OUTPUT FOLLOWS: *)

rasterization attempt

Oddly, the rasterized version of myDateObject doesn't appear to be 0.75 times as wide as myDateObject. Why is this the case?

On the other hand, using (for example) 0.5 instead of 0.75 gives a more reasonable result:

myDateObject
originalImageSize = ImageDimensions[Rasterize[myDateObject]]
originalImageSize = First[originalImageSize]

newImageSize = Round[0.5 * originalImageSize];
Rasterize[myDateObject, ImageSize -> newImageSize]
(* OUTPUT FOLLOWS: *)

rasterization attempt 2

Although, honestly, it doesn't appear to be half the width of the original.

Resizing the DateObject by modifying / styling its underlying box structure

My second idea is to somehow modify or style the DateObject's underlying box structure. Applying ToBoxes to myDateObject yields the following:

ToBoxes[myDateObject]

(* TemplateBox[List[RowBox[List["\"Wed 7 May 2025 16:07:46\"",
  StyleBox[RowBox[List["\"GMT\"","\[InvisibleSpace]",
  StyleBox[RowBox[List["-","4"]],Rule[NumberMarks,False],
  Rule[StripOnInput,False]]]],Rule[FontColor,GrayLevel[0.5`]]]]],
  RowBox[List["DateObject","[", RowBox[List[RowBox[List["{",RowBox[List["2025",",
  ","5",",","7",",","16",",","7",",","46.1461525`9.416710360655179"]],"}"]],",",
  "\"Instant\"",",","\"Gregorian\"",",",RowBox[List["-","4.`"]]]],"]"]]],
  "DateObject",Rule[Editable,False]] *)

The code above is quite involved and, because I don't have much experience with box structures, it's difficult for me to understand. It appears, though, that the styling of the DateObject is dictated by the notebook's stylesheet.

Is there any straightforward way to display the DateObject with a smaller font size — without modifying the notebook's stylesheet?

POSTED BY: Andrew D
Posted 17 hours ago

My suggestion would be to avoid trying to mess with these front end "objects", especially if you're not willing to dive into stylesheet, boxes, options, etc. You can create your own version of the "object" with DateString and a Panel (as one example--there are many other ways to do this).

As for why your Rasterize didn't work as expected, one thing to keep in mind is that the display of images in the front end isn't always faithful to the image's actual size. ImageSize is used to control the display size, so it was reasonable for you to try it, but you can't assume that 75% of the original image dimensions will display as 75% of the displayed size of the original. You'll see what I mean if you just try Rasterize[myDateObject] (without any options specified). It should appear bigger than what the front end displayed for myDateObject itself. So, when you set ImageSize to 75% of the image dimensions of the original, it just so happened that that display size was very close to the display size the front end chose automatically for the original myDateObject. (FWIW, if you wanted to actually change the data itself, you should play with RasterSize instead of ImageSize.)

It turns out to be a whole complicated topic to figure out how to get from the dimensions of the data of a thing to how big that thing appears in the front end, and it's almost never as easy as making one screen pixel correspond to one "cell" of image data.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard