Created
June 24, 2017 09:18
-
-
Save htsign/c6d7e7007a79470ee28e54e581c043ab to your computer and use it in GitHub Desktop.
how to get scale type of d3 (require es6-shim)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ChartHelper { | |
| public static checkScaleType<T, R>(scale: Scale<T, R>): ScaleType { | |
| const f = scale.copy.toString(); | |
| switch (true) { | |
| case f.includes("d3_scale_linear") : return "linear"; | |
| case f.includes("d3_scale_identity"): return "identity"; | |
| case f.includes("d3_scale_pow") : return "power"; | |
| case f.includes("d3_scale_log") : return "log"; | |
| case f.includes("d3_scale_quantize"): return "quantize"; | |
| case f.includes("d3_scale_quantile"): return "quantile"; | |
| case f.includes("d3_scale_ordinal") : return "ordinal"; | |
| case f.includes("d3_time_scale") : return "time"; | |
| } | |
| throw new TypeError("unexpected type"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type ScaleType = "linear" | "identity" | "power" | "log" | "quantize" | "quantile" | "ordinal" | "time"; | |
| type Scale<T, R> = | |
| | d3.scale.Linear<T, R> | |
| | d3.scale.Identity | |
| | d3.scale.Pow<T, R> | |
| | d3.scale.Log<T, R> | |
| | d3.scale.Quantize<T> | |
| | d3.scale.Quantile<T> | |
| | d3.scale.Ordinal<T, R> | |
| | d3.time.Scale<T, R> | |
| ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment