3
3
{-# LANGUAGE OverloadedStrings #-}
4
4
{-# LANGUAGE RecordWildCards #-}
5
5
{-# LANGUAGE ScopedTypeVariables #-}
6
- {-# LANGUAGE TemplateHaskell #-}
7
6
8
7
module Codec.Xlsx.Types.ConditionalFormatting
9
8
( ConditionalFormatting ,
@@ -21,28 +20,6 @@ module Codec.Xlsx.Types.ConditionalFormatting
21
20
DataBarOptions (.. ),
22
21
dataBarWithColor ,
23
22
24
- -- * Lenses
25
-
26
- -- ** CfRule
27
- cfrCondition ,
28
- cfrDxfId ,
29
- cfrPriority ,
30
- cfrStopIfTrue ,
31
-
32
- -- ** IconSetOptions
33
- isoIconSet ,
34
- isoValues ,
35
- isoReverse ,
36
- isoShowValue ,
37
-
38
- -- ** DataBarOptions
39
- dboMaxLength ,
40
- dboMinLength ,
41
- dboShowValue ,
42
- dboMinimum ,
43
- dboMaximum ,
44
- dboColor ,
45
-
46
23
-- * Misc
47
24
topCfPriority ,
48
25
)
@@ -310,14 +287,14 @@ instance NFData CfvType
310
287
-- See 18.3.1.49 "iconSet (Icon Set)" (p. 1645)
311
288
data IconSetOptions = IconSetOptions
312
289
{ -- | icon set used, default value is 'IconSet3Trafficlights1'
313
- _isoIconSet :: IconSetType ,
290
+ isoIconSet :: IconSetType ,
314
291
-- | values describing per icon ranges
315
- _isoValues :: [CfValue ],
292
+ isoValues :: [CfValue ],
316
293
-- | reverses the default order of the icons in the specified icon set
317
- _isoReverse :: Bool ,
294
+ isoReverse :: Bool ,
318
295
-- | indicates whether to show the values of the cells on which this
319
296
-- icon set is applied.
320
- _isoShowValue :: Bool
297
+ isoShowValue :: Bool
321
298
}
322
299
deriving (Eq , Ord , Show , Generic )
323
300
@@ -359,16 +336,16 @@ instance NFData IconSetType
359
336
data DataBarOptions = DataBarOptions
360
337
{ -- | The maximum length of the data bar, as a percentage of the cell
361
338
-- width.
362
- _dboMaxLength :: Int ,
339
+ dboMaxLength :: Int ,
363
340
-- | The minimum length of the data bar, as a percentage of the cell
364
341
-- width.
365
- _dboMinLength :: Int ,
342
+ dboMinLength :: Int ,
366
343
-- | Indicates whether to show the values of the cells on which this
367
344
-- data bar is applied.
368
- _dboShowValue :: Bool ,
369
- _dboMinimum :: MinCfValue ,
370
- _dboMaximum :: MaxCfValue ,
371
- _dboColor :: Color
345
+ dboShowValue :: Bool ,
346
+ dboMinimum :: MinCfValue ,
347
+ dboMaximum :: MaxCfValue ,
348
+ dboColor :: Color
372
349
}
373
350
deriving (Eq , Ord , Show , Generic )
374
351
@@ -384,32 +361,32 @@ dataBarWithColor :: Color -> Condition
384
361
dataBarWithColor c =
385
362
DataBar
386
363
DataBarOptions
387
- { _dboMaxLength = defaultDboMaxLength,
388
- _dboMinLength = defaultDboMinLength,
389
- _dboShowValue = True ,
390
- _dboMinimum = CfvMin ,
391
- _dboMaximum = CfvMax ,
392
- _dboColor = c
364
+ { dboMaxLength = defaultDboMaxLength,
365
+ dboMinLength = defaultDboMinLength,
366
+ dboShowValue = True ,
367
+ dboMinimum = CfvMin ,
368
+ dboMaximum = CfvMax ,
369
+ dboColor = c
393
370
}
394
371
395
372
-- | This collection represents a description of a conditional formatting rule.
396
373
--
397
374
-- See 18.3.1.10 "cfRule (Conditional Formatting Rule)" (p. 1602)
398
375
data CfRule = CfRule
399
- { _cfrCondition :: Condition ,
376
+ { cfrCondition :: Condition ,
400
377
-- | This is an index to a dxf element in the Styles Part
401
378
-- indicating which cell formatting to
402
379
-- apply when the conditional formatting rule criteria is met.
403
- _cfrDxfId :: Maybe Int ,
380
+ cfrDxfId :: Maybe Int ,
404
381
-- | The priority of this conditional formatting rule. This value
405
382
-- is used to determine which format should be evaluated and
406
383
-- rendered. Lower numeric values are higher priority than
407
384
-- higher numeric values, where 1 is the highest priority.
408
- _cfrPriority :: Int ,
385
+ cfrPriority :: Int ,
409
386
-- | If this flag is set, no rules with lower priority shall
410
387
-- be applied over this rule, when this rule
411
388
-- evaluates to true.
412
- _cfrStopIfTrue :: Maybe Bool
389
+ cfrStopIfTrue :: Maybe Bool
413
390
}
414
391
deriving (Eq , Ord , Show , Generic )
415
392
@@ -418,17 +395,13 @@ instance NFData CfRule
418
395
instance Default IconSetOptions where
419
396
def =
420
397
IconSetOptions
421
- { _isoIconSet = IconSet3TrafficLights1 ,
422
- _isoValues = [CfPercent 0 , CfPercent 33.33 , CfPercent 66.67 ],
398
+ { isoIconSet = IconSet3TrafficLights1 ,
399
+ isoValues = [CfPercent 0 , CfPercent 33.33 , CfPercent 66.67 ],
423
400
-- IconSet3TrafficLights1 (CfPercent 0) (CfPercent 33.33) (CfPercent 66.67)
424
- _isoReverse = False ,
425
- _isoShowValue = True
401
+ isoReverse = False ,
402
+ isoShowValue = True
426
403
}
427
404
428
- makeLenses ''CfRule
429
- makeLenses ''IconSetOptions
430
- makeLenses ''DataBarOptions
431
-
432
405
type ConditionalFormatting = [CfRule ]
433
406
434
407
topCfPriority :: Int
@@ -440,13 +413,13 @@ topCfPriority = 1
440
413
441
414
instance FromCursor CfRule where
442
415
fromCursor cur = do
443
- _cfrDxfId <- maybeAttribute " dxfId" cur
444
- _cfrPriority <- fromAttribute " priority" cur
445
- _cfrStopIfTrue <- maybeAttribute " stopIfTrue" cur
416
+ cfrDxfId <- maybeAttribute " dxfId" cur
417
+ cfrPriority <- fromAttribute " priority" cur
418
+ cfrStopIfTrue <- maybeAttribute " stopIfTrue" cur
446
419
-- spec shows this attribute as optional but it's not clear why could
447
420
-- conditional formatting record be needed with no condition type set
448
421
cfType <- fromAttribute " type" cur
449
- _cfrCondition <- readCondition cfType cur
422
+ cfrCondition <- readCondition cfType cur
450
423
return CfRule {.. }
451
424
452
425
readCondition :: Text -> Cursor -> [Condition ]
@@ -537,13 +510,13 @@ readOpExpression _ _ = []
537
510
538
511
instance FromXenoNode CfRule where
539
512
fromXenoNode root = parseAttributes root $ do
540
- _cfrDxfId <- maybeAttr " dxfId"
541
- _cfrPriority <- fromAttr " priority"
542
- _cfrStopIfTrue <- maybeAttr " stopIfTrue"
513
+ cfrDxfId <- maybeAttr " dxfId"
514
+ cfrPriority <- fromAttr " priority"
515
+ cfrStopIfTrue <- maybeAttr " stopIfTrue"
543
516
-- spec shows this attribute as optional but it's not clear why could
544
517
-- conditional formatting record be needed with no condition type set
545
518
cfType <- fromAttr " type"
546
- _cfrCondition <- readConditionX cfType
519
+ cfrCondition <- readConditionX cfType
547
520
return CfRule {.. }
548
521
where
549
522
readConditionX (" aboveAverage" :: ByteString ) = do
@@ -749,21 +722,21 @@ defaultIconSet = IconSet3TrafficLights1
749
722
750
723
instance FromCursor IconSetOptions where
751
724
fromCursor cur = do
752
- _isoIconSet <- fromAttributeDef " iconSet" defaultIconSet cur
753
- let _isoValues = cur $/ element (n_ " cfvo" ) >=> fromCursor
754
- _isoReverse <- fromAttributeDef " reverse" False cur
755
- _isoShowValue <- fromAttributeDef " showValue" True cur
725
+ isoIconSet <- fromAttributeDef " iconSet" defaultIconSet cur
726
+ let isoValues = cur $/ element (n_ " cfvo" ) >=> fromCursor
727
+ isoReverse <- fromAttributeDef " reverse" False cur
728
+ isoShowValue <- fromAttributeDef " showValue" True cur
756
729
return IconSetOptions {.. }
757
730
758
731
instance FromXenoNode IconSetOptions where
759
732
fromXenoNode root = do
760
- (_isoIconSet, _isoReverse, _isoShowValue ) <-
733
+ (isoIconSet, isoReverse, isoShowValue ) <-
761
734
parseAttributes root $
762
735
(,,)
763
736
<$> fromAttrDef " iconSet" defaultIconSet
764
737
<*> fromAttrDef " reverse" False
765
738
<*> fromAttrDef " showValue" True
766
- _isoValues <- collectChildren root $ fromChildList " cfvo"
739
+ isoValues <- collectChildren root $ fromChildList " cfvo"
767
740
return IconSetOptions {.. }
768
741
769
742
instance FromAttrVal IconSetType where
@@ -808,15 +781,15 @@ instance FromAttrBs IconSetType where
808
781
809
782
instance FromCursor DataBarOptions where
810
783
fromCursor cur = do
811
- _dboMaxLength <- fromAttributeDef " maxLength" defaultDboMaxLength cur
812
- _dboMinLength <- fromAttributeDef " minLength" defaultDboMinLength cur
813
- _dboShowValue <- fromAttributeDef " showValue" True cur
784
+ dboMaxLength <- fromAttributeDef " maxLength" defaultDboMaxLength cur
785
+ dboMinLength <- fromAttributeDef " minLength" defaultDboMinLength cur
786
+ dboShowValue <- fromAttributeDef " showValue" True cur
814
787
let cfvos = cur $/ element (n_ " cfvo" ) &| node
815
788
case cfvos of
816
789
[nMin, nMax] -> do
817
- _dboMinimum <- fromCursor (fromNode nMin)
818
- _dboMaximum <- fromCursor (fromNode nMax)
819
- _dboColor <- cur $/ element (n_ " color" ) >=> fromCursor
790
+ dboMinimum <- fromCursor (fromNode nMin)
791
+ dboMaximum <- fromCursor (fromNode nMax)
792
+ dboColor <- cur $/ element (n_ " color" ) >=> fromCursor
820
793
return DataBarOptions {.. }
821
794
ns -> do
822
795
fail $
@@ -826,13 +799,13 @@ instance FromCursor DataBarOptions where
826
799
827
800
instance FromXenoNode DataBarOptions where
828
801
fromXenoNode root = do
829
- (_dboMaxLength, _dboMinLength, _dboShowValue ) <-
802
+ (dboMaxLength, dboMinLength, dboShowValue ) <-
830
803
parseAttributes root $
831
804
(,,)
832
805
<$> fromAttrDef " maxLength" defaultDboMaxLength
833
806
<*> fromAttrDef " minLength" defaultDboMinLength
834
807
<*> fromAttrDef " showValue" True
835
- (_dboMinimum, _dboMaximum, _dboColor ) <-
808
+ (dboMinimum, dboMaximum, dboColor ) <-
836
809
collectChildren root $
837
810
(,,)
838
811
<$> fromChild " cfvo"
@@ -858,13 +831,13 @@ instance FromAttrBs NStdDev where
858
831
859
832
instance ToElement CfRule where
860
833
toElement nm CfRule {.. } =
861
- let (condType, condAttrs, condNodes) = conditionData _cfrCondition
834
+ let (condType, condAttrs, condNodes) = conditionData cfrCondition
862
835
baseAttrs =
863
836
M. fromList . catMaybes $
864
837
[ Just $ " type" .= condType,
865
- " dxfId" .=? _cfrDxfId ,
866
- Just $ " priority" .= _cfrPriority ,
867
- " stopIfTrue" .=? _cfrStopIfTrue
838
+ " dxfId" .=? cfrDxfId ,
839
+ Just $ " priority" .= cfrPriority ,
840
+ " stopIfTrue" .=? cfrStopIfTrue
868
841
]
869
842
in Element
870
843
{ elementName = nm,
@@ -985,13 +958,13 @@ instance ToAttrVal CfvType where
985
958
986
959
instance ToElement IconSetOptions where
987
960
toElement nm IconSetOptions {.. } =
988
- elementList nm attrs $ map (toElement " cfvo" ) _isoValues
961
+ elementList nm attrs $ map (toElement " cfvo" ) isoValues
989
962
where
990
963
attrs =
991
964
catMaybes
992
- [ " iconSet" .=? justNonDef defaultIconSet _isoIconSet ,
993
- " reverse" .=? justTrue _isoReverse ,
994
- " showValue" .=? justFalse _isoShowValue
965
+ [ " iconSet" .=? justNonDef defaultIconSet isoIconSet ,
966
+ " reverse" .=? justTrue isoReverse ,
967
+ " showValue" .=? justFalse isoShowValue
995
968
]
996
969
997
970
instance ToAttrVal IconSetType where
@@ -1018,14 +991,14 @@ instance ToElement DataBarOptions where
1018
991
where
1019
992
attrs =
1020
993
catMaybes
1021
- [ " maxLength" .=? justNonDef defaultDboMaxLength _dboMaxLength ,
1022
- " minLength" .=? justNonDef defaultDboMinLength _dboMinLength ,
1023
- " showValue" .=? justFalse _dboShowValue
994
+ [ " maxLength" .=? justNonDef defaultDboMaxLength dboMaxLength ,
995
+ " minLength" .=? justNonDef defaultDboMinLength dboMinLength ,
996
+ " showValue" .=? justFalse dboShowValue
1024
997
]
1025
998
elements =
1026
- [ toElement " cfvo" _dboMinimum ,
1027
- toElement " cfvo" _dboMaximum ,
1028
- toElement " color" _dboColor
999
+ [ toElement " cfvo" dboMinimum ,
1000
+ toElement " cfvo" dboMaximum ,
1001
+ toElement " color" dboColor
1029
1002
]
1030
1003
1031
1004
toNode :: (ToElement a ) => Name -> a -> Node
0 commit comments