@@ -1964,28 +1964,38 @@ fun labeled-num-dot-chart-from-list(labels :: P.LoS, x-values :: P.LoN) -> DataS
1964
1964
} ^ scatter-plot-series
1965
1965
end
1966
1966
1967
- fun dot-chart-from-list( labels :: P . LoS , values :: P . LoN ) -> DataSeries block:
1967
+ fun dot-chart-from-list( input- labels :: P . LoS ) -> DataSeries block:
1968
1968
doc: ```
1969
- Consume labels, a list of string, and values, a list of numbers
1970
- and construct a dot chart
1969
+ Consume a list of string-values and construct a dot chart
1971
1970
```
1972
- # Type Checking
1973
- values. each( check-num)
1974
- labels. each( check-string)
1975
-
1976
- # Constants
1977
- label-length = labels. length()
1978
- value-length = values. length()
1979
- rational-values = map( num-to-rational, values)
1980
1971
1981
1972
# Edge Case Error Checking
1982
- when value- length == 0 :
1973
+ when input-labels . length() == 0 :
1983
1974
raise( "dot-chart: can't have empty data" )
1984
1975
end
1985
- when label-length <> value-length:
1986
- raise( 'dot-chart: labels and values should have the same length' )
1987
- end
1988
1976
1977
+ # Type Checking
1978
+ input-labels. each( check-string)
1979
+
1980
+ # Walk through the (sorted) values, creating lists of labels and counts
1981
+ unique-counts = foldl(
1982
+ lam ( acc, elt) :
1983
+ labels = acc. { 0 }
1984
+ counts = acc. { 1 }
1985
+ if labels. member( elt) :
1986
+ { labels; counts. set( 0 , counts. get( 0 ) + 1 ) }
1987
+ else :
1988
+ { link( elt, labels) ; link( 1 , counts) }
1989
+ end
1990
+ end ,
1991
+ {[ list: ] ; [ list: ]} ,
1992
+ input-labels. sort())
1993
+
1994
+ labels = unique-counts. { 0 }
1995
+ values = unique-counts. { 1 }
1996
+ rational-values = map( num-to-rational, values)
1997
+
1998
+ # set the vAxis values, and create the data series
1989
1999
{ max-positive-height; max-negative-height} = prep-axis( rational-values)
1990
2000
1991
2001
data-series = default-bar-chart-series. {
0 commit comments