Skip to content

Instantly share code, notes, and snippets.

@meoyawn
Created May 26, 2019 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meoyawn/c084b6e1bf2ff86bd7c9300783884e94 to your computer and use it in GitHub Desktop.
Save meoyawn/c084b6e1bf2ff86bd7c9300783884e94 to your computer and use it in GitHub Desktop.
enum ColumnType: String, Codable {
case line
case x
case area
case bar
}
typealias LineId = String
struct Columns {
let val: [LineId: [Int64]]
}
typealias ColorString = String
struct Chart: Decodable {
let columns: Columns
let types: [LineId: ColumnType]
let names: [LineId: String]
let colors: [LineId: ColorString]
let percentage: Bool?
let stacked: Bool?
let y_scaled: Bool?
}
extension Columns: Decodable {
init(from: Decoder) throws {
var outer = try from.unkeyedContainer()
var dict = [LineId: [Int64]]()
while !outer.isAtEnd {
var inner = try outer.nestedUnkeyedContainer()
var values = [Int64]()
let id = try inner.decode(LineId.self)
while !inner.isAtEnd {
values.append(try inner.decode(Int64.self))
}
dict[id] = values
}
self.val = dict
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let data = """
{"columns":[["x",1523059200000,1523145600000,1523232000000,1523318400000,1523404800000,1523491200000,1523577600000,1523664000000,1523750400000,1523836800000,1523923200000,1524009600000,1524096000000,1524182400000,1524268800000,1524355200000,1524441600000,1524528000000,1524614400000,1524700800000,1524787200000,1524873600000,1524960000000,1525046400000,1525132800000,1525219200000,1525305600000,1525392000000,1525478400000,1525564800000,1525651200000,1525737600000,1525824000000,1525910400000,1525996800000,1526083200000,1526169600000,1526256000000,1526342400000,1526428800000,1526515200000,1526601600000,1526688000000,1526774400000,1526860800000,1526947200000,1527033600000,1527120000000,1527206400000,1527292800000,1527379200000,1527465600000,1527552000000,1527638400000,1527724800000,1527811200000,1527897600000,1527984000000,1528070400000,1528156800000,1528243200000,1528329600000,1528416000000,1528502400000,1528588800000,1528675200000,1528761600000,1528848000000,1528934400000,1529020800000,1529107200000,1529193600000,1529280000000,1529366400000,1529452800000,1529539200000,1529625600000,1529712000000,1529798400000,1529884800000,1529971200000,1530057600000,1530144000000,1530230400000,1530316800000,1530403200000,1530489600000,1530576000000,1530662400000,1530748800000,1530835200000,1530921600000,1531008000000,1531094400000,1531180800000,1531267200000,1531353600000,1531440000000,1531526400000,1531612800000,1531699200000,1531785600000,1531872000000,1531958400000,1532044800000,1532131200000,1532217600000,1532304000000,1532390400000,1532476800000,1532563200000,1532649600000,1532736000000,1532822400000,1532908800000,1532995200000,1533081600000,1533168000000,1533254400000,1533340800000,1533427200000,1533513600000,1533600000000,1533686400000,1533772800000,1533859200000,1533945600000,1534032000000,1534118400000,1534204800000,1534291200000,1534377600000,1534464000000,1534550400000,1534636800000,1534723200000,1534809600000,1534896000000,1534982400000,1535068800000,1535155200000,1535241600000,1535328000000,1535414400000,1535500800000,1535587200000,1535673600000,1535760000000,1535846400000,1535932800000,1536019200000,1536105600000,1536192000000,1536278400000,1536364800000,1536451200000,1536537600000,1536624000000,1536710400000,1536796800000,1536883200000,1536969600000,1537056000000,1537142400000,1537228800000,1537315200000,1537401600000,1537488000000,1537574400000,1537660800000,1537747200000,1537833600000,1537920000000,1538006400000,1538092800000,1538179200000,1538265600000,1538352000000,1538438400000,1538524800000,1538611200000,1538697600000,1538784000000,1538870400000,1538956800000,1539043200000,1539129600000,1539216000000,1539302400000,1539388800000,1539475200000,1539561600000,1539648000000,1539734400000,1539820800000,1539907200000,1539993600000,1540080000000,1540166400000,1540252800000,1540339200000,1540425600000,1540512000000,1540598400000,1540684800000,1540771200000,1540857600000,1540944000000,1541030400000,1541116800000,1541203200000,1541289600000,1541376000000,1541462400000,1541548800000,1541635200000,1541721600000,1541808000000,1541894400000,1541980800000,1542067200000,1542153600000,1542240000000,1542326400000,1542412800000,1542499200000,1542585600000,1542672000000,1542758400000,1542844800000,1542931200000,1543017600000,1543104000000,1543190400000,1543276800000,1543363200000,1543449600000,1543536000000,1543622400000,1543708800000,1543795200000,1543881600000,1543968000000,1544054400000,1544140800000,1544227200000,1544313600000,1544400000000,1544486400000,1544572800000,1544659200000,1544745600000,1544832000000,1544918400000,1545004800000,1545091200000,1545177600000,1545264000000,1545350400000,1545436800000,1545523200000,1545609600000,1545696000000,1545782400000,1545868800000,1545955200000,1546041600000,1546128000000,1546214400000,1546300800000,1546387200000,1546473600000,1546560000000,1546646400000,1546732800000,1546819200000,1546905600000,1546992000000,1547078400000,1547164800000,1547251200000,1547337600000,1547424000000,1547510400000,1547596800000,1547683200000,1547769600000,1547856000000,1547942400000,1548028800000,1548115200000,1548201600000,1548288000000,1548374400000,1548460800000,1548547200000,1548633600000,1548720000000,1548806400000,1548892800000,1548979200000,1549065600000,1549152000000,1549238400000,1549324800000,1549411200000,1549497600000,1549584000000,1549670400000,1549756800000,1549843200000,1549929600000,1550016000000,1550102400000,1550188800000,1550275200000,1550361600000,1550448000000,1550534400000,1550620800000,1550707200000,1550793600000,1550880000000,1550966400000,1551052800000,1551139200000,1551225600000,1551312000000,1551398400000,1551484800000,1551571200000,1551657600000,1551744000000,1551830400000,1551916800000,1552003200000,1552089600000,1552176000000,1552262400000,1552348800000,1552435200000,1552521600000,1552608000000,1552694400000,1552780800000,1552867200000,1552953600000,1553040000000,1553126400000,1553212800000,1553299200000,1553385600000,1553472000000,1553558400000,1553644800000,1553731200000,1553817600000,1553904000000,1553990400000,1554076800000,1554163200000,1554249600000,1554336000000,1554422400000,1554508800000],["y0",930,890,900,980,1120,1250,1220,1030,960,1390,1300,1200,1030,880,1820,1680,1190,1320,1790,1610,1210,1170,1300,1080,1320,1200,970,760,1230,1250,1040,1020,1300,1290,970,900,1050,1040,980,1070,1410,1080,1000,1100,1070,1010,940,1160,1110,990,1070,830,940,1070,1160,1040,1020,1120,1210,3030,2530,1660,1170,1240,1180,1000,1170,720,1010,1300,1020,1180,1080,960,1050,880,950,970,1360,1020,1280,1140,1150,1100,1100,1260,1280,1540,1360,1250,1060,1330,930,1060,940,1190,1320,1180,1050,1210,1370,1330,950,1270,1130,1300,1170,1530,1110,1380,1240,1390,1150,1230,1340,1160,1140,1380,1690,1460,1240,1610,1320,1360,1320,1460,1450,1330,1080,1720,1600,1250,1570,1530,1610,1860,1450,1560,1690,1560,1730,1600,2170,1540,1940,1430,1410,1840,1790,1850,1620,1520,2190,1870,1550,2080,1560,1720,2040,1810,1890,2000,1900,2270,2060,1890,1930,1590,2030,1890,1810,1620,1690,1310,1700,1530,1970,2080,1620,1510,1990,1720,1750,1870,1740,1620,1840,1980,1910,1790,2080,1820,1530,2140,2440,2130,2430,2180,2080,2190,2090,1910,2440,1940,2680,3310,2510,2200,3020,2550,2450,2800,2450,2780,3020,2680,2210,2550,3160,2870,2690,3140,2820,2850,2160,2540,3050,2720,2540,3000,2630,2660,2780,2350,2510,2980,2650,2770,2220,3000,2950,2450,2610,2270,2200,2200,2920,2600,2470,2180,2480,2400,2450,2970,2830,2740,2680,2750,2200,2720,2270,3100,3510,3400,2920,2240,2330,2660,3400,3240,2940,3300,3760,3270,3460,3340,2820,2300,2830,2690,2760,2570,2420,2730,2480,3000,3260,2920,2750,2660,3130,3480,2530,3140,2200,2970,2900,2510,2500,2660,2970,2810,3200,2640,2790,3360,2690,2750,2810,3090,3080,2490,2810,2570,2630,2370,3320,2610,2300,2670,2470,2680,3270,3580,3000,2670,2540,2740,2940,2800,3590,3000,3130,3030,2460,2400,2610,3240,4010,2880,2930,2890,3240,2600,3530,2850,3580,3480,3210,3150,2730,3240,2720,3210,3090,3310,2670,2750,2540,2600,2930,3400,3050,3480,2930],["y1",1060,990,1140,1090,1210,1160,1450,970,1400,1140,1230,1440,1660,1130,1390,1410,1110,1060,1100,1340,1140,1340,980,1390,1190,1350,1390,1230,1280,1250,1360,1470,1540,1170,1500,1330,1330,1190,1280,1370,1460,1160,1490,1300,1240,1370,1330,1360,1780,1470,1300,1390,1420,1450,1520,1270,1180,1270,1440,1470,1500,1440,1710,1460,1390,1510,1510,1730,1630,1440,1690,1480,1340,1550,1410,1470,1380,1550,1280,1550,1500,1350,1280,1270,1430,1330,1190,1380,1790,1610,1240,1520,1120,1250,1040,1370,1140,1650,1840,1320,1860,1490,1680,1920,1190,1410,1180,1510,1490,1950,1700,1060,1630,1410,1230,1340,1640,1620,1610,1780,1320,1430,1510,1410,1660,1610,1320,1420,1360,1330,1300,1370,1590,1380,1580,1250,1460,1740,2250,1820,1670,1590,1710,1630,1770,1410,2100,1640,1670,1560,1820,1580,1560,1680,1520,1660,1570,1790,1560,1850,1670,2050,1660,1690,2110,1900,2280,1680,1770,2250,1910,2190,2070,2160,1810,1890,2130,2470,2150,2320,2420,2510,2390,2340,2260,2250,2250,2560,2090,1620,2340,2410,2270,2470,2360,2520,2380,2690,2590,2600,3010,2970,2480,2680,2910,2960,3150,3290,2380,2860,3130,2680,2980,3030,2900,3570,3340,2970,2910,3130,3180,3370,3590,3380,3720,3670,3480,3470,3770,3400,3060,3080,3090,3380,3040,3080,3410,3620,3320,2890,3570,3260,3100,3450,3490,3070,2640,3360,3260,3030,3250,3690,2950,2910,3540,3140,3090,3350,2960,2930,2940,3280,3080,2750,3370,3740,2550,2340,3290,2800,2910,3160,3200,3640,2910,2930,2830,3230,3190,2930,3090,2530,2760,2990,2700,3130,3140,3020,2790,2820,3400,3360,3100,3470,2560,3030,3340,3240,3540,3310,3300,3040,2870,2960,3140,2960,3130,2910,3140,2380,3080,3100,2910,2700,3020,2590,2790,2880,3390,3190,3130,3320,2480,2850,3070,3030,2750,3190,3130,2960,3060,2810,2810,2980,3130,3150,2990,2310,2690,3070,3670,3530,2890,2510,2890,3090,2930,2850,3260,3720,2460,2610,3280,2860,3240,3420,2920,2280,2840,3030,3370,2650,3200,3190,2590]],"types":{"y0":"line","y1":"line","x":"x"},"names":{"y0":"Joined","y1":"Left"},"colors":{"y0":"#4BD964","y1":"#FE3C30"}}
"""
do {
print(try JSONDecoder().decode(Chart.self,from: data.data(using: .utf8)!))
} catch {
print(error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment