Skip to content

Commit

Permalink
Added visualizer class
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Sep 10, 2023
1 parent 78c1071 commit 11bde76
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/AI-KMeans-Visualization/AIKMeansVisualizer.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
Class {
#name : #AIKMeansVisualizer,
#superclass : #Object,
#instVars : [
'xLabel',
'yLabel'
],
#category : #'AI-KMeans-Visualization'
}

{ #category : #building }
AIKMeansVisualizer >> buildChartX: x y: y [

^ RSCompositeChart new
add: (RSScatterPlot new x: x y: y);
xlabel: xLabel;
ylabel: yLabel;
yourself
]

{ #category : #building }
AIKMeansVisualizer >> buildChartX: x y: y clusters: aClustersArray [

| chart plot colors |
chart := self buildChartX: x y: y.
chart build.

colors := self colorPalette.
plot := chart plots first.
plot ellipses doWithIndex: [ :e :i | e color: (colors at: (aClustersArray at: i)) ].
^ chart
]

{ #category : #building }
AIKMeansVisualizer >> buildDataFrameChart: aDataFrame xColumn: xColumnName yColumn: yColumnName [

| chart x y |
x := (aDataFrame column: xColumnName) asArray.
y := (aDataFrame column: yColumnName) asArray.
xLabel := xColumnName.
yLabel := yColumnName.
chart := self buildChartX: x y: y.
chart build.
^ chart
]

{ #category : #building }
AIKMeansVisualizer >> buildDataFrameChart: aDataFrame xColumn: xColumnName yColumn: yColumnName clusters: aClustersArray [

| chart x y |
x := (aDataFrame column: xColumnName) asArray.
y := (aDataFrame column: yColumnName) asArray.
xLabel := xColumnName.
yLabel := yColumnName.
chart := self buildChartX: x y: y clusters: aClustersArray.
^ chart
]

{ #category : #building }
AIKMeansVisualizer >> colorPalette [

^ NSScale google20 range
]

{ #category : #initialization }
AIKMeansVisualizer >> initialize [

xLabel := 'X'.
yLabel := 'Y'
]

{ #category : #ploting }
AIKMeansVisualizer >> plotData: aDataFrame xColumn: xColumnName yColumn: yColumnName [

| chart |
chart := self buildDataFrameChart: aDataFrame xColumn: xColumnName yColumn: yColumnName.
^ chart canvas open
]

{ #category : #ploting }
AIKMeansVisualizer >> plotData: aDataFrame xColumn: xColumnName yColumn: yColumnName clusters: aClustersArray [

| chart |
chart := self buildDataFrameChart: aDataFrame
xColumn: xColumnName
yColumn: yColumnName
clusters: aClustersArray.
^ chart canvas open
]

{ #category : #accessing }
AIKMeansVisualizer >> xLabel: anObject [

xLabel := anObject
]

{ #category : #accessing }
AIKMeansVisualizer >> yLabel: anObject [

yLabel := anObject
]
1 change: 1 addition & 0 deletions src/AI-KMeans-Visualization/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'AI-KMeans-Visualization' }

0 comments on commit 11bde76

Please sign in to comment.