_chartist.scss 6.7 KB

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