diff --git a/README.md b/README.md index 9d9d84b..eb96fd0 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ -# graphfunctions v1.2 -*(08 Oct 2024)* +# graphfunctions v1.3 +*(11 Oct 2024)* A suite of programs to help enhance figures in Stata. The program is designed to be called by other programs, but it can be used as a standalone as well. The page will provide some minimum examples, but for the full scope of each program, see the relevant help files. @@ -19,8 +19,8 @@ Currently, this package contains: |----| ---- | ---- | ----- | | [labsplit](#labsplit) | 1.1 | 28 Sep 2024 | Text wrapping | | [catspline](#catspline) | 1.0 | 04 Oct 2024 | Catmull-Rom splines | -| [arc](#arc) | 1.0 | 08 Oct 2024 | Arcs between two points | - +| [arc](#arc) | 1.1 | 11 Oct 2024 | Arcs between two points | +| [shapes](#shapes) | 1.0 | 11 Oct 2024 | Draw shapes | The programs here are designed/upgraded/bug-fixed on a needs basis, mostly to support other packages. If you have specific requests, or find major bugs, then please open an [issue](https://github.com/asjadnaqvi/stata-graphfunctions/issues). @@ -35,7 +35,7 @@ SSC (**v1.0**): ssc install graphfunctions, replace ``` -GitHub (**v1.2**): +GitHub (**v1.3**): ```stata net install graphfunctions, from("https://raw.githubusercontent.com/asjadnaqvi/stata-graphfunctions/main/installation/") replace @@ -147,7 +147,7 @@ twoway /// ### arc -*(v1.0: 08 Oct 2024)* +*(v1.1: 11 Oct 2024)* Draw minor or major arcs between two points. The arc orientation and be switched using `swap`, and major arcs can be drawn using `major`. @@ -210,6 +210,11 @@ twoway /// +### shapes +*(v1.0: 11 Oct 2024)* + + + ## Feedback Please open an [issue](https://github.com/asjadnaqvi/stata-graphfunctions/issues) to report errors, feature enhancements, and/or other requests. @@ -217,6 +222,10 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-graphfunctions/issues ## Change log +**v1.3 (11 Oct 2024)** +- `shapes` added. +- `arc` bug fixes plus code cleanup. + **v1.2 (08 Oct 2024)** - `arc` added. - Bug fixes in `labsplit`. diff --git a/installation/arc.ado b/installation/arc.ado index aa8e538..07408d7 100644 --- a/installation/arc.ado +++ b/installation/arc.ado @@ -1,6 +1,7 @@ -*! arc v1.0 (08 Oct 2024) +*! arc v1.1 (11 Oct 2024) *! Asjad Naqvi (asjadnaqvi@gmail.com) +* v1.1 (11 Oct 2024): Minor bug fixes. * v1.0 (08 Oct 2024): first release. @@ -13,7 +14,7 @@ version 11 syntax, /// x1(numlist max=1) y1(numlist max=1) /// // from x2(numlist max=1) y2(numlist max=1) /// // to - [ n(real 80) RADius(numlist max=1 >0) major swap ] /// + [ n(real 40) RADius(numlist max=1 >0) major swap ] /// [ genx(string) geny(string) replace ] @@ -27,7 +28,6 @@ version 11 local xm = (`x1' + `x2') / 2 local ym = (`y1' + `y2') / 2 - // slope local dx = `x2' - `x1' local dy = `y2' - `y1' @@ -40,8 +40,7 @@ version 11 display in yellow "Radius of `radius' assumed." } - - // Check that radius is valid + // validate the radius if `radius' <= `L'/2 { local mychord = `L' / 2 di as error "Radius must be greater than half the chord length. Half chord length for given coordinates = `mychord'" @@ -51,39 +50,27 @@ version 11 return local chord `L' return local radius `radius' - // Distance from midpoint to center + // distance from midpoint to center local h_dist = sqrt(`radius'^2 - (`L'/2)^2) - // Determine the direction of the perpendicular bisector + // direction of the perpendicular bisector local ux_perp = -`dy' / `L' local uy_perp = `dx' / `L' local cross_prod = `dx' * `uy_perp' - `dy' * `ux_perp' - // switch from left to right orientation + // swap left to right orientation if "`swap'" == "" { - if `cross_prod' > 0 { - local h = `xm' + `h_dist' * `ux_perp' - local k = `ym' + `h_dist' * `uy_perp' - } - else { - local h = `xm' - `h_dist' * `ux_perp' - local k = `ym' - `h_dist' * `uy_perp' - } - } + local h = `xm' + `h_dist' * `ux_perp' + local k = `ym' + `h_dist' * `uy_perp' + } else { - if `cross_prod' < 0 { - local h = `xm' + `h_dist' * `ux_perp' - local k = `ym' + `h_dist' * `uy_perp' - } - else { - local h = `xm' - `h_dist' * `ux_perp' - local k = `ym' - `h_dist' * `uy_perp' - } + local h = `xm' - `h_dist' * `ux_perp' + local k = `ym' - `h_dist' * `uy_perp' } - + // get the angles in order local angle_start = atan2(`y1' - `k', `x1' - `h') local angle_end = atan2(`y2' - `k', `x2' - `h') @@ -93,41 +80,36 @@ version 11 if `angle_end' < 0 local angle_end = `angle_end' + 2 * _pi - - // minor (smaller arc) vs major (larger arc) + // correct for minor vs major arc if "`swap'"!= "" { if "`major'" != "" { - if (`angle_end' - `angle_start') < _pi local angle_end = `angle_end' + 2 * _pi + if (`angle_end' - `angle_start') < _pi local angle_end = `angle_end' + 2 * _pi } else { - if (`angle_end' - `angle_start') > _pi local angle_end = `angle_end' - 2 * _pi + if (`angle_end' - `angle_start') > _pi local angle_end = `angle_end' - 2 * _pi } } else { if "`major'" != "" { - if (`angle_end' - `angle_start') > _pi local angle_end = `angle_end' - 2 * _pi - if (`angle_end' - `angle_start') > 2 * _pi local angle_end = `angle_end' - 2 * _pi - + if (`angle_end' - `angle_start') > _pi local angle_end = `angle_end' - 2 * _pi } else { - if (`angle_end' - `angle_start') < _pi local angle_end = `angle_end' + 2 * _pi - if (`angle_end' - `angle_start') > 2 * _pi local angle_end = `angle_end' - 2 * _pi + if (`angle_end' - `angle_start') < _pi local angle_end = `angle_end' + 2 * _pi } + if (`angle_end' - `angle_start') > 2 * _pi local angle_end = `angle_end' - 2 * _pi } - - // angle segments local delta_theta = (`angle_end' - `angle_start') / (`n' - 1) + if _N < `n' set obs `n' + tempvar theta gen double `theta' = `angle_start' + (_n - 1) * `delta_theta' - if _N < `n' set obs `n' local xvar _x local yvar _y - if "`genx'" != "" local xvar `genx' if "`geny'" != "" local yvar `geny' @@ -135,11 +117,10 @@ version 11 capture drop `xvar' capture drop `yvar' } - + gen double `xvar' = `h' + `radius' * cos(`theta') gen double `yvar' = `k' + `radius' * sin(`theta') - - + return local xcirc = `h' return local ycirc = `k' diff --git a/installation/arc.sthlp b/installation/arc.sthlp index 94d974f..f75ebdb 100644 --- a/installation/arc.sthlp +++ b/installation/arc.sthlp @@ -1,5 +1,5 @@ {smcl} -{* 08Oct2024}{...} +{* 11Oct2024}{...} {hi:help arc}{...} {right:{browse "https://github.com/asjadnaqvi/stata-graphfunctions":graphfunctions (GitHub)}} @@ -53,8 +53,8 @@ More examples on {browse "https://github.com/asjadnaqvi/stata-graphfunctions":Gi {title:Package details} -Version : {bf:arc} v1.0 in {stata help graphfunctions:graphfunctions} -This release : 08 Oct 2024 +Version : {bf:arc} v1.1 in {stata help graphfunctions:graphfunctions} +This release : 11 Oct 2024 First release: 08 Oct 2024 Repository : {browse "https://github.com/asjadnaqvi/stata-graphfunctions":GitHub} Keywords : Stata, graph, arcs diff --git a/installation/graphfunctions.pkg b/installation/graphfunctions.pkg index e0851c0..8c7fe3d 100644 --- a/installation/graphfunctions.pkg +++ b/installation/graphfunctions.pkg @@ -1,4 +1,4 @@ -v 1.2 +v 1.3 d {bf:GRAPHFUNCTIONS}: A collection of functions to extend graph functionality in Stata d d Requires: Stata version 11 or higher. @@ -8,8 +8,9 @@ d KW: graphs d KW: figures d KW: text wrap d KW: splines +d KW: shapes d -d Distribution-Date: 20241008 +d Distribution-Date: 20241011 d License: MIT d d Author: Asjad Naqvi (asjadnaqvi@gmail.com) @@ -20,4 +21,6 @@ f labsplit.sthlp f catspline.ado f catspline.sthlp f arc.ado -f arc.sthlp \ No newline at end of file +f arc.sthlp +f shapes.ado +f shapes.sthlp \ No newline at end of file diff --git a/installation/graphfunctions.sthlp b/installation/graphfunctions.sthlp index f8d84d4..a2a8f82 100644 --- a/installation/graphfunctions.sthlp +++ b/installation/graphfunctions.sthlp @@ -1,7 +1,7 @@ {smcl} -{* 08Oct2024}{...} +{* 11Oct2024}{...} {hi:help graphfunctions}{...} -{right:{browse "https://github.com/asjadnaqvi/stata-graphfunctions":graphfunctions v1.2 (GitHub)}} +{right:{browse "https://github.com/asjadnaqvi/stata-graphfunctions":graphfunctions v1.3 (GitHub)}} {title:GRAPH FUNCTIONS}: @@ -12,8 +12,9 @@ This package contains the following program(s): {hline} {stata help labsplit:labsplit} Various options for wrapping labels. -{stata help labsplit:catspline} Generate Catmull-Rom splines. -{stata help labsplit:arc} Draw an arc between two points. +{stata help catspline:catspline} Generate Catmull-Rom splines. +{stata help arc:arc} Draw an arc between two points. +{stata help shapes:shapes} Draw shapes. {hline} @@ -32,21 +33,21 @@ Please submit bugs, errors, feature requests on {browse "https://github.com/asja Suggested citation guidlines for this package: -Naqvi, A. (2024). Stata package "graphfunctions" version 1.2. Release date 08 October 2024. https://github.com/asjadnaqvi/stata-graphfunctions. +Naqvi, A. (2024). Stata package "graphfunctions" version 1.3. Release date 11 October 2024. https://github.com/asjadnaqvi/stata-graphfunctions. @software{graphfunctions, author = {Naqvi, Asjad}, title = {Stata package ``graphfunctions''}, url = {https://github.com/asjadnaqvi/stata-graphfunctions}, - version = {1.2}, - date = {2024-10-08} + version = {1.3}, + date = {2024-10-11} } {title:Package details} -Version : {bf:graphfunctions} v1.2 -This release : 08 Oct 2024 +Version : {bf:graphfunctions} v1.3 +This release : 11 Oct 2024 First release: 28 Sep 2024 Repository : {browse "https://github.com/asjadnaqvi/stata-graphfunctions":GitHub} License : {browse "https://opensource.org/licenses/MIT":MIT} diff --git a/installation/shapes.ado b/installation/shapes.ado new file mode 100644 index 0000000..ebf9906 --- /dev/null +++ b/installation/shapes.ado @@ -0,0 +1,56 @@ +*! shapes v1.0 (11 Oct 2024) +*! Asjad Naqvi (asjadnaqvi@gmail.com) + +* v1.0 (11 Oct 2024): first release. + + +cap program drop shapes + +program define shapes + +version 11 + gettoken left 0: 0, parse(", ") + + if "`left'" == "circle" { + _circle `0' + } + +end + + + +program define _circle + version 11 + + syntax [, n(real 6) ROtate(real 0) RADius(real 10) ] + + +quietly { + if _N < `n' set obs `n' + + local rotate = `rotate' * _pi / 180 + + tempvar _seq _angle + + gen `_seq' = _n + gen double `_angle' = (`_seq' * 2 * _pi / `n') + `rotate' + + gen double _x = `radius' * cos(`_angle') + gen double _y = `radius' * sin(`_angle') + + + expand 2 if `_seq'== 1 + set obs `=_N+1' // pad a row in case more rows are added. + gen _id = _n + + order _id +} + + +end + + + + + + diff --git a/installation/shapes.sthlp b/installation/shapes.sthlp new file mode 100644 index 0000000..e16d489 --- /dev/null +++ b/installation/shapes.sthlp @@ -0,0 +1,79 @@ +{smcl} +{* 11Oct2024}{...} +{hi:help shapes}{...} +{right:{browse "https://github.com/asjadnaqvi/stata-graphfunctions":graphfunctions (GitHub)}} + +{hline} + +{title:shapes}: A program for generating shapes. + + + +{marker syntax}{title:Syntax} + +Generic syntax: + +{p 8 15 2} +{cmd:shapes} circle, {cmd:[} {cmd:n}({it:int}) {cmd:n}({it:int}) {cmdab:ro:tate}({it:degrees}) {cmdab:rad:ius}({it:num}) {cmd:]} + +Generates three variables {it:_id}, {it:_x}, {it:_y}. + + +{synoptset 36 tabbed}{...} +{synopthdr} +{synoptline} + +{p2coldent : {opt rad:ius(num)}}Specify the radius length. Default is {opt rad(10)}.{p_end} + +{p2coldent : {opt n(int)}}Number of equi distant points in a circle. Default is {opt n(6)} which generate a hexagon. Option {opt n(4)} will yield a square.{p_end} + +{p2coldent : {opt ro:tate(degrees)}}Rotate the shape by {it:degrees}. Default is {opt ro(0)}.{p_end} + +{synoptline} +{p2colreset}{...} + + +{title:Examples} + +Generate data: +{stata shapes circle, n(8) ro(22.5) rad(8)} + +{stata twoway (connected _y _x), xsize(1) ysize(1) aspect(1) xlabel(-10 10) ylabel(-10 10)} + +More examples on {browse "https://github.com/asjadnaqvi/stata-graphfunctions":GitHub}. + + +{title:Package details} + +Version : {bf:shapes} v1.0 in {stata help graphfunctions:graphfunctions} +This release : 11 Oct 2024 +First release: 11 Oct 2024 +Repository : {browse "https://github.com/asjadnaqvi/stata-graphfunctions":GitHub} +Keywords : Stata, graph, shapes +License : {browse "https://opensource.org/licenses/MIT":MIT} + +Author : {browse "https://github.com/asjadnaqvi":Asjad Naqvi} +E-mail : asjadnaqvi@gmail.com +Twitter/X : {browse "https://x.com/AsjadNaqvi":@AsjadNaqvi} + + +{title:Feedback} + +Please submit bugs, errors, feature requests on {browse "https://github.com/asjadnaqvi/stata-graphfunctions/issues":GitHub} by opening a new issue. + + +{title:Citation guidelines} + +See {stata help graphfunctions:graphfunctions}. + + +{title:Other packages} + +{psee} + {helpb arcplot}, {helpb alluvial}, {helpb bimap}, {helpb bumparea}, {helpb bumpline}, {helpb circlebar}, {helpb circlepack}, {helpb clipgeo}, {helpb delaunay}, {helpb graphfunctions}, {helpb joyplot}, + {helpb marimekko}, {helpb polarspike}, {helpb sankey}, {helpb schemepack}, {helpb spider}, {helpb splinefit}, {helpb streamplot}, {helpb sunburst}, {helpb ternary}, {helpb treecluster}, {helpb treemap}, {helpb trimap}, {helpb waffle} + +or visit {browse "https://github.com/asjadnaqvi":GitHub}. + + +