2022-09-02 00:00:10 +00:00
|
|
|
Class {
|
|
|
|
#name : #EcCalendar,
|
|
|
|
#superclass : #Object,
|
|
|
|
#instVars : [
|
|
|
|
'events'
|
|
|
|
],
|
|
|
|
#category : #EchartsPharo
|
|
|
|
}
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> asEcScript [
|
|
|
|
|
2022-09-19 14:25:14 +00:00
|
|
|
^ 'var myCalendar = echarts.init(document.getElementById(','''', 'calendar', '''', '));', Character cr asString,
|
2022-09-02 00:00:10 +00:00
|
|
|
'var option = {
|
|
|
|
tooltip: {},
|
|
|
|
animation: true,
|
|
|
|
animationDuration: 500,
|
|
|
|
|
|
|
|
legend: {
|
|
|
|
data:', self eventsLabel, ',',
|
2022-09-19 14:25:14 +00:00
|
|
|
'left:', '''', '0', '''',
|
2022-09-02 00:00:10 +00:00
|
|
|
'},
|
|
|
|
|
|
|
|
calendar: {
|
2022-09-19 14:25:14 +00:00
|
|
|
top:', '''', 'middle', '''', ',',
|
|
|
|
'left:', '''','0', '''', ',',
|
|
|
|
'orient:', '''', 'horizontal', '''', ',',
|
2022-09-02 00:00:10 +00:00
|
|
|
'cellSize: 40,
|
|
|
|
yearLabel: {
|
|
|
|
margin: 50,
|
|
|
|
fontSize: 30,
|
2022-09-19 14:25:14 +00:00
|
|
|
color:', '''', '#999', '''',
|
2022-09-02 00:00:10 +00:00
|
|
|
'},
|
|
|
|
dayLabel: {
|
|
|
|
firstDay: 1,
|
2022-09-19 14:25:14 +00:00
|
|
|
nameMap:', '''', 'cn', '''',
|
2022-09-02 00:00:10 +00:00
|
|
|
'},
|
|
|
|
monthLabel: {
|
2022-09-19 14:25:14 +00:00
|
|
|
nameMap:', '''','cn', '''', ',',
|
2022-09-02 00:00:10 +00:00
|
|
|
'margin: 15,
|
|
|
|
fontSize: 20,
|
2022-09-19 14:25:14 +00:00
|
|
|
color:', '''', '#999', '''',
|
2022-09-02 00:00:10 +00:00
|
|
|
'},
|
|
|
|
range:', self datesRangeWithMarginString,
|
|
|
|
'},
|
|
|
|
|
|
|
|
series: [', Character cr asString,
|
|
|
|
self eventsAsStringSnippets,
|
|
|
|
']
|
|
|
|
};
|
|
|
|
myCalendar.setOption(option);'
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> asHTMLElement [
|
|
|
|
|
|
|
|
^ '<div id="calendar" style="width:90vw;height:400px;"></div>', Character cr asString,
|
|
|
|
'<script type="text/javascript">', Character cr asString,
|
|
|
|
self asEcScript, Character cr asString,
|
|
|
|
'</script>'
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> datesRange [
|
|
|
|
|
|
|
|
| tempEventsDates |
|
|
|
|
tempEventsDates := self events collect: [ :each | each dates ].
|
|
|
|
tempEventsDates := tempEventsDates flattened collect: [ :each | each asDate ].
|
|
|
|
^ {tempEventsDates asSortedCollection first .
|
|
|
|
tempEventsDates asSortedCollection last }.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> datesRangeString [
|
|
|
|
|
|
|
|
| datesRangeTemp |
|
|
|
|
datesRangeTemp := self datesRange collect: [ :date | ($' asString), date yyyymmdd, ($' asString) ].
|
|
|
|
^ '[', (',' join: datesRangeTemp), ']'
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> datesRangeWithMargin [
|
|
|
|
|
|
|
|
| tempEventsDates |
|
|
|
|
tempEventsDates := self events collect: [ :each | each dates ].
|
|
|
|
tempEventsDates := tempEventsDates flattened collect: [ :each | each asDate ].
|
|
|
|
^ {(tempEventsDates asSortedCollection first asDateAndTime - 10 days) asDate .
|
|
|
|
(tempEventsDates asSortedCollection last) addDays: 10 }.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> datesRangeWithMarginString [
|
|
|
|
|
|
|
|
| datesRangeTemp |
|
2022-09-19 14:25:14 +00:00
|
|
|
datesRangeTemp := self datesRangeWithMargin collect: [ :date | '''', date yyyymmdd, '''' ].
|
2022-09-02 00:00:10 +00:00
|
|
|
^ '[', (',' join: datesRangeTemp), ']'
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> events [
|
|
|
|
^ events ifNil: [ events := OrderedCollection new ].
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> eventsAsStringSnippets [
|
|
|
|
|
|
|
|
| tempEvents |
|
|
|
|
tempEvents := self events.
|
|
|
|
tempEvents ifNil: [ ^ self ].
|
|
|
|
^ Character cr join: (tempEvents collect: [ :each | each asStringSnippet ])
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
EcCalendar >> eventsLabel [
|
|
|
|
|
|
|
|
| tempEvents |
|
|
|
|
tempEvents := self events collect: [ :each | each name ].
|
2022-09-19 14:25:14 +00:00
|
|
|
tempEvents := tempEvents collect: [ :each | '''', each, '''' ].
|
2022-09-02 00:00:10 +00:00
|
|
|
^ '[', (',' join: tempEvents), ']'
|
|
|
|
]
|