{ "cells": [ { "cell_type": "markdown", "id": "60162da2", "metadata": {}, "source": [ "# inframe\n", "Drawing primitives inside and outside of the frame.\n", "\n", "In normal ROOT graphics all objects drawn on the pad and therefore\n", "requires special treatment to be able drawn only inside frame borders.\n", "In web-based graphics objects automatically clipped by frame border - if drawn inside frame.\n", "Macro demonstrates usage of \"frame\" draw option for TLine, TBox, TMarker and TLatex classes.\n", "If user interactively change zooming range \"in-frame\" objects automatically clipped.\n", "\n", "Functionality available only in web-based graphics\n", "\n", "\n", "\n", "\n", "**Author:** Sergey Linev \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:38 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "247758e9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:55.081524Z", "iopub.status.busy": "2026-05-19T20:38:55.081410Z", "iopub.status.idle": "2026-05-19T20:38:55.550353Z", "shell.execute_reply": "2026-05-19T20:38:55.549621Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "auto c1 = new TCanvas(\"c1\", \"Drawing inside frame\", 1200, 800);\n", "\n", "if (!gROOT->IsBatch() && !c1->IsWeb())\n", " ::Warning(\"inframe.cxx\", \"macro may not work without enabling web-based canvas\");\n", "\n", "c1->DrawFrame(0., 0., 10., 10., \"Usage of \\\"frame\\\" draw options\");\n", "\n", "auto latex = new TLatex(3., 8., \"Text in the frame\");\n", "latex->SetTextColor(kCyan);\n", "latex->SetTextSize(0.08);\n", "latex->SetTextAlign(22);\n", "c1->Add(latex, \"frame\");" ] }, { "cell_type": "markdown", "id": "ae51b79e", "metadata": {}, "source": [ "draw line and label on the pad" ] }, { "cell_type": "code", "execution_count": 2, "id": "c885bfdc", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:55.552259Z", "iopub.status.busy": "2026-05-19T20:38:55.552133Z", "iopub.status.idle": "2026-05-19T20:38:55.764824Z", "shell.execute_reply": "2026-05-19T20:38:55.764106Z" } }, "outputs": [], "source": [ "auto l1 = new TLine(-0.5, 5, 10.5, 5);\n", "l1->SetLineColor(kBlue);\n", "c1->Add(l1);\n", "\n", "auto tl1 = new TLatex(0.5, 5, \"line outside\");\n", "tl1->SetTextColor(kBlue);\n", "tl1->SetTextAlign(13);\n", "c1->Add(tl1);" ] }, { "cell_type": "markdown", "id": "29c00ad5", "metadata": {}, "source": [ "draw line and label in the frame" ] }, { "cell_type": "code", "execution_count": 3, "id": "1f377fb0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:55.766774Z", "iopub.status.busy": "2026-05-19T20:38:55.766643Z", "iopub.status.idle": "2026-05-19T20:38:55.974531Z", "shell.execute_reply": "2026-05-19T20:38:55.973808Z" } }, "outputs": [], "source": [ "auto l2 = new TLine(-0.5, 5.2, 10.5, 5.2);\n", "l2->SetLineColor(kGreen);\n", "c1->Add(l2, \"frame\");\n", "\n", "auto tl2 = new TLatex(0.5, 5.3, \"line inside\");\n", "tl2->SetTextColor(kGreen);\n", "tl2->SetTextAlign(11);\n", "c1->Add(tl2, \"frame\");" ] }, { "cell_type": "markdown", "id": "b1ec207d", "metadata": {}, "source": [ "draw box and label on the pad" ] }, { "cell_type": "code", "execution_count": 4, "id": "d73cdfd6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:55.976337Z", "iopub.status.busy": "2026-05-19T20:38:55.976222Z", "iopub.status.idle": "2026-05-19T20:38:56.188717Z", "shell.execute_reply": "2026-05-19T20:38:56.188012Z" } }, "outputs": [], "source": [ "auto b1 = new TBox(-0.5, 1, 4, 3);\n", "b1->SetFillColor(kBlue);\n", "c1->Add(b1);\n", "\n", "auto tb1 = new TLatex(0.5, 3.1, \"box outside\");\n", "tb1->SetTextColor(kBlue);\n", "tb1->SetTextAlign(11);\n", "c1->Add(tb1);" ] }, { "cell_type": "markdown", "id": "c772faa3", "metadata": {}, "source": [ "draw box and label in the frame" ] }, { "cell_type": "code", "execution_count": 5, "id": "2d162033", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:56.190479Z", "iopub.status.busy": "2026-05-19T20:38:56.190355Z", "iopub.status.idle": "2026-05-19T20:38:56.398297Z", "shell.execute_reply": "2026-05-19T20:38:56.397612Z" } }, "outputs": [], "source": [ "auto b2 = new TBox(6, 1, 10.5, 3);\n", "b2->SetFillColor(kGreen);\n", "c1->Add(b2, \"frame\");\n", "\n", "auto b2_dash = new TBox(6, 1, 10.5, 3);\n", "b2_dash->SetFillStyle(0);\n", "b2_dash->SetLineColor(kRed);\n", "b2_dash->SetLineStyle(kDotted);\n", "b2_dash->SetLineWidth(3);\n", "c1->Add(b2_dash); // show clipped\n", "\n", "auto tb2 = new TLatex(6.5, 3.1, \"box inside\");\n", "tb2->SetTextColor(kGreen);\n", "tb2->SetTextAlign(11);\n", "c1->Add(tb2, \"frame\");" ] }, { "cell_type": "markdown", "id": "db41a3e6", "metadata": {}, "source": [ "draw marker and label on the pad" ] }, { "cell_type": "code", "execution_count": 6, "id": "a8fadd7e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:56.400166Z", "iopub.status.busy": "2026-05-19T20:38:56.400046Z", "iopub.status.idle": "2026-05-19T20:38:56.612542Z", "shell.execute_reply": "2026-05-19T20:38:56.611830Z" } }, "outputs": [], "source": [ "auto m1 = new TMarker(9.5, 7., 29);\n", "m1->SetMarkerColor(kBlue);\n", "m1->SetMarkerSize(3);\n", "c1->Add(m1);\n", "\n", "auto tm1 = new TLatex(9.3, 7., \"outside\");\n", "tm1->SetTextColor(kBlue);\n", "tm1->SetTextAlign(32);\n", "c1->Add(tm1);" ] }, { "cell_type": "markdown", "id": "412285a4", "metadata": {}, "source": [ "draw marker and label in the frame" ] }, { "cell_type": "code", "execution_count": 7, "id": "3653ccc6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:56.614298Z", "iopub.status.busy": "2026-05-19T20:38:56.614180Z", "iopub.status.idle": "2026-05-19T20:38:56.821783Z", "shell.execute_reply": "2026-05-19T20:38:56.821134Z" } }, "outputs": [], "source": [ "auto m2 = new TMarker(9.5, 8., 34);\n", "m2->SetMarkerColor(kGreen);\n", "m2->SetMarkerSize(3);\n", "c1->Add(m2, \"frame\");\n", "\n", "auto tm2 = new TLatex(9.3, 8., \"inside\");\n", "tm2->SetTextColor(kGreen);\n", "tm2->SetTextAlign(32);\n", "c1->Add(tm2, \"frame\");" ] }, { "cell_type": "markdown", "id": "2a4e93d7", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 8, "id": "480c94ef", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:56.823685Z", "iopub.status.busy": "2026-05-19T20:38:56.823554Z", "iopub.status.idle": "2026-05-19T20:38:57.045704Z", "shell.execute_reply": "2026-05-19T20:38:57.045065Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%jsroot on\n", "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }