Add tick size control
This commit is contained in:
@@ -18,6 +18,13 @@ import Data.Set as Set
|
||||
import Data.Tuple as Tup
|
||||
import Data.Tuple.Nested (Tuple3, tuple3, get1, get2, get3)
|
||||
|
||||
-- A spatial value (position, size) in pixels
|
||||
-- TODO: Apply this across all spatial values
|
||||
newtype Pixels = Pixels Number
|
||||
|
||||
unpixel :: Pixels -> Number
|
||||
unpixel (Pixels value) = value
|
||||
|
||||
type Dimension =
|
||||
{ widthPx :: Number
|
||||
, heightPx :: Number
|
||||
@@ -42,6 +49,7 @@ type GraphDefinition =
|
||||
, axis3Start :: Int
|
||||
, numTicks :: Int
|
||||
, tickTextStyle :: TextStyle
|
||||
, tickSize :: Pixels
|
||||
, axisTitleTextStyle :: TextStyle
|
||||
}
|
||||
|
||||
@@ -101,21 +109,20 @@ svgTextID idMaybe text { x: x, y: y } angle style dimension =
|
||||
Maybe.Nothing -> ""
|
||||
Maybe.Just id -> "id=\"" <> id <> "\""
|
||||
|
||||
-- TODO: Make axis tick size a parameter
|
||||
getTick :: Number -> Int -> Int -> Line
|
||||
getTick scale numTicks tickI =
|
||||
{start: {x: x, y: -(0.5 + 5.0 / scale)}, end: {x: x, y: y}}
|
||||
getTick :: Number -> Int -> Pixels -> Int -> Line
|
||||
getTick scale numTicks tickSize tickI =
|
||||
{start: {x: x, y: -(0.5 + (unpixel tickSize) / scale)}, end: {x: x, y: y}}
|
||||
where
|
||||
x = 2.0 * (sin (pi / 3.0)) * (Int.toNumber tickI) / (Int.toNumber numTicks) - (sin (pi / 3.0))
|
||||
y = if tickI <= numTicks / 2
|
||||
then 1.0 + x * 1.5 / (sin (pi / 3.0))
|
||||
else 1.0 - x * 1.5 / (sin (pi / 3.0))
|
||||
|
||||
getTicks :: Number -> Number -> Int -> Tuple3 (Array Line) (Array Line) (Array Line)
|
||||
getTicks scale angle numTicks =
|
||||
getTicks :: Number -> Number -> Pixels -> Int -> Tuple3 (Array Line) (Array Line) (Array Line)
|
||||
getTicks scale angle tickSize numTicks =
|
||||
tuple3 axis1Lines axis2Lines axis3Lines
|
||||
where
|
||||
foo = map (getTick scale numTicks) (Array.range 0 numTicks)
|
||||
foo = map (getTick scale numTicks tickSize) (Array.range 0 numTicks)
|
||||
axis1Lines = map (rotateLine angle) foo
|
||||
axis2Lines = map (rotateLine (2.0 * pi / 3.0)) axis1Lines
|
||||
axis3Lines = map (rotateLine (2.0 * pi / 3.0)) axis2Lines
|
||||
@@ -159,7 +166,7 @@ tickLabelStrings def =
|
||||
ternaryGraph :: Number -> Number -> Number -> GraphDefinition -> Map.Map (Tup.Tuple String TextStyle) Dimension -> Either.Either String String
|
||||
ternaryGraph scale xOffset yOffset definition textDimensions = result
|
||||
where
|
||||
axisTickLines = getTicks scale pi definition.numTicks
|
||||
axisTickLines = getTicks scale pi definition.tickSize definition.numTicks
|
||||
axis1TickLines = map (transformLine scale xOffset yOffset) (get1 axisTickLines)
|
||||
axis2TickLines = map (transformLine scale xOffset yOffset) (get2 axisTickLines)
|
||||
axis3TickLines = map (transformLine scale xOffset yOffset) (get3 axisTickLines)
|
||||
|
||||
Reference in New Issue
Block a user