Welcome to mirror list, hosted at ThFree Co, Russian Federation.

scales-test.coffee « test « chroma-js « node_modules - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f0e93bd5820f4ba75e82d6126870c7681cdf1d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require 'es6-shim'
vows = require 'vows'
assert = require 'assert'
chroma = require '../chroma'


vows
    .describe('Some tests for chroma.scale()')

    .addBatch

        'simple rgb scale (white-->black)':
            topic: -> chroma.scale ['white','black']
            'starts white': (topic) -> assert.equal topic(0).hex(), '#ffffff'
            'mid gray': (topic) -> assert.equal topic(0.5).hex(), '#7f7f7f'
            'ends black': (topic) -> assert.equal topic(1).hex(), '#000000'

        'simple hsv scale (white-->black)':
            topic: -> chroma.scale(['white','black']).mode('hsv')
            'starts white': (topic) -> assert.equal topic(0).hex(), '#ffffff'
            'mid gray': (topic) -> assert.equal topic(0.5).hex(), '#808080'
            'ends black': (topic) -> assert.equal topic(1).hex(), '#000000'
            'colors': (topic) -> assert.deepEqual topic.colors(), ['#ffffff', '#000000']

        'simple hsv scale (white-->black), classified':
            topic: -> chroma.scale(['white','black']).domain([0, 1], 7).mode('hsv')
            'starts white': (topic) -> assert.equal topic(0).hex(), '#ffffff'
            'mid gray': (topic) -> assert.equal topic(0.5).hex(), '#808080'
            'ends black': (topic) -> assert.equal topic(1).hex(), '#000000'
            'colors': (topic) -> assert.deepEqual topic.colors(), ['#ffffff', '#d5d5d5', '#aaaaaa', '#808080', '#555555', '#2a2a2a', '#000000']

        'simple lab scale (white-->black)':
            topic: -> chroma.scale(['white','black']).mode('lab')
            'starts white': (topic) -> assert.equal topic(0).hex(), '#ffffff'
            'mid gray': (topic) -> assert.equal topic(0.5).hex(), '#777777'
            'ends black': (topic) -> assert.equal topic(1).hex(), '#000000'

        'colorbrewer scale':
            topic: -> chroma.scale 'RdYlGn'
            'starts white': (topic) -> assert.equal topic(0).hex(), '#a50026'
            'mid gray': (topic) -> assert.equal topic(0.5).hex(), '#ffffbf'
            'ends black': (topic) -> assert.equal topic(1).hex(), '#006837'

        'colorbrewer scale - domained':
            topic: -> chroma.scale('RdYlGn').domain([0, 100])
            'starts white': (topic) -> assert.equal topic(0).hex(), '#a50026'
            'foo': (topic) -> assert.notEqual topic(10).hex(), '#ffffbf'
            'mid gray': (topic) -> assert.equal topic(50).hex(), '#ffffbf'
            'ends black': (topic) -> assert.equal topic(100).hex(), '#006837'

        'colorbrewer scale - domained - classified':
            topic: -> chroma.scale('RdYlGn').domain([0, 100], 5)
            'starts white': (topic) -> assert.equal topic(0).hex(), '#a50026'
            '10': (topic) -> assert.equal topic(10).hex(), '#a50026'
            'mid gray': (topic) -> assert.equal topic(50).hex(), '#ffffbf'
            'ends black': (topic) -> assert.equal topic(100).hex(), '#006837'
            'get colors': (topic) -> assert.deepEqual topic.colors(), ['#a50026', '#f88d52', '#ffffbf', '#86cb66', '#006837']

        'calling domain with no arguments':
            topic: -> chroma.scale('RdYlGn').domain([0, 100], 5)
            'returns domain': (topic) -> assert.deepEqual topic.domain(), [0, 20, 40, 60, 80, 100]

        # 'check spread':
        #     topic: ->
        #         cs = new chroma._ColorScale()
        #         cs.domain [0, 0.5, 1]
        #         cs
        #     'spread zero': (cs) ->
        #         assert.equal cs.classifyValue(0.25), 0.25
        #         assert.equal cs.classifyValue(0.75), 0.75
        #     'spread one': (cs) ->
        #         cs._spread = 1
        #         assert.equal cs.classifyValue(0.25), 0
        #         assert.equal cs.classifyValue(0.75), 1
        #         #assert.deepEqual res, [0.33, 0.33, 0.33, 0.33, 0.80, 100]

        'source array keeps untouched':
            topic: chroma.brewer.Blues.slice(0)
            'colors are an array': (colors) ->
                assert.equal colors.length, 9
            'colors are strings': (colors) ->
                assert.equal typeof colors[0], 'string'
            'creating a color scale': (colors) ->
                chroma.scale(colors)
                assert true
            'colors are still strings': (colors) ->
                assert.equal typeof colors[0], 'string'


        'domain with same min and max':
            topic: -> chroma.scale(['white','black']).domain([1, 1], 5)
            'returns color': (topic) -> assert.deepEqual topic(1).hex(), '#000000'

        # 'fixed color scale':
        #     topic: ->
        #         cs = new chroma.ColorScale()
        #         cs.range ['white', 'black']
        #         cs.domain [0, 0.5, 0.75, 1]
        #         cs
        #     'returns domain': (topic) -> assert.deepEqual topic.domain(), [0, 20, 40, 60, 80, 100]

    .export(module)