Skip to content

s-n-1-0/MMHeatmap

Repository files navigation

MMHeatmap

HeatmapSample

Heatmap style calendar made in SwiftUI.

Installation

  1. Use "Swift Package Manager":
    File -> Swift Packages -> Add Package Dependency

  2. Paste URL:
    https://github.com/s-n-1-0/MMHeatmap.git

MMHeatmapView

Displays a calendar from "start" to "end".

//"import  MMHeatmap" is required

let calendar = Calendar(identifier: .gregorian)
let start = calendar.date(from: DateComponents(year:2021,month: 12,day: 20))!
let end = calendar.date(from: DateComponents(year:2022,month: 4,day: 3))! // or nil = now
let data = [
    MMHeatmapData(year: 2022, month: 3, day: 10, value: 5),
    MMHeatmapData(year: 2022, month: 4, day:1, value: 10)
]

//view
HStack{
    MMHeatmapView(start: start,end:end, data: data, style: MMHeatmapStyle(baseCellColor: UIColor.systemIndigo,isScroll: true))
    Spacer()
}

*The variable "style:" is optional.

MMHeatmapViewData

Calendar cell data.
Please not duplicate dates in MMHeatmapViewData.

(year,month,day) or date

public init(date _date:Date,value:Int)
public init(year:Int,month:Int,day:Int,value:Int)

value:

Specifies the color strength of the cell.
Specify a value greater than or equal to 0.
*If you want to set Color.clear, use "nil".

MMHeatmapStyle

Variable Description
baseCellColor Maximum color
minCellColor Color when value is 0
week Notation of the day of the week
dateMMFormat Months format
Example: 4
"M" = 4
"MM" = 04
"MMM" = en: Apr , ja: 4月
clippedWithEndDate true : If you want to display cells up to end parameter.
false : if you want to display cells until the end of the month in the last month.
isScroll scrolling.
*Disabled for iOS13

Use in Widget Extension

Read this. #2

PR / Issues

Please PR or Issues if you have any questions.