chartist.scss 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. @import "settings/chartist-settings";
  2. @mixin ct-responsive-svg-container($width: 100%, $ratio: $ct-container-ratio) {
  3. display: block;
  4. position: relative;
  5. width: $width;
  6. &:before {
  7. display: block;
  8. float: left;
  9. content: "";
  10. width: 0;
  11. height: 0;
  12. padding-bottom: $ratio * 100%;
  13. }
  14. &:after {
  15. content: "";
  16. display: table;
  17. clear: both;
  18. }
  19. > svg {
  20. display: block;
  21. position: absolute;
  22. top: 0;
  23. left: 0;
  24. }
  25. }
  26. @mixin ct-align-justify($ct-text-align: $ct-text-align, $ct-text-justify: $ct-text-justify) {
  27. -webkit-box-align: $ct-text-align;
  28. -webkit-align-items: $ct-text-align;
  29. -ms-flex-align: $ct-text-align;
  30. align-items: $ct-text-align;
  31. -webkit-box-pack: $ct-text-justify;
  32. -webkit-justify-content: $ct-text-justify;
  33. -ms-flex-pack: $ct-text-justify;
  34. justify-content: $ct-text-justify;
  35. // Fallback to text-align for non-flex browsers
  36. @if($ct-text-justify == 'flex-start') {
  37. text-align: left;
  38. } @else if ($ct-text-justify == 'flex-end') {
  39. text-align: right;
  40. } @else {
  41. text-align: center;
  42. }
  43. }
  44. @mixin ct-flex() {
  45. // Fallback to block
  46. display: block;
  47. display: -webkit-box;
  48. display: -moz-box;
  49. display: -ms-flexbox;
  50. display: -webkit-flex;
  51. display: flex;
  52. }
  53. @mixin ct-chart-label($ct-text-color: $ct-text-color, $ct-text-size: $ct-text-size, $ct-text-line-height: $ct-text-line-height) {
  54. fill: $ct-text-color;
  55. color: $ct-text-color;
  56. font-size: $ct-text-size;
  57. line-height: $ct-text-line-height;
  58. }
  59. @mixin ct-chart-grid($ct-grid-color: $ct-grid-color, $ct-grid-width: $ct-grid-width, $ct-grid-dasharray: $ct-grid-dasharray) {
  60. stroke: $ct-grid-color;
  61. stroke-width: $ct-grid-width;
  62. @if ($ct-grid-dasharray) {
  63. stroke-dasharray: $ct-grid-dasharray;
  64. }
  65. }
  66. @mixin ct-chart-point($ct-point-size: $ct-point-size, $ct-point-shape: $ct-point-shape) {
  67. stroke-width: $ct-point-size;
  68. stroke-linecap: $ct-point-shape;
  69. }
  70. @mixin ct-chart-line($ct-line-width: $ct-line-width, $ct-line-dasharray: $ct-line-dasharray) {
  71. fill: none;
  72. stroke-width: $ct-line-width;
  73. @if ($ct-line-dasharray) {
  74. stroke-dasharray: $ct-line-dasharray;
  75. }
  76. }
  77. @mixin ct-chart-area($ct-area-opacity: $ct-area-opacity) {
  78. stroke: none;
  79. fill-opacity: $ct-area-opacity;
  80. }
  81. @mixin ct-chart-bar($ct-bar-width: $ct-bar-width) {
  82. fill: none;
  83. stroke-width: $ct-bar-width;
  84. }
  85. @mixin ct-chart-donut($ct-donut-width: $ct-donut-width) {
  86. fill: none;
  87. stroke-width: $ct-donut-width;
  88. }
  89. @mixin ct-chart-series-color($color) {
  90. .#{$ct-class-point}, .#{$ct-class-line}, .#{$ct-class-bar}, .#{$ct-class-slice-donut} {
  91. stroke: $color;
  92. }
  93. .#{$ct-class-slice-pie}, .#{$ct-class-slice-donut-solid}, .#{$ct-class-area} {
  94. fill: $color;
  95. }
  96. }
  97. @mixin ct-chart($ct-container-ratio: $ct-container-ratio, $ct-text-color: $ct-text-color, $ct-text-size: $ct-text-size, $ct-grid-color: $ct-grid-color, $ct-grid-width: $ct-grid-width, $ct-grid-dasharray: $ct-grid-dasharray, $ct-point-size: $ct-point-size, $ct-point-shape: $ct-point-shape, $ct-line-width: $ct-line-width, $ct-bar-width: $ct-bar-width, $ct-donut-width: $ct-donut-width, $ct-series-names: $ct-series-names, $ct-series-colors: $ct-series-colors) {
  98. .#{$ct-class-label} {
  99. @include ct-chart-label($ct-text-color, $ct-text-size);
  100. }
  101. .#{$ct-class-chart-line} .#{$ct-class-label},
  102. .#{$ct-class-chart-bar} .#{$ct-class-label} {
  103. @include ct-flex();
  104. }
  105. .#{$ct-class-chart-pie} .#{$ct-class-label},
  106. .#{$ct-class-chart-donut} .#{$ct-class-label} {
  107. dominant-baseline: central;
  108. }
  109. .#{$ct-class-label}.#{$ct-class-horizontal}.#{$ct-class-start} {
  110. @include ct-align-justify(flex-end, flex-start);
  111. // Fallback for browsers that don't support foreignObjects
  112. text-anchor: start;
  113. }
  114. .#{$ct-class-label}.#{$ct-class-horizontal}.#{$ct-class-end} {
  115. @include ct-align-justify(flex-start, flex-start);
  116. // Fallback for browsers that don't support foreignObjects
  117. text-anchor: start;
  118. }
  119. .#{$ct-class-label}.#{$ct-class-vertical}.#{$ct-class-start} {
  120. @include ct-align-justify(flex-end, flex-end);
  121. // Fallback for browsers that don't support foreignObjects
  122. text-anchor: end;
  123. }
  124. .#{$ct-class-label}.#{$ct-class-vertical}.#{$ct-class-end} {
  125. @include ct-align-justify(flex-end, flex-start);
  126. // Fallback for browsers that don't support foreignObjects
  127. text-anchor: start;
  128. }
  129. .#{$ct-class-chart-bar} .#{$ct-class-label}.#{$ct-class-horizontal}.#{$ct-class-start} {
  130. @include ct-align-justify(flex-end, center);
  131. // Fallback for browsers that don't support foreignObjects
  132. text-anchor: start;
  133. }
  134. .#{$ct-class-chart-bar} .#{$ct-class-label}.#{$ct-class-horizontal}.#{$ct-class-end} {
  135. @include ct-align-justify(flex-start, center);
  136. // Fallback for browsers that don't support foreignObjects
  137. text-anchor: start;
  138. }
  139. .#{$ct-class-chart-bar}.#{$ct-class-horizontal-bars} .#{$ct-class-label}.#{$ct-class-horizontal}.#{$ct-class-start} {
  140. @include ct-align-justify(flex-end, flex-start);
  141. // Fallback for browsers that don't support foreignObjects
  142. text-anchor: start;
  143. }
  144. .#{$ct-class-chart-bar}.#{$ct-class-horizontal-bars} .#{$ct-class-label}.#{$ct-class-horizontal}.#{$ct-class-end} {
  145. @include ct-align-justify(flex-start, flex-start);
  146. // Fallback for browsers that don't support foreignObjects
  147. text-anchor: start;
  148. }
  149. .#{$ct-class-chart-bar}.#{$ct-class-horizontal-bars} .#{$ct-class-label}.#{$ct-class-vertical}.#{$ct-class-start} {
  150. //@include ct-chart-label($ct-text-color, $ct-text-size, center, $ct-vertical-text-justify);
  151. @include ct-align-justify(center, flex-end);
  152. // Fallback for browsers that don't support foreignObjects
  153. text-anchor: end;
  154. }
  155. .#{$ct-class-chart-bar}.#{$ct-class-horizontal-bars} .#{$ct-class-label}.#{$ct-class-vertical}.#{$ct-class-end} {
  156. @include ct-align-justify(center, flex-start);
  157. // Fallback for browsers that don't support foreignObjects
  158. text-anchor: end;
  159. }
  160. .#{$ct-class-grid} {
  161. @include ct-chart-grid($ct-grid-color, $ct-grid-width, $ct-grid-dasharray);
  162. }
  163. .#{$ct-class-grid-background} {
  164. fill: $ct-grid-background-fill;
  165. }
  166. .#{$ct-class-point} {
  167. @include ct-chart-point($ct-point-size, $ct-point-shape);
  168. }
  169. .#{$ct-class-line} {
  170. @include ct-chart-line($ct-line-width);
  171. }
  172. .#{$ct-class-area} {
  173. @include ct-chart-area();
  174. }
  175. .#{$ct-class-bar} {
  176. @include ct-chart-bar($ct-bar-width);
  177. }
  178. .#{$ct-class-slice-donut} {
  179. @include ct-chart-donut($ct-donut-width);
  180. }
  181. @if $ct-include-colored-series {
  182. @for $i from 0 to length($ct-series-names) {
  183. .#{$ct-class-series}-#{nth($ct-series-names, $i + 1)} {
  184. $color: nth($ct-series-colors, $i + 1);
  185. @include ct-chart-series-color($color);
  186. }
  187. }
  188. }
  189. }
  190. @if $ct-include-classes {
  191. @include ct-chart();
  192. @if $ct-include-alternative-responsive-containers {
  193. @for $i from 0 to length($ct-scales-names) {
  194. .#{nth($ct-scales-names, $i + 1)} {
  195. @include ct-responsive-svg-container($ratio: nth($ct-scales, $i + 1));
  196. }
  197. }
  198. }
  199. }