Skip to content

Commit

Permalink
do not refresh color scale on each lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Feb 17, 2020
1 parent 54f5cc1 commit e9dae3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const D3_SCALING_FUNCTIONS = {
};

export class TagCloud extends EventEmitter {
constructor(domNode, colors) {
constructor(domNode, colorScale) {
super();

//DOM
Expand All @@ -54,7 +54,6 @@ export class TagCloud extends EventEmitter {
this._spiral = 'archimedean'; //layout shape
this._timeInterval = 1000; //time allowed for layout algorithm
this._padding = 5;
this._seedColors = colors.seedColors;

//OPTIONS
this._orientation = 'single';
Expand All @@ -67,6 +66,7 @@ export class TagCloud extends EventEmitter {
this._words = null;

//UTIL
this._colorScale = colorScale;
this._setTimeoutId = null;
this._pendingJob = null;
this._layoutIsUpdating = null;
Expand Down Expand Up @@ -371,8 +371,7 @@ export class TagCloud extends EventEmitter {
}

getFill(tag) {
const colorScale = d3.scale.ordinal().range(this._seedColors);
return colorScale(tag.text);
return this._colorScale(tag.text);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import { getFormat } from '../legacy_imports';
import { Label } from './label';
import { TagCloud } from './tag_cloud';
import { FeedbackMessage } from './feedback_message';
import d3 from 'd3';

const MAX_TAG_COUNT = 200;

export function createTagCloudVisualization({ colors }) {
const colorScale = d3.scale.ordinal().range(colors.seedColors);
return class TagCloudVisualization {
constructor(node, vis) {
this._containerNode = node;
Expand All @@ -48,7 +50,7 @@ export function createTagCloudVisualization({ colors }) {

this._vis = vis;
this._truncated = false;
this._tagCloud = new TagCloud(cloudContainer, colors);
this._tagCloud = new TagCloud(cloudContainer, colorScale);
this._tagCloud.on('select', event => {
if (!this._visParams.bucket) {
return;
Expand Down

0 comments on commit e9dae3a

Please sign in to comment.