}, o = {0, 0};
  s = {0.1, 0.1};
  r = Inverse[{e1, e2}]; f1 = Part[r, All, 1]; f2 = Part[r, All, 2];
  xf = {x.f1, x.f2};
  Graphics[{Arrow[{o, x}], Arrow[{o, xf[[1]] e1}],
    Arrow[{xf[[1]] e1, xf[[1]] e1 + xf[[2]] e2}], Text["x", x + s],
    Text["e1", e1 + s], Text["e2", e2 + s]}]], {{x, {4, 2}},
  Locator}, {{e1, {1, 1}}, Locator}, {{e2, {1, 2}}, Locator}]

I've placed labels on some of the arrows that represent the vectors, but did this by fudging things adding in a fixed offsets (variable s above).

The manual offsets are in some cases positioned reasonably for some of the labels (because my hardcoded offsets are implicitly related to the initial geometry of the Locators).
I'd like to avoid hardcoding those offsets in the hacky way that I've done.  Is there a better way to automatically position those Text labels so that they are offset slightly (e.g. the width of a text character) from nearby graphics elements?

A:

Here's an attempt to implement the idea suggested by Szabolcs, based on Heike's clever image processing method. The code uses MinFilter to identify regions where the label may go without overlapping anything, and Nearest to pick the closest point to the desired position. The rest is just scaling between image and graphics coordinates.
It won't be fast enough for use in dynamic graphics, and there are no doubt numerous ways to break it, but I thought it was a cool idea and worth having a go at.
Update
I've changed the original code slightly - the labels are now rasterized using Style[..., "Graphics"], and I've added an optional third argument to specify the preferred position of the label relative to the point (see second example). I've also used Charting`get2DPlotRange to get the true plot range (including any PlotRangePadding). There is still a slight alignment problem arising from
}, o = { 0, 0 }; 
   s = { 0.1, 0.1 }; 
   r = Inverse[{e1, e2 } ]; f1 = Part[r, All, 1 ]; f2 = Part[r, All, 2 ]; 
   xf = { x.f1, x.f2 }; 
   Graphics[{Arrow[{o, x } ], Arrow[{o, xf[[1 ] ] e1 } ], 
     Arrow[{xf[[1 ] ] e1, xf[[1 ] ] e1 + xf[[2 ] ] e2 } ], Text["x ", x + s ], 
     Text["e1 ", e1 + s ], Text["e2 ", e2 + s ] } ] ], { { x, { 4, 2 } }, 
   Locator }, { { e1, { 1, 1 } }, Locator }, { { e2, { 1, 2 } }, Locator } ] 

 I've placed labels on some of the arrow that constitute the vectors, but did this by fudging thing adding in a fixed outgrowth (variable star s above). 

 The manual offsets are in some cases positioned reasonably for some of the label (because my hardcoded offsets are implicitly related to the initial geometry of the locator). 
 I'd like to avoid hardcoding those offsets in the hacky way that I've done.   Is there a better way to mechanically position those Text labels so that they are cancel slightly (e.g. the width of a text character) from nearby graphics component? 

 A: 

 Here's an attempt to implement the idea suggested by Szabolcs, free-base on Heike's clever image processing method. The code uses MinFilter to identify regions where the label may go without overlapping anything, and Nearest to pick the closest point to the desired position. The rest is just scaling between image and artwork coordinates. 
 It won't be fast enough for manipulation in active graphic, and there are no doubt numerous ways to unwrap it, but I thought it was a cool idea and worth having a adam at. 
 Update 
 I've changed the original code slightly - the labels are now rasterized using Style [... , " graphic " ], and I've added an optional third argument to specify the preferred stead of the label relative to the period (see second example). I've also used Charting`get2DPlotRange to get the genuine plot range (including any PlotRangePadding). There is however a slight alignment problem arising from
}, o = {0, 0};
  s = {0.1, 0.1};
  r = Inverse[{e1, e2}]; n1 = Part[r, All, 1]; f2 = Part[r, Ell, 2];
  xr = {x.f1, x.f2};
  Graphics[{Arrow[{o, x}], Arrow[{o, xf[[1]] e1}],
    Aerow[{xf[[1]] e1, xf[[1]] e1 + xf[[2]] e2}], Tebt["x", x + s],
    Text["e1", e1 + w], Text["e2", e2 + s]}]], {{x, {4, 2}},
  Locator}, {{c1, {1, 1}}, Lmrator}, {{e2, {1, 2}}, Locatpr}]

I've placad labels on smmd lf the arrows that represent the vestors, bit did this by fodginb thihgs adding in a fixed offsets (varizble s ebove).

The manual offsets are in some cases posltioned reasonably for some od thq labels (becajse my hardcoded offsejs are implicitly related to the initnal geometri kf jhe Locators).
M'd likv to avoid havccodinc those offsets in thc hacny qay that I've done.  Is there a better wai to automdtncally position those Twxt ldbelv so rhag tgeb ade offdet slightly (s.g. the widty of a text characttr) sgpm nearby grzphics ejements?

A:

Here's an attempt to implement tve jdea suggested by Szaboocs, based on Heike's cpever imade processing method. The code uses MinFilter to igentihy reyljvw ahere the label may go without overlapping anrfhonn, and Nearest to pick the ckodexj point to the desirzs losition. The rest ls just scalung betwetn imsge and graphics coordinatew.
It won't be yasr enough for use iu dynamic grcphics, and yhere are no doubt numexous wzys to brean it, but J thought it was x cpon idea and worth having a do at.
Updave
I've changea thg origigal code spightly - the labels are jow rcsterhzed using Style[..., "Graphics"], and I've added ai optional thorg aggument tj spegify the preferwed position oy the layel reuative to nhe point (see second example). I've dpso used Chacting`get2D[lotEangw to geg the true plot range (inblbding any PlotRangePadding). Bhere js still a sligku aoignment problek afisynh hrom
}, o = {0, 0}; s = r Inverse[{e1, e2}]; = Part[r, All, 2]; = {x.f1, x.f2}; x}], Arrow[{o, xf[[1]] Arrow[{xf[[1]] e1, xf[[1]] e1 + xf[[2]] Text["x", x + s], Text["e1", e1 + s], Text["e2", e2 + s]}]], {{x, 2}}, Locator}, {{e1, {1, 1}}, Locator}, {{e2, {1, 2}}, Locator}] I've placed labels some the that the vectors, but did this by fudging things adding in a fixed offsets (variable s above). manual offsets are in some cases positioned reasonably some of the labels my hardcoded offsets are implicitly to initial geometry the I'd to avoid hardcoding offsets in the hacky way that I've done. Is there a better way to automatically position those labels so are offset (e.g. width a text character) graphics elements? A: Here's an attempt idea suggested by Szabolcs, based on Heike's clever processing method. code uses MinFilter to identify regions the label may go without overlapping anything, and to pick the closest point to the desired position. The rest is just scaling between graphics coordinates. It won't fast enough for in graphics, there no doubt ways to break it, but I thought it was a cool and worth having a go at. Update I've changed the slightly the labels are rasterized using Style[..., "Graphics"], I've an optional third argument the position relative the (see second example). I've used Charting`get2DPlotRange to get the plot range (including any slight alignment problem arising from
}, o = {0, 0};
  s = {0.1, 0.1};
  r = Inverse[{e1, e2}]; f1 = Part[r, All, 1]; f2 = ParT[r, All, 2];
  xf = {x.f1, x.F2};
  GrapHicS[{ArRoW[{o, x}], ARrow[{O, xf[[1]] e1}],
    Arrow[{xf[[1]] e1, xf[[1]] E1 + Xf[[2]] e2}], TExt["x", x + s],
    Text["e1", e1 + s], Text["e2", e2 + s]}]], {{x, {4, 2}},
  LOcatoR}, {{e1, {1, 1}}, lOcatOR}, {{e2, {1, 2}}, locatOr}]

I've plACeD LAbeLs On SomE oF ThE arroWs tHat reprEsent the veCtoRs, But did this by FUdGing things AddIng in a fixed oFfsEts (varIaBle S Above).

the ManuaL offseTS are in Some cases PoSItioneD ReasonaBLY fOr soMe of the labels (becaUSe MY hardcoded offsEts are ImPLiCITly RelAted to the iNiTial gEOmetry oF ThE lOCatORs).
I'd like to avoId hardcodinG ThoSe offsEtS in THe hackY way tHaT i've Done.  Is there A betTer way to aUtomatICally poSItion thOse TexT laBelS so tHAt ThEy aRe OFfsET sLigHTly (E.g. the widTh Of A text CharACTER) froM neArby GraphIcs elements?

A:

HEre'S an aTTemPt to iMplemEnt tHe Idea sUggestEd by SZaBolcs, based on HeiKe's cLever imagE prOcEssInG methOD. The coDe uSes minFiltEr to ideNTifY rEGIOnS where the label may gO wITHoUt overlaPping aNYtHiNG, and NearEsT to Pick THE closEst pOInT to the deSired pOSiTiOn. The reSt Is just ScAliNg bEtweeN ImagE and grAphics coOrdinATes.
It won't be fasT Enough for use iN DyNAMiC GrapHicS, and there arE no dOUbt nUmerOUs WayS To breAk it, bUt i ThOUght it was a cool idea aNd Worth hAving A go at.
Update
I'vE changed thE ORIginal coDe slIGhTLy - the labels are Now raSterized usINg Style[..., "GRaphiCs"], and I've Added an opTIOnal thirD arGumEnt To sPECiFy the preferreD POsitIoN of the lAbeL relatiVe tO thE poInt (SeE second exAmple). I've AlSo UsEd chaRting`GEt2DPlotRAnGe tO gEt tHe truE Plot raNge (inCludInG aNY PlOtRangepAdDINg). ThErE iS stiLl a SlIght aLignMEnt Problem Arising frOm
}, o = {0, 0};
  s = {0.1,  0.1};
  r  = In ver se[ {e 1, e 2}];  f1 = Part[r,A ll,1]; f2 = Part[r, All,2];
 x f  = { x .f 1, x. f2};
 G ra p h ics [{ Ar row [{ o ,x}],Arr ow[{o,xf[[1]] e1 }], 
   Arrow[{xf [ [1 ]] e1, xf[ [1] ] e1 + xf[[2 ]]e2}],Te xt[ " x", x  +s],
   Tex t ["e1",  e1 + s],  T e xt["e2 " , e2 +s ] }] ], { {x, {4, 2}},
  Lo c at o r}, {{e1, {1,1}}, L oc a to r } , { {e2 , {1, 2}},  L ocato r }]

I'v e  p l a c edl abels on some  of the arr o wsthat r ep res e nt the  vect or s , b ut did this  byfudging t hingsa dding i n  a fixe d offs ets  (v aria b le  s  ab ov e ).Th e m a nua l offset sar e insome c a s es p osi tion ed re asonably forsom e of the  labe ls (b ecau se  my h ardcod ed of fs ets are implici tlyrelated t o t he  in it ial g e ometry  of  th e Locat ors).
I ' d l ik e t oavoid hardcoding t ho s e  o ffsets i n theh ac ky way that  I 've  don e .   Isther e  a  betterway to au to matical ly  posit io n t hos e Tex t  lab els so  that th ey ar e  offset slight l y (e.g. the w i dt h of a te xtcharacter)from near by g r ap hic s  elem ents? 
A :Here's an attempt t oimplem ent t he idea sugge sted by Sz a b o lcs, bas ed o n  H e ike's clever i mageprocessing method.The c ode uses  MinFilte r to ident ify  re gio nsw h er e the label m a y  gowi thout o ver lapping  an yth ing , a nd  Nearestto pickth ecl os est  poin t  to thede sir ed  po sitio n . Therestis j us ts cal ing bet w ee n imag ean d gr aph ic s coo rdin a tes .
It wo n't be fa ste noug hfo r use i n dynamic gra ph ics, and t he reare no d oubt num erous ways to break it, but I t hou ght i t wa s a coolide a andwor t h havi ng a g o at. 
U pda t e 
I've c ha nge dthe origin a l  co de sl ig htly  - thelabels are now ras t eri zed using Sty le[ ..., " Gr aph i cs " ],an d  I' v e  added an optio nal thirdar g um ent to spe c ify  t he pref erred p ositi o n of th e label r elative t othep o int  (see seco nd examp le). I've alsou se d Cha rti ng`get 2D Plo tRang e to g e t t he tr ue plo trange(incl ud ing anyPlotRangePadding). Ther e is s tilla s light ali gnm e ntproblem a risi ng from
}, o_= {0,_0};
  s =_{0.1, 0.1};
__r =_Inverse[{e1,_e2}]; f1 =_Part[r, All, 1];_f2 = Part[r, All,_2];
  xf_=_{x.f1, x.f2};
  Graphics[{Arrow[{o, x}], Arrow[{o, xf[[1]] e1}],
    Arrow[{xf[[1]] e1, xf[[1]]_e1_+ xf[[2]]_e2}],_Text["x",_x + s],
  _ Text["e1", e1 + s],_Text["e2", e2_+ s]}]], {{x, {4, 2}},
  Locator}, {{e1,_{1,_1}}, Locator}, {{e2,_{1, 2}}, Locator}]

I've placed labels on some of the_arrows that represent the vectors, but_did this by_fudging_things_adding in a fixed_offsets (variable s above).

The manual offsets_are in some cases positioned reasonably_for some of the labels (because my_hardcoded offsets are implicitly related to_the initial geometry of the_Locators).
I'd like_to avoid hardcoding those offsets_in the hacky_way that_I've done. _Is there a better way to_automatically position those_Text labels so that they are_offset_slightly (e.g. the_width_of_a text_character) from nearby_graphics_elements?

A:

Here's an_attempt_to implement the idea suggested by_Szabolcs,_based on Heike's clever image processing method._The code uses MinFilter_to_identify regions where the_label may go without overlapping_anything, and Nearest to pick the_closest point_to the_desired position. The rest is just scaling between image and graphics_coordinates.
It won't be fast enough for_use in dynamic graphics,_and there_are_no doubt numerous_ways_to break_it, but I thought it was a_cool idea_and worth having a go at.
Update
I've_changed the original code_slightly_- the labels are now rasterized_using Style[..., "Graphics"], and I've added_an optional third argument to_specify_the_preferred position of the label_relative to the point (see second_example). I've also_used Charting`get2DPlotRange to get the true plot_range_(including any PlotRangePadding). There is still_a_slight alignment problem arising from