Skip to content

Commit 81abd5f

Browse files
committed
use axis reversal instead of adhoc type
1 parent a7fa70d commit 81abd5f

File tree

2 files changed

+9
-37
lines changed

2 files changed

+9
-37
lines changed

chart-tests/tests/Test20.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dat = [ [66.22192174833207, 50.85424119528999]
3838
, [4.73981774972079753, 5.092283613261595367]
3939
]
4040

41-
chart :: Renderable (LayoutPick LogValue PlotIndexRev PlotIndexRev)
41+
chart :: Renderable (LayoutPick LogValue PlotIndex PlotIndex)
4242
chart = layoutToRenderable layout
4343
where
4444
layout =
@@ -58,17 +58,18 @@ chart = layoutToRenderable layout
5858
$ layout_bottom_axis_visibility . axis_show_ticks .~ True
5959

6060
-- Y
61-
$ layout_y_axis . laxis_generate .~ autoIndexRevTicksAxis alabels
61+
$ layout_y_axis . laxis_generate .~ autoIndexAxis' True alabels
6262
$ layout_y_axis . laxis_override .~ axisGridAtTicks
63+
$ layout_y_axis . laxis_reverse .~ True
6364
$ layout_y_axis . laxis_style . axis_grid_style .~ solidLine 0.3 (opaque lightgrey)
6465
$ layout_left_axis_visibility . axis_show_ticks .~ False
6566

6667
-- data
6768
$ layout_plots .~ [ plotHBars bars2 ]
6869

69-
$ def :: Layout LogValue PlotIndexRev
70+
$ def :: Layout LogValue PlotIndex
7071

71-
bars2 = plot_bars_values_with_labels .~ addRevIndexes dat'
72+
bars2 = plot_bars_values_with_labels .~ addIndexes dat'
7273
$ plot_bars_titles .~ ["","after","before"]
7374
$ plot_bars_style .~ BarsStacked
7475
$ plot_bars_spacing .~ BarsFixGap 12 5

chart/Graphics/Rendering/Chart/Axis/Indexed.hs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@
1111

1212
module Graphics.Rendering.Chart.Axis.Indexed(
1313
PlotIndex(..),
14-
PlotIndexRev(..),
1514
autoIndexAxis',
1615
autoIndexAxis,
17-
autoIndexTicksAxis,
18-
autoIndexRevAxis,
19-
autoIndexRevTicksAxis,
2016
addIndexes,
21-
addRevIndexes,
2217
) where
2318

2419
import Data.Default.Class
@@ -39,31 +34,16 @@ instance PlotValue PlotIndex where
3934
addIndexes :: [a] -> [(PlotIndex,a)]
4035
addIndexes = zipWith (\n x -> (PlotIndex n, x)) [0..]
4136

42-
-- | Indices in a reverse order
43-
newtype PlotIndexRev = PlotIndexRev { plotindexr_i :: Int }
44-
deriving (Eq,Ord,Enum,Num,Real,Integral,Show)
45-
46-
instance PlotValue PlotIndexRev where
47-
toValue (PlotIndexRev i) = fromIntegral i
48-
fromValue = PlotIndexRev . round
49-
autoAxis = autoIndexRevAxis []
50-
51-
-- | Augment a list of values with reversed index numbers for plotting.
52-
addRevIndexes :: [a] -> [(PlotIndexRev,a)]
53-
addRevIndexes xs =
54-
let l = length xs in
55-
zipWith (\n x -> (PlotIndexRev (l - n - 1), x)) [0..] xs
56-
5737
-- | Create an axis for values indexed by position. The
5838
-- list of strings are the labels to be used.
59-
autoIndexAxis' :: Integral i => Bool -> Bool -> [String] -> AxisFn i
60-
autoIndexAxis' rev tks labels vs = AxisData {
39+
autoIndexAxis' :: Integral i => Bool -> [String] -> AxisFn i
40+
autoIndexAxis' tks labels vs = AxisData {
6141
_axis_visibility = def { _axis_show_ticks = False },
6242
_axis_viewport = vport,
6343
_axis_tropweiv = invport,
6444
_axis_ticks = if tks then map (, 5) $ take (length labels) [0..] else [],
6545
_axis_labels = [filter (\(i,_) -> i >= imin && i <= imax)
66-
(zip [0..] (if rev then reverse labels else labels))],
46+
(zip [0..] labels)],
6747
_axis_grid = []
6848
}
6949
where
@@ -74,13 +54,4 @@ autoIndexAxis' rev tks labels vs = AxisData {
7454
imax = maximum vs
7555

7656
autoIndexAxis :: Integral i => [String] -> AxisFn i
77-
autoIndexAxis = autoIndexAxis' False False
78-
79-
autoIndexTicksAxis :: Integral i => [String] -> AxisFn i
80-
autoIndexTicksAxis = autoIndexAxis' False True
81-
82-
autoIndexRevAxis :: Integral i => [String] -> AxisFn i
83-
autoIndexRevAxis = autoIndexAxis' True False
84-
85-
autoIndexRevTicksAxis :: Integral i => [String] -> AxisFn i
86-
autoIndexRevTicksAxis = autoIndexAxis' True True
57+
autoIndexAxis = autoIndexAxis' False

0 commit comments

Comments
 (0)