Skip to content

Commit

Permalink
v1.54
Browse files Browse the repository at this point in the history
  • Loading branch information
asjadnaqvi committed Apr 20, 2024
1 parent 9cbf6f8 commit d8fc3b6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ authors:
- family-names: "Naqvi"
given-names: "Asjad"
title: "Stata package ``treemap''"
version: 1.53
date-released: 2024-04-10
version: 1.54
date-released: 2024-04-20
url: "https://github.com/asjadnaqvi/stata-treemap"
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

---

# treemap v1.53
(10 Apr 2024)
# treemap v1.54
(20 Apr 2024)

This package provides the ability to draw treemaps Stata.

Expand All @@ -29,7 +29,7 @@ The SSC version (**v1.51**):
ssc install treemap, replace
```

Or it can be installed from GitHub (**v1.53**):
Or it can be installed from GitHub (**v1.54**):

```stata
net install treemap, from("https://raw.githubusercontent.com/asjadnaqvi/stata-treemap/main/installation/") replace
Expand Down Expand Up @@ -66,7 +66,7 @@ The syntax for the latest version is as follows:

```stata
treemap numvar [if] [in], by(variables (min=1 max=3))
[ xsize(num) ysize(num) percent format(str) sformat(str) labcond(num) palette(it:str) colorby(name)
[ xsize(num) ysize(num) percent format(str) sformat(str) labcond(num) palette(it:str) colorby(var)
pad(list) labsize(list) linewidth(list) linecolor(list) fi(list)
addtitles novalues nolabels labsize(num) titlegap(num) labgap(str)
threshold(num) fade(num) labprop titleprop labscale(num) colorprop
Expand Down Expand Up @@ -372,8 +372,12 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-treemap/issues) to re

## Change log

**v1.53 (04 Apr 2024)**
- Fixed a critical bug where adding three layers was causing errors in the drawing of the second and third layers (reported by Aurelio Tobias)
**v1.54 (20 Apr 2024)**
- `colorby()` fixed. This option now requires a variable name that determines the color order (reported by Adam Okulicz-Kozaryn).
- Minor fixes.

**v1.53 (10 Apr 2024)**
- Fixed a critical bug where adding three layers was causing errors in the drawing of the second and third layers (reported by Aurelio Tobias).
- Some minor code cleanups.

**v1.52 (10 Jan 2024)** (unreleased internal version subsumed in v1.53)
Expand Down
4 changes: 2 additions & 2 deletions installation/stata.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
v 1.53
v 1.54
d 'TREEMAP': A Stata package for tree maps.
d
d Distribution-Date: 20240410
d Distribution-Date: 20240420
d
d Asjad Naqvi
d [email protected]
Expand Down
36 changes: 16 additions & 20 deletions installation/treemap.ado
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*! treemap v1.53 (10 Apr 2024)
*! treemap v1.54 (20 Apr 2024)
*! Asjad Naqvi ([email protected])

* v1.54 (20 Apr 2024): colorby() fixed. Now requires a variable name for the color order.
* v1.53 (10 Apr 2024): Critical bug fix which was messing up the drawings if a third layer was defined.
* v1.52 (20 Jan 2024): If by() variables had empty rows, the program was giving an error. These are now dropped by default.
* v1.51 (24 Oct 2023): further stabilized the sort for categories with same totals that was causing a crash.
Expand Down Expand Up @@ -28,7 +29,8 @@ prog def treemap, sortpreserve
[ pad(numlist max=3) labprop labscale(real 0.3333) labcond(real 0) colorprop titlegap(real 0.1) titleprop LINEWidth(string) LINEColor(string) LABSize(string) ] /// // v1.1 options. labscale is undocumented labprop scaling
[ fi(numlist max=3) ] /// // v1.2 options
[ LABGap(string) ] /// // v1.3 options
[ Share SFORmat(str) THRESHold(numlist max=1 >=0) fade(real 10) colorby(string) percent ] // v1.4, v1.5 options
[ Share SFORmat(str) THRESHold(numlist max=1 >=0) fade(real 10) percent ] /// // v1.4, v1.5 options
[ colorby(varname) sharevar(varname) ]

marksample touse, strok

Expand Down Expand Up @@ -67,9 +69,7 @@ preserve
}
}





if `length' == 1 {
local var0 `by'

Expand Down Expand Up @@ -148,8 +148,8 @@ preserve
egen var0_t = tag(`var0')
gen double var0_o = sum(`var0' != `var0'[_n-1])

if "`colorby'" == "name" {
egen var0_c = group(`var0') // namewise color ordering
if "`colorby'" != "" {
egen var0_c = group(`colorby') // namewise color ordering
}
else {
gen var0_c = var0_o
Expand All @@ -174,8 +174,6 @@ preserve
}

sort id



// set up the base values

Expand Down Expand Up @@ -309,14 +307,16 @@ preserve
}




local ratio = (1 + sqrt(5)) / 2

mata: xmin = 0; xmax = `xsize'; ymin = 0; ymax = `ysize'; dy = ymax - ymin; dx = xmax - xmin; myratio = `ratio'


*** define format options
if "`format'" == "" local format %12.0fc // values
if "`sormat'" == "" local sformat %5.1f // percentages
if "`format'" == "" local format %12.0fc // values
if "`sformat'" == "" local sformat %5.1f // percentages

if "`percent'" != "" local share pewpew

Expand Down Expand Up @@ -434,7 +434,6 @@ preserve
replace _l1_`z'_lab0= "{it:" + _l1_`z'_lab1 + "}" if _l1_`z'_val >= `labcond'
}


}

}
Expand Down Expand Up @@ -512,8 +511,6 @@ preserve





**************
// draw //
**************
Expand Down Expand Up @@ -555,13 +552,12 @@ preserve
local labs0 = `ls0'
}




local clr0 `i'
if "`colorby'" == "name" {
summ var0_c if var0_o==`i', meanonly
local clr0 `r(mean)'
}

summ var0_c if var0_o==`i', meanonly
local clr0 `r(mean)'


colorpalette `palette', n(`lvl0') `poptions' nograph

Expand Down
6 changes: 3 additions & 3 deletions installation/treemap.pkg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v 1.53
v 1.54
d {bf:TREEMAP}: A Stata package for treemaps
d
d Requires: Stata version 15 or higher.
Expand All @@ -8,9 +8,9 @@ d KW: graphs
d KW: treemap
d KW: squarify
d
d Distribution-Date: 20240410
d Distribution-Date: 20240420
d
d This version: 10 Apr 2024
d This version: 20 Apr 2024
d First version: 08 Sep 2022
d License: MIT
d
Expand Down
15 changes: 8 additions & 7 deletions installation/treemap.sthlp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{smcl}
{* 10Apr2024}{...}
{* 20Apr2024}{...}
{hi:help treemap}{...}
{right:{browse "https://github.com/asjadnaqvi/stata-treemap":treemap v1.53 (GitHub)}}
{right:{browse "https://github.com/asjadnaqvi/stata-treemap":treemap v1.54 (GitHub)}}

{hline}

Expand All @@ -19,7 +19,7 @@ and on the Python's {browse "https://github.com/laserson/squarify":squarify} alg
{p 8 15 2}

{cmd:treemap} {it:numvar} {ifin}, {cmd:by}({it:variables (min=1 max=3}))
{cmd:[} {cmdab:xs:ize}({it:num}) {cmdab:ys:ize}({it:num}) {cmd:format}({it:str}) {cmd:share} {cmd:sformat}({it:str}) {cmd:palette}(it:str) {cmd:colorby}({it:name})
{cmd:[} {cmdab:xs:ize}({it:num}) {cmdab:ys:ize}({it:num}) {cmd:format}({it:str}) {cmd:share} {cmd:sformat}({it:str}) {cmd:palette}(it:str) {cmd:colorby}({it:var})
{cmd:pad}({it:list}) {cmdab:labs:ize}({it:list}) {cmdab:linew:idth}({it:list}) {cmdab:linec:olor}({it:list}) {cmd:fi}({it:list}) {cmd:labcond}({it:num})
{cmdab:addt:itles} {cmdab:noval:ues} {cmdab:nolab:els} {cmdab:labs:ize}({it:num}) {cmd:titlegap}({it:num}) {cmdab:labg:ap}({it:str})
{cmdab:thresh:old}({it:num}) {cmd:fade}({it:num}) {cmd:labprop} {cmd:titleprop} {cmd:labscale}({it:num}) {cmd:colorprop}
Expand All @@ -43,8 +43,9 @@ Note that changing the {opt xsize} and {opt ysize} will change the layout of the

{p2coldent : {opt palette(str)}}Here one can use an named color scheme defined in the {stata help colorpalette:colorpalette} package. Default is {stata colorpalette tableau:{it:tableau}}.{p_end}

{p2coldent : {opt colorby(name)}}The option allows us to preserve the color order by alphabetical order of the {opt by()} variables rather than values. This is useful if multiple
treemaps are drawn for the same data over time, and colors are likely to change across the same {opt by()} categories if their relative order changes.{p_end}
{p2coldent : {opt colorby(var)}}Here one can define a variable to control the sequence of the colors drawn. This is useful if box positions are changing across
different treemaps which might make them confusing to compare. The color order is defined by alpha or numeric sorting, so numeric variables are ideal
for maximum control.{p_end}

{p2coldent : {opt share}}Show percentages as a share of the overall total. Users can also use the undocumented option {opt percent} as a substitute.{p_end}

Expand Down Expand Up @@ -127,8 +128,8 @@ Please submit bugs, errors, feature requests on {browse "https://github.com/asja

{title:Package details}

Version : {bf:treemap} v1.53
This release : 10 Apr 2024
Version : {bf:treemap} v1.54
This release : 20 Apr 2024
First release: 08 Sep 2022
Repository : {browse "https://github.com/asjadnaqvi/treemap":GitHub}
Keywords : Stata, graph, treemap, squarify
Expand Down

0 comments on commit d8fc3b6

Please sign in to comment.